Crc8Codec

Struct Crc8Codec 

Source
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:

ParameterTypeDescription
HEADER_SIZEusizeThe size of the command header (register address) in bytes
CHUNK_SIZEusizeThe size of a chunk that has a singular crc sum attached in bytes
CCrc8AlgorithmA 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>

Source§

async fn read_register<R, I, A>( bound_bus: &mut I2cBoundBusAsync<I, A>, ) -> Result<R, I::Error>
where R: ReadableRegister, I: I2c<A> + ErrorType, A: AddressMode + Copy,

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>
where R: WritableRegister, I: I2c<A> + ErrorType, A: AddressMode + Copy,

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>

Source§

fn read_register<R, I, A>( bound_bus: &mut I2cBoundBusSync<I, A>, ) -> Result<R, I::Error>
where R: ReadableRegister, I: I2c<A> + ErrorType, A: AddressMode + Copy,

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>
where R: WritableRegister, I: I2c<A> + ErrorType, A: AddressMode + Copy,

Write this register to the given I2C interface/device.
Source§

impl<const HEADER_SIZE: usize, const CHUNK_SIZE: usize, C: Default + Crc8Algorithm> Default for Crc8Codec<HEADER_SIZE, CHUNK_SIZE, C>

Source§

fn default() -> Crc8Codec<HEADER_SIZE, CHUNK_SIZE, C>

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.