Skip to content

Bring up clockless I2S parallel-out on classic ESP32 (esp32dev / WROOM) — ground-up rewrite #3471

Closed

Description

@zackees

Goal

Bring up clockless I2S parallel-out (WS2812 / SK6812 family) on classic ESP32 / esp32dev / WROOM as a ground-up rewrite, mirroring the shape of the ESP32-S3 LCD_CAM I2S driver that already lives in this tree (src/platforms/esp/32/drivers/i2s/channel_driver_i2s.{h,cpp.hpp} + ii2s_lcd_cam_peripheral.h + peripheral esp/mock impls). At end of the port, the third-party Yves Bazin driver code — i2s_esp32dev.{h,cpp.hpp} + clockless_i2s_esp32.h — is deprecated and removed from the tree.

Today users on classic ESP32 get RMT4 (up to 8 parallel strips) and, after #3467, RX loopback via rmt_rx_4. I2S clockless is unreachable through the modern FastLED.add<>() / Channel::create<>() channel-manager path. Adding it as a first-class ChannelEngine unlocks 16+ parallel strips and gives users a second architectural path when the RMT ISR is under pressure from WiFi.

Non-goals — explicit

Reference template — the S3 LCD_CAM driver

Use src/platforms/esp/32/drivers/i2s/ as-is for the file layout. The S3 driver's shape is:

channel_driver_i2s.h            -- ChannelEngineI2S : IChannelDriver
                                    (public interface + concrete class)
channel_driver_i2s.cpp.hpp      -- implementation body (~800 lines)
ii2s_lcd_cam_peripheral.h       -- II2sLcdCamPeripheral virtual interface
                                    (lifecycle + DMA buffer alloc + transmit +
                                    callback registration; no register touches)
i2s_lcd_cam_peripheral_esp.h    -- concrete real-hardware impl
i2s_lcd_cam_peripheral_esp.cpp.hpp
i2s_lcd_cam_peripheral_mock.h   -- host-side mock (single-threaded, no threads,
                                    matches the #3462 / #3463 / #3469
                                    mock precedent)
i2s_lcd_cam_peripheral_mock.cpp.hpp
wave8_encoder_i2s.h             -- bit-transpose kernel (parallel-output
                                    waveform generator from packed RGB bytes)

ChannelEngineI2S (public class in channel_driver_i2s.h:109) implements IChannelDriver; the peripheral is injected via constructor and every ESP-IDF call goes through II2sLcdCamPeripheral. Host tests instantiate the engine with the mock and drive lifecycle synchronously via simulate* methods on the peripheral. This is exactly the shape the WROOM I2S driver should have.

Naming

Keep everything under drivers/i2s/ and colocate WROOM-specific files next to the S3-specific ones. Suggested names — bikeshed at PR time:

drivers/i2s/
├── channel_engine_i2s_esp32dev.{h,cpp.hpp}
├── ii2s_peripheral_esp32dev.h
├── i2s_peripheral_esp32dev_esp.{h,cpp.hpp}
├── i2s_peripheral_esp32dev_mock.{h,cpp.hpp}
└── wave8_encoder_i2s_esp32dev.{h,cpp.hpp}  (or reuse the S3 wave8 encoder if
                                             the bit layout matches — it might)

Parallel-IO code-review rule applies

Per agents/docs/cpp-standards.md and src/fl/channels/README.md:

Any LED channel-engine wrapping a parallel-IO peripheral (FlexIO, ObjectFLED, PARLIO, LCD_CAM, I2S, …) MUST handle both its clockless and its SPI mode in the SAME ChannelEngine class, returning Capabilities(true, true) and routing per-channel in show() based on data->isSpi() vs data->isClockless().

Applied here:

  • Classic ESP32 I2S is a parallel-IO peripheral. One engine covers both clockless (WS2812 family) and SPI (APA102 / SK9822 / HD108) modes.
  • The current drivers/i2s_spi/ directory today owns the SPI half on classic ESP32 via its own BusTraits<Bus::FLEX_IO, 0> specialisation. That directory is folded into the new engine and either deleted or reduced to a compatibility shim.
  • The engine reports Capabilities(true, true), dispatches per channel at show() time, and configures the peripheral clock + waveform generator for whichever mode the current channel needs.
  • No new Bus::I2S enum row. Bus::FLEX_IO, 0 stays the single dispatch slot for classic-ESP32 I2S.

Plan

Phase 1 — Draft II2sPeripheralEsp32Dev

Mirror ii2s_lcd_cam_peripheral.h (lines 126+):

  • initialize(config) / deinitialize() / isInitialized()
  • allocateBuffer(size_bytes) / freeBuffer(buf) for DMA-capable memory
  • transmit(buffer, size_bytes) async submit
  • waitTransmitDone(timeout_ms) and isBusy()
  • registerTransmitCallback(cb, user_ctx)
  • getConfig(), getMicroseconds(), delay(ms) utilities

