Repository navigation
feat(i2s-esp32dev): Stage 5 — restore proven classic-ESP32 I2S driver alongside modern architecture (#3474) - #3479
Conversation
… 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]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThis PR restores the classic ESP32 register/DMA/ISR-based parallel I2S clockless LED driver. It adds a new Estimated code review effort: 4 (Complex) | ~60 minutes ChangesESP32 I2S Driver Restoration
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
Possibly related issues
Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
…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.
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]>
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]>
…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]>
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:
addLeds<WS2812, PIN, GRB>()path — routes throughclockless_i2s_esp32.h→I2SClocklessLedDriver→i2s_esp32devregister + DMA + ISR machinery. This is what actually generates WS2812 waveforms on hardware.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.I2sPeripheralEsp32DevEspis present as a compilable TU but intentionally NOT linked into the classic-ESP32 unity build in this PR — itsdriver/gpio.hinclude collided with the restored code at link time producing anADC: 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
RESULT: {"type":"ready","pinRx":19,"pinTx":18,"drivers":5,...}at 0.68s.testGpioConnection([[33, 34]])→connected: true.Test plan
bash compile esp32dev --examples AutoResearchsucceeds.bash test --cpp --clean— 344/344 pass.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
Bug Fixes