pub struct I2CPeripheral<'a, I2C, E, const ADDRESS: u8> { /* private fields */ }Expand description
The I2C Implementation of the Interface trait
This seems to work and has been tested a bit.
Note the lifetimes. This struct takes ownership of the mutable borrow until it is dropped out of scope
Implementations§
Source§impl<'a, I2C, E, const ADDRESS: u8> I2CPeripheral<'a, I2C, E, ADDRESS>
impl<'a, I2C, E, const ADDRESS: u8> I2CPeripheral<'a, I2C, E, ADDRESS>
Sourcepub fn new(bus: &'a mut I2C) -> I2CPeripheral<'a, I2C, E, ADDRESS>
pub fn new(bus: &'a mut I2C) -> I2CPeripheral<'a, I2C, E, ADDRESS>
This makes a peripheral struct that implements the Interface trait
The peripheral takes ownership of the mut borrow for the life Of the struct so the struct is only ever expected to live breifely but it might be nice to make a parent thing that know the chip id etc that can have long life and then spawns on of these periodically
Trait Implementations§
Source§impl<'a, I2C, E, const ADDRESS: u8> Interface for I2CPeripheral<'a, I2C, E, ADDRESS>
impl<'a, I2C, E, const ADDRESS: u8> Interface for I2CPeripheral<'a, I2C, E, ADDRESS>
Source§fn read_register(
&mut self,
register: u8,
buffer: &mut [u8],
) -> Result<(), Self::Error>
fn read_register( &mut self, register: u8, buffer: &mut [u8], ) -> Result<(), Self::Error>
Read buffer.len() bytes starting at the reg at register This is the i2c implementation for the interface trait
Source§fn write_register(
&mut self,
register: u8,
bytes: &[u8],
) -> Result<(), Self::Error>
fn write_register( &mut self, register: u8, bytes: &[u8], ) -> Result<(), Self::Error>
Write buffer.len() bytes starting at the reg at register This is the i2c implementation for the interface trait NOTE: The current implementation only works for 10 bytes And will panic if more are given.