Trait mpu9250::Device

source ·
pub trait Device: Releasable {
    type Error;

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

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

An MPU communication device abstraction

This allows us to generalize the device over either an I2C or SPI peripheral

Required Associated Types§

source

type Error

The type of error for all results

Required Methods§

source

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

Read many values from register

source

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

Write the provided value to register

source

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

Write the provided data block (up to 16 bytes) to register

Provided Methods§

source

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

Read a single value from the register

source

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

Modify the value in the register using the provided closure. The closure accepts the current value of the register, permitting conditional checks before modification.

Implementors§

source§

impl<E, I2C> Device for I2cDevice<I2C>where I2C: Read<Error = E> + Write<Error = E> + WriteRead<Error = E>,

§

type Error = I2CError<E>

source§

impl<SPI, NCS, E, EO> Device for SpiDevice<SPI, NCS>where SPI: Write<u8, Error = E> + Transfer<u8, Error = E>, NCS: OutputPin<Error = EO>,

§

type Error = SpiError<E, EO>