Skip to main content

Module parallel

Module parallel 

Source
Expand description

§Parallel Interface (via I2S)

§Overview

The I2S parallel interface provides high-speed data transfer between the ESP32 and external devices. It is commonly used with devices such as LED matrices, LCD displays, and printers. Only TX is implemented. Each unit can have up to 8 or 16 data signals (depending on the target hardware) plus one clock signal.

§Notes

Data output is interleaved:

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

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

§Configuration

The driver uses DMA 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 mut parallel =
    I2sParallel::new(i2s, dma_channel, Rate::from_mhz(1), pins, clock).into_async();

let mut tx_buf = dma_tx_buffer!(BUFFER_SIZE).unwrap();
for (i, data) in tx_buf.as_mut_slice().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;
}

// 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§

I2sParallelunstable
I2S parallel interface
I2sParallelTransferunstable
Represents an ongoing (or potentially finished) transfer using the I2S parallel interface.
TxEightBitsunstable
Represents a group of 8 output pins configured for 8-bit parallel data transmission.
TxSixteenBitsunstable
Represents a group of 16 output pins configured for 16-bit parallel data transmission.

Enums§

I2sParallelInterruptunstable
Interrupts from the I2S parallel peripheral.

Traits§

I2sParallelDmaChannel
DMA channel trait for I2S peripherals.
Instance
A peripheral singleton compatible with the I2S parallel driver.