diff --git a/services/llio/src/api.rs b/services/llio/src/api.rs index 7eb0c40a5..27a05c86d 100644 --- a/services/llio/src/api.rs +++ b/services/llio/src/api.rs @@ -64,10 +64,13 @@ pub enum I2cStatus { ResponseWriteOk, } #[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] -pub enum I2cCallback { +pub(crate) enum I2cCallback { Result, Drop, } +// maybe once things stabilize, it's probably a good idea to make this structure private to the crate, +// and create a "public" version for return values via callbacks. But for now, it's pretty +// convenient to reach into the state of the I2C machine to debug problems in the callbacks. #[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] pub struct I2cTransaction { pub bus_addr: u8, @@ -87,7 +90,7 @@ impl I2cTransaction { } } #[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] -pub enum I2cOpcode { +pub(crate) enum I2cOpcode { /// initiate an I2C transaction I2cTxRx, /// from i2c interrupt handler (internal API only) diff --git a/services/llio/src/i2c/hardware.rs b/services/llio/src/i2c/hardware.rs index fc4c1b1fc..2e18ee915 100644 --- a/services/llio/src/i2c/hardware.rs +++ b/services/llio/src/i2c/hardware.rs @@ -1,4 +1,4 @@ -use llio::api::*; +use crate::api::*; use utralib::*; diff --git a/services/llio/src/lib.rs b/services/llio/src/lib.rs index c9ec0864f..20b210f86 100644 --- a/services/llio/src/lib.rs +++ b/services/llio/src/lib.rs @@ -64,55 +64,6 @@ impl Llio { ///////////////////////// I2C /////////////// // used to hook a callback for I2c responses - pub fn hook_i2c_callback(&mut self, cb: fn(I2cTransaction)) -> Result<(), xous::Error> { - if unsafe{I2C_CB}.is_some() { - return Err(xous::Error::MemoryInUse) // can't hook it twice - } - unsafe{I2C_CB = Some(cb)}; - if self.i2c_sid.is_none() { - let sid = xous::create_server().unwrap(); - self.i2c_sid = Some(sid); - let sid_tuple = sid.to_u32(); - xous::create_thread_4(i2c_cb_server, sid_tuple.0 as usize, sid_tuple.1 as usize, sid_tuple.2 as usize, sid_tuple.3 as usize).unwrap(); - // note: we don't register a callback, because we hand our SID directly to the i2c request for a 1:1 message return - } - Ok(()) - } - // used by other servers to request an I2C transaction - pub fn send_i2c_request(&self, transaction: I2cTransaction) -> Result { - // copy the transaction, and annotate with our private callback listener server address - // the server is used only for this connection, and shared only to the LLIO server - // it's sanitized on the callback response. It's not the end of the world if this server address is - // discovered, just unhygenic. - let mut local_transaction = transaction; - match self.i2c_sid { - None => { - local_transaction.listener = None; - log::warn!("Initiating I2C request with no listener. Are you sure?"); - }, - Some(sid) => local_transaction.listener = Some(sid.to_u32()), - } - let mut buf = Buffer::into_buf(local_transaction).or(Err(xous::Error::InternalError))?; - buf.lend_mut(self.i2c_conn, I2cOpcode::I2cTxRx.to_u32().unwrap()).or(Err(xous::Error::InternalError))?; - - let status = buf.to_original::().unwrap(); - Ok(status) - } - pub fn poll_i2c_busy(&self) -> Result { - let response = send_message(self.i2c_conn, - Message::new_blocking_scalar(I2cOpcode::I2cIsBusy.to_usize().unwrap(), 0, 0, 0, 0))?; - if let xous::Result::Scalar1(val) = response { - if val != 0 { - Ok(true) - } else { - Ok(false) - } - } else { - log::error!("LLIO: unexpected return value: {:#?}", response); - Err(xous::Error::InternalError) - } - } - fn check_cb_init(&mut self) { if self.i2c_sid.is_none() { let sid = xous::create_server().unwrap(); @@ -300,7 +251,7 @@ impl Llio { } Ok(I2cStatus::ResponseReadOk) } - ///////////////////////// I2C /////////////// + ///////////////////////// I2C done /////////////// diff --git a/services/llio/src/main.rs b/services/llio/src/main.rs index 1d03ac779..c67771ba7 100644 --- a/services/llio/src/main.rs +++ b/services/llio/src/main.rs @@ -500,7 +500,7 @@ fn i2c_thread(sid0: usize, sid1: usize, sid2: usize, sid3: usize) { }), Some(I2cOpcode::I2cTxRx) => { let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) }; - let i2c_txrx = buffer.to_original::().unwrap(); + let i2c_txrx = buffer.to_original::().unwrap(); let status = i2c.initiate(i2c_txrx); buffer.replace(status).unwrap(); },