pub struct Lpspi<P, const N: u8> { /* 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§
source§impl<P, const N: u8> Lpspi<P, N>
impl<P, const N: u8> Lpspi<P, N>
sourcepub fn dma_write<'a>(
&'a mut self,
channel: &'a mut Channel,
buffer: &'a [u32]
) -> Result<Write<'a, Self, u32>, LpspiError>
pub fn dma_write<'a>( &'a mut self, channel: &'a mut Channel, buffer: &'a [u32] ) -> Result<Write<'a, Self, 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.
sourcepub fn dma_read<'a>(
&'a mut self,
channel: &'a mut Channel,
buffer: &'a mut [u32]
) -> Result<Read<'a, Self, u32>, LpspiError>
pub fn dma_read<'a>( &'a mut self, channel: &'a mut Channel, buffer: &'a mut [u32] ) -> Result<Read<'a, Self, 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.
sourcepub fn dma_full_duplex<'a>(
&'a mut self,
rx: &'a mut Channel,
tx: &'a mut Channel,
buffer: &'a mut [u32]
) -> Result<FullDuplex<'a, Self, 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, Self, 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.
source§impl<SDO, SDI, SCK, PCS0, const N: u8> Lpspi<Pins<SDO, SDI, SCK, PCS0>, N>
impl<SDO, SDI, SCK, PCS0, const N: u8> Lpspi<Pins<SDO, SDI, SCK, PCS0>, N>
sourcepub fn new(lpspi: Instance<N>, pins: Pins<SDO, SDI, SCK, PCS0>) -> Self
pub fn new(lpspi: Instance<N>, pins: Pins<SDO, SDI, SCK, PCS0>) -> Self
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
.
source§impl<const N: u8> Lpspi<(), N>
impl<const N: u8> Lpspi<(), N>
sourcepub fn without_pins(lpspi: Instance<N>) -> Self
pub fn without_pins(lpspi: Instance<N>) -> Self
Create a new LPSPI driver from the RAL LPSPI instance.
This is similar to new()
, 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.
source§impl<P, const N: u8> Lpspi<P, N>
impl<P, const N: u8> Lpspi<P, N>
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Indicates if the driver is (true
) or is not (false
) enabled.
sourcepub 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.
sourcepub 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.
sourcepub fn release(self) -> (Instance<N>, P)
pub fn release(self) -> (Instance<N>, P)
Release the SPI driver components.
This does not change any component state; it releases the components as-is.
If you need to obtain the registers in a known, good state, consider calling
methods like reset()
before releasing the registers.
sourcepub 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.
sourcepub 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.
sourcepub fn disabled<R>(&mut self, func: impl FnOnce(&mut Disabled<'_, N>) -> R) -> R
pub fn disabled<R>(&mut self, func: impl FnOnce(&mut Disabled<'_, N>) -> R) -> R
Temporarily disable the LPSPI peripheral.
The handle to a Disabled
driver lets you modify
LPSPI settings that require a fully disabled peripheral.
sourcepub 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.
sourcepub fn interrupts(&self) -> Interrupts
pub fn interrupts(&self) -> Interrupts
Read the interrupt enable bits.
sourcepub 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.
sourcepub 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.
sourcepub fn clear_fifos(&mut self)
pub fn clear_fifos(&mut self)
Clear both FIFOs.
sourcepub fn watermark(&self, direction: Direction) -> u8
pub fn watermark(&self, direction: Direction) -> u8
Returns the watermark level for the given direction.
sourcepub fn fifo_status(&self) -> FifoStatus
pub fn fifo_status(&self) -> FifoStatus
Returns the FIFO status.
sourcepub 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.
sourcepub 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.
sourcepub 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.
sourcepub fn enqueue_transaction(&mut self, transaction: &Transaction)
pub fn enqueue_transaction(&mut 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.
sourcepub fn flush(&mut self) -> Result<(), LpspiError>
pub fn flush(&mut self) -> Result<(), LpspiError>
Wait for all ongoing transactions to be finished.
sourcepub 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.
sourcepub 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.
sourcepub 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.
sourcepub 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.
sourcepub 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.
sourcepub 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.
sourcepub 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.
sourcepub 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
.