Skip to main content

Spi

Struct Spi 

Source
pub struct Spi<'d, T: Instance, M: PeriMode> { /* private fields */ }
Expand description

SPI driver.

Implementations§

Source§

impl<'d, T: Instance, M: PeriMode> Spi<'d, T, M>

Source

pub fn set_config(&mut self, config: &Config) -> Result<(), ()>

Reconfigure the SPI peripheral.

Source

pub fn get_current_config(&self) -> Config

Get current SPI configuration. Useful for get the current baudrate.

Source

pub fn blocking_flush(&mut self) -> Result<(), Error>

Wait for the final bit to leave the peripheral.

Source

pub fn blocking_write<W: Word>(&mut self, words: &[W]) -> Result<(), Error>

Blocking write.

Source

pub fn blocking_read<W: Word>(&mut self, words: &mut [W]) -> Result<(), Error>

Blocking read, generating exactly one frame of clocks per word.

Source

pub fn blocking_transfer_in_place<W: Word>( &mut self, words: &mut [W], ) -> Result<(), Error>

Blocking transfer using the same buffer for transmit and receive.

Source

pub fn blocking_transfer<W: Word>( &mut self, read: &mut [W], write: &[W], ) -> Result<(), Error>

Blocking transfer of max(read.len(), write.len()) words.

Missing transmit words are zero; extra received words are discarded.

Source§

impl<'d, T: Instance> Spi<'d, T, Blocking>

Source

pub fn new_blocking<const REMAP: u8>( peri: Peri<'d, T>, sck: Peri<'d, impl SckPin<T, REMAP>>, mosi: Peri<'d, impl MosiPin<T, REMAP>>, miso: Peri<'d, impl MisoPin<T, REMAP>>, config: Config, ) -> Self

Create a new SPI driver.

Source

