Skip to content

I2S classic-ESP32: unify Yves + modern paths and add IDF 6+ (LL API) support #3509

Closed

Description

@zackees

Goal

The classic-ESP32 I2S clockless driver has two coexisting paths in the tree and a hard cutoff at ESP-IDF 6. Consolidate them into a single production surface that works on every supported IDF version (v4.x, v5.x, v6.x+) and validate on real WROOM hardware via autoresearch loopback.

Current state (post #3479 / PR #3495)

Path A — Yves classic driver (WORKING on IDF 4.x/5.x, hard-stubs on 6+)

  • Files: src/platforms/esp/32/drivers/i2s/{i2s_esp32dev,clockless_i2s_esp32}.{h,cpp.hpp}
  • Peripheral: I2S1 in parallel mode, direct SoC register writes (i2s_esp32dev.cpp.hpp:475-491).
  • DMA: N-buffer chained ring via qe.stqe_next at line 436-438, out_link.addr kick at line 477.
  • ISR: interruptHandler() at line 145, FL_IRAM-resident, esp_intr_alloc()'d on I2S_OUT_EOF_INT. Refills freshly-emptied buffers by calling gCallback() (which routes to ClocklessI2S::fillBuffer() in clockless_i2s_esp32.h:227). Streaming ping-pong pipeline confirmed working.
  • Entry: users call FastLED.addLeds<WS2812, PIN, GRB>(leds, N) with -DFASTLED_ESP32_I2S=1, gated on !ESP_IDF_VERSION_6_OR_HIGHER in platforms/esp/clockless.h:32.
  • IDF 6+ break: PERIPH_I2S1_MODULE was removed from IDF 6 (i2s_esp32dev.cpp.hpp:14). The whole TU stubs to FL_WARN_F_ONCE("I2S parallel driver is disabled") (line 583). No LL API port yet.
  • Global state: 10+ file-scope statics (gCallback, gCntBuffer, dmaBuffers[], gTX_semaphore, gI2S_intr_handle, etc.) — tracked separately in singleton: migrate i2s_esp32dev driver state — 19 hits, ISR pattern (Tier 2a) #3489 for singleton migration.

Path B — Modern channel-driver architecture (SCAFFOLDED, no real hardware I/O)

  • Files: src/platforms/esp/32/drivers/i2s/{channel_engine_i2s_esp32dev,i2s_peripheral_esp32dev_esp,i2s_peripheral_esp32dev_mock}.{h,cpp.hpp} + ii2s_peripheral_esp32dev.h interface.
  • Engine: ChannelEngineI2sEsp32Dev is a full IChannelDriver with Capabilities(true, true) per the parallel-IO unified-engine rule. State machine READY → BUSY → READY driven by peripheral completion callback (channel_engine_i2s_esp32dev.cpp.hpp:200,281).
  • Peripheral impl is a stub: I2sPeripheralEsp32DevEsp::transmit() (i2s_peripheral_esp32dev_esp.cpp.hpp:153-177) accepts the buffer, does (void)buffer, fires the callback synchronously, returns true. No DMA. No ISR. No register touches. Comment on line 105: "Register-level bring-up on I2S1 moves into Stage 5 alongside the DMA descriptor chain + ISR install."
  • Stage 5 landed the DMA/ISR work but put it in Path A instead of Path B (see feat(i2s-esp32dev): Stage 5 — restore proven classic-ESP32 I2S driver alongside modern architecture (#3474) #3479 body).
  • Unity-build excluded: i2s_peripheral_esp32dev_esp.cpp.hpp is UNITY_BUILD_EXCLUDE'd (from PR chore(lint): drive pre-existing bash lint violations to zero #3496 marker). Rationale documented inline: driver/gpio.h include collided with the restored classic driver at link time as ADC: CONFLICT! driver_ng is not allowed to be used with the legacy driver boot loop.
  • Host tests: 21 tests in tests/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp pass; 28 in channel_driver_i2s.cpp; 17 in i2s_lcd_cam_peripheral_mock.cpp. All exercise the state machine + peripheral surface via the mock.

Why unify

  • Two codepaths for one peripheral violates the parallel-IO unified-engine rule (see agents/docs/cpp-standards.md — "Parallel-IO Driver: Unified Clockless + SPI Engine"). Path A is legacy addLeds<>, Path B is the modern FastLED.add<Channel::create<>>() / FastLED.enableAllDrivers() surface — but they wrap the same silicon.
  • IDF 6+ leaves classic ESP32 with NO clockless I2S option — the fallback is RMT (which is fine, but users who explicitly opted into I2S for the 24-strip parallel win lose that on IDF 6).
  • Global state in Path A can't move to Singleton<T> cleanly until it's inside a class (singleton: migrate i2s_esp32dev driver state — 19 hits, ISR pattern (Tier 2a) #3489). Consolidating around the peripheral interface in Path B gets both wins in one pass.

Scope

Phase 1 — Root-cause the ADC: CONFLICT

The driver/gpio.h include in i2s_peripheral_esp32dev_esp.cpp.hpp is the same header used by pin_esp32_native_impl.hpp and every other classic-ESP32 driver in the tree — those don't trip the conflict. Actual root cause is likely:

  • Both Path A's periph_module_enable(PERIPH_I2S1_MODULE) AND Path B's future initialize() racing to configure I2S1, OR
  • Static-init ordering between the two TUs' file-scope state (gI2S_intr_handle in Path A vs. peripheral state in Path B) making the linker treat both as "owner" of the same hardware.

Reproduce the crash log with both TUs linked in, get the actual failing symbol / driver-registry entry, then decide the fix.

Phase 2 — Move the working DMA+ISR machinery into Path B

Replace I2sPeripheralEsp32DevEsp::transmit()'s synchronous-callback stub with the real DMA descriptor chain kick + esp_intr_alloc ISR handler. Reference: the exact register sequence from i2s_esp32dev.cpp.hpp:444-491 (i2s_init + i2s_start). The DMA-done ISR fires the registered completion callback via onTransmitDoneTrampoline (already wired at channel_engine_i2s_esp32dev.cpp.hpp:281).

Keep the peripheral interface (ii2s_peripheral_esp32dev.h) unchanged — 21 host tests continue to pass without modification.

Phase 3 — LL API port for IDF 6+

PERIPH_I2S1_MODULE and periph_module_enable/disable were removed in IDF 6. Replace with:

  • i2s_ll_enable_bus_clock(1, true) — new bus-clock enable
  • i2s_ll_reset_register(1) — peripheral reset
  • Include path: #include "hal/i2s_ll.h" (private HAL, but that's what IDF 6 exposes for direct-register users)

Version-gate with #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(6, 0, 0) so IDF 4.x/5.x continue using the periph_module_* path. Confirm that soc/i2s_struct.h (the i2s_dev_t register layout used throughout Path A) survives into IDF 6 — if it doesn't, the direct-register writes need HAL equivalents too.

Phase 4 — Wire ClocklessI2S<> to the peripheral

The user-facing addLeds<WS2812, PIN, GRB>() template (via platforms/esp/clockless.h:35) currently instantiates ClocklessI2S which pokes the Path A globals directly. Rewrite ClocklessI2S to construct/reuse a Singleton<I2sPeripheralEsp32DevEsp> and use the peripheral interface for init/allocateBuffer/transmit/waitTransmitDone. Result: one hardware access surface, two user-facing entry points (legacy addLeds<> and modern FastLED.add<Channel::create<>>()).

Ping-pong buffer refill in the ISR still lives in the peripheral impl (unchanged behavior), but the fillBuffer callback now goes through registerTransmitCallback() instead of a raw file-scope function-pointer global.

Phase 5 — Unity-build re-include

Remove UNITY_BUILD_EXCLUDE(...) marker from i2s_peripheral_esp32dev_esp.cpp.hpp and add it to _build.cpp.hpp alongside the other includes. bash lint --cpp will confirm the unity build is well-formed.

Phase 6 — Global-state migration (piggyback on #3489)

Once the peripheral owns the DMA state, most of the 10+ file-scope globals in i2s_esp32dev.cpp.hpp become peripheral-instance state. Singleton<I2sPeripheralEsp32DevEsp>::instance() handles storage-elision naturally. Remove the FL_LINT_ALLOW_GLOBAL_FILE(...) marker from the top of i2s_esp32dev.cpp.hpp. Close #3489.

Phase 7 — Autoresearch validation

  • Add/verify bash autoresearch --i2s flag on AutoResearch.ino.
  • WROOM COM11 loopback: TX 4+ parallel WS2812B strips → capture on RX pin via rmt_rx_4 (landed in feat(rmt_rx): backport RmtRxChannel to IDF 4.x (#3465) #3467) → decode → byte-level comparison against sent stream. Success = every strip's decoded byte stream matches the pattern.
  • Repeat on ESP-IDF 4.x, 5.x, AND 6.x build to confirm all three version paths compile, boot cleanly, and pass the loopback.

Phase 8 — README

src/platforms/esp/32/drivers/i2s/README.md documenting the single unified path, the peripheral interface, the LL-API version-gate, and the loopback test. Reference the parallel-IO unified-engine invariant.

Acceptance criteria

  • Root cause of ADC: CONFLICT! documented (Phase 1)
  • I2sPeripheralEsp32DevEsp::transmit() does real DMA+ISR — no more synchronous-callback stub (Phase 2)
  • #if ESP_IDF_VERSION >= 6.0 path uses i2s_ll_* and compiles/boots on real IDF 6 (Phase 3)
  • ClocklessI2S<> uses the peripheral interface — no direct globals (Phase 4)
  • i2s_peripheral_esp32dev_esp.cpp.hpp back in unity build, no UNITY_BUILD_EXCLUDE marker (Phase 5)
  • i2s_esp32dev.cpp.hpp has no file-scope statics — closes singleton: migrate i2s_esp32dev driver state — 19 hits, ISR pattern (Tier 2a) #3489, removes FL_LINT_ALLOW_GLOBAL_FILE marker (Phase 6)
  • bash autoresearch --i2s decodes a 4+ strip WS2812B loopback on WROOM, on all three IDF version paths (Phase 7)
  • Modern FastLED.add<Channel::create<Bus::FLEX_IO, 0>()> path also drives real WS2812 output (proves both entry points hit the same peripheral)
  • bash test --cpp — all 344 host tests green, no regression
  • README updated (Phase 8)

Non-goals

  • ESP32-S3 i2s_lcd_cam_peripheral_esp.cpp.hpp is a different peripheral (I2S in LCD_CAM mode) and stays separate — the parallel-IO rule allows separate drivers per silicon block, not per mode. Any refactor here is out of scope.
  • ESP32-P4 / C6 / H2 / C5 continue using PARLIO as the clockless default (platforms/esp/clockless.h:38-44) — untouched.

Confirmation of what already works (baseline for this issue)

Verified during investigation (2026-07-01):

  • Path A on IDF 4.x/5.x is production: PR feat(i2s-esp32dev): Stage 5 — restore proven classic-ESP32 I2S driver alongside modern architecture (#3474) #3479 landed the restored Yves driver with clean WROOM boot, RPC ready in 0.68s, testGpioConnection([[33, 34]]) passing. Real DMA descriptor chain + IRAM ISR + ping-pong refill emit WS2812 timing on I2S1.
  • Host test coverage of Path B is solid: 21 + 28 + 17 = 66 unit tests exercise the modern engine state machine, driver contract, and mock peripheral. bash test --cpp reports 344/344 passing on master.
  • What's NOT confirmed: that Path B's real-hardware impl drives real waveforms (it doesn't — it's a stub); that Path A works on IDF 6 (it doesn't — it stubs to a warning).

Reference material

Blockers

Activity

  1. added
    type: feature
    priority: high
    platform: esp32
    area: drivers
    on Jul 1, 2026
  2. moved this from Triage to Done in FastLED Trackeron Jul 1, 2026
  3. zackees commented on Jul 1, 2026

    @zackees
    MemberAuthor

    Progress update

    Phase 3 landed via #3511 (merged 2026-07-01T15:11:45Z):

    • src/platforms/esp/32/drivers/i2s/i2s_periph_compat.h wraps periph enable/reset for IDF 4/5 (public periph_module_enable) vs IDF 6+ (i2s_ll_enable_bus_clock + i2s_ll_reset_register via hal/i2s_ll.h).
    • Classic driver rewired through the shim.
    • Feature-flag gate + top-level clockless selector no longer exclude IDF 6.

    Remaining work — external blocker on IDF 6 confirmation

    IDF 6 is not a shipping target yet. Current state:

    • ESP-IDF v5.5 is the most recent stable release (pioarduino: 55.03.35).
    • ESP-IDF v6.0 has not been released stable — no espressif/platform-espressif32 binding available.
    • No pioarduino / arduino-esp32 platform tag for IDF 6 exists in ci/boards.py; the CI matrix cannot add an IDF 6 target until upstream ships.

    So the goal condition "confirmed working on IDF 6" is genuinely blocked on the ESP-IDF release cycle, not on FastLED. The compat shim is written against the documented IDF 6 LL-API surface (hal/i2s_ll.h — i2s_ll_enable_bus_clock + i2s_ll_reset_register) and will work when IDF 6 ships and pioarduino publishes a platform binding.

    What IS confirmed:

    Follow-up when IDF 6 stable ships:

    1. Add ESP32_IDF_6_0_PIOARDUINO platform string to ci/boards.py.
    2. Add ESP32DEV_IDF6 board with -DFASTLED_ESP32_I2S=1 default.
    3. Add .github/workflows/build_esp32dev_idf6.yml compile smoke.
    4. Run bash autoresearch --i2s on real WROOM + IDF 6.
    5. If hal/i2s_ll.h symbol names shifted (they can across IDF minor releases), patch the compat shim.

    Phases 2, 4-8

    Documented in the umbrella issue body. Each is scoped for its own PR:

    • Phase 2 (real DMA/ISR into I2sPeripheralEsp32DevEsp) — largest, requires WROOM bench validation to preserve buffer-refill ISR behavior. Not attempted in feat(i2s-esp32dev): enable IDF 6+ via i2s_ll_* compat shim (#3509 Phase 3) #3511.
    • Phases 4-6 depend on Phase 2 landing first.
    • Phase 7 hardware loopback — requires WROOM + bash autoresearch --i2s runtime.
    • Phase 8 README — fast follow-up once Phase 2 lands.

    Recommendation

    Keep this issue open until IDF 6 stable ships AND Phase 2 lands. The Phase 3 enable (#3511) is the forward-compatible groundwork. Users on IDF 4/5 continue to get the production Yves path unchanged.

  4. zackees commented on Jul 1, 2026

    @zackees
    MemberAuthor

    Additional Phase 3 correctness fix landed as PR #3514 (merged 2026-07-01T15:38:18Z).

    What changed

    The compat shim in #3511 called i2s_ll_enable_bus_clock + i2s_ll_reset_register directly. Direct source-code verification against real ESP-IDF master (commit fa8039b5, file components/esp_hal_i2s/esp32/include/hal/i2s_ll.h) showed the macro-form of both functions requires __DECLARE_RCC_ATOMIC_ENV to be in scope — otherwise the caller fails to compile on IDF 6.

    The correct wrap is PERIPH_RCC_ATOMIC() { … } from esp_private/periph_ctrl.h. That's what ESP-IDF's own components/esp_driver_i2s/i2s_platform.c uses when calling the same LL functions.

    IDF 6 confirmation status now

    • ✅ Header symbol signatures verified against espressif/esp-idf@master:
      • i2s_ll_enable_bus_clock(int i2s_id, bool enable) ✓
      • i2s_ll_reset_register(int i2s_id) ✓
    • ✅ Caller pattern matches ESP-IDF's own i2s_platform.c
    • ✅ Required critical-section wrap (PERIPH_RCC_ATOMIC()) in place
    • ⏸ Bench validation on real WROOM + IDF 6 stable + pioarduino IDF 6 platform still tracked under I2S classic-ESP32 unified path: Phases 2, 4-8 (follow-up to #3509) #3512 Phase 7 when the upstream release ships

    This is the maximum "confirmed working on IDF 6" that can be established without physical IDF 6 silicon in the loop. The shim now matches ESP-IDF's own convention for calling these LL functions.

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: driversplatform: esp32priority: hightype: feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions