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
impl Transaction
Sourcepub const fn set_byte_swap(&mut self, swap: bool) -> &mut Self
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.
Sourcepub const fn set_bit_order(&mut self, bit_order: BitOrder) -> &mut Self
pub const fn set_bit_order(&mut self, bit_order: BitOrder) -> &mut Self
Bit order.
See BitOrder for details. The default is BitOrder::Msb.
Sourcepub const fn set_receive_data_mask(&mut self, rxmask: bool) -> &mut Self
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.
Sourcepub const fn set_transmit_data_mask(&mut self, txmask: bool) -> &mut Self
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.
Sourcepub const fn set_continuous(&mut self, cont: bool) -> &mut Self
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.
Sourcepub const fn set_continuing(&mut self, contc: bool) -> &mut Self
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§impl Transaction
impl Transaction
Sourcepub fn new_u32s(data: &[u32]) -> Result<Self, LpspiError>
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.
Sourcepub const fn new(frame_size: u16) -> Result<Self, LpspiError>
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_sizefits within 12 bits; the implementation enforces this maximum value.- The minimum value for
frame_sizeis 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
impl Clone for Transaction
Source§fn clone(&self) -> Transaction
fn clone(&self) -> Transaction
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more