RTIC error when using resources

I'm using the RTIC framework. Part of code:

let mut i2c: stm32f1xx_hal::i2c::blocking::BlockingI2c::<I2C1, (PB6<Alternate<OpenDrain>>, PB7<Alternate<OpenDrain>>)> = ...;
let mut bq76940: bq769x0::BQ769x0::<15> = bq769x0::BQ769x0::<15>::new(0x08, 15, true).unwrap();
bq76940.current(&mut i2c);

The RTIC requires the structure with field use in future:

 #[local]
    struct Local
    {
        i2c: stm32f1xx_hal::i2c::blocking::BlockingI2c::<I2C1, (PB6<Alternate<OpenDrain>>, PB7<Alternate<OpenDrain>>)>,
        bq76940: bq769x0::BQ769x0::<15>,
    }

So I have returned it:

return Local { i2c, bq76940 }

And try to use it inside interrupt:

#[task(local = [i2c, bq76940])]
fn pollbq(mut ctx: pollbq::Context) {
    ctx.local.bq76940.current(&mut ctx.local.i2c);
}

But got next error:

197 |         ctx.local.bq76940.current(&mut ctx.local.i2c);
    |                           ------- -^^^^^^^^^^^^^^^^^
    |                           |       |
    |                           |       the trait `cortex_m::prelude::_embedded_hal_blocking_i2c_Write` is not implemented for `&mut BlockingI2c<stm32f1xx_hal::pac::I2C1, (stm32f1xx_hal::gpio::Pin<stm32f1xx_hal::gpio::Alternate<stm32f1xx_hal::gpio::OpenDrain>, CRL, 'B', 6>, stm32f1xx_hal::gpio::Pin<stm32f1xx_hal::gpio::Alternate<stm32f1xx_hal::gpio::OpenDrain>, CRL, 'B', 7>)>`
    |                           |       help: consider removing the leading `&`-reference
    |                           required by a bound introduced by this call

Why rust require the cortex_m::prelude::_embedded_hal_blocking_i2c_Write instead of the embedded_hal::blocking::i2c::Write

bq76940 is bq769x0/lib.rs at master · romixlab/bq769x0 · GitHub

I have wrapped the i2c and the bq76940 into structure and it compiles without error. Why?

pub struct BqSens {
        pub i2c: stm32f1xx_hal::i2c::blocking::BlockingI2c::<I2C1, (PB6<Alternate<OpenDrain>>, PB7<Alternate<OpenDrain>>)>,
        pub bq76940: bq769x0::BQ769x0::<15>,
}

...

    #[task(local = [/*i2c, bq76940*/ bq])]
    fn pollbq(mut ctx: pollbq::Context) {
         ctx.local.bq.bq76940.current(&mut ctx.local.bq.i2c);
    }

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.