Repository navigation
feat(i2s-esp32dev): Stage 1 — peripheral + singleton mock + engine + tests (#3471) - #3473
Conversation
… ChannelEngine + tests (#3471) Ground-up rewrite of the classic-ESP32 I2S LED path, following the S3 LCD_CAM sibling's shape line-for-line. This is Stage 1 of the issue's plan — the peripheral interface, the singleton host mock, the ChannelEngine, and full unit tests. Stage 2 (real-hw impl + BusTraits switch + deletion of the Yves Bazin code) is deferred to a follow-up because on-device WROOM validation is blocked on this box by the pre-existing fbuild spec-file backslash regression. ## New files - `src/platforms/esp/32/drivers/i2s/ii2s_peripheral_esp32dev.h` — virtual peripheral interface. Full async DMA-streaming surface (initialize / allocateBuffer / transmit / waitTransmitDone / isBusy / registerTransmitCallback / freeBuffer) so Stage 2 doesn't need to change the callable shape. - `src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_mock.{h,cpp.hpp}` — host-side singleton mock. Same shape as every other peripheral mock in the tree: abstract public class + concrete `Impl` private to the .cpp.hpp, `static instance()` via `fl::Singleton<Impl>`, single-threaded by design (no `std::thread`, no async callbacks — tests advance simulation manually via `simulateTransmitDone()`). Error-injection knobs for every fallible entry point, transmit- history recording, allocation-count / outstanding-buffer tracking so tests can catch leaks in the engine's buffer lifetime. - `src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.{h,cpp.hpp}` — the ChannelEngine. Takes `fl::shared_ptr<II2sPeripheralEsp32Dev>` via constructor, reports `Capabilities(true, true)` per the parallel-IO code-review rule (one engine handles both clockless and SPI, dispatched per-channel at show() time based on data->isSpi()). State machine: READY → enqueue → show → BUSY → poll (peripheral completion callback flips a flag; poll picks it up and drops back to READY). Stage 1 packing is linear byte concatenation into a DMA-capable scratch buffer allocated via the peripheral. Stage 2 replaces packScratchBuffer() with the parallel bit-transpose + wave8 slot expansion so the emitted waveform drives real WS2812 timing — no other changes required. - `tests/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp` — 21 host FL_TEST_CASEs covering: constructor + callback registration, name / Capabilities, canHandle null-rejection, state-machine transitions, transmit payload capture and byte- ordering, allocation reuse vs reallocation on larger frames, no buffer leak on destructor, error injection for initialize / allocateBuffer / transmit / registerCallback, setInUse channel accounting during BUSY, enqueue-during-BUSY isolation, and a full 4-frame cycle. All 21 pass. ## Wiring the mock into the engine tests Tests use the same singleton + MockWrapper forwarder pattern the S3 sibling uses (`tests/.../channel_driver_i2s.cpp:43-87`) — the `MockWrapper` class in the test TU forwards every II2sPeripheralEsp32Dev method to `I2sPeripheralEsp32DevMock::instance().foo(...)`, and the engine ctor gets `fl::make_shared<MockWrapper>()`. This is now codified as a required pattern in .coderabbit.yaml and agents/docs/cpp-standards.md — see the new "Peripheral Mocks: Singleton + MockWrapper Forwarder" rule. ## Non-changes (deferred to Stage 2) - `BusTraits<Bus::FLEX_IO, 0>` on classic ESP32 still routes to the SPI-only i2s_spi/ driver. The new engine is available but not yet the default for the platform. - `i2s_esp32dev.{h,cpp.hpp}` (Yves Bazin) still present. Deletion lands with the BusTraits switch. - `clockless_i2s_esp32.h` (legacy addLeds<> template) unchanged. - `drivers/i2s_spi/` unchanged. - `packScratchBuffer()` is byte-copy, not bit-transpose — Stage 2 work. - `I2sPeripheralEsp32DevEsp` real-hardware impl not landed here. The peripheral surface is stable, so Stage 2 adds it without touching the engine or the mock. ## Doc updates Both .coderabbit.yaml and agents/docs/cpp-standards.md now spell out that peripheral mocks MUST use the singleton pattern, and that engine tests wire them in via the MockWrapper forwarder. This was already the de-facto convention across every peer mock in the tree (RMT4/5, UART, S3 LCD_CAM, SPI, FlexIO); making it explicit stops new code from drifting into per-test factory patterns. ## Tests - `bash test channel_engine_i2s_esp32dev --cpp --clean` — 21/21 pass. - `bash test --cpp` — 343/343 host suite pass (no regression). - `clang-format --dry-run --Werror` clean on every new + edited file. - `bash compile esp32dev` — pre-existing fbuild Windows spec-file backslash regression continues to block local compile. Not this PR. CI on Linux exercises the cross-compile. Ref #3471 (Stage 2 completes the issue). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Caution Review failedThe pull request is closed. Warning Ignoring CodeRabbit configuration file changes. For security, only the configuration from the base branch is applied for open source repositories. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
📝 WalkthroughWalkthroughThis PR adds a new classic ESP32 I2S channel engine driver (ChannelEngineI2sEsp32Dev) with a platform-agnostic peripheral interface (II2sPeripheralEsp32Dev), a host-side singleton mock implementation, unity-build wiring, host tests, and documentation/review-config updates specifying the required singleton + MockWrapper testing pattern for peripheral mocks. ChangesESP32 I2S Channel Engine
Sequence Diagram(s)sequenceDiagram
participant Test
participant ChannelEngineI2sEsp32Dev
participant I2sPeripheralEsp32DevMock
Test->>ChannelEngineI2sEsp32Dev: enqueue(channelData)
Test->>ChannelEngineI2sEsp32Dev: show()
ChannelEngineI2sEsp32Dev->>I2sPeripheralEsp32DevMock: initialize(config) [first call]
ChannelEngineI2sEsp32Dev->>I2sPeripheralEsp32DevMock: allocateBuffer(size)
ChannelEngineI2sEsp32Dev->>I2sPeripheralEsp32DevMock: transmit(scratchBuffer, size)
I2sPeripheralEsp32DevMock-->>ChannelEngineI2sEsp32Dev: state = BUSY
Test->>I2sPeripheralEsp32DevMock: simulateTransmitDone()
I2sPeripheralEsp32DevMock-->>ChannelEngineI2sEsp32Dev: onTransmitDoneTrampoline callback
Test->>ChannelEngineI2sEsp32Dev: poll()
ChannelEngineI2sEsp32Dev-->>Test: state = READY
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 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 |
… (#3476) 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]>
…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]>
… alongside modern architecture (#3474) (#3479) 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]>
Summary
Ground-up rewrite of the classic-ESP32 I2S LED path, Stage 1 — the peripheral interface, singleton host mock, ChannelEngine, and full unit tests. Mirrors the S3 LCD_CAM sibling's shape line-for-line.
Stage 2 (real-hw impl +
BusTraits<Bus::FLEX_IO, 0>switch + deletion of the Yves Bazin code) is deferred to a follow-up because on-device WROOM validation is blocked on this box by the pre-existing fbuild spec-file backslash regression.Ref #3471 (Stage 2 completes the issue).
New files
ii2s_peripheral_esp32dev.h— virtual peripheral interface. Full async DMA-streaming surface (initialize/allocateBuffer/transmit/waitTransmitDone/isBusy/registerTransmitCallback/freeBuffer) so Stage 2 doesn't need to change the callable shape.i2s_peripheral_esp32dev_mock.{h,cpp.hpp}— host-side singleton mock. Abstract public class + concreteImplprivate to the.cpp.hpp,static instance()viafl::Singleton<Impl>, single-threaded by design (nostd::thread, no async callbacks — tests advance simulation manually viasimulateTransmitDone()). Error-injection knobs for every fallible entry point, transmit-history recording, allocation-count / outstanding-buffer tracking.channel_engine_i2s_esp32dev.{h,cpp.hpp}— the ChannelEngine. Takesfl::shared_ptr<II2sPeripheralEsp32Dev>via constructor, reportsCapabilities(true, true)per the parallel-IO rule.tests/.../channel_engine_i2s_esp32dev.cpp— 21 hostFL_TEST_CASEs.Mock consumption pattern (now a documented standard)
Singleton mock +
MockWrapperforwarder — the same pattern the S3 sibling uses attests/.../channel_driver_i2s.cpp:43-87. TheMockWrapperclass in the test TU forwards every interface method toI2sPeripheralEsp32DevMock::instance().foo(...), and the engine ctor getsfl::make_shared<MockWrapper>().Codified as mandatory in
.coderabbit.yamlandagents/docs/cpp-standards.md— see the new "Peripheral Mocks: Singleton + MockWrapper Forwarder" rule. Was already the de-facto convention across every peer mock (RMT4/5, UART, S3 LCD_CAM, SPI, FlexIO); making it explicit stops new code from drifting into per-test factory patterns.State machine
Async DMA streaming path
Engine registers
onTransmitDoneTrampolinewith the peripheral at construction time. Real hardware fires the trampoline from the DMA-done ISR; the mock fires it fromsimulateTransmitDone()on the test thread — same call path, same semantics.Stage 1 packing is byte-copy for now. Stage 2 replaces
packScratchBuffer()with the parallel bit-transpose + wave8 slot expansion so the emitted waveform drives real WS2812 timing — no other changes required.Non-changes (deferred to Stage 2)
BusTraits<Bus::FLEX_IO, 0>on classic ESP32 still routes to the SPI-onlyi2s_spi/driver.i2s_esp32dev.{h,cpp.hpp}(Yves Bazin) still present.clockless_i2s_esp32.h(legacyaddLeds<>) unchanged.drivers/i2s_spi/unchanged.I2sPeripheralEsp32DevEspreal-hardware impl not landed here — peripheral surface is stable, so Stage 2 adds it without touching the engine or the mock.Test plan
bash test channel_engine_i2s_esp32dev --cpp --clean— 21/21 pass.bash test --cpp— 343/343 host suite (no regression).clang-format --dry-run --Werrorclean on every new + edited file.bash compile esp32dev --examples AutoResearch— pre-existing fbuild Windows spec-file backslash regression continues to block local compile. Not this PR. CI on Linux exercises the cross-compile.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Documentation