From 2d5c1dd6db7e556b474c354e2450bfd8384528f0 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 18 Mar 2021 04:00:38 +0800 Subject: [PATCH] leverage min_const_generics and cleanup the spoils of a hard fought battle to refactor to rkyv 0.4.1 --- services/llio/src/api.rs | 24 ++---------------------- services/llio/src/i2c.rs | 4 ++-- xous-rs/src/string.rs | 1 + 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/services/llio/src/api.rs b/services/llio/src/api.rs index 7658cdf63..9b10852b1 100644 --- a/services/llio/src/api.rs +++ b/services/llio/src/api.rs @@ -69,9 +69,9 @@ pub enum I2cStatus { pub struct I2cTransaction { pub bus_addr: u8, // write address and read address are encoded in the packet field below - pub txbuf: Option<[u8; 31]>, // limited by trait types available in Rkyv + pub txbuf: Option<[u8; 258]>, // long enough for a 256-byte operation + 2 bytes of "register address" pub txlen: u32, - pub rxbuf: Option<[u8; 31]>, + pub rxbuf: Option<[u8; 258]>, pub rxlen: u32, pub timeout_ms: u32, // response field to the calling server @@ -83,26 +83,6 @@ impl I2cTransaction { } pub fn status(&self) -> I2cStatus { self.status } } -use core::ops::{DerefMut, Deref}; -impl Deref for I2cTransaction { - type Target = [u8]; - fn deref(&self) -> &[u8] { - unsafe { - core::slice::from_raw_parts(self as *const I2cTransaction as *const u8, core::mem::size_of::()) - as &[u8] - } - } -} -impl DerefMut for I2cTransaction { - fn deref_mut(&mut self) -> &mut [u8] { - unsafe { - core::slice::from_raw_parts_mut(self as *mut I2cTransaction as *mut u8, core::mem::size_of::()) - as &mut [u8] - } - } -} - - ////////////////////////////////// VIBE #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] diff --git a/services/llio/src/i2c.rs b/services/llio/src/i2c.rs index cc7f5b332..a777e2ecd 100644 --- a/services/llio/src/i2c.rs +++ b/services/llio/src/i2c.rs @@ -55,8 +55,8 @@ impl I2cStateMachine { } } pub fn initiate(&mut self, transaction: I2cTransaction ) -> I2cStatus { - // sanity-check the bounds limits, currently imposed by trait implementations available in rkyv - if transaction.txlen > 31 || transaction.rxlen > 31 { + // sanity-check the bounds limits + if transaction.txlen > 258 || transaction.rxlen > 258 { return I2cStatus::ResponseFormatError } diff --git a/xous-rs/src/string.rs b/xous-rs/src/string.rs index 230033568..f2c0f5c51 100644 --- a/xous-rs/src/string.rs +++ b/xous-rs/src/string.rs @@ -274,6 +274,7 @@ impl rkyv::Serialize for S }) } } +// Turn an `ArchivedString` back into a String use rkyv::Fallible; impl rkyv::Deserialize, D> for ArchivedString { fn deserialize(&self, _deserializer: &mut D) -> core::result::Result, D::Error> {