io_expander: check I2C (n)ack on write
This commit is contained in:
parent
3fdb7e80a8
commit
f5d8ee3fef
|
@ -111,9 +111,15 @@ impl IoExpander {
|
||||||
|
|
||||||
fn write(&self, i2c: &mut i2c::I2c, addr: u8, value: u8) -> Result<(), &'static str> {
|
fn write(&self, i2c: &mut i2c::I2c, addr: u8, value: u8) -> Result<(), &'static str> {
|
||||||
i2c.start()?;
|
i2c.start()?;
|
||||||
i2c.write(self.address)?;
|
if !i2c.write(self.address)? {
|
||||||
i2c.write(addr)?;
|
return Err("io expander failed to ack control byte (read)");
|
||||||
i2c.write(value)?;
|
}
|
||||||
|
if !i2c.write(addr)? {
|
||||||
|
return Err("io expander failed to ack register address");
|
||||||
|
}
|
||||||
|
if !i2c.write(value)? {
|
||||||
|
return Err("io expander failed to ack value");
|
||||||
|
}
|
||||||
i2c.stop()?;
|
i2c.stop()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue