Function imxrt_hal::dma::peripheral::full_duplex
source · pub fn full_duplex<P, E, 'a>(
rx_channel: &'a mut Channel,
tx_channel: &'a mut Channel,
peripheral: &'a mut P,
buffer: &'a mut [E]
) -> FullDuplex<'a, P, E> ⓘwhere
P: Bidirectional<E>,
E: Element,
Expand description
Perform a full-duplex DMA transfer using two DMA channels that read and write from a single buffer.
Consider using a DMA interrupt handler that calls on_interrupt()
to wake the executor when the transfer completes. Otherwise, poll the future.
Example
Perform a full-duplex transfer of five u32
s with a LPSPI peripheral. Generate an interrupt
after receiving the final LPSPI word.
use imxrt_dma::{peripheral, channel::Channel};
// #[cortex_m_rt::interrupt]
fn DMA7() {
// Safety: DMA channel 7 valid and used by a future.
unsafe { DMA.on_interrupt(7) };
}
let mut lpspi = // A LPSPI peripheral
let mut channel_7: Channel = // DMA channel 7
let mut channel_8: Channel = // DMA channel 8
// Using channel_7 for the receive data. Once we've received
// the last word from the LPSPI peripheral, generate an interrupt.
channel_7.set_interrupt_on_completion(true);
// Don't trigger an interrupt after we _send_ the last LPSPI
// word from memory; we're still waiting for one word response.
channel_8.set_interrupt_on_completion(false);
// TODO unmask interrupts in NVIC!
let mut buffer = [4u32, 5, 6, 7, 8];
peripheral::full_duplex(
&mut channel_7,
&mut channel_8,
&mut lpspi,
&mut buffer,
).await?;