Module parallel

Source
Available on crate feature unstable only.
Expand description

§Parallel Interface (via I2S)

§Overview

The I2S parallel interface allows for high-speed data transfer between the ESP32 and external devices. It is commonly used to external devices such as LED matrix, LCD display, and Printer. Only TX is implemented. Each unit can have up to 8 or 16 data signals (depending on your target hardware) plus 1 clock signal.

§Notes

Data output is interleaved:

  • 8bit: [A, B, C, D] is output as [C, D, A, B] (i.e., swapped as 16bit words)
  • 16bit: [A, B, C, D] is output as [B, A, D, C] (i.e., 16bit words are swapped)

I2S0 does not support true 8bit parallel output, so if you want to do 8bit you should use I2S1. If you have to use I2S0, it will only output the even bytes! so [A, B, C, D] will be output as [A, C]!!!!

§Configuration

The driver uses DMA (Direct Memory Access) for efficient data transfer and supports various configurations, such as different data formats, standards (e.g., Philips) and pin configurations. It relies on other peripheral modules, such as

  • GPIO
  • DMA
  • system (to configure and enable the I2S peripheral)

§Examples


const BUFFER_SIZE: usize = 256;

let delay = Delay::new();
let dma_channel = peripherals.DMA_I2S1;
let i2s = peripherals.I2S1;
let clock = peripherals.GPIO25;

let pins = TxEightBits::new(
    peripherals.GPIO16,
    peripherals.GPIO4,
    peripherals.GPIO17,
    peripherals.GPIO18,
    peripherals.GPIO5,
    peripherals.GPIO19,
    peripherals.GPIO12,
    peripherals.GPIO14,
);

let (_, _, tx_buffer, tx_descriptors) = dma_buffers!(0, BUFFER_SIZE);
let mut parallel = I2sParallel::new(
    i2s,
    dma_channel,
    Rate::from_mhz(1),
    pins,
    clock,
).into_async();

for (i, data) in tx_buffer.chunks_mut(4).enumerate() {
    let offset = i * 4;
    // i2s parallel driver expects the buffer to be interleaved
    data[0] = (offset + 2) as u8;
    data[1] = (offset + 3) as u8;
    data[2] = offset as u8;
    data[3] = (offset + 1) as u8;
}

let mut tx_buf: DmaTxBuf =
    DmaTxBuf::new(tx_descriptors, tx_buffer).expect("DmaTxBuf::new failed");

// Sending 256 bytes.
loop {
    let xfer = match parallel.send(tx_buf) {
        Ok(xfer) => xfer,
        Err(_) => {
            panic!("Failed to send buffer");
        }
    };
    (parallel, tx_buf) = xfer.wait();
    delay.delay_millis(10);
}

Structs§

I2sParallel
I2S Parallel Interface
I2sParallelTransfer
Represents an ongoing (or potentially finished) transfer using the i2s parallel interface
TxEightBits
Represents a group of 8 output pins configured for 8-bit parallel data transmission.
TxSixteenBits
Represents a group of 16 output pins configured for 16-bit parallel data transmission.

Traits§

Instance
A peripheral singleton compatible with the I2S parallel driver.