Skip to content

feat(esp32-s3): LCD_CAM ISR-driven buffer refill for chunked DMA streaming #2258

Closed

Description

@zackees

Summary

The ESP32-S3 LCD_CAM I80 bus driver needs ISR-driven chunked DMA streaming for both SPI chipsets (APA102, SK9822) and clockless protocols (WS2812, SK6812). This driver replaces the legacy "I2S" driver on ESP32-S3 (the ESP32-S3 has no I2S LED peripheral -- the existing I2S driver is a misnomer that actually wraps LCD_CAM). The "I2S" name is only retained for the original ESP32dev which has a real I2S peripheral.

Current State

SPI path -- working (Phase 1 partial)

  • ChannelDriverLcdSpi refactored for ISR-driven chunked DMA with 3-buffer ring
  • isrChunkDone() transposes next chunk and submits on DMA completion
  • Mock's simulateTransmitComplete() drains full callback chain
  • All 296 tests pass (ASAN/LSAN/UBSAN clean, lint clean)
  • 10 new chunked streaming test cases added

What needs fixing in SPI path

  • Chunk size too large: kDefaultChunkInputBytes = 2048 (32KB per ring slot). Should cap at ~100 LEDs = ~400 source bytes = ~6.4KB per ring slot.
  • No wave8 usage: Uses naive transposeToWords() bit loop instead of optimized wave8 LUT transposition.

Clockless path -- not yet started

The existing "I2S" driver (src/platforms/esp/32/drivers/i2s/) is the LCD_CAM clockless driver misnamed as I2S. It will be replaced by a new clockless path in the LCD driver with ISR-driven chunked DMA.

Architecture

The "I2S" naming confusion

On ESP32dev (original): There is a real I2S peripheral used for LED driving. The I2S driver name is correct.

On ESP32-S3: There is no I2S LED peripheral. The existing "I2S" driver (ChannelEngineI2S) actually wraps the LCD_CAM I80 bus via esp_lcd_panel_io. This is a misnomer. The new LCD driver replaces it with a properly named implementation.

Platform Real peripheral Current driver name New driver
ESP32dev I2S ChannelEngineI2S (correct) Keep as-is
ESP32-S3 LCD_CAM I80 ChannelEngineI2S (misnomer) Replace with LCD driver

Two drivers sharing infrastructure (Option B)

Separate ChannelDriverLcdSpi and ChannelDriverLcdClockless that share:

  • Unified peripheral interface (merging the nearly-identical ILcdSpiPeripheral and II2sLcdCamPeripheral)
  • Ring buffer + ISR context types
  • ISR callback chain mechanism
  • Separate encoding paths

The encoding paths are fundamentally different:

SPI (APA102) Clockless wave3 Clockless wave8
Source byte 1 byte 1 byte 1 byte
Output per byte 8 u16 words (16 bytes) 24 u16 words (48 bytes) 64 u16 words (128 bytes)
Expansion ratio 16x 48x 128x
100 LEDs DMA/slot ~6.4KB ~14KB ~38KB
3-ring total ~19KB ~43KB ~115KB

Chunk Sizing

Cap at 100 LEDs worth of pre-computed data per ring buffer slot:

Protocol Bytes/LED Source bytes (100 LEDs) DMA bytes/slot 3-ring total
SPI (APA102) 4 408 ~6.5KB ~19KB
Clockless wave3 3 300 ~14KB ~43KB
Clockless wave8 3 300 ~38KB ~115KB

wave8 vs wave3 for clockless

wave3 (current LCD_CAM approach) wave8
Memory per LED 72 bytes (3B x 24) 192 bytes (3B x 64)
Timing precision 3 levels per bit 8 levels per bit
PCLK for WS2812 ~2.4 MHz ~6.4 MHz
ISR transpose time Faster (less data) Slower (more data)
Compatibility Proven in current LCD_CAM driver Proven in SPI/PARLIO

Recommendation: Support both. wave3 as default (memory efficient), wave8 as opt-in for timing-sensitive applications.

Next Steps

Immediate (SPI path fixes)

  • Reduce kDefaultChunkInputBytes to cap at ~100 LEDs (~400 bytes for APA102)
  • Replace naive transposeToWords() with wave8-style LUT transposition

Design phase (clockless path)

  • Unify peripheral interfaces (ILcdSpiPeripheral + II2sLcdCamPeripheral -> shared interface)
  • Define clockless encoding API (wave3 default, wave8 opt-in)
  • Plan channel_manager_esp32 priority changes (new LCD clockless replaces misnamed I2S on S3)

Implementation (clockless path)

  • Implement ChannelDriverLcdClockless with ISR-driven chunked DMA
  • Use wave3/wave8 encoding in ISR callback
  • Mock + unit tests (Phase 1)
  • Comprehensive sweep tests (Phase 2)

Hardware validation (Phase 3)

  • trans_queue_depth research on ESP32-S3 LCD_CAM I80 bus
  • AutoResearch validation with bridged I/O ESP32-S3
  • SPI path: bash autoresearch --i2s --lanes 1-4 --strip-sizes tiny,small,medium,large
  • Clockless path: similar sweep

Open Research

trans_queue_depth > 1 on ESP32-S3 LCD_CAM

  • Test depth=2 and depth=3 with chained esp_lcd_panel_io_tx_color() calls
  • Check for FSM limitations similar to PARLIO on ESP32-C6
  • If depth > 1 works: zero-gap streaming via hardware queuing
  • If depth = 1 only: measure inter-chunk gap, implement software ring restart

ESP peripheral ISR safety

Current transmit() uses FreeRTOS semaphore (not ISR-safe). For ISR-driven chunking on real hardware, need a lightweight non-blocking submit path.

Related

Activity

  1. added a commit that references this issue on Apr 15, 2026
    4a0fa7e
  2. added
    platform: esp32
    area: core
    status: triage
    on Apr 16, 2026
  3. added a commit that references this issue on Apr 16, 2026
    2320b2f
  4. zackees commented on Apr 17, 2026

    @zackees
    MemberAuthor

    will fix #1961

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreplatform: esp32status: triage

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions