pub struct Spi<'d, M: PeriMode, CM: CommunicationMode> { /* private fields */ }Expand description
SPI driver.
Implementations§
Source§impl<'d> Spi<'d, Async, Slave>
impl<'d> Spi<'d, Async, Slave>
Sourcepub fn into_ring_buffered<W: Word>(
self,
dma_buf: &'d mut [W],
) -> RingBufferedSpiRx<'d, W>
pub fn into_ring_buffered<W: Word>( self, dma_buf: &'d mut [W], ) -> RingBufferedSpiRx<'d, W>
Turn the Spi into a buffered spi which can continuously receive in the background
without the possibility of losing bytes. The dma_buf is a buffer registered to the
DMA controller, and must be large enough to prevent overflows.
Source§impl<'d, M: PeriMode, CM: CommunicationMode> Spi<'d, M, CM>
impl<'d, M: PeriMode, CM: CommunicationMode> Spi<'d, M, CM>
Sourcepub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError>
pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError>
Reconfigures it with the supplied config.
Sourcepub fn rx_crc_value(&self) -> u16
pub fn rx_crc_value(&self) -> u16
Read the TX CRC register value.
Sourcepub fn get_current_config(&self) -> Config
pub fn get_current_config(&self) -> Config
Get current SPI configuration.
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.
Source§impl<'d> Spi<'d, Blocking, Master>
impl<'d> Spi<'d, Blocking, Master>
Sourcepub fn new_blocking<T: Instance>(
peri: Peri<'d, T>,
sck: Peri<'d, impl SckPin<T>>,
mosi: Peri<'d, impl MosiPin<T>>,
miso: Peri<'d, impl MisoPin<T>>,
config: Config,
) -> Self
pub fn new_blocking<T: Instance>( peri: Peri<'d, T>, sck: Peri<'d, impl SckPin<T>>, mosi: Peri<'d, impl MosiPin<T>>, miso: Peri<'d, impl MisoPin<T>>, config: Config, ) -> Self
Create a new blocking SPI driver.
Sourcepub fn new_blocking_rxonly<T: Instance>(
peri: Peri<'d, T>,
sck: Peri<'d, impl SckPin<T>>,
miso: Peri<'d, impl MisoPin<T>>,
config: Config,
) -> Self
pub fn new_blocking_rxonly<T: Instance>( peri: Peri<'d, T>, sck: Peri<'d, impl SckPin<T>>, miso: Peri<'d, impl MisoPin<T>>, config: Config, ) -> Self
Create a new blocking SPI driver, in RX-only mode (only MISO pin, no MOSI).
Source§impl<'d> Spi<'d, Async, Slave>
impl<'d> Spi<'d, Async, Slave>
Sourcepub fn new_slave<T: Instance, D1: TxDma<T>, D2: RxDma<T>, C: CsPin<T> + ExtiPin>(
peri: Peri<'d, T>,
sck: Peri<'d, impl SckPin<T>>,
mosi: Peri<'d, impl MosiPin<T>>,
miso: Peri<'d, impl MisoPin<T>>,
cs: Peri<'d, C>,
tx_dma: Peri<'d, D1>,
rx_dma: Peri<'d, D2>,
irq: impl Binding<D1::Interrupt, InterruptHandler<D1>> + Binding<D2::Interrupt, InterruptHandler<D2>> + Binding<<<C as ExtiPin>::ExtiChannel as Channel>::IRQ, InterruptHandler<<<C as ExtiPin>::ExtiChannel as Channel>::IRQ>> + 'd,
exti: Option<Peri<'d, C::ExtiChannel>>,
config: Config,
) -> Self
pub fn new_slave<T: Instance, D1: TxDma<T>, D2: RxDma<T>, C: CsPin<T> + ExtiPin>( peri: Peri<'d, T>, sck: Peri<'d, impl SckPin<T>>, mosi: Peri<'d, impl MosiPin<T>>, miso: Peri<'d, impl MisoPin<T>>, cs: Peri<'d, C>, tx_dma: Peri<'d, D1>, rx_dma: Peri<'d, D2>, irq: impl Binding<D1::Interrupt, InterruptHandler<D1>> + Binding<D2::Interrupt, InterruptHandler<D2>> + Binding<<<C as ExtiPin>::ExtiChannel as Channel>::IRQ, InterruptHandler<<<C as ExtiPin>::ExtiChannel as Channel>::IRQ>> + 'd, exti: Option<Peri<'d, C::ExtiChannel>>, config: Config, ) -> Self
Create a new SPI slave driver.
Sourcepub fn new_rxonly_slave<T: Instance, D1: RxDma<T>, C: CsPin<T> + ExtiPin>(
peri: Peri<'d, T>,
sck: Peri<'d, impl SckPin<T>>,
mosi: Peri<'d, impl MosiPin<T>>,
cs: Peri<'d, C>,
rx_dma: Peri<'d, D1>,
irq: impl Binding<D1::Interrupt, InterruptHandler<D1>> + Binding<<<C as ExtiPin>::ExtiChannel as Channel>::IRQ, InterruptHandler<<<C as ExtiPin>::ExtiChannel as Channel>::IRQ>> + 'd,
exti: Option<Peri<'d, C::ExtiChannel>>,
config: Config,
) -> Self
pub fn new_rxonly_slave<T: Instance, D1: RxDma<T>, C: CsPin<T> + ExtiPin>( peri: Peri<'d, T>, sck: Peri<'d, impl SckPin<T>>, mosi: Peri<'d, impl MosiPin<T>>, cs: Peri<'d, C>, rx_dma: Peri<'d, D1>, irq: impl Binding<D1::Interrupt, InterruptHandler<D1>> + Binding<<<C as ExtiPin>::ExtiChannel as Channel>::IRQ, InterruptHandler<<<C as ExtiPin>::ExtiChannel as Channel>::IRQ>> + 'd, exti: Option<Peri<'d, C::ExtiChannel>>, config: Config, ) -> Self
Create a new SPI slave driver in RX-only mode (only MOSI pin, no MISO).
Source§impl<'d> Spi<'d, Async, Master>
impl<'d> Spi<'d, Async, Master>
Sourcepub fn new<T: Instance, D1: TxDma<T>, D2: RxDma<T>>(
peri: Peri<'d, T>,
sck: Peri<'d, impl SckPin<T>>,
mosi: Peri<'d, impl MosiPin<T>>,
miso: Peri<'d, impl MisoPin<T>>,
tx_dma: Peri<'d, D1>,
rx_dma: Peri<'d, D2>,
_irq: impl Binding<D1::Interrupt, InterruptHandler<D1>> + Binding<D2::Interrupt, InterruptHandler<D2>> + 'd,
config: Config,
) -> Self
pub fn new<T: Instance, D1: TxDma<T>, D2: RxDma<T>>( peri: Peri<'d, T>, sck: Peri<'d, impl SckPin<T>>, mosi: Peri<'d, impl MosiPin<T>>, miso: Peri<'d, impl MisoPin<T>>, tx_dma: Peri<'d, D1>, rx_dma: Peri<'d, D2>, _irq: impl Binding<D1::Interrupt, InterruptHandler<D1>> + Binding<D2::Interrupt, InterruptHandler<D2>> + 'd, config: Config, ) -> Self
Create a new SPI driver.
Sourcepub fn new_rxonly<T: Instance, D2: RxDma<T>>(
peri: Peri<'d, T>,
sck: Peri<'d, impl SckPin<T>>,
miso: Peri<'d, impl MisoPin<T>>,
rx_dma: Peri<'d, D2>,
_irq: impl Binding<D2::Interrupt, InterruptHandler<D2>> + 'd,
config: Config,
) -> Self
pub fn new_rxonly<T: Instance, D2: RxDma<T>>( peri: Peri<'d, T>, sck: Peri<'d, impl SckPin<T>>, miso: Peri<'d, impl MisoPin<T>>, rx_dma: Peri<'d, D2>, _irq: impl Binding<D2::Interrupt, InterruptHandler<D2>> + 'd, config: Config, ) -> Self
Create a new SPI driver, in RX-only mode (only MISO pin, no MOSI).
Sourcepub fn new_txonly<T: Instance, D1: TxDma<T>>(
peri: Peri<'d, T>,
sck: Peri<'d, impl SckPin<T>>,
mosi: Peri<'d, impl MosiPin<T>>,
tx_dma: Peri<'d, D1>,
_irq: impl Binding<D1::Interrupt, InterruptHandler<D1>> + 'd,
config: Config,
) -> Self
pub fn new_txonly<T: Instance, D1: TxDma<T>>( peri: Peri<'d, T>, sck: Peri<'d, impl SckPin<T>>, mosi: Peri<'d, impl MosiPin<T>>, tx_dma: Peri<'d, D1>, _irq: impl Binding<D1::Interrupt, InterruptHandler<D1>> + 'd, config: Config, ) -> Self
Create a new SPI driver, in TX-only mode (only MOSI pin, no MISO).
Sourcepub fn new_txonly_nosck<T: Instance, D1: TxDma<T>>(
peri: Peri<'d, T>,
mosi: Peri<'d, impl MosiPin<T>>,
tx_dma: Peri<'d, D1>,
_irq: impl Binding<D1::Interrupt, InterruptHandler<D1>> + 'd,
config: Config,
) -> Self
pub fn new_txonly_nosck<T: Instance, D1: TxDma<T>>( peri: Peri<'d, T>, mosi: Peri<'d, impl MosiPin<T>>, tx_dma: Peri<'d, D1>, _irq: impl Binding<D1::Interrupt, InterruptHandler<D1>> + '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> Spi<'d, Async, Master>
impl<'d> Spi<'d, Async, Master>
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.
Source§impl<'d> Spi<'d, Async, Slave>
impl<'d> Spi<'d, Async, Slave>
Sourcepub async fn read<W: Word>(&mut self, data: &mut [W]) -> Result<usize, Error>
pub async fn read<W: Word>(&mut self, data: &mut [W]) -> Result<usize, Error>
Reads data from the SPI bus, using DMA.
Clocks out dummy bytes so the master can clock data in. Blocks until data
is full or the slave is deselected.
Returns the number of bytes read. If the master deselects the slave before
data is full, the number of bytes received so far is returned, like
embassy-nrf’s Spis.
Sourcepub async fn write<W: Word>(&mut self, data: &[W]) -> Result<usize, Error>
pub async fn write<W: Word>(&mut self, data: &[W]) -> Result<usize, Error>
Sends data on the SPI bus, using DMA.
Any data clocked in from the master is discarded. Blocks until data is
fully sent or the slave is deselected.
Returns the number of bytes sent. If the master deselects the slave before
data is fully sent, the number of bytes sent so far is returned, like
embassy-nrf’s Spis.
Sourcepub async fn transfer<W: Word>(
&mut self,
read: &mut [W],
write: &[W],
) -> Result<(usize, usize), Error>
pub async fn transfer<W: Word>( &mut self, read: &mut [W], write: &[W], ) -> Result<(usize, usize), Error>
Simultaneously sends and receives data, 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.
Blocks until the longest buffer is exhausted or the slave is deselected.
Returns the number of bytes transferred (n_rx, n_tx). If the master
deselects the slave first, the number of bytes transferred so far is
returned, like embassy-nrf’s Spis.
Sourcepub async fn transfer_in_place<W: Word>(
&mut self,
data: &mut [W],
) -> Result<usize, Error>
pub async fn transfer_in_place<W: Word>( &mut self, data: &mut [W], ) -> Result<usize, 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.
Returns the number of bytes transferred. If the master deselects the slave
before data is exhausted, the number of bytes transferred so far is
returned, like embassy-nrf’s Spis.
Trait Implementations§
Source§impl<'d, M: PeriMode, CM: CommunicationMode> SetConfig for Spi<'d, M, CM>
impl<'d, M: PeriMode, CM: CommunicationMode> SetConfig for Spi<'d, M, CM>
Source§type ConfigError = ConfigError
type ConfigError = ConfigError
set_config fails.Source§fn set_config(&mut self, config: &Self::Config) -> Result<(), Self::ConfigError>
fn set_config(&mut self, config: &Self::Config) -> Result<(), Self::ConfigError>
Source§impl<'d, W: Word, M: PeriMode> SpiBus<W> for Spi<'d, M, Master>
impl<'d, W: Word, M: PeriMode> SpiBus<W> for Spi<'d, M, Master>
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, W: Word> SpiBus<W> for Spi<'d, Async, Master>
impl<'d, W: Word> SpiBus<W> for Spi<'d, Async, Master>
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