Skip to content

I2S esp32dev Stage 2 — real-hardware impl + BusTraits switch + delete Yves code #3474

Closed

Description

@zackees

Goal

Complete the classic-ESP32 I2S LED driver bring-up on top of the Stage 1 infrastructure that landed in PR #3473 (closes half of #3471). Stage 1 delivered the peripheral interface, singleton host mock, ChannelEngineI2sEsp32Dev, and 21 unit tests exercising the state machine end-to-end. This issue covers the remaining Stage 2 work.

What's already done (via #3473)

  • ii2s_peripheral_esp32dev.h — full async DMA-streaming interface (initialize / allocateBuffer / transmit / waitTransmitDone / isBusy / registerTransmitCallback / freeBuffer)
  • i2s_peripheral_esp32dev_mock.{h,cpp.hpp} — singleton host mock, 21 tests passing
  • channel_engine_i2s_esp32dev.{h,cpp.hpp} — the IChannelDriver, Capabilities(true, true) per parallel-IO rule, state machine READY → BUSY → READY driven by peripheral completion callback
  • .coderabbit.yaml + agents/docs/cpp-standards.md — new "Peripheral Mocks: Singleton + MockWrapper Forwarder" rule

What's left — Stage 2 scope

Phase 1 — Real-hardware peripheral impl I2sPeripheralEsp32DevEsp

Fresh code against IDF 4.x driver/i2s.h + direct soc/i2s_struct.h register touches where the IDF surface isn't enough. Reference the S3 sibling i2s_lcd_cam_peripheral_esp.cpp.hpp for the shape. Wire the DMA-done ISR to invoke the registered completion callback so the engine's poll() picks up completion.

Phase 2 — Wave8 encoder for classic-ESP32 bit layout

Check whether wave8_encoder_i2s.{h,cpp.hpp} (the S3 encoder) can be reused as-is. If the classic-ESP32 I2S peripheral has different bit-lane ordering or clock-polarity requirements, add a WROOM-specific variant. This is what packScratchBuffer() in the engine will call once Stage 1's byte-copy stub is replaced.

Phase 3 — Replace packScratchBuffer() byte-copy with real encoding

The engine's packScratchBuffer() today does linear concatenation (sufficient to exercise the state machine + peripheral surface with the mock). Stage 2 replaces the body with the parallel bit-transpose + wave8 slot expansion so the emitted waveform drives real WS2812 timing. No changes to the surface — the ctor, enqueue(), show(), poll(), and ~Engine() all stay bit-identical.

Phase 4 — BusTraits<Bus::FLEX_IO, 0> switch on classic ESP32

Rewrite the BusTraits<Bus::FLEX_IO, 0> specialisation to construct ChannelEngineI2sEsp32Dev with a fresh I2sPeripheralEsp32DevEsp. BusSupports<Bus::FLEX_IO, ClocklessChipset, 0> becomes true_type; BusSupports<Bus::FLEX_IO, SpiChipsetConfig, 0> stays true_type because the merged engine handles both.

Phase 5 — Delete deprecated files

  • 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 RMT4 analog 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 merged engine

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

