Embassy
embassy-stm32

Crates

git

Versions

stm32l552zc

Flavors

Struct embassy_stm32::spi::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<(), ()>

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, T: Instance> Spi<'d, T, Blocking>

source

pub fn new_blocking( 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( 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( 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( 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, T: Instance> Spi<'d, T, Async>

source

pub fn new( 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( peri: impl Peripheral<P = T> + 'd, sck: impl Peripheral<P = impl SckPin<T>> + 'd, miso: impl Peripheral<P = impl MisoPin<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( 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( 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, T: Instance, M: PeriMode> Drop for Spi<'d, T, M>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

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

§

type Error = Error

Error type.
source§

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

§

type Config = Config

The configuration type used by this driver.
§

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, T: Instance, W: Word> SpiBus<W> for Spi<'d, T, 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, 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
source§

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

§

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, T: Instance, M: PeriMode> Transfer<u8> for Spi<'d, T, M>

§

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, T: Instance, M: PeriMode> Write<u16> for Spi<'d, T, M>

§

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, T: Instance, M: PeriMode> Write<u8> for Spi<'d, T, M>

§

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, T, M> Freeze for Spi<'d, T, M>
where T: Freeze,

§

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

§

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> !UnwindSafe for Spi<'d, T, 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>,

§

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>,

§

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.