-
Hi, I would like to read a sensor and afterwards display it's readings on a display. All the devices are connected on one I2C bus, thus; let i2c = I2C::new(
peripherals.I2C0,
io.pins.gpio21,
io.pins.gpio22,
20u32.kHz(),
&mut system.peripheral_clock_control,
&clocks,
); This can be passed in for example a SSD1306 display interface, but when you want to read a sensor you'll need I tried to work around this with pub struct I2cShare<'a, T> {
i2c_bit: &'a mut I2C<'a, T>,
}
impl<'a, T> I2cShare<'a, T> {
pub fn new(i2c_bit: &'a mut I2C<'a, T>) -> Self {
Self { i2c_bit }
}
}
impl<'a, T> Write for I2cShare<'a, T> where T : Instance {
type Error = Error;
fn write(&mut self, address: SevenBitAddress, bytes: &[u8]) -> Result<(), Self::Error> {
self.i2c_bit.write(address, bytes)
}
}
impl<'a, T> Read for I2cShare<'a, T> where T : Instance {
type Error = Error;
fn read(&mut self, address: SevenBitAddress, buffer: &mut [u8]) -> Result<(), Self::Error> {
self.i2c_bit.read(address, buffer)
}
} But I was wondering if there is already built-in support for this matter? Later on I stumbled upon also lifetime annotation issues and it boils down that I run in to multiple borrows which are forbidden |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This is supported via https://crates.io/crates/shared-bus (for embedded-hal 0.2) and https://crates.io/crates/embedded-hal-bus (for embedded-hal 1.x) |
Beta Was this translation helpful? Give feedback.
This is supported via https://crates.io/crates/shared-bus (for embedded-hal 0.2) and https://crates.io/crates/embedded-hal-bus (for embedded-hal 1.x)