Struct SimpleCodec

Source
pub struct SimpleCodec<const HEADER_SIZE: usize, const ADDR_MSB: u8, const ADDR_LSB: u8, const RW_BIT: u8, const RW_1_IS_READ: bool, const READ_DELAY: usize> {}
Expand description

This codec represents the most commonly found codecs for SPI devices. It consists of an N-bit big-endian register address, a 1-bit R/W indicator and uses zero initializion for reserved bits. The header is always a multiple of 8-bit in width.

This codec has no information over register sizes or the existence of read/write address-auto-increment which some devices support. It will always send one header and then receive/send the associated register data, so it’s compatible with auto-increment usage, but cannot be used to read or write registers that require interspersing the address between bytes.

Devices often use a mixed mode, where some registers allow auto-increment while others don’t, or where the address is directly associated with a specific, but varying, register size. Therefore, it is up to the user to make sure that accessing a register via this codec is supported by the hardware.

The following generic parameters are available:

ParameterTypeDescription
HEADER_SIZEusizeThe size of the command header in bytes
ADDR_MSBu8The bit index of the MSB of the register-address (inclusive)
ADDR_LSBu8The bit index of the LSB of the register-address (inclusive)
RW_BITu8The bit index of the RW bit when interpreting the struct in big-endian
RW_1_IS_READboolwhether the setting the RW bit signals read-mode (true) or write-mode (false)
READ_DELAYusizeNumber of bytes that we have to wait (send additional zeros) after sending the header until data arrives

Implementations§

Source§

impl<const HEADER_SIZE: usize, const ADDR_MSB: u8, const ADDR_LSB: u8, const RW_BIT: u8, const RW_1_IS_READ: bool, const READ_DELAY: usize> SimpleCodec<HEADER_SIZE, ADDR_MSB, ADDR_LSB, RW_BIT, RW_1_IS_READ, READ_DELAY>

Source

pub fn fill_addr_header<R>(header: &mut [u8])
where R: Register,

Trait Implementations§

Source§

impl<const HEADER_SIZE: usize, const ADDR_MSB: u8, const ADDR_LSB: u8, const RW_BIT: u8, const RW_1_IS_READ: bool, const READ_DELAY: usize> CodecAsync for SimpleCodec<HEADER_SIZE, ADDR_MSB, ADDR_LSB, RW_BIT, RW_1_IS_READ, READ_DELAY>

Source§

async fn read_register<R, I>(interface: &mut I) -> Result<R, I::Error>

Read this register from the given SPI interface/device.
Source§

async fn write_register<R, I>( interface: &mut I, register: impl AsRef<R>, ) -> Result<(), I::Error>

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

impl<const HEADER_SIZE: usize, const ADDR_MSB: u8, const ADDR_LSB: u8, const RW_BIT: u8, const RW_1_IS_READ: bool, const READ_DELAY: usize> CodecSync for SimpleCodec<HEADER_SIZE, ADDR_MSB, ADDR_LSB, RW_BIT, RW_1_IS_READ, READ_DELAY>

Source§

fn read_register<R, I>(interface: &mut I) -> Result<R, I::Error>

Read this register from the given SPI interface/device.
Source§

fn write_register<R, I>( interface: &mut I, register: impl AsRef<R>, ) -> Result<(), I::Error>

Write this register to the given SPI interface/device.

Auto Trait Implementations§

§

impl<const HEADER_SIZE: usize, const ADDR_MSB: u8, const ADDR_LSB: u8, const RW_BIT: u8, const RW_1_IS_READ: bool, const READ_DELAY: usize> Freeze for SimpleCodec<HEADER_SIZE, ADDR_MSB, ADDR_LSB, RW_BIT, RW_1_IS_READ, READ_DELAY>

§

impl<const HEADER_SIZE: usize, const ADDR_MSB: u8, const ADDR_LSB: u8, const RW_BIT: u8, const RW_1_IS_READ: bool, const READ_DELAY: usize> RefUnwindSafe for SimpleCodec<HEADER_SIZE, ADDR_MSB, ADDR_LSB, RW_BIT, RW_1_IS_READ, READ_DELAY>

§

impl<const HEADER_SIZE: usize, const ADDR_MSB: u8, const ADDR_LSB: u8, const RW_BIT: u8, const RW_1_IS_READ: bool, const READ_DELAY: usize> Send for SimpleCodec<HEADER_SIZE, ADDR_MSB, ADDR_LSB, RW_BIT, RW_1_IS_READ, READ_DELAY>

§

impl<const HEADER_SIZE: usize, const ADDR_MSB: u8, const ADDR_LSB: u8, const RW_BIT: u8, const RW_1_IS_READ: bool, const READ_DELAY: usize> Sync for SimpleCodec<HEADER_SIZE, ADDR_MSB, ADDR_LSB, RW_BIT, RW_1_IS_READ, READ_DELAY>

§

impl<const HEADER_SIZE: usize, const ADDR_MSB: u8, const ADDR_LSB: u8, const RW_BIT: u8, const RW_1_IS_READ: bool, const READ_DELAY: usize> Unpin for SimpleCodec<HEADER_SIZE, ADDR_MSB, ADDR_LSB, RW_BIT, RW_1_IS_READ, READ_DELAY>

§

impl<const HEADER_SIZE: usize, const ADDR_MSB: u8, const ADDR_LSB: u8, const RW_BIT: u8, const RW_1_IS_READ: bool, const READ_DELAY: usize> UnwindSafe for SimpleCodec<HEADER_SIZE, ADDR_MSB, ADDR_LSB, RW_BIT, RW_1_IS_READ, READ_DELAY>

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.