Struct SimpleCodec

Source
pub struct SimpleCodec<const HEADER_SIZE: usize> {}
Expand description

This codec represents the most commonly found codecs for I2C devices. The main variable is the size of register addresses in bytes.

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 (register address) in bytes

Trait Implementations§

Source§

impl<const HEADER_SIZE: usize> CodecAsync for SimpleCodec<HEADER_SIZE>

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> CodecSync for SimpleCodec<HEADER_SIZE>

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> Default for SimpleCodec<HEADER_SIZE>

Source§

fn default() -> SimpleCodec<HEADER_SIZE>

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

Auto Trait Implementations§

§

impl<const HEADER_SIZE: usize> Freeze for SimpleCodec<HEADER_SIZE>

§

impl<const HEADER_SIZE: usize> RefUnwindSafe for SimpleCodec<HEADER_SIZE>

§

impl<const HEADER_SIZE: usize> Send for SimpleCodec<HEADER_SIZE>

§

impl<const HEADER_SIZE: usize> Sync for SimpleCodec<HEADER_SIZE>

§

impl<const HEADER_SIZE: usize> Unpin for SimpleCodec<HEADER_SIZE>

§

impl<const HEADER_SIZE: usize> UnwindSafe for SimpleCodec<HEADER_SIZE>

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.