Skip to main content

Transaction

Struct Transaction 

Source
pub struct Transaction(/* private fields */);
Expand description

An LPSPI transaction definition.

The transaction defines how many bits the driver sends or recieves. It also describes

  • endianness
  • bit order
  • transmit and receive masking
  • continuous and continuing transfers (default: both disabled)
  • the hardware-managed peripheral chip select, Pcs

The LPSPI enqueues the transaction data into the transmit FIFO. When it pops the values from the FIFO, the values take effect immediately. This may affect, or abort, any ongoing transactions. Consult the reference manual to understand when you should enqueue transaction definitions, since it may only be supported on word / frame boundaries.

Construct Transaction with new, and supply the number of bits to transmit per frame.

use imxrt_hal as hal;
use hal::lpspi::Transaction;

// Send one u32.
let mut transaction
    = Transaction::new(8 * core::mem::size_of::<u32>() as u16).unwrap();

// Transactions can be computed at compile time.
const TRANS: Transaction = {
    let Ok(mut t) = Transaction::new(16) else { panic!(); };
    t.set_receive_data_mask(true);
    t.set_mode(hal::lpspi::MODE_2);
    t
};

Once constructed, use the set_* methods to change the configuration.

§Continuous transactions

The pseudo-code below shows how to set continuous and continuing to model a continuous transaction. Keep in mind the hardware limitations; see the module-level docs for details.

use imxrt_hal as hal;
use hal::lpspi::Transaction;

// Skipping LPSPI initialization; see module-level example.

// Start byte exchange as a continuous transaction. Each frame
// exchanges one byte (eight bits) with a device.
let mut transaction = Transaction::new(8)?;
transaction.set_continuous(true);
// Enqueue transaction with LPSPI...
// Enqueue one byte with LPSPI...   <-- PCS asserts here.

for byte in buffer {
    // Set 'continuing' to indicate that the next
    // transaction continues the previous one...
    transaction.set_continuing(true);

    // Enqueue transaction with LPSPI...
    // Enqueue byte with LPSPI...
}

transaction.set_continuous(false);
transaction.set_continuing(false);
// Enqueue transaction with LPSPI... <-- PCS de-asserts here.

Implementations§

Source§

impl Transaction

Source

pub const fn set_byte_swap(&mut self, swap: bool) -> &mut Self

Enable byte swap.

When enabled (true), swap bytes within the u32 word. This allows you to change the endianness of the 32-bit word transfer. The default is false.

Source

pub const fn set_bit_order(&mut self, bit_order: BitOrder) -> &mut Self

Bit order.

See BitOrder for details. The default is BitOrder::Msb.

Source

pub const fn set_receive_data_mask(&mut self, rxmask: bool) -> &mut Self

Mask the received data.

If true, the peripheral discards received data. Use this when you only care about sending data. The default is false; the peripheral puts received data in the receive FIFO.

Source

pub const fn set_transmit_data_mask(&mut self, txmask: bool) -> &mut Self

Mask the transmit data.

If true, the peripheral doesn’t send any data. Use this when you only care about receiving data. The default is false; the peripheral expects to send data using the transmit FIFO.

Source

pub const fn set_continuous(&mut self, cont: bool) -> &mut Self

Indicates (true) the start of a continuous transfer.

If set, the peripherals chip select will remain asserted after exchanging the frame. This allows you to enqueue new commands and data words within the same transaction. Those new commands should have continuing set to true.

The default is false; chip select de-asserts after exchanging the frame. To stop a continuous transfer, enqueue a new Transaction in which this flag, and continuing, is false.

Source

pub const fn set_continuing(&mut self, contc: bool) -> &mut Self

Indicates (true) that this command belongs to a previous transaction.

Set this to indicate that this new Transaction belongs to a previous Transaction, one that had continuous set. The default value is false.

Source

pub const fn set_mode(&mut self, mode: Mode) -> &mut Self

The SPI mode for the transaction.

By default, this is MODE_0.

Source

pub const fn set_pcs(&mut self, pcs: Pcs) -> &mut Self

Selects the hardware-managed peripheral chip select for the transaction.

See Pcs for more information.

Source§

impl Transaction

Source

pub fn new_u32s(data: &[u32]) -> Result<Self, LpspiError>

Defines a transaction for a u32 buffer.

After successfully defining a transaction of this buffer, supply it to the LPSPI driver, then start sending the data.

Returns an error if any are true:

  • the buffer is empty.
  • there’s more than 128 elements in the buffer.
Source

pub const fn new(frame_size: u16) -> Result<Self, LpspiError>

Define a transaction by specifying the frame size, in bits.

The frame size describes the number of bits that will be transferred and received during the next transaction. Specifically, it describes the number of bits for which the PCS pin signals a transaction.

§Requirements
  • frame_size fits within 12 bits; the implementation enforces this maximum value.
  • The minimum value for frame_size is 8; the implementation enforces this minimum value.
  • The last 32-bit word in the frame is at least 2 bits long.

Trait Implementations§

Source§

impl Clone for Transaction

Source§

fn clone(&self) -> Transaction

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Transaction

Source§

impl Debug for Transaction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Transaction

Source§

impl PartialEq for Transaction

Source§

fn eq(&self, other: &Transaction) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Transaction

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.