Skip to main content

Lpspi

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

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>

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>

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

pub fn with_pins<SDO, SDI, SCK, const N: u8>( lpspi: Instance<RegisterBlock, N>, pins: Pins<SDO, SDI, SCK>, ) -> Lpspi
where 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

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

Indicates if the driver is (true) or is not (false) enabled.

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)

Reset the driver.

Note that this may not not reset all peripheral state, like the enabled state.

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)

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

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

Read the status register.

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

Read the interrupt enable bits.

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)

Clear any existing data in the SPI receive or transfer FIFOs.

pub fn clear_fifos(&mut self)

Clear both FIFOs.

pub fn watermark(&self, direction: Direction) -> u8

Returns the watermark level for the given direction.

pub fn fifo_status(&self) -> FifoStatus

Returns the FIFO status.

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)

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)

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)

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 flush(&mut self) -> Result<(), LpspiError>

Wait for all ongoing transactions to be finished.

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)

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)

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)

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>

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>

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)

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

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

Return the driver’s clock configurations.

These values are decided by calls to set_clock_hz and set_clock_configs.

Trait Implementations§

§

impl Bidirectional<u32> for Lpspi

§

impl Destination<u32> for Lpspi

§

fn destination_signal(&self) -> u32

Peripheral destination request signal Read more
§

fn destination_address(&self) -> *const u32

Returns a pointer to the register into which the DMA channel writes data Read more
§

fn enable_destination(&mut self)

Perform any actions necessary to enable DMA transfers Read more
§

fn disable_destination(&mut self)

Perform any actions necessary to disable or cancel DMA transfers Read more
§

impl Source<u32> for Lpspi

§

fn source_signal(&self) -> u32

Peripheral source request signal Read more
§

fn source_address(&self) -> *const u32

Returns a pointer to the register from which the DMA channel reads data Read more
§

fn enable_source(&mut self)

Perform any actions necessary to enable DMA transfers Read more
§

fn disable_source(&mut self)

Perform any actions necessary to disable or cancel DMA transfers Read more
§

impl Transfer<u8> for Lpspi

§

type Error = LpspiError

Error type
§

fn transfer<'a>( &mut self, words: &'a mut [u8], ) -> Result<&'a [u8], <Lpspi as Transfer<u8>>::Error>

Sends words to the slave. Returns the words received from the slave
§

impl Transfer<u16> for Lpspi

§

type Error = LpspiError

Error type
§

fn transfer<'a>( &mut self, words: &'a mut [u16], ) -> Result<&'a [u16], <Lpspi as Transfer<u16>>::Error>

Sends words to the slave. Returns the words received from the slave
§

impl Transfer<u32> for Lpspi

§

type Error = LpspiError

Error type
§

fn transfer<'a>( &mut self, words: &'a mut [u32], ) -> Result<&'a [u32], <Lpspi as Transfer<u32>>::Error>

Sends words to the slave. Returns the words received from the slave
§

impl Write<u8> for Lpspi

§

type Error = LpspiError

Error type
§

fn write(&mut self, words: &[u8]) -> Result<(), <Lpspi as Write<u8>>::Error>

Sends words to the slave, ignoring all the incoming words
§

impl Write<u16> for Lpspi

§

type Error = LpspiError

Error type
§

fn write(&mut self, words: &[u16]) -> Result<(), <Lpspi as Write<u16>>::Error>

Sends words to the slave, ignoring all the incoming words
§

impl Write<u32> for Lpspi

§

type Error = LpspiError

Error type
§

fn write(&mut self, words: &[u32]) -> Result<(), <Lpspi as Write<u32>>::Error>

Sends words to the slave, ignoring all the incoming words

Auto Trait Implementations§

§

impl !RefUnwindSafe for Lpspi

§

impl !Sync for Lpspi

§

impl !UnwindSafe for Lpspi

§

impl Freeze for Lpspi

§

impl Send for Lpspi

§

impl Unpin for Lpspi

§

impl UnsafeUnpin for Lpspi

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.