Config struct captures: I2S peripheral number (0 or 1), bit width (16-bit parallel typical for LEDs), pixel clock, GPIO pin list, invert flags. Wave8-style timing parameters live in the encoder, not the peripheral config.

Phase 2 — Real-hardware I2sPeripheralEsp32DevEsp

Concrete impl using ESP-IDF v4 legacy I2S APIs (driver/i2s.h + soc/i2s_struct.h register touches where the driver API doesn't expose enough). This is where the "written fresh, not lifted from Yves" work lives. Reference material: ESP-IDF 4.x I2S driver docs, soc/i2s_reg.h, and the S3 sibling for the API-shape prior art.

Phase 3 — Host mock I2sPeripheralEsp32DevMock

Follow the Rmt4PeripheralMock / I2sLcdCamPeripheralMock template exactly:

  • Singleton via fl::Singleton<Impl>.
  • Single-threaded by design — no std::thread, no condition_variable. Tests advance simulation manually via simulateTransmitDone().
  • Error-injection knobs for each fallible entry point (setTransmitFailure, setInitializeFailure, etc.).
  • Per-channel state inspection so tests can assert what the engine passed to the peripheral.

Phase 4 — ChannelEngineI2sEsp32Dev

Mirror ChannelEngineI2S (channel_driver_i2s.h:109). The engine:

  • Takes fl::shared_ptr<II2sPeripheralEsp32Dev> via constructor. Overloaded factory create() builds a default real-hardware peripheral for production; test factory takes an injected mock.
  • Implements the full IChannelDriver surface: canHandle / enqueue / show / poll / getName / getCapabilities.
  • Capabilities(true, true).
  • show() iterates enrolled channels, sets the wave8 encoder for the current chipset's timing, packs the bit-transposed waveform, hands to II2sPeripheralEsp32Dev::transmit().
  • Handles the per-channel clockless-vs-SPI mode switch inline.

Phase 5 — wave8_encoder_i2s_esp32dev

Check whether the S3 sibling's wave8_encoder_i2s.{h,cpp.hpp} can be reused as-is — the parallel-bit-transpose kernel is likely portable. If the classic-ESP32 I2S peripheral has different bit-lane ordering or clock-polarity requirements, add a WROOM-specific variant.

Phase 6 — BusTraits<Bus::FLEX_IO, 0> rewiring

Move / rewrite the BusTraits<Bus::FLEX_IO, 0> specialisation to point at the merged engine. The drivers/i2s_spi/ directory (which owns this specialisation today for SPI-only support) is deleted or reduced to a compatibility shim. BusSupports<Bus::FLEX_IO, ClocklessChipset, 0> and BusSupports<Bus::FLEX_IO, SpiChipsetConfig, 0> both become true_type because the engine now handles both.

Phase 7 — Delete deprecated files

Remove from the tree:

  • src/platforms/esp/32/drivers/i2s/i2s_esp32dev.h
  • src/platforms/esp/32/drivers/i2s/i2s_esp32dev.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/clockless_i2s_esp32.h (unless the legacy addLeds<> fast path still needs it — decide at PR time; the equivalent template in RMT-land, idf4_clockless_rmt_esp32.h, was kept and rerouted, so the precedent leans towards keeping the file but rerouting its innards)
  • src/platforms/esp/32/drivers/i2s_spi/ — folded into the new engine

Update _build.cpp.hpp in drivers/i2s/ and remove the _build.cpp.hpp under drivers/i2s_spi/.

Phase 8 — Tests

  • Host tests for the peripheral mock (contract-only, no engine wiring). Same shape as the RMT4 mock tests in test(rmt4): Rmt4PeripheralMock + 22 host unit tests, no threads (#3462) #3463 — cover: lifecycle recording, ISR cookie symmetry, per-error-injection knob, simulateTransmitDone fires the stored callback, reset() clears state.
  • Host tests for the engine's channel-management state machine wired against the mock. Follow the same shape as the S3 LCD_CAM tests already in tests/platforms/esp/32/drivers/i2s/.
  • On-device WROOM — bash autoresearch --i2s. Requires adding an --i2s flag to the autoresearch harness. Success = 4+ parallel WS2812B strips decoded via rmt_rx_4 loopback with matching timing.

Phase 9 — README

Document the new driver at src/platforms/esp/32/drivers/i2s/README.md. Call out the parallel-IO unified-engine rule as the design invariant.

Out of scope

  • ESP32-S3 LCD_CAM I2S driver — unchanged. It's the template for this work, not the target.
  • ESP32-S2 I2S — the S2 I2S peripheral has different register semantics and there's no wave8_encoder_i2s variant. Separate port if / when someone asks for it.
  • IDF 5 / IDF 6 classic-ESP32 I2S — the PERIPH_I2S1_MODULE register access changed in IDF 5 and was removed in IDF 6. FASTLED_ESP32_HAS_I2S already excludes IDF 6+. This issue targets IDF 4.x on WROOM, which is what the WROOM AutoResearch harness runs today.
  • RmtMemoryManager4 extension for I2S accounting. The I2S peripheral has its own DMA descriptor pool independent of RMT symbol memory; no cross-peripheral contention on classic ESP32.

Acceptance

  • II2sPeripheralEsp32Dev + real-hardware + host-mock impls exist under drivers/i2s/, mirroring the II2sLcdCamPeripheral structure line-for-line.
  • ChannelEngineI2sEsp32Dev implements IChannelDriver, returns Capabilities(true, true), dispatches on data->isSpi() at show() time.
  • BusTraits<Bus::FLEX_IO, 0> on classic ESP32 constructs the merged engine. BusSupports<Bus::FLEX_IO, ClocklessChipset, 0> == BusSupports<Bus::FLEX_IO, SpiChipsetConfig, 0> == true_type.
  • i2s_esp32dev.{h,cpp.hpp} and clockless_i2s_esp32.h deleted (or, for the latter, decidedly-retained-with-a-good-reason).
  • drivers/i2s_spi/ deleted or reduced to a shim.
  • bash test --cpp — host suite green, including new peripheral-mock + engine tests.
  • bash compile esp32dev --examples AutoResearch — links cleanly.
  • WROOM live: bash autoresearch --i2s decodes a WS2812B loopback capture from 4+ parallel strips.
  • No behavioural regression on ESP32-S3 LCD_CAM I2S (Bus::FLEX_IO, 0 on S3 still routes to the existing channel_driver_i2s.* — the S3 gate FASTLED_ESP32_HAS_I2S_LCD_CAM is orthogonal to the classic-ESP32 gate FASTLED_ESP32_HAS_I2S).

Plan drafted with assistance from Claude Code.

Activity

  1. changed the title [-]Bring up clockless I2S parallel-out on classic ESP32 (esp32dev / WROOM)[/-] [+]Bring up clockless I2S parallel-out on classic ESP32 (esp32dev / WROOM) — ground-up rewrite[/+] on Jul 1, 2026
  2. zackees commented on Jul 1, 2026

    @zackees
    MemberAuthor

    Stage 1 landed via #3473 (merged). Delivers the infrastructure that the rest of the work builds on:

    • II2sPeripheralEsp32Dev virtual interface with the full async DMA-streaming surface (initialize / allocateBuffer / transmit / waitTransmitDone / isBusy / registerTransmitCallback / freeBuffer). Interface is stable — Stage 2 can add the real-hardware impl without touching it.
    • I2sPeripheralEsp32DevMock singleton host mock following the peer pattern (RMT4/5, UART, S3 LCD_CAM, SPI, FlexIO) — no std::thread, no async callbacks; tests advance simulation manually via simulateTransmitDone(). Error injection knobs, transmit-history recording, allocation-count / outstanding-buffer tracking.
    • ChannelEngineI2sEsp32Dev — the IChannelDriver, Capabilities(true, true) per the parallel-IO code-review rule, READY → BUSY → READY state machine driven by the peripheral completion callback. Stage 1 packs the scratch buffer via linear byte concatenation; Stage 2 replaces the packScratchBuffer() body with the real bit-transpose + wave8 slot expansion.
    • 21 host FL_TEST_CASEs covering state-machine transitions, transmit payload capture, allocation reuse vs reallocation, no-buffer-leak on destructor, error injection, setInUse channel accounting, enqueue-during-BUSY isolation, and a full 4-frame cycle. All pass.
    • New "Peripheral Mocks: Singleton + MockWrapper Forwarder" rule in .coderabbit.yaml and agents/docs/cpp-standards.md. Codifies what every peer mock already did but was never explicitly required.

    Stage 2 (real-hardware I2sPeripheralEsp32DevEsp, real wave8 encoding, BusTraits<Bus::FLEX_IO, 0> switch, deletion of the Yves Bazin i2s_esp32dev.* + clockless_i2s_esp32.h + folding-in of drivers/i2s_spi/, and on-device WROOM validation) is now tracked separately as #3474 because on-device validation is blocked on the local box by the pre-existing fbuild spec-file backslash regression.

    Closing this issue to reflect Stage 1 landed. Stage 2 continues at #3474.

  3. moved this from Triage to Done in FastLED Trackeron Jul 1, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions