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, 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 moreSource§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 more