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>
impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx>
sourcepub 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
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.
sourcepub 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
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).
sourcepub 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
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).
sourcepub 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
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.
sourcepub fn set_config(&mut self, config: &Config) -> Result<(), ()>
pub fn set_config(&mut self, config: &Config) -> Result<(), ()>
Reconfigures it with the supplied config.
sourcepub fn get_current_config(&self) -> Config
pub fn get_current_config(&self) -> Config
Get current SPI configuration.
sourcepub async fn write<W: Word>(&mut self, data: &[W]) -> Result<(), Error>where
Tx: TxDma<T>,
pub async fn write<W: Word>(&mut self, data: &[W]) -> Result<(), Error>where
Tx: TxDma<T>,
SPI write, using DMA.
sourcepub async fn read<W: Word>(&mut self, data: &mut [W]) -> Result<(), Error>
pub async fn read<W: Word>(&mut self, data: &mut [W]) -> Result<(), Error>
SPI read, using DMA.
sourcepub async fn transfer<W: Word>(
&mut self,
read: &mut [W],
write: &[W]
) -> Result<(), Error>
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.
sourcepub async fn transfer_in_place<W: Word>(
&mut self,
data: &mut [W]
) -> Result<(), Error>
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.
sourcepub fn blocking_transfer_in_place<W: Word>(
&mut self,
words: &mut [W]
) -> Result<(), Error>
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.
sourcepub fn blocking_transfer<W: Word>(
&mut self,
read: &mut [W],
write: &[W]
) -> Result<(), Error>
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: TxDma<T>, Rx: RxDma<T>, W: Word> SpiBus<W> for Spi<'d, T, Tx, Rx>
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>
async fn flush(&mut self) -> Result<(), Self::Error>
source§async fn write(&mut self, words: &[W]) -> Result<(), Self::Error>
async fn write(&mut self, words: &[W]) -> Result<(), Self::Error>
words
to the slave, ignoring all the incoming words. Read moresource§async fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error>
async fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error>
words
from the slave. Read moresource§impl<'d, T: Instance, W: Word, Tx, Rx> SpiBus<W> for Spi<'d, T, Tx, Rx>
impl<'d, T: Instance, W: Word, Tx, Rx> SpiBus<W> for Spi<'d, T, Tx, Rx>
source§fn flush(&mut self) -> Result<(), Self::Error>
fn flush(&mut self) -> Result<(), Self::Error>
source§fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error>
fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error>
words
from the slave. Read moresource§fn write(&mut self, words: &[W]) -> Result<(), Self::Error>
fn write(&mut self, words: &[W]) -> Result<(), Self::Error>
words
to the slave, ignoring all the incoming words. Read more