use super::Interface; use embedded_hal_async::i2c::I2c; const I2C_ADDRESS: u8 = 0x6A; #[derive(Debug)] pub enum InterfaceE { Comm(CommE), } /// I2C communication interface pub struct I2cInterface { i2c: I2C, } impl I2cInterface { pub fn new(i2c: I2C) -> Self { Self { i2c } } } impl Interface for I2cInterface where I2C: I2c, { type Error = InterfaceE; async fn write(&mut self, addr: u8, value: u8) -> Result<(), Self::Error> { self.i2c .write(I2C_ADDRESS, &[addr, value]) .await .map_err(InterfaceE::Comm) } async fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Self::Error> { self.i2c .write_read(I2C_ADDRESS, &[addr], buffer) .await .map_err(InterfaceE::Comm) } }