From 73a171477277d1dc197c6de09e49b75a8948c148 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 7 Jun 2025 22:46:14 +0800 Subject: [PATCH] Modify I2C API to accommodate Nack responses specifically --- libs/cramium-api/src/i2c.rs | 8 +++++--- libs/cramium-api/src/udma.rs | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/cramium-api/src/i2c.rs b/libs/cramium-api/src/i2c.rs index dc6498e4c..ed8e9f6f7 100644 --- a/libs/cramium-api/src/i2c.rs +++ b/libs/cramium-api/src/i2c.rs @@ -1,5 +1,5 @@ pub trait I2cApi { - fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result; + fn i2c_write(&mut self, dev: u8, adr: u8, data: &[u8]) -> Result; /// initiate an i2c read. The read buffer is passed during the await. fn i2c_read( @@ -8,7 +8,7 @@ pub trait I2cApi { adr: u8, buf: &mut [u8], repeated_start: bool, - ) -> Result; + ) -> Result; } #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] @@ -20,7 +20,7 @@ pub enum I2cTransactionType { } #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] -#[derive(Debug)] +#[derive(Debug, PartialEq, Eq, Copy, Clone)] pub enum I2cResult { /// For the outbound message holder Pending, @@ -28,6 +28,8 @@ pub enum I2cResult { Ack(usize), /// An error occurred. Nack, + /// An unhandled error has occurred. + InternalError, } #[cfg_attr(feature = "derive-rkyv", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize))] #[cfg(feature = "std")] diff --git a/libs/cramium-api/src/udma.rs b/libs/cramium-api/src/udma.rs index b11550aad..1e08f8180 100644 --- a/libs/cramium-api/src/udma.rs +++ b/libs/cramium-api/src/udma.rs @@ -236,6 +236,7 @@ pub enum EventChannel { #[derive(Debug, Copy, Clone, num_derive::FromPrimitive)] pub enum IrqBank { I2c, + I2cErr, } /// Use a trait that will allow us to share code between both `std` and `no-std` implementations