Skip to content

feat(i2s-esp32dev): Stage 5 — restore proven classic-ESP32 I2S driver alongside modern architecture (#3474) - #3479

Merged
zackees merged 2 commits into
masterfrom
feat/3474-i2s-stage5
Jul 1, 2026
Merged

zackees merged 2 commits into
masterfrom
feat/3474-i2s-stage5

Conversation

@zackees

@zackees zackees commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Stage 4 (#3478) landed the modern peripheral impl but its transmit() was a synchronous stub — no real WS2812 waveform generation. The architecture is complete but the 'driver confirmed working' bar still needed actual on-device output.

This PR restores the classic-ESP32 I2S driver that was deleted in Stage 3 (#3477): i2s_esp32dev.{h,cpp.hpp} + clockless_i2s_esp32.{h,cpp.hpp}. That code is the field-proven, register-level, DMA-driven, ISR-completion-callback implementation that actually emits WS2812 parallel-out timing on I2S1. It's been running in production on classic ESP32 for years.

Ref #3474.

Coexistence with the modern architecture

Both live in the tree side-by-side:

  • Legacy addLeds<WS2812, PIN, GRB>() path — routes through clockless_i2s_esp32.h → I2SClocklessLedDriver → i2s_esp32dev register + DMA + ISR machinery. This is what actually generates WS2812 waveforms on hardware.
  • Modern channel-driver path — ChannelEngineI2sEsp32Dev + II2sPeripheralEsp32Dev + mock (Stage 1 feat(i2s-esp32dev): Stage 1 — peripheral + singleton mock + engine + tests (#3471) #3473). Full test coverage (21 host unit tests), stable peripheral surface.

I2sPeripheralEsp32DevEsp is present as a compilable TU but intentionally NOT linked into the classic-ESP32 unity build in this PR — its driver/gpio.h include collided with the restored code at link time producing an ADC: CONFLICT! boot loop. A future PR that reworks the modern peripheral to share the I2S1/periph_module state (rather than duplicating it) can drop the modern impl into the unity build cleanly.

Verification on WROOM COM11

  • Clean boot (no ADC conflict, no boot loop).
  • RESULT: {"type":"ready","pinRx":19,"pinTx":18,"drivers":5,...} at 0.68s.
  • testGpioConnection([[33, 34]]) → connected: true.

Test plan

  • bash compile esp32dev --examples AutoResearch succeeds.
  • Device boots + RPC works.
  • bash test --cpp --clean — 344/344 pass.
  • Users can call FastLED.addLeds<WS2812, PIN, GRB>(leds, N) on classic ESP32 to invoke the restored code path, which emits real WS2812 timing via DMA + ISR on I2S1. Production path FastLED users have been using for years.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added improved ESP32 LED output support with a new parallel I2S driver path.
    • Added support for RGBW strips and automatic RGBW-to-RGB handling.
    • Added compatibility handling for different ESP-IDF versions, including newer releases.
  • Bug Fixes

    • Improved driver selection to avoid problematic hardware paths on unsupported ESP-IDF versions.
    • Reduced allocation overhead during repeated frame updates for smoother performance.

… alongside modern architecture (#3474)

Stage 4 (#3478) landed the modern peripheral impl but its transmit()
was a synchronous stub — no real WS2812 waveform generation. The
architecture is complete but the "driver confirmed working" bar
still needed actual on-device output.

This restores the classic-ESP32 I2S driver code that was deleted in
Stage 3 (#3477): `i2s_esp32dev.{h,cpp.hpp}` +
`clockless_i2s_esp32.{h,cpp.hpp}`. That code is the field-proven,
register-level, DMA-driven, ISR-completion-callback implementation
that actually emits WS2812 parallel-out timing on I2S1. It's been
running in production on classic ESP32 for years.

## Coexistence with the modern architecture

Both live in the tree side-by-side:

- **Legacy `addLeds<WS2812, PIN, GRB>()` path** — routes through
  `clockless_i2s_esp32.h` → `I2SClocklessLedDriver` → `i2s_esp32dev`
  register + DMA + ISR machinery. This is what actually generates
  WS2812 waveforms on hardware.

- **Modern channel-driver path** — `ChannelEngineI2sEsp32Dev` +
  `II2sPeripheralEsp32Dev` + mock (Stage 1 #3473). Full test
  coverage (21 host unit tests), stable peripheral surface.
  `I2sPeripheralEsp32DevEsp` is present as a compilable TU but is
  intentionally NOT included in the classic-ESP32 unity build in
  this PR — its `driver/gpio.h` include collided with Yves' code
  at link time producing an `ADC: CONFLICT!` boot loop. A future
  PR that reworks the modern peripheral to share Yves'
  I2S1/periph_module state (rather than duplicating it) can drop
  the modern impl into the unity build cleanly.

## Verification

- `bash compile esp32dev --examples AutoResearch` — succeeds.
- Flashed to WROOM on COM11:
    - Clean boot (no ADC conflict, no boot loop).
    - `RESULT: {..."type":"ready","pinRx":19,"pinTx":18,"drivers":5,...}`
      at 0.68s (matches pre-Stage-2 baseline bit-for-bit).
    - `testGpioConnection([[33, 34]])` → `connected: true`.
- `bash test --cpp --clean` — 344/344 host suite pass.
- Users on classic ESP32 wanting I2S parallel-out LED drive:
  `FastLED.addLeds<WS2812, PIN, GRB>(leds, N)` invokes the
  restored code path, which emits real WS2812 timing via DMA + ISR
  on I2S1. This is the production path FastLED users have been
  using for years.

Ref #3474.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ec9313cd-3234-4fbc-96e8-9e5966f2b1b7

📥 Commits

Reviewing files that changed from the base of the PR and between e6fb6d8 and f614916.

📒 Files selected for processing (6)
  • src/platforms/esp/32/core/fastled_esp32.h
  • src/platforms/esp/32/drivers/i2s/_build.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/clockless_i2s_esp32.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/clockless_i2s_esp32.h
  • src/platforms/esp/32/drivers/i2s/i2s_esp32dev.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/i2s_esp32dev.h

📝 Walkthrough

Walkthrough

This PR restores the classic ESP32 register/DMA/ISR-based parallel I2S clockless LED driver. It adds a new i2s_esp32dev.h/.cpp.hpp low-level driver, a new clockless_i2s_esp32.h controller with an RGBW scratchpad helper, updates unity-build wiring, and gates inclusion by ESP-IDF version in the core header.

Estimated code review effort: 4 (Complex) | ~60 minutes

Changes

ESP32 I2S Driver Restoration

Layer / File(s) Summary
Low-level I2S peripheral driver
src/platforms/esp/32/drivers/i2s/i2s_esp32dev.h, src/platforms/esp/32/drivers/i2s/i2s_esp32dev.cpp.hpp
New DMA buffer struct, extern globals, bit-pattern/pulse timing computation, IRAM ISR, transpose/encode helpers, and full init/start/stop/reset lifecycle functions, with a disabled stub when FASTLED_ESP32_HAS_I2S is off.
ClocklessI2S controller and RGBW scratchpad
src/platforms/esp/32/drivers/i2s/clockless_i2s_esp32.h, src/platforms/esp/32/drivers/i2s/clockless_i2s_esp32.cpp.hpp
New templated ClocklessI2S controller integrating with CPixelLEDController, coordinating multi-strip DMA buffer fill/encode/showPixels(), plus a thread-local get_rgbw_scratchpad() buffer for RGBW-to-RGB conversion.
Unity build wiring and version gating
src/platforms/esp/32/drivers/i2s/_build.cpp.hpp, src/platforms/esp/32/core/fastled_esp32.h
Unity build now includes clockless_i2s_esp32 and i2s_esp32dev (dropping the real-hw peripheral header); core header conditionally includes clockless_i2s_esp32.h only pre-ESP-IDF-6.0 under FASTLED_ESP32_I2S.

Sequence Diagram(s)

sequenceDiagram
  participant ClocklessI2S
  participant i2s_init
  participant InterruptHandler
  participant DMAHardware

  ClocklessI2S->>i2s_init: i2s_define_bit_patterns, i2s_init(device)
  i2s_init->>DMAHardware: allocateDMABuffer, link descriptors
  ClocklessI2S->>DMAHardware: i2s_clear_dma_buffer, fillBuffer
  ClocklessI2S->>DMAHardware: i2s_start
  DMAHardware->>InterruptHandler: out-of-eof interrupt
  InterruptHandler->>ClocklessI2S: fill callback (gCallback)
  InterruptHandler->>ClocklessI2S: release TX semaphore (last buffer)
  ClocklessI2S->>DMAHardware: i2s_wait, i2s_stop
Loading

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2450: Both PRs modify the ESP32 I2S unity-build wiring in _build.cpp.hpp, changing which I2S driver headers are included.

Poem

A rabbit hops through DMA lanes,
Reviving pulses, clocks, and chains,
ISR fires, buffers spin,
Classic I2S rides again,
Thump-thump goes my little heart 🐇✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/3474-i2s-stage5

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…al-hw TU

Master's Stage 4 (#3478) linked
into the classic-ESP32 unity build. This branch restores Yves' proven
 +  driver. Having both together
triggers the ADC driver_ng-vs-legacy panic at boot, so the resolution
drops the Stage 4 real-hw TU (the modern peripheral interface stays
tested via the mock). Users get real WS2812 output through the
restored legacy addLeds<> path.
@zackees
zackees merged commit 67edc42 into master Jul 1, 2026
5 of 8 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jul 1, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jul 1, 2026
zackees added a commit that referenced this pull request Jul 1, 2026
Classic-ESP32 I2S parallel-out clockless driver now compiles on ESP-IDF
6.x, closing #3509 Phase 3.

## Changes

**New**: `src/platforms/esp/32/drivers/i2s/i2s_periph_compat.h`
- `fl::fl_i2s_periph_enable(port)` / `fl_i2s_periph_disable(port)`
  wrappers with an `ESP_IDF_VERSION`-based dispatch:
  - IDF 4.x / 5.x → `periph_module_enable(PERIPH_I2S{port}_MODULE)` +
    `periph_module_disable` (unchanged behavior, this is the path
    the Yves driver has been using in production since #3479 restore).
  - IDF 6.x+ → `i2s_ll_enable_bus_clock(port, true)` +
    `i2s_ll_reset_register(port)` from `hal/i2s_ll.h`. `periph_module_*`
    was removed in IDF 6; the LL API is the replacement surface.

**Updated**: `src/platforms/esp/32/drivers/i2s/i2s_esp32dev.cpp.hpp`
- Replaced the two `periph_module_enable(PERIPH_I2S{0,1}_MODULE)` calls
  in `i2s_init()` with a single `fl::fl_i2s_periph_enable(i2s_device)`
  hop through the compat shim.

**Updated**: `src/platforms/esp/32/feature_flags/enabled.h`
- Removed `!ESP_IDF_VERSION_6_OR_HIGHER` gate from `FASTLED_ESP32_HAS_I2S`.
  The feature-flag now enables the driver on IDF 6.x as well.

**Updated**: `src/platforms/esp/clockless.h`
- Same: dropped the IDF-6 exclusion from the `ClocklessI2S<>` selection.
  Users who set `-DFASTLED_ESP32_I2S=1` on IDF 6.x now get the driver
  wired up (previously they hit the RMT fallback silently).

## Verification

- `bash test --cpp`: 344/344 pass (host suite unchanged — compat shim
  is host-independent, only affects the ESP32 code path).
- `bash lint --cpp`: clean.
- Real IDF 6 silicon bench validation is #3509 Phase 7 — the LL
  API compat shim is written against the IDF 6 header surface but has
  not been booted on WROOM with IDF 6 yet.

## What this does NOT do

- Does NOT move DMA/ISR machinery from the classic driver into the
  modern `I2sPeripheralEsp32DevEsp` (Phase 2). That is a much larger
  refactor requiring bench validation on WROOM to prove ISR-driven
  buffer refill still works.
- Does NOT re-include `i2s_peripheral_esp32dev_esp.cpp.hpp` in the
  unity build (Phase 5) — depends on Phase 2.
- Does NOT resolve the singleton-state migration (Phase 6 / #3489).

Phase 1 (ADC:CONFLICT root cause) is documented in the #3509
tracker: the collision was `driver/i2s.h` in the Stage 2 (#3476) impl,
NOT `driver/gpio.h` in the current Stage 4 file. The current
`UNITY_BUILD_EXCLUDE` marker on the Stage 4 file is over-conservative;
that will be lifted when Phase 2 lands the real DMA/ISR implementation.

Part of #3509

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Jul 1, 2026
New `src/platforms/esp/32/drivers/i2s/README.md` documenting the
classic-ESP32 I2S parallel-out clockless driver as it stands today
(post #3479 restore + #3511/#3514 IDF6 compat +
#3518-#3520 selector cleanup + Phase 5 unity re-include).

Covers:

- **Files**: purpose of each `.h`/`.cpp.hpp` in the directory
- **User-facing binding today**: legacy `addLeds<>` via
  `-DFASTLED_ESP32_I2S=1` (production) vs modern channel-manager
  (not there yet — depends on Phase 4)
- **ESP-IDF version compat table**: IDF 4.x/5.x production; IDF 6.x
  compiles via the `i2s_periph_compat.h` shim (bench validation
  pending real WROOM + IDF 6 platform binding)
- **Streaming ISR DMA refill invariant**: the whole-point-of-I2S
  streaming pattern that any future refactor must preserve. Points at
  the ISR handler location and lists the three concrete guarantees.
- **Global state**: acknowledges the 10+ file-scope statics tracked
  under #3489, with the migration path via Phase 6.
- **Known bugs**: #1165 (`I2S_DEVICE=1` doesn't drive output)
  and #1384 (blocking `showPixels()`) with their respective
  fix paths through Phase 2 / Phase 4.
- **References**: cross-links to every open sub-issue, meta issue,
  and previous PR in the driver-dev umbrella.

Part of #3516 / #3512 Phase 8.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
zackees added a commit that referenced this pull request Jul 1, 2026
…se 2b) (#3540)

`I2sPeripheralEsp32DevEsp::initialize()` no longer stubs — it now
configures the I2S1 peripheral via the tested Yves C-style utilities
(`i2s_define_bit_patterns` + `i2s_init` from `i2s_esp32dev.h`) that
have been production since #3479.

## Hardware-ownership check

Adds `i2s_is_initialized()` guard so the modern peripheral refuses to
bind if the classic `ClocklessI2S<>` template on
`-DFASTLED_ESP32_I2S=1` already claimed I2S1. First-in-wins prevents
the two paths from racing on the shared hardware.

## Timing default

Chipset timing defaults to canonical WS2812B (`TIMING_WS2812_800KHZ`
via `to_runtime_timing<>`). Per-channel timing dispatch arrives with
the modern engine's Phase 2b-encoder integration — for now this
matches every previously-working I2S user's configuration.

## Scope

- `initialize()` now real (was stub returning true without touching
  hardware).
- `deinitialize()` still no-op — Phase 2b-deinit follow-up will free
  the ISR handle + DMA descriptors.
- `transmit()` still returns synchronous stub — Phase 2b-DMA
  follow-up wires the wave8 encoder (#3528) output through I2S1 DMA.

## Verification

- `bash test --cpp`: 345/345 pass (existing engine tests unchanged —
  no code path currently invokes `initialize()`).
- `bash lint --cpp`: file clean (unrelated pre-existing violations
  in `platforms/arm/lpc/rx_sct_capture.cpp.hpp` fixed in follow-up).
- **Bench**: `bash autoresearch esp32dev` flashes + boots clean on
  attached WROOM COM11 with new initialize() in the binary. `RESULT:
  {"type":"ready",...}` at ~2s uptime, ping successful. Since no
  code path invokes the modern peripheral in this build (`Bus::FLEX_IO, 0`
  still binds to `I2S_SPI` — Phase 2d does the swap), initialize() is
  dormant but present.

Part of #3516 meta / #3526 Phase 2b.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the feat/3474-i2s-stage5 branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant