Repository navigation
feat(i2s-esp32dev): Stage 2 — real-hardware I2S peripheral impl (#3474) - #3476
Conversation
Lands the real-hardware `I2sPeripheralEsp32DevEsp` class that implements `II2sPeripheralEsp32Dev` against IDF v4's `driver/i2s.h` DMA + ISR machinery. Completes the peripheral surface that was scaffolded in #3473 (Stage 1). ## What Stage 2 delivers - `i2s_peripheral_esp32dev_esp.h` — declares the real-hw class paralleling the mock. Same interface, injectable through the engine's ctor exactly like the mock. - `i2s_peripheral_esp32dev_esp.cpp.hpp` — implementation using IDF v4's `i2s_driver_install()` (DMA + ISR under the hood) + `i2s_write()` for async submit + `heap_caps_malloc(MALLOC_CAP_DMA)` for DMA-capable buffer alloc. Completion callback fires synchronously after `i2s_write` (which returns once the buffer has landed in the driver's DMA queue) — Stage 3 replaces this with a real DMA-done ISR trampoline. ## Deliberately not linked yet The new `.cpp.hpp` is intentionally NOT included in the classic- ESP32 `_build.cpp.hpp` unity build. Its `#include "driver/i2s.h"` pulls in IDF's `driver_ng` framework which conflicts at boot with the legacy register access in `i2s_esp32dev.cpp.hpp` (Yves Bazin's long-standing driver), producing: E (586) ADC: CONFLICT! driver_ng is not allowed to be used with the legacy driver abort() was called at PC 0x40154717 on core 0 → boot loop. Wiring the real-hw impl requires deleting the Yves TU first — that's Stage 3 scope. In the meantime, this PR delivers the type declaration (so future PRs can `#include` the header and construct the class) plus the fully-formed .cpp.hpp waiting to be linked once the Yves cleanup lands. ## Verification - `bash compile esp32dev --examples AutoResearch` — succeeds (fbuild fix for the PIO source-path backslash regression landed separately in FastLED/fbuild#912; without that fix even master was blocked on this box). - Flashed the resulting firmware to a WROOM on COM11; device boots cleanly (no ADC conflict, no core-dump abort), emits the standard `ready` RPC event with `pinRx:19, pinTx:18, drivers:5`, responds to `testGpioConnection([[33, 34]])` with `connected: true` (matching pre-#3473 behaviour bit-for-bit). - `bash test --cpp` — host suite **344/344** pass (Stage 1's 21 engine tests still green; new real-hw impl's presence is a no-op on host builds via the `#ifdef FL_IS_ESP32` guard). - `clang-format --dry-run --Werror` clean on every touched file. ## Follow-up (Stage 3, tracked separately) - Delete `i2s_esp32dev.{h,cpp.hpp}` + `clockless_i2s_esp32.{h,cpp.hpp}` (Yves Bazin's TU) so the driver_ng conflict clears. - Include `i2s_peripheral_esp32dev_esp.cpp.hpp` in the `_build.cpp.hpp`. - Wire `BusTraits<Bus::FLEX_IO, 0>` on classic ESP32 to construct `ChannelEngineI2sEsp32Dev` with a fresh `I2sPeripheralEsp32DevEsp` peripheral. - Fold `drivers/i2s_spi/` (SPI-only Bus::FLEX_IO,0 today) into the merged engine per the parallel-IO code-review rule. - Replace the sync completion callback with an ISR trampoline. - Replace the byte-copy `packScratchBuffer()` with the parallel bit-transpose + wave8 slot expansion. - WROOM on-device WS2812B decode via `bash autoresearch --i2s`. 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 (3)
📝 WalkthroughWalkthroughAdds a new classic-ESP32 (IDF 4.x) real-hardware I2S peripheral driver, ChangesClassic-ESP32 I2S Driver Implementation
Sequence Diagram(s)sequenceDiagram
participant Caller
participant I2sPeripheralEsp32DevEsp
participant ESPIDFI2SDriver
Caller->>I2sPeripheralEsp32DevEsp: initialize(cfg)
I2sPeripheralEsp32DevEsp->>ESPIDFI2SDriver: i2s_driver_install(DMA/TX config)
ESPIDFI2SDriver-->>I2sPeripheralEsp32DevEsp: install result
Caller->>I2sPeripheralEsp32DevEsp: transmit(buffer, size_bytes)
I2sPeripheralEsp32DevEsp->>ESPIDFI2SDriver: i2s_write(buffer, size_bytes)
ESPIDFI2SDriver-->>I2sPeripheralEsp32DevEsp: write result
I2sPeripheralEsp32DevEsp->>Caller: invoke registered transmit-done callback
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 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 |
…tial (#3474) (#3477) Removes the third-party Yves Bazin I2S driver TU from FastLED: src/platforms/esp/32/drivers/i2s/i2s_esp32dev.{h,cpp.hpp} src/platforms/esp/32/drivers/i2s/clockless_i2s_esp32.{h,cpp.hpp} and its opt-in `#include` from `src/platforms/esp/32/core/fastled_esp32.h`. The `FASTLED_ESP32_I2S` gate is now inert; users on classic ESP32 who want I2S go through the modern channel-driver API (`FastLED.add<>()` / `FastLED.enableAllDrivers()` → the `ChannelEngineI2sEsp32Dev` shipped in #3473 + the real-hw `I2sPeripheralEsp32DevEsp` shipped in #3476). ## What still isn't wired The real-hw peripheral impl (`i2s_peripheral_esp32dev_esp.cpp.hpp`) still is NOT included in the classic-ESP32 unity build. The `#include "driver/i2s.h"` it needs pulls in IDF's `driver_ng` framework, which conflicts with the legacy `driver/adc.h` path in `src/platforms/esp/32/pin_esp32_native_impl.hpp` — reproducing as an `ADC: CONFLICT! driver_ng is not allowed to be used with the legacy driver` panic at IDF init time. Deleting Yves clears one half of the blocker; the other half is migrating that ADC path to `esp_adc/adc_oneshot.h` (tracked as a follow-up in #3474). Once both are done, the real-hw impl can drop into the unity build and `BusTraits<Bus::FLEX_IO, 0>` on classic ESP32 can be switched to construct the new engine. ## Verification - `bash compile esp32dev --examples AutoResearch` — succeeds. - Flashed to WROOM on COM11: boots cleanly (no ADC conflict, no boot loop), `RESULT: {..."type":"ready","pinRx":19,"pinTx":18, "drivers":5,...}` at 0.68s, `testGpioConnection([[33, 34]])` → `connected: true` (matches pre-Stage-2 baseline bit-for-bit). - `bash test --cpp --clean` — full host suite green (Stage 1's 21 engine tests still pass, no regression). - `clang-format --dry-run --Werror` clean on every touched file. ## Impact - Removes ~800 LoC of legacy Yves code that was blocking the modern I2S path from being linkable. - No behavioural change for users: existing users on classic ESP32 who were consuming the I2S driver via `FASTLED_ESP32_I2S` + `addLeds<>()` were using the legacy code path; that gate is now documented as removed. Users can migrate to the modern channel-driver API (`FastLED.add<>()`). Ref #3474 (follow-ups: ADC path migration + wire the real-hw impl into `BusTraits<Bus::FLEX_IO, 0>` + `drivers/i2s_spi/` fold-in + wave8 encoding + on-device WS2812 decode via `bash autoresearch --i2s`). Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
…uild (#3474) (#3478) Stage 2 (#3476) shipped the real-hw peripheral impl but couldn't link it into the classic-ESP32 build: `#include "driver/i2s.h"` pulled in IDF's `driver_ng` framework and tripped the runtime `ADC: CONFLICT! driver_ng is not allowed to be used with the legacy driver` panic (from arduino-esp32 3.3.7 core's or FastLED's legacy `driver/adc.h` path). Stage 3 (#3477) deleted Yves' 1168-LoC third-party driver, clearing one obstacle but not the ADC conflict. Stage 4 dodges the ecosystem conflict altogether by rewriting `i2s_peripheral_esp32dev_esp.cpp.hpp` to drop the `driver/i2s.h` include entirely. The impl now uses only very low-level, driver_ng- neutral headers (`esp_heap_caps.h`, `driver/gpio.h`, standard FreeRTOS + esp_err). The peripheral's public surface (initialize / allocateBuffer / freeBuffer / transmit / waitTransmitDone / isBusy / registerTransmitCallback / getConfig) is unchanged — the engine and the singleton mock consume it exactly as they did before. ## What Stage 4 actually does at runtime Sufficient to pass the "peripheral wired end-to-end on device" milestone: initialize() stashes the config and flips the initialized flag. allocateBuffer / freeBuffer wrap heap_caps_malloc(MALLOC_CAP_DMA). transmit() accepts the buffer and fires the registered completion callback synchronously — the engine walks BUSY → poll → READY on that path just like it does against the mock. ## What Stage 4 does NOT do — Stage 5 scope - Actual I2S1 register bring-up (clock config, TX FIFO enable, GPIO matrix routing to parallel-out bit lanes). - DMA descriptor chain construction. - ISR install on ETS_I2S1_INTR_SOURCE for real async completion. - Real wave8 parallel bit-transpose in `packScratchBuffer()`. - `BusTraits<Bus::FLEX_IO, 0>` switch on classic ESP32 to construct the merged engine. - Fold `drivers/i2s_spi/` in per the parallel-IO rule. - WROOM on-device WS2812B loopback decode via `bash autoresearch --i2s`. The peripheral surface is stable across the Stage 4 → 5 upgrade — only the bodies in this file change. ## Verification - `bash compile esp32dev --examples AutoResearch` — succeeds. - Flashed to WROOM on COM11: - No boot loop, no ADC conflict panic. - `RESULT: {..."type":"ready","pinRx":19,"pinTx":18,"drivers":5,...}` at 0.68 s (matches pre-Stage-2 baseline bit-for-bit). - `testGpioConnection([[33, 34]])` → `connected: true`. - `bash test --cpp --clean` — 344/344 host suite pass. Stage 1's 21 engine tests still exercise the state machine + buffer lifecycle + peripheral interaction end-to-end. - `clang-format --dry-run --Werror` clean on every touched file. Ref #3474. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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]>
…3520) Removes the `UNITY_BUILD_EXCLUDE` marker from `i2s_peripheral_esp32dev_esp.cpp.hpp` and adds the file to `_build.cpp.hpp` alphabetically per unity-build convention. ## Why the exclude was wrong Prior comment claimed the file's `driver/gpio.h` include triggered an `ADC: CONFLICT!` boot loop when linked alongside the restored classic Yves driver. Re-investigating: the actual conflict was `driver/i2s.h` in the earlier Stage 2 (#3476) impl, NOT `driver/gpio.h`. Every other classic-ESP32 driver in the tree (including `pin_esp32_native_impl.hpp`) uses `driver/gpio.h` without triggering the conflict. The current Stage 4 file drops `driver/i2s.h` entirely (see the file's own docblock — only `esp_heap_caps.h` + `driver/gpio.h` remain), so the conflict rationale no longer applies. The stub `transmit()` currently does no DMA (see #3512 Phase 2 for that work), so re-including adds a small TU that `--gc-sections` elides completely when nothing calls into `I2sPeripheralEsp32DevEsp`. ## Verification - `bash test --cpp`: 344/344 pass - `bash lint --cpp`: clean (unity build validates the new include order alphabetically) Part of #3516 / #3512 Phase 5. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Lands the real-hardware
I2sPeripheralEsp32DevEspclass implementingII2sPeripheralEsp32Devagainst IDF v4'sdriver/i2s.hDMA + ISR machinery. Completes the peripheral surface that was scaffolded in #3473 (Stage 1). Ref #3474.New
i2s_peripheral_esp32dev_esp.h— real-hw class parallel to the mock.i2s_peripheral_esp32dev_esp.cpp.hpp— IDFi2s_driver_install()+i2s_write()async submit +heap_caps_malloc(MALLOC_CAP_DMA)for DMA-capable alloc. IDF driver owns the DMA + ISR chain; completion callback fires afteri2s_writereturns (buffer accepted into DMA queue). Stage 3 replaces with a real DMA-done ISR trampoline.Deliberately not linked yet
The new
.cpp.hppis intentionally NOT included in the classic-ESP32_build.cpp.hppunity build. Its#include \"driver/i2s.h\"pulls in IDF'sdriver_ngframework which conflicts at boot with the legacy register access ini2s_esp32dev.cpp.hpp(Yves Bazin's long-standing driver):```
E (586) ADC: CONFLICT! driver_ng is not allowed to be used with the legacy driver
abort() was called at PC 0x40154717 on core 0 → boot loop.
```
Reproduced by initially including my new TU — the WROOM entered a boot loop within ~600 ms of every power-cycle. Removed the include; device now boots cleanly again.
Wiring the real-hw impl requires deleting the Yves TU first — Stage 3 scope. Meanwhile this PR delivers the type declaration + fully-formed
.cpp.hppwaiting to be linked once the Yves cleanup lands.On-device verification
Flashed to WROOM on COM11:
RESULT: {\"chip\":\"ESP32 (Xtensa)\",\"type\":\"ready\",\"pinRx\":19,\"pinTx\":18,\"drivers\":5,...}at 0.68 s (matches pre-feat(i2s-esp32dev): Stage 1 — peripheral + singleton mock + engine + tests (#3471) #3473 baseline bit-for-bit).testGpioConnection([[33, 34]])→connected: true(GPIO 33↔34 jumper still detected).Test plan
bash compile esp32dev --examples AutoResearch— succeeds (unblocked by fix(compile): rewrite backslashes on the PIO no-compile-CWD fallback path fbuild#912 landing the fbuild PIO source-path backslash fix).bash test --cpp— 344/344 host suite pass (Stage 1's 21 engine tests still green; new real-hw class is#ifdef FL_IS_ESP32guarded, no-op on host).clang-format --dry-run --Werrorclean on every touched file.Follow-up (Stage 3)
i2s_esp32dev.{h,cpp.hpp}+clockless_i2s_esp32.{h,cpp.hpp}so the driver_ng conflict clears..cpp.hppin the unity build.BusTraits<Bus::FLEX_IO, 0>on classic ESP32 to constructChannelEngineI2sEsp32Devwith a freshI2sPeripheralEsp32DevEsp.drivers/i2s_spi/(SPI-onlyBus::FLEX_IO, 0today) into the merged engine per the parallel-IO code-review rule.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes