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>
impl<'d, T: Instance, M: PeriMode> Spi<'d, T, M>
Sourcepub fn set_config(&mut self, config: &Config) -> Result<(), ()>
pub fn set_config(&mut self, config: &Config) -> Result<(), ()>
Reconfigure the SPI peripheral.
Sourcepub fn get_current_config(&self) -> Config
pub fn get_current_config(&self) -> Config
Get current SPI configuration. Useful for get the current baudrate.
Sourcepub fn blocking_flush(&mut self) -> Result<(), Error>
pub fn blocking_flush(&mut self) -> Result<(), Error>
Wait for the final bit to leave the peripheral.
Sourcepub fn blocking_write<W: Word>(&mut self, words: &[W]) -> Result<(), Error>
pub fn blocking_write<W: Word>(&mut self, words: &[W]) -> Result<(), Error>
Blocking write.
Sourcepub fn blocking_read<W: Word>(&mut self, words: &mut [W]) -> Result<(), Error>
pub fn blocking_read<W: Word>(&mut self, words: &mut [W]) -> Result<(), Error>
Blocking read, generating exactly one frame of clocks per word.
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 transfer using the same buffer for transmit and receive.
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 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>
impl<'d, T: Instance> Spi<'d, T, Blocking>
Sourcepub 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
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.
Sourcepub 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
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§impl<'d, T: Instance> Spi<'d, T, Async>
impl<'d, T: Instance> Spi<'d, T, Async>
Sourcepub 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
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.
Sourcepub 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
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).
Sourcepub 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
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.
Sourcepub 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
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).
Sourcepub 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
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.
Sourcepub async fn flush(&mut self) -> Result<(), Error>
pub async fn flush(&mut self) -> Result<(), Error>
Wait until the transmit buffer and shift register are empty.
Sourcepub async fn write<W: Word>(&mut self, data: &[W]) -> Result<(), Error>
pub async fn write<W: Word>(&mut self, data: &[W]) -> Result<(), Error>
Write using DMA; received data is ignored in transmit-only hardware mode.
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>
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.
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>
Transfer max(read.len(), write.len()) words using DMA.
Missing transmit words are zero; extra received words are discarded.
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>
Transfer using the same buffer for transmit and receive.
Trait Implementations§
Source§impl<'d, T: Instance, W: Word> SpiBus<W> for Spi<'d, T, Async>
impl<'d, T: Instance, W: Word> SpiBus<W> for Spi<'d, T, Async>
Source§async fn write(&mut self, data: &[W]) -> Result<(), Self::Error>
async fn write(&mut self, data: &[W]) -> Result<(), Self::Error>
words to the slave, ignoring all the incoming words. Read moreSource§async fn read(&mut self, data: &mut [W]) -> Result<(), Self::Error>
async fn read(&mut self, data: &mut [W]) -> Result<(), Self::Error>
words from the slave. Read moreSource§async fn transfer(
&mut self,
read: &mut [W],
write: &[W],
) -> Result<(), Self::Error>
async fn transfer( &mut self, read: &mut [W], write: &[W], ) -> Result<(), Self::Error>
write is written to the slave on MOSI and
words received on MISO are stored in read. Read moreSource§async fn transfer_in_place(&mut self, data: &mut [W]) -> Result<(), Self::Error>
async fn transfer_in_place(&mut self, data: &mut [W]) -> Result<(), Self::Error>
words are
written to the slave, and the received words are stored into the same
words buffer, overwriting it. Read moreSource§impl<'d, T: Instance, W: Word, M: PeriMode> SpiBus<W> for Spi<'d, T, M>
impl<'d, T: Instance, W: Word, M: PeriMode> SpiBus<W> for Spi<'d, T, M>
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 moreSource§fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error>
fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error>
write is written to the slave on MOSI and
words received on MISO are stored in read. Read moreSource§fn transfer_in_place(&mut self, words: &mut [W]) -> Result<(), Self::Error>
fn transfer_in_place(&mut self, words: &mut [W]) -> Result<(), Self::Error>
words are
written to the slave, and the received words are stored into the same
words buffer, overwriting it. Read more