1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use super::{config::AnyConfig, flags::Error, I2c};
use embedded_hal::blocking::i2c::{Read, Write, WriteRead};
impl<C: AnyConfig> Write for I2c<C> {
type Error = Error;
fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> {
self.do_write(addr, bytes)?;
self.cmd_stop();
Ok(())
}
}
impl<C: AnyConfig> Read for I2c<C> {
type Error = Error;
fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
self.do_read(addr, buffer)?;
self.cmd_stop();
Ok(())
}
}
impl<C: AnyConfig> WriteRead for I2c<C> {
type Error = Error;
fn write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Self::Error> {
self.do_write_read(addr, bytes, buffer)?;
self.cmd_stop();
Ok(())
}
}