pub struct Crc8Codec<const HEADER_SIZE: usize, const CHUNK_SIZE: usize, C: Crc8Algorithm> { /* private fields */ }Expand description
This codec implements an I2C codec utilizing crc checksums for data The main variables are:
- the size of register addresses in bytes.
- the crc algorithm in use
- set chunk size that get checksummed
This implements the codec only for crc outputs of single byte size. If your device has larger crc sums, you cannot use this implementation as is.
This codec has no information over register sizes or contents. It will always send one header and then receive/send the associated register data, interspersed with crc sums each CHUNK_SIZE bytes. This makes the codec unsuited for cases where the device has registers that require interspersing the crc between fields of differing sizes.
The following generic parameters are available:
| Parameter | Type | Description |
|---|---|---|
HEADER_SIZE | usize | The size of the command header (register address) in bytes |
CHUNK_SIZE | usize | The size of a chunk that has a singular crc sum attached in bytes |
C | Crc8Algorithm | A static reference to the crc algorithm to be used |
| Example implemenation for a basic CRC Algorithm: |
#[derive(Default)]
struct MyCrc {}
impl Crc8Algorithm for MyCrc {
fn instance() -> &'static Algorithm<u8> {
const CUSTOM_ALG: crc::Algorithm<u8> = CRC_8_NRSC_5;
&CUSTOM_ALG
}
}Trait Implementations§
Source§impl<const HEADER_SIZE: usize, const CHUNK_SIZE: usize, C: Crc8Algorithm + 'static> CodecAsync for Crc8Codec<HEADER_SIZE, CHUNK_SIZE, C>
impl<const HEADER_SIZE: usize, const CHUNK_SIZE: usize, C: Crc8Algorithm + 'static> CodecAsync for Crc8Codec<HEADER_SIZE, CHUNK_SIZE, C>
Source§async fn read_register<R, I, A>(
bound_bus: &mut I2cBoundBusAsync<I, A>,
) -> Result<R, I::Error>
async fn read_register<R, I, A>( bound_bus: &mut I2cBoundBusAsync<I, A>, ) -> Result<R, I::Error>
Read this register from the given I2C interface/device.
Source§async fn write_register<R, I, A>(
bound_bus: &mut I2cBoundBusAsync<I, A>,
register: impl AsRef<R>,
) -> Result<(), I::Error>
async fn write_register<R, I, A>( bound_bus: &mut I2cBoundBusAsync<I, A>, register: impl AsRef<R>, ) -> Result<(), I::Error>
Write this register to the given I2C interface/device.
Source§impl<const HEADER_SIZE: usize, const CHUNK_SIZE: usize, C: Crc8Algorithm + 'static> CodecSync for Crc8Codec<HEADER_SIZE, CHUNK_SIZE, C>
impl<const HEADER_SIZE: usize, const CHUNK_SIZE: usize, C: Crc8Algorithm + 'static> CodecSync for Crc8Codec<HEADER_SIZE, CHUNK_SIZE, C>
Source§fn read_register<R, I, A>(
bound_bus: &mut I2cBoundBusSync<I, A>,
) -> Result<R, I::Error>
fn read_register<R, I, A>( bound_bus: &mut I2cBoundBusSync<I, A>, ) -> Result<R, I::Error>
Read this register from the given I2C interface/device.
Source§fn write_register<R, I, A>(
bound_bus: &mut I2cBoundBusSync<I, A>,
register: impl AsRef<R>,
) -> Result<(), I::Error>
fn write_register<R, I, A>( bound_bus: &mut I2cBoundBusSync<I, A>, register: impl AsRef<R>, ) -> Result<(), I::Error>
Write this register to the given I2C interface/device.
Auto Trait Implementations§
impl<const HEADER_SIZE: usize, const CHUNK_SIZE: usize, C> Freeze for Crc8Codec<HEADER_SIZE, CHUNK_SIZE, C>
impl<const HEADER_SIZE: usize, const CHUNK_SIZE: usize, C> RefUnwindSafe for Crc8Codec<HEADER_SIZE, CHUNK_SIZE, C>where
C: RefUnwindSafe,
impl<const HEADER_SIZE: usize, const CHUNK_SIZE: usize, C> Send for Crc8Codec<HEADER_SIZE, CHUNK_SIZE, C>where
C: Send,
impl<const HEADER_SIZE: usize, const CHUNK_SIZE: usize, C> Sync for Crc8Codec<HEADER_SIZE, CHUNK_SIZE, C>where
C: Sync,
impl<const HEADER_SIZE: usize, const CHUNK_SIZE: usize, C> Unpin for Crc8Codec<HEADER_SIZE, CHUNK_SIZE, C>where
C: Unpin,
impl<const HEADER_SIZE: usize, const CHUNK_SIZE: usize, C> UnwindSafe for Crc8Codec<HEADER_SIZE, CHUNK_SIZE, C>where
C: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more