Skip to content

Conversation

@TrAyZeN
Copy link

@TrAyZeN TrAyZeN commented Dec 1, 2025

Currently calling listen on blocking I2C drivers (created with I2c::new_blocking) blocks the program as the interrupt handlers are not binded. This PR restricts the listen implementation to async I2C drivers and adds blocking_listen implementation for blocking I2C drivers.

Here is a snippet of the previously mentioned issue:

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
    let mut i2c = I2c::new_blocking(p.I2C1, p.PB6, p.PB9, i2c::Config::default())
        .into_slave_multimaster(SlaveAddrConfig::basic(MCU2_I2C_ADDR));

    // The following call blocks the program
    let res = i2c.listen().await;

    debug!("Listen completed");
    loop {}
}

@xoviat
Copy link
Contributor

xoviat commented Dec 1, 2025

Is the concern about code size or that you can't use blocking without an executor?

@TrAyZeN
Copy link
Author

TrAyZeN commented Dec 1, 2025

Sorry I am not sure to get your question. My issue is that listen is implemented for both blocking and async I2C drivers, but the implementation depends on the interrupt handlers being binded. It works fine for async I2C drivers that requires these interrupt handlers to be binded. However, this is not ensured when creating a new blocking I2C driver. From what I understand, blocking drivers are not using interrupts, so I am proposing to restrict the listen implementation only to async I2C drivers and to add a blocking_listen methods for blocking drivers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants