Struct Lpspi
pub struct Lpspi { /* private fields */ }Expand description
An LPSPI driver.
The driver exposes low-level methods for coordinating
DMA transfers. However, you may find it easier to use the
dma interface to coordinate DMA transfers.
The driver implements embedded-hal SPI traits. You should prefer
these implementations for their ease of use.
See the module-level documentation for an example of how to construct this driver.
Implementations§
§impl Lpspi
impl Lpspi
pub fn dma_write<'a>(
&'a mut self,
channel: &'a mut Channel,
buffer: &'a [u32],
) -> Result<Write<'a, Lpspi, u32>, LpspiError>
pub fn dma_write<'a>( &'a mut self, channel: &'a mut Channel, buffer: &'a [u32], ) -> Result<Write<'a, Lpspi, u32>, LpspiError>
Use a DMA channel to write data to the LPSPI peripheral.
The future completes when all data in buffer has been written to the
peripheral. This call may block until space is available in the
command queue. An error indicates that there was an issue preparing the
transaction, or there was an issue while waiting for space in the command
queue.
pub fn dma_read<'a>(
&'a mut self,
channel: &'a mut Channel,
buffer: &'a mut [u32],
) -> Result<Read<'a, Lpspi, u32>, LpspiError>
pub fn dma_read<'a>( &'a mut self, channel: &'a mut Channel, buffer: &'a mut [u32], ) -> Result<Read<'a, Lpspi, u32>, LpspiError>
Use a DMA channel to read data from the LPSPI peripheral.
The future completes when buffer is filled. This call may block until
space is available in the command queue. An error indicates that there was
an issue preparing the transaction, or there was an issue waiting for space
in the command queue.
pub fn dma_full_duplex<'a>(
&'a mut self,
rx: &'a mut Channel,
tx: &'a mut Channel,
buffer: &'a mut [u32],
) -> Result<FullDuplex<'a, Lpspi, u32>, LpspiError>
pub fn dma_full_duplex<'a>( &'a mut self, rx: &'a mut Channel, tx: &'a mut Channel, buffer: &'a mut [u32], ) -> Result<FullDuplex<'a, Lpspi, u32>, LpspiError>
Use a DMA channel to simultaneously read and write from a buffer and the LPSPI peripheral.
The future completes when buffer is filled and after sending buffer elements.
This call may block until space is available in the command queue. An error
indicates that there was an issue preparing the transaction, or there was an
issue waiting for space in the command queue.
§impl Lpspi
impl Lpspi
pub fn with_pins<SDO, SDI, SCK, const N: u8>(
lpspi: Instance<RegisterBlock, N>,
pins: Pins<SDO, SDI, SCK>,
) -> Lpspiwhere
SDO: Pin<Module = Const<N>, Signal = Sdo>,
SDI: Pin<Module = Const<N>, Signal = Sdi>,
SCK: Pin<Module = Const<N>, Signal = Sck>,
pub fn with_pins<SDO, SDI, SCK, const N: u8>(
lpspi: Instance<RegisterBlock, N>,
pins: Pins<SDO, SDI, SCK>,
) -> Lpspiwhere
SDO: Pin<Module = Const<N>, Signal = Sdo>,
SDI: Pin<Module = Const<N>, Signal = Sdi>,
SCK: Pin<Module = Const<N>, Signal = Sck>,
Create a new LPSPI driver from the RAL LPSPI instance and a set of pins.
When this call returns, the LPSPI pins are configured for their function.
The peripheral is enabled after reset. The LPSPI clock speed is unspecified.
The mode is [MODE_0]. The sample point is [SamplePoint::DelayedEdge].
The pins are consumed to ensure they’re properly configured, but they are not stored in the driver.
pub fn without_pins<const N: u8>(lpspi: Instance<RegisterBlock, N>) -> Lpspi
pub fn without_pins<const N: u8>(lpspi: Instance<RegisterBlock, N>) -> Lpspi
Create a new LPSPI driver from the RAL LPSPI instance.
This is similar to with_pins(), but it does not configure
pins. You’re responsible for configuring pins, and for making sure
the pin configuration doesn’t change while this driver is in use.
pub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Indicates if the driver is (true) or is not (false) enabled.
pub fn set_enable(&mut self, enable: bool)
pub fn set_enable(&mut self, enable: bool)
Enable (true) or disable (false) the peripheral.
Note that disabling does not take effect immediately; instead the
peripheral finishes the current transfer and then disables itself.
It is required to check is_enabled() repeatedly until the
peripheral is actually disabled.
pub fn reset(&mut self)
pub fn reset(&mut self)
Reset the driver.
Note that this may not not reset all peripheral state, like the enabled state.
pub fn bit_order(&self) -> BitOrder
pub fn bit_order(&self) -> BitOrder
Returns the bit order configuration.
See notes in set_bit_order to
understand when this configuration takes effect.
pub fn set_bit_order(&mut self, bit_order: BitOrder)
pub fn set_bit_order(&mut self, bit_order: BitOrder)
Set the bit order configuration.
This applies to all higher-level write and transfer operations.
If you’re using the [Transaction] API with manual word reads
and writes, set the configuration as part of the transaction.
pub fn disabled<R>(&mut self, func: impl FnOnce(&mut Disabled<'_>) -> R) -> R
pub fn disabled<R>(&mut self, func: impl FnOnce(&mut Disabled<'_>) -> R) -> R
Temporarily disable the LPSPI peripheral.
The handle to a Disabled driver lets you modify
LPSPI settings that require a fully disabled peripheral.
pub fn status(&self) -> Status
pub fn status(&self) -> Status
Read the status register.
pub fn clear_status(&self, flags: Status)
pub fn clear_status(&self, flags: Status)
Clear the status flags.
To clear status flags, set them high, then call clear_status().
The implementation will ensure that only the W1C bits are written, so it’s
OK to supply Status::all() to clear all bits.
pub fn interrupts(&self) -> Interrupts
pub fn interrupts(&self) -> Interrupts
Read the interrupt enable bits.
pub fn set_interrupts(&self, interrupts: Interrupts)
pub fn set_interrupts(&self, interrupts: Interrupts)
Set the interrupt enable bits.
This writes the bits described by interrupts as is to the register.
To modify the existing interrupts flags, you should first call interrupts
to get the current state, then modify that state.
pub fn clear_fifo(&mut self, direction: Direction)
pub fn clear_fifo(&mut self, direction: Direction)
Clear any existing data in the SPI receive or transfer FIFOs.
pub fn clear_fifos(&mut self)
pub fn clear_fifos(&mut self)
Clear both FIFOs.
pub fn watermark(&self, direction: Direction) -> u8
pub fn watermark(&self, direction: Direction) -> u8
Returns the watermark level for the given direction.
pub fn fifo_status(&self) -> FifoStatus
pub fn fifo_status(&self) -> FifoStatus
Returns the FIFO status.
pub fn read_data(&mut self) -> Option<u32>
pub fn read_data(&mut self) -> Option<u32>
Read the data register.
Returns None if the receive FIFO is empty. Otherwise, returns the complete
read of the register. You’re reponsible for interpreting the raw value as
a data word, depending on the frame size.
pub fn enqueue_data(&self, word: u32)
pub fn enqueue_data(&self, word: u32)
Place word into the transmit FIFO.
This will result in the value being sent from the LPSPI. You’re responsible for making sure that the transmit FIFO can fit this word.
pub fn set_mode(&mut self, mode: Mode)
pub fn set_mode(&mut self, mode: Mode)
Set the SPI mode for the peripheral.
This only affects the next transfer; ongoing transfers will not be influenced.
pub fn enqueue_transaction(&self, transaction: &Transaction)
pub fn enqueue_transaction(&self, transaction: &Transaction)
Place a transaction definition into the transmit FIFO.
Once this definition is popped from the transmit FIFO, this may affect, or abort, any ongoing transactions.
You’re responsible for making sure there’s space in the transmit FIFO for this transaction command.
pub fn enable_dma_receive(&mut self)
pub fn enable_dma_receive(&mut self)
Let the peripheral act as a DMA source.
After this call, the peripheral will signal to the DMA engine whenever it has data available to read.
pub fn disable_dma_receive(&mut self)
pub fn disable_dma_receive(&mut self)
Stop the peripheral from acting as a DMA source.
See the DMA chapter in the reference manual to understand when this should be called in the DMA transfer lifecycle.
pub fn enable_dma_transmit(&mut self)
pub fn enable_dma_transmit(&mut self)
Let the peripheral act as a DMA destination.
After this call, the peripheral will signal to the DMA engine whenever it has free space in its transfer buffer.
pub fn disable_dma_transmit(&mut self)
pub fn disable_dma_transmit(&mut self)
Stop the peripheral from acting as a DMA destination.
See the DMA chapter in the reference manual to understand when this should be called in the DMA transfer lifecycle.
pub fn rdr(&self) -> *const RORegister<u32>
pub fn rdr(&self) -> *const RORegister<u32>
Produces a pointer to the receiver data register.
You should use this pointer when coordinating a DMA transfer. You’re not expected to read from this pointer in software.
pub fn tdr(&self) -> *const WORegister<u32>
pub fn tdr(&self) -> *const WORegister<u32>
Produces a pointer to the transfer data register.
You should use this pointer when coordinating a DMA transfer. You’re not expected to read from this pointer in software.
pub fn soft_reset(&mut self)
pub fn soft_reset(&mut self)
Reset all internal logic while preserving the driver’s configurations.
Unlike reset(), this preserves all peripheral registers.
pub fn set_watermark(&mut self, direction: Direction, watermark: u8) -> u8
pub fn set_watermark(&mut self, direction: Direction, watermark: u8) -> u8
Set the watermark level for a given direction.
Returns the watermark level committed to the hardware. This may be different
than the supplied watermark, since it’s limited by the hardware.
When direction == Direction::Rx, the receive data flag is set whenever the
number of words in the receive FIFO is greater than watermark.
When direction == Direction::Tx, the transmit data flag is set whenever the
the number of words in the transmit FIFO is less than, or equal, to watermark.
pub fn clock_configs(&self) -> ClockConfigs
pub fn clock_configs(&self) -> ClockConfigs
Return the driver’s clock configurations.
These values are decided by calls to set_clock_hz
and set_clock_configs.