Struct embassy_stm32::spi::Spi

source ·
pub struct Spi<'d, T: Instance, Tx, Rx> { /* private fields */ }
Expand description

SPI driver.

Implementations§

source§

impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx>

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, txdma: impl Peripheral<P = Tx> + 'd, rxdma: impl Peripheral<P = Rx> + '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, txdma: impl Peripheral<P = Tx> + 'd, rxdma: impl Peripheral<P = Rx> + '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, txdma: impl Peripheral<P = Tx> + 'd, rxdma: impl Peripheral<P = Rx> + '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, txdma: impl Peripheral<P = Tx> + 'd, rxdma: impl Peripheral<P = Rx> + '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 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 async fn write<W: Word>(&mut self, data: &[W]) -> Result<(), Error>
where Tx: TxDma<T>,

SPI write, using DMA.

source

pub async fn read<W: Word>(&mut self, data: &mut [W]) -> Result<(), Error>
where Tx: TxDma<T>, Rx: RxDma<T>,

SPI read, using DMA.

source

pub async fn transfer<W: Word>( &mut self, read: &mut [W], write: &[W] ) -> Result<(), Error>
where Tx: TxDma<T>, Rx: RxDma<T>,

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>
where Tx: TxDma<T>, Rx: RxDma<T>,

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.

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.

Trait Implementations§

source§

impl<'d, T: Instance, Tx, Rx> Drop for Spi<'d, T, Tx, Rx>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'d, T: Instance, Tx, Rx> ErrorType for Spi<'d, T, Tx, Rx>

§

type Error = Error

Error type.
source§

impl<'d, T: Instance, Tx, Rx> SetConfig for Spi<'d, T, Tx, Rx>

§

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, Tx: TxDma<T>, Rx: RxDma<T>, W: Word> SpiBus<W> for Spi<'d, T, Tx, Rx>

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, Tx, Rx> SpiBus<W> for Spi<'d, T, Tx, Rx>

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, Tx, Rx> Transfer<u16> for Spi<'d, T, Tx, Rx>

§

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, Tx, Rx> Transfer<u8> for Spi<'d, T, Tx, Rx>

§

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, Tx, Rx> Write<u16> for Spi<'d, T, Tx, Rx>

§

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, Tx, Rx> Write<u8> for Spi<'d, T, Tx, Rx>

§

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

§

impl<'d, T, Tx, Rx> RefUnwindSafe for Spi<'d, T, Tx, Rx>

§

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

§

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

§

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

§

impl<'d, T, Tx, Rx> !UnwindSafe for Spi<'d, T, Tx, Rx>

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.