SpiInterface

Struct SpiInterface 

Source
pub struct SpiInterface<SPI> { /* private fields */ }
Expand description

SPI interface for the ICM-20948

§Note on Chip Select

This interface uses the SpiDevice trait from embedded-hal, which manages the chip select (CS) pin automatically. The CS pin is handled internally by the SPI device implementation you provide, so you don’t need to pass it separately.

If using embedded-hal-bus, you would typically create an SpiDevice like:

let spi_device = embedded_hal_bus::spi::ExclusiveDevice::new(spi_bus, cs_pin, delay);
let interface = SpiInterface::new(spi_device);

Implementations§

Source§

impl<SPI> SpiInterface<SPI>

Source

pub const fn new(spi: SPI) -> Self

Create a new SPI interface with the given SPI device

The SPI device should already include chip select management via the SpiDevice trait (e.g., using embedded_hal_bus::spi::ExclusiveDevice).

Source

pub fn release(self) -> SPI

Consume the interface and return the SPI device

Trait Implementations§

Source§

impl<SPI, E> AsyncRegisterInterface for SpiInterface<SPI>
where SPI: SpiDevice<Error = E>,

Available on crate feature async only.
Source§

type Error = Error<E>

The error type
Source§

type AddressType = u8

The address type used by this interface. Should likely be an integer.
Source§

async fn read_register( &mut self, address: Self::AddressType, size_bits: u32, read_data: &mut [u8], ) -> Result<(), Self::Error>

Read the register located at the given addres to the given data slice
Source§

async fn write_register( &mut self, address: Self::AddressType, size_bits: u32, write_data: &[u8], ) -> Result<(), Self::Error>

Write the given data to the register located at the given address
Source§

impl<SPI, E> RegisterInterface for SpiInterface<SPI>
where SPI: SpiDevice<Error = E>,

Source§

type Error = Error<E>

The error type
Source§

type AddressType = u8

The address type used by this interface. Should likely be an integer.
Source§

fn read_register( &mut self, address: Self::AddressType, size_bits: u32, read_data: &mut [u8], ) -> Result<(), Self::Error>

Read the register located at the given addres to the given data slice
Source§

fn write_register( &mut self, address: Self::AddressType, size_bits: u32, write_data: &[u8], ) -> Result<(), Self::Error>

Write the given data to the register located at the given address

Auto Trait Implementations§

§

impl<SPI> Freeze for SpiInterface<SPI>
where SPI: Freeze,

§

impl<SPI> RefUnwindSafe for SpiInterface<SPI>
where SPI: RefUnwindSafe,

§

impl<SPI> Send for SpiInterface<SPI>
where SPI: Send,

§

impl<SPI> Sync for SpiInterface<SPI>
where SPI: Sync,

§

impl<SPI> Unpin for SpiInterface<SPI>
where SPI: Unpin,

§

impl<SPI> UnwindSafe for SpiInterface<SPI>
where SPI: 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.