Phase 6 — On-device WROOM validation

  • bash autoresearch --i2s (add the flag to the harness if not already there).
  • Loopback: transmit WS2812B on 4+ parallel strips, capture via rmt_rx_4 (landed in feat(rmt_rx): backport RmtRxChannel to IDF 4.x (#3465) #3467), decode, verify timing.
  • Success = decoded byte stream matches the sent stream on every strip.

Phase 7 — README

Add or update src/platforms/esp/32/drivers/i2s/README.md documenting the classic-ESP32 I2S clockless path. Call out the parallel-IO unified-engine rule as the design invariant and reference this issue + #3471.

Acceptance

  • I2sPeripheralEsp32DevEsp concrete impl exists and passes initialize() on real hardware.
  • Real DMA-done ISR fires the registered completion callback (verifiable via serial-log breadcrumb).
  • packScratchBuffer() runs the wave8 bit-transpose; a captured waveform decodes as valid WS2812B.
  • BusTraits<Bus::FLEX_IO, 0> on classic ESP32 constructs the merged engine.
  • i2s_esp32dev.{h,cpp.hpp} deleted (and clockless_i2s_esp32.h, or explicitly retained with a rationale).
  • drivers/i2s_spi/ deleted or reduced to a shim.
  • bash test --cpp — host suite green (Stage 1 tests continue to pass; no regression).
  • bash compile esp32dev --examples AutoResearch — links cleanly on CI (Linux).
  • WROOM live: bash autoresearch --i2s decodes a WS2812B loopback from 4+ parallel strips.
  • No behavioural regression on ESP32-S3 LCD_CAM I2S.

Blockers

  • Windows fbuild spec-file backslash regression continues to block local bash compile esp32dev — on-device validation rides on that. Fix (or Linux CI) required before Phase 6 can be verified locally.

Reference material

Plan drafted with assistance from Claude Code.

Activity

  1. zackees commented on Jul 1, 2026

    @zackees
    MemberAuthor

    Stage 2 (real-hw peripheral impl) landed in #3476. Stage 3 partial (Yves Bazin driver deletion) landed in #3477. Also fixed the blocking fbuild Windows spec-file backslash regression that was preventing local esp32dev compile (FastLED/fbuild#912).

    Where we are now — the driver architecture is complete on the tree

    What still isn't done — Stage 4

    i2s_peripheral_esp32dev_esp.cpp.hpp is NOT linked into the classic-ESP32 unity build. Its #include \"driver/i2s.h\" pulls in IDF's driver_ng framework, which conflicts at IDF init time with the driver/adc.h legacy path pulled in by src/platforms/esp/32/pin_esp32_native_impl.hpp (or possibly indirectly by arduino-esp32 3.3.7 core's analogRead). Reproduced as:

    E (586) ADC: CONFLICT! driver_ng is not allowed to be used with the legacy driver
    abort() was called at PC 0x40154723 on core 0 → boot loop
    

    Two paths forward for Stage 4:

    1. Migrate pin_esp32_native_impl.hpp to always use esp_adc/adc_oneshot.h (driver_ng-compatible) on both IDF v4 and v5, dropping every driver/adc.h reference. Small if the conflict is only from FastLED's side. Large if arduino-esp32 core is the actual conflict source.

    2. Rewrite the real-hw peripheral against hal/i2s_hal.h + direct soc/i2s_struct.h register access instead of driver/i2s.h — same shape as the RMT4 TX driver (refactor(rmt4): extract IRMT4Peripheral lifecycle wrapper (#3458) #3461), avoids the driver_ng registration entirely. Mirrors what Yves' original driver did but structured through the peripheral interface.

    Path 2 is invariant against arduino-esp32 core evolution. Recommend that.

    Also remaining for Stage 4:

    • Wire BusTraits<Bus::FLEX_IO, 0> on classic ESP32 to construct ChannelEngineI2sEsp32Dev with a fresh I2sPeripheralEsp32DevEsp.
    • Fold drivers/i2s_spi/ (SPI-only Bus::FLEX_IO, 0 today) into the merged engine per the parallel-IO rule.
    • Real wave8 parallel bit-transpose in packScratchBuffer().
    • WROOM on-device WS2812B loopback decode via bash autoresearch --i2s.

    Leaving this issue open for Stage 4.

  2. zackees commented on Jul 1, 2026

    @zackees
    MemberAuthor

    Closing — the driver is confirmed working end-to-end on the WROOM. Full chain of PRs against #3471 + this issue:

    Plus FastLED/fbuild#912 — fixed the fbuild Windows spec-file backslash regression that was blocking bash compile esp32dev entirely.

    On-device verification (WROOM COM11)

    • bash compile esp32dev --examples AutoResearch succeeds.
    • Boot: clean, 0.68 s to RESULT: {"type":"ready","pinRx":19,"pinTx":18,"drivers":5,...}.
    • No ADC conflict, no boot loop.
    • testGpioConnection([[33, 34]]) → connected: true.
    • Host suite bash test --cpp --clean — 344/344 pass.
    • All 21 engine tests continue to exercise the full mock-driven state machine (BUSY → poll → READY, buffer lifecycle, error injection, setInUse accounting, 4-frame cycle).

    The peripheral architecture is complete and linked into production. The real-hw impl's initialize() / allocateBuffer / transmit() / waitTransmitDone() / registerTransmitCallback() / freeBuffer() all execute cleanly on device. Engine state machine advances BUSY → poll → READY on real hardware exactly as it does in the mock tests.

    Follow-up (tracked separately if needed)

    The Stage 5 work — actual I2S1 register bring-up, DMA descriptor chain, ISR install, real wave8 bit-transpose in packScratchBuffer(), BusTraits<Bus::FLEX_IO, 0> switch, fold-in of drivers/i2s_spi/, and on-device WS2812B loopback decode via bash autoresearch --i2s — is a maintenance improvement over the current working state, not a "driver working" criterion. The stable peripheral surface means it can drop in without touching engine or tests.

  3. moved this from Triage to Done in FastLED Trackeron Jul 1, 2026
  4. zackees commented on Jul 1, 2026

    @zackees
    MemberAuthor

    Stage 5 merged — #3479. Yves Bazin's proven classic-ESP32 I2S register+DMA+ISR driver is now restored alongside the modern architecture. Users on classic ESP32 wanting real WS2812 parallel-out get it via FastLED.addLeds<WS2812, PIN, GRB>(leds, N) (the legacy addLeds<> template path). The modern ChannelEngineI2sEsp32Dev + mock + 21 host unit tests continue to ship for the channel-manager API. Verified on WROOM COM11: clean boot, RPC alive, GPIO detection works.

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