Skip to main content

Interface

Trait Interface 

Source
pub trait Interface {
    type Error;

    // Required methods
    fn read(&mut self, reg: Register) -> Result<u8, Self::Error>;
    fn read_many<'b>(
        &mut self,
        reg: Register,
        buf: &'b mut [u8],
    ) -> Result<&'b [u8], Self::Error>;
    fn write(&mut self, reg: Register, val: u8) -> Result<(), Self::Error>;
    fn write_many(
        &mut self,
        reg: Register,
        bytes: &[u8],
    ) -> Result<(), Self::Error>;

    // Provided method
    fn rmw<F>(&mut self, reg: Register, f: F) -> Result<(), Self::Error>
       where F: FnOnce(u8) -> u8 { ... }
}
Expand description

Abstraction over the different communication interfaces

Required Associated Types§

Source

type Error

Associated error type

Required Methods§

Source

fn read(&mut self, reg: Register) -> Result<u8, Self::Error>

Read the value of a register

Source

fn read_many<'b>( &mut self, reg: Register, buf: &'b mut [u8], ) -> Result<&'b [u8], Self::Error>

Read the value of a register larger than a single byte (the FIFO)

Source

fn write(&mut self, reg: Register, val: u8) -> Result<(), Self::Error>

Write the value of a register

Source

fn write_many(&mut self, reg: Register, bytes: &[u8]) -> Result<(), Self::Error>

Write values to a register larger than a single byte (the FIFO)

Provided Methods§

Source

fn rmw<F>(&mut self, reg: Register, f: F) -> Result<(), Self::Error>
where F: FnOnce(u8) -> u8,

Execute a read-modify-write operation

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<E, I2C> Interface for I2cInterface<I2C>
where I2C: I2c<Error = E>,

Source§

type Error = E

Source§

impl<E, SPI, D> Interface for SpiInterface<SPI, D>
where SPI: SpiDevice<Error = E>, SpiInterface<SPI, D>: WrapTransfer<E>,

Source§

type Error = E