From f5d8ee3fef87ecdb5811591ec3af841d5ee33ee3 Mon Sep 17 00:00:00 2001 From: occheung Date: Fri, 6 Sep 2024 16:25:55 +0800 Subject: [PATCH] io_expander: check I2C (n)ack on write --- src/libboard_artiq/src/io_expander.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/libboard_artiq/src/io_expander.rs b/src/libboard_artiq/src/io_expander.rs index 55a1694..7b8aa51 100644 --- a/src/libboard_artiq/src/io_expander.rs +++ b/src/libboard_artiq/src/io_expander.rs @@ -111,9 +111,15 @@ impl IoExpander { fn write(&self, i2c: &mut i2c::I2c, addr: u8, value: u8) -> Result<(), &'static str> { i2c.start()?; - i2c.write(self.address)?; - i2c.write(addr)?; - i2c.write(value)?; + if !i2c.write(self.address)? { + return Err("io expander failed to ack control byte (read)"); + } + 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()?; Ok(()) }