Support 0 byte I2C write
@@ -246,13 +246,24 @@ macro_rules! hal {
type Error = Error;
fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Error> {
- assert!(bytes.len() > 0);
-
// Detect Bus busy
if self.i2c.isr.read().busy().is_busy() {
return Err(Error::Busy);
}
+ if bytes.len() == 0 {
+ // 0 byte write
+ self.i2c.cr2.modify(|_, w| {
+ w
+ .add10().bit7()
+ .sadd().bits((addr << 1) as u16)
+ .rd_wrn().write()
+ .nbytes().bits(0)
+ .reload().completed()
+ .autoend().automatic()
+ .start().start()
+ });
+ } else {
let end = bytes.len() / 0xFF;
// Process 255 bytes at a time
@@ -289,6 +300,7 @@ macro_rules! hal {
busy_wait!(self.i2c, tcr, is_complete);
}
}
+ }
// automatic STOP
// Wait until the last transmission is finished
