embassy-stm32

Crates

git

Versions

stm32l4p5re

Flavors

embassy_stm32::spi

Struct Spi

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

SPI driver.

Implementations§

Source§

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

Source

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

Reconfigures it with the supplied config.

Source

pub fn get_current_config(&self) -> Config

Get current SPI configuration.

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.

Source

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

Blocking in-place bidirectional transfer.

This writes the contents of data on MOSI, and puts the received data on MISO in data, at the same time.

Source

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

Blocking bidirectional transfer.

This transfers both buffers at the same time, so it is NOT equivalent to write followed by read.

The transfer runs for max(read.len(), write.len()) bytes. If read is shorter extra bytes are ignored. If write is shorter it is padded with zero bytes.

Source§

impl<'d> Spi<'d, Blocking>

Source

pub fn new_blocking<T: Instance>( peri: impl Peripheral<P = T> + 'd, sck: impl Peripheral<P = impl SckPin<T>> + 'd, mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, miso: impl Peripheral<P = impl MisoPin<T>> + 'd, config: Config, ) -> Self

Create a new blocking SPI driver.

Source

pub fn new_blocking_rxonly<T: Instance>( peri: impl Peripheral<P = T> + 'd, sck: impl Peripheral<P = impl SckPin<T>> + 'd, miso: impl Peripheral<P = impl MisoPin<T>> + 'd, config: Config, ) -> Self

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

Source

pub fn new_blocking_txonly<T: Instance>( peri: impl Peripheral<P = T> + 'd, sck: impl Peripheral<P = impl SckPin<T>> + 'd, mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, config: Config, ) -> Self

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

Source

pub fn new_blocking_txonly_nosck<T: Instance>( peri: impl Peripheral<P = T> + 'd, mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, 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> Spi<'d, Async>

Source

pub fn new<T: Instance>( peri: impl Peripheral<P = T> + 'd, sck: impl Peripheral<P = impl SckPin<T>> + 'd, mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, miso: impl Peripheral<P = impl MisoPin<T>> + 'd, tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, config: Config, ) -> Self

Create a new SPI driver.

Source

pub fn new_rxonly<T: Instance>( peri: impl Peripheral<P = T> + 'd, sck: impl Peripheral<P = impl SckPin<T>> + 'd, miso: impl Peripheral<P = impl MisoPin<T>> + 'd, tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, rx_dma: impl Peripheral<P = impl RxDma<T>> + 'd, config: Config, ) -> Self

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

Source

pub fn new_txonly<T: Instance>( peri: impl Peripheral<P = T> + 'd, sck: impl Peripheral<P = impl SckPin<T>> + 'd, mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, config: Config, ) -> Self

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

Source

pub fn new_txonly_nosck<T: Instance>( peri: impl Peripheral<P = T> + 'd, mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, tx_dma: impl Peripheral<P = impl TxDma<T>> + 'd, 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 write<W: Word>(&mut self, data: &[W]) -> Result<(), Error>

SPI write, using DMA.

Source

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

SPI read, using DMA.

Source

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

Bidirectional transfer, using DMA.

This transfers both buffers at the same time, so it is NOT equivalent to write followed by read.

The transfer runs for max(read.len(), write.len()) bytes. If read is shorter extra bytes are ignored. If write is shorter it is padded with zero bytes.

Source

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

In-place bidirectional transfer, using DMA.

This writes the contents of data on MOSI, and puts the received data on MISO in data, at the same time.

Trait Implementations§

Source§

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

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

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

Source§

type Error = Error

Error type.
Source§

impl<'d, M: PeriMode> SetConfig for Spi<'d, M>

Source§

type Config = Config

The configuration type used by this driver.
Source§

type ConfigError = ()

The error type that can occur if set_config fails.
Source§

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

Set the configuration of the driver.
Source§

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

Source§

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

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

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

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

async fn read(&mut self, words: &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, 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
Source§

impl<'d, W: Word, M: PeriMode> SpiBus<W> for Spi<'d, 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
Source§

impl<'d, M: PeriMode> Transfer<u16> for Spi<'d, M>

Source§

type Error = Error

Error type
Source§

fn transfer<'w>( &mut self, words: &'w mut [u16], ) -> Result<&'w [u16], Self::Error>

Sends words to the slave. Returns the words received from the slave
Source§

impl<'d, M: PeriMode> Transfer<u8> for Spi<'d, M>

Source§

type Error = Error

Error type
Source§

fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error>

Sends words to the slave. Returns the words received from the slave
Source§

impl<'d, M: PeriMode> Write<u16> for Spi<'d, M>

Source§

type Error = Error

Error type
Source§

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

Sends words to the slave, ignoring all the incoming words
Source§

impl<'d, M: PeriMode> Write<u8> for Spi<'d, M>

Source§

type Error = Error

Error type
Source§

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

Sends words to the slave, ignoring all the incoming words

Auto Trait Implementations§

§

impl<'d, M> Freeze for Spi<'d, M>

§

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

§

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

§

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

§

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

§

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

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.