Struct imxrt_hal::lpspi::Lpspi

source ·
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>

source

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.

source

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.

source

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>
where SDO: Pin<Module = Const<N>, Signal = Sdo>, SDI: Pin<Module = Const<N>, Signal = Sdi>, SCK: Pin<Module = Const<N>, Signal = Sck>, PCS0: Pin<Module = Const<N>, Signal = Pcs0>,

source

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>

source

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>

source

pub const N: u8 = N

The peripheral instance.

source

pub fn is_enabled(&self) -> bool

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

source

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.

source

pub fn reset(&mut self)

Reset the driver.

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

source

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.

source

pub fn bit_order(&self) -> BitOrder

Returns the bit order configuration.

See notes in set_bit_order to understand when this configuration takes effect.

source

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.

source

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.

source

pub fn status(&self) -> Status

Read the status register.

source

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.

source

pub fn interrupts(&self) -> Interrupts

Read the interrupt enable bits.

source

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.

source

pub fn clear_fifo(&mut self, direction: Direction)

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

source

pub fn clear_fifos(&mut self)

Clear both FIFOs.

source

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

Returns the watermark level for the given direction.

source

pub fn fifo_status(&self) -> FifoStatus

Returns the FIFO status.

source

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.

source

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.

source

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.

source

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.

source

pub fn flush(&mut self) -> Result<(), LpspiError>

Wait for all ongoing transactions to be finished.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn soft_reset(&mut self)

Reset all internal logic while preserving the driver’s configurations.

Unlike reset(), this preserves all peripheral registers.

source

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.

Trait Implementations§

source§

impl<P, const N: u8> Destination<u32> for Lpspi<P, N>

source§

fn destination_signal(&self) -> u32

Peripheral destination request signal Read more
source§

fn destination_address(&self) -> *const u32

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

fn enable_destination(&mut self)

Perform any actions necessary to enable DMA transfers Read more
source§

fn disable_destination(&mut self)

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

impl<P, const N: u8> Source<u32> for Lpspi<P, N>

source§

fn source_signal(&self) -> u32

Peripheral source request signal Read more
source§

fn source_address(&self) -> *const u32

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

fn enable_source(&mut self)

Perform any actions necessary to enable DMA transfers Read more
source§

fn disable_source(&mut self)

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

impl<P, const N: u8> Transfer<u16> for Lpspi<P, N>

§

type Error = LpspiError

Error type
source§

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

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

impl<P, const N: u8> Transfer<u32> for Lpspi<P, N>

§

type Error = LpspiError

Error type
source§

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

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

impl<P, const N: u8> Transfer<u8> for Lpspi<P, N>

§

type Error = LpspiError

Error type
source§

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

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

impl<P, const N: u8> Write<u16> for Lpspi<P, N>

§

type Error = LpspiError

Error type
source§

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

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

impl<P, const N: u8> Write<u32> for Lpspi<P, N>

§

type Error = LpspiError

Error type
source§

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

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

impl<P, const N: u8> Write<u8> for Lpspi<P, N>

§

type Error = LpspiError

Error type
source§

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

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

impl<P, const N: u8> Bidirectional<u32> for Lpspi<P, N>

Auto Trait Implementations§

§

impl<P, const N: u8> Freeze for Lpspi<P, N>
where P: Freeze,

§

impl<P, const N: u8> !RefUnwindSafe for Lpspi<P, N>

§

impl<P, const N: u8> Send for Lpspi<P, N>
where P: Send,

§

impl<P, const N: u8> !Sync for Lpspi<P, N>

§

impl<P, const N: u8> Unpin for Lpspi<P, N>
where P: Unpin,

§

impl<P, const N: u8> !UnwindSafe for Lpspi<P, N>

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>,

§

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>,

§

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.