mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
leverage min_const_generics and cleanup
the spoils of a hard fought battle to refactor to rkyv 0.4.1
This commit is contained in:
parent
ea8b208a15
commit
2d5c1dd6db
3 changed files with 5 additions and 24 deletions
|
|
@ -69,9 +69,9 @@ pub enum I2cStatus {
|
||||||
pub struct I2cTransaction {
|
pub struct I2cTransaction {
|
||||||
pub bus_addr: u8,
|
pub bus_addr: u8,
|
||||||
// write address and read address are encoded in the packet field below
|
// 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 txlen: u32,
|
||||||
pub rxbuf: Option<[u8; 31]>,
|
pub rxbuf: Option<[u8; 258]>,
|
||||||
pub rxlen: u32,
|
pub rxlen: u32,
|
||||||
pub timeout_ms: u32,
|
pub timeout_ms: u32,
|
||||||
// response field to the calling server
|
// response field to the calling server
|
||||||
|
|
@ -83,26 +83,6 @@ impl I2cTransaction {
|
||||||
}
|
}
|
||||||
pub fn status(&self) -> I2cStatus { self.status }
|
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::<I2cTransaction>())
|
|
||||||
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::<I2cTransaction>())
|
|
||||||
as &mut [u8]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////// VIBE
|
////////////////////////////////// VIBE
|
||||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,8 @@ impl I2cStateMachine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn initiate(&mut self, transaction: I2cTransaction ) -> I2cStatus {
|
pub fn initiate(&mut self, transaction: I2cTransaction ) -> I2cStatus {
|
||||||
// sanity-check the bounds limits, currently imposed by trait implementations available in rkyv
|
// sanity-check the bounds limits
|
||||||
if transaction.txlen > 31 || transaction.rxlen > 31 {
|
if transaction.txlen > 258 || transaction.rxlen > 258 {
|
||||||
return I2cStatus::ResponseFormatError
|
return I2cStatus::ResponseFormatError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -274,6 +274,7 @@ impl<S: rkyv::ser::Serializer + ?Sized, const N: usize> rkyv::Serialize<S> for S
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Turn an `ArchivedString` back into a String
|
||||||
use rkyv::Fallible;
|
use rkyv::Fallible;
|
||||||
impl<D: Fallible + ?Sized, const N: usize> rkyv::Deserialize<String<N>, D> for ArchivedString {
|
impl<D: Fallible + ?Sized, const N: usize> rkyv::Deserialize<String<N>, D> for ArchivedString {
|
||||||
fn deserialize(&self, _deserializer: &mut D) -> core::result::Result<String<N>, D::Error> {
|
fn deserialize(&self, _deserializer: &mut D) -> core::result::Result<String<N>, D::Error> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue