From d17f9881b2269ff5270a055245613abd39847c38 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 7 Jun 2025 22:56:51 +0800 Subject: [PATCH] modify user mode i2c lib calls to return nacks Note that a NACK is returned as an Ok(I2cResult::Nack) - this is because the Err() path is still reserved for "OS failure" errors. A Nack isn't a terminal failure, it is a recoverable fault, and so it's handled in the Ok() path. --- services/cram-hal-service/src/i2c_lib.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/services/cram-hal-service/src/i2c_lib.rs b/services/cram-hal-service/src/i2c_lib.rs index af511538e..609b6f981 100644 --- a/services/cram-hal-service/src/i2c_lib.rs +++ b/services/cram-hal-service/src/i2c_lib.rs @@ -33,7 +33,7 @@ impl I2cApi for I2c { adr: u8, buf: &mut [u8], repeated_start: bool, - ) -> Result { + ) -> Result { let r = I2cTransaction { i2c_type: if repeated_start { I2cTransactionType::ReadRepeatedStart @@ -46,16 +46,14 @@ impl I2cApi for I2c { result: I2cResult::Pending, }; let result = self.i2c_transactions(I2cTransactions::from(vec![r]))?; - match result.transactions[0].result { - I2cResult::Ack(b) => { - buf.copy_from_slice(&result.transactions[0].data); - Ok(b) - } - _ => Err(xous::Error::InternalError), + if result.transactions[0].result == I2cResult::InternalError { + Err(xous::Error::InternalError) + } else { + Ok(result.transactions[0].result) } } - fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result { + fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result { let w = I2cTransaction { i2c_type: I2cTransactionType::Write, device: dev, @@ -64,9 +62,10 @@ impl I2cApi for I2c { result: I2cResult::Pending, }; let result = self.i2c_transactions(I2cTransactions::from(vec![w]))?; - match result.transactions[0].result { - I2cResult::Ack(b) => Ok(b), - _ => Err(xous::Error::InternalError), + if result.transactions[0].result == I2cResult::InternalError { + Err(xous::Error::InternalError) + } else { + Ok(result.transactions[0].result) } } }