pub fn new_blocking_rxonly<const REMAP: u8>( peri: Peri<'d, T>, sck: Peri<'d, impl SckPin<T, REMAP>>, miso: Peri<'d, impl MisoPin<T, REMAP>>, config: Config, ) -> Self

Create a new SPI driver, in RX-only mode (only MISO pin, no MOSI).

Source

pub fn new_blocking_txonly<const REMAP: u8>( peri: Peri<'d, T>, sck: Peri<'d, impl SckPin<T, REMAP>>, mosi: Peri<'d, impl MosiPin<T, REMAP>>, config: Config, ) -> Self

Create a new SPI driver, in TX-only mode (only MOSI pin, no MISO).

Source

pub fn new_blocking_txonly_nosck<const REMAP: u8>( peri: Peri<'d, T>, mosi: Peri<'d, impl MosiPin<T, REMAP>>, config: Config, ) -> Self

Create a new SPI driver, in TX-only mode, without SCK pin.

This can be useful for bit-banging non-SPI protocols.

Source§

impl<'d, T: Instance> Spi<'d, T, Async>

Source

pub fn new<const REMAP: u8>( peri: Peri<'d, T>, sck: Peri<'d, impl SckPin<T, REMAP>>, mosi: Peri<'d, impl MosiPin<T, REMAP>>, miso: Peri<'d, impl MisoPin<T, REMAP>>, tx_dma: Peri<'d, impl TxDma<T>>, rx_dma: Peri<'d, impl RxDma<T>>, config: Config, ) -> Self

Create a new SPI driver.

Source

pub fn new_rxonly<const REMAP: u8>( peri: Peri<'d, T>, sck: Peri<'d, impl SckPin<T, REMAP>>, miso: Peri<'d, impl MisoPin<T, REMAP>>, rx_dma: Peri<'d, impl RxDma<T>>, config: Config, ) -> Self

Create a new SPI driver, in RX-only mode (only MISO pin, no MOSI).

Source

pub fn new_rxonly_with_tx_dma<const REMAP: u8>( peri: Peri<'d, T>, sck: Peri<'d, impl SckPin<T, REMAP>>, miso: Peri<'d, impl MisoPin<T, REMAP>>, tx_dma: Peri<'d, impl TxDma<T>>, rx_dma: Peri<'d, impl RxDma<T>>, config: Config, ) -> Self

Create a receive-only driver with DMA-generated dummy transmit words.

Source

pub fn new_txonly<const REMAP: u8>( peri: Peri<'d, T>, sck: Peri<'d, impl SckPin<T, REMAP>>, mosi: Peri<'d, impl MosiPin<T, REMAP>>, tx_dma: Peri<'d, impl TxDma<T>>, config: Config, ) -> Self

Create a new SPI driver, in TX-only mode (only MOSI pin, no MISO).

Source

pub fn new_txonly_nosck<const REMAP: u8>( peri: Peri<'d, T>, mosi: Peri<'d, impl MosiPin<T, REMAP>>, tx_dma: Peri<'d, impl TxDma<T>>, config: Config, ) -> Self

Create a new SPI driver, in TX-only mode, without SCK pin.

This can be useful for bit-banging non-SPI protocols.

Source

pub async fn flush(&mut self) -> Result<(), Error>

Wait until the transmit buffer and shift register are empty.

Source

pub async fn write<W: Word>(&mut self, data: &[W]) -> Result<(), Error>

Write using DMA; received data is ignored in transmit-only hardware mode.

Source

pub async fn read<W: Word>(&mut self, data: &mut [W]) -> Result<(), Error>

Read using DMA and exactly one frame of clocks per word.

RX-only constructors generate dummy transmit words in software. Supply both DMA channels with new_rxonly_with_tx_dma for DMA clock generation.

Source

pub async fn transfer<W: Word>( &mut self, read: &mut [W], write: &[W], ) -> Result<(), Error>

Transfer max(read.len(), write.len()) words using DMA.

Missing transmit words are zero; extra received words are discarded.

Source

pub async fn transfer_in_place<W: Word>( &mut self, data: &mut [W], ) -> Result<(), Error>

Transfer using the same buffer for transmit and receive.

Trait Implementations§

Source§

impl<'d, T: Instance, M: PeriMode> Drop for Spi<'d, T, M>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<'d, T: Instance, M: PeriMode> ErrorType for Spi<'d, T, M>

Source§

type Error = Error

Error type.
Source§

impl<'d, T: Instance, W: Word> SpiBus<W> for Spi<'d, T, Async>

Source§

async fn write(&mut self, data: &[W]) -> Result<(), Self::Error>

Write words to the slave, ignoring all the incoming words. Read more
Source§

async fn read(&mut self, data: &mut [W]) -> Result<(), Self::Error>

Read words from the slave. Read more
Source§

async fn transfer( &mut self, read: &mut [W], write: &[W], ) -> Result<(), Self::Error>

Write and read simultaneously. write is written to the slave on MOSI and words received on MISO are stored in read. Read more
Source§

async fn transfer_in_place(&mut self, data: &mut [W]) -> Result<(), Self::Error>

Write and read simultaneously. The contents of words are written to the slave, and the received words are stored into the same words buffer, overwriting it. Read more
Source§

async fn flush(&mut self) -> Result<(), Self::Error>

Wait until all operations have completed and the bus is idle. Read more
Source§

impl<'d, T: Instance, W: Word, M: PeriMode> SpiBus<W> for Spi<'d, T, M>

Source§

fn flush(&mut self) -> Result<(), Self::Error>

Wait until all operations have completed and the bus is idle. Read more
Source§

fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error>

Read words from the slave. Read more
Source§

fn write(&mut self, words: &[W]) -> Result<(), Self::Error>

Write words to the slave, ignoring all the incoming words. Read more
Source§

fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error>

Write and read simultaneously. write is written to the slave on MOSI and words received on MISO are stored in read. Read more
Source§

fn transfer_in_place(&mut self, words: &mut [W]) -> Result<(), Self::Error>

Write and read simultaneously. The contents of words are written to the slave, and the received words are stored into the same words buffer, overwriting it. Read more

Auto Trait Implementations§

§

impl<'d, T, M> !UnwindSafe for Spi<'d, T, M>

§

impl<'d, T, M> Freeze for Spi<'d, T, M>
where T: Freeze,

§

impl<'d, T, M> RefUnwindSafe for Spi<'d, T, M>
where T: RefUnwindSafe, M: RefUnwindSafe,

§

impl<'d, T, M> Send for Spi<'d, T, M>
where T: Send, M: Send,

§

impl<'d, T, M> Sync for Spi<'d, T, M>
where T: Sync, M: Sync,

§

impl<'d, T, M> Unpin for Spi<'d, T, M>
where T: Unpin, M: Unpin,

§

impl<'d, T, M> UnsafeUnpin for Spi<'d, T, M>
where T: UnsafeUnpin,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.