Skip to content

feat(i2s-esp32dev): Stage 4 — link real-hw peripheral into esp32dev build (#3474) - #3478

Merged
zackees merged 1 commit into
masterfrom
feat/3474-i2s-stage4
Jul 1, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/3474-i2s-stage4

Conversation

@zackees

@zackees zackees commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Stage 2 (#3476) shipped the real-hw peripheral impl but couldn't link it: `#include "driver/i2s.h"` tripped the runtime `ADC: CONFLICT!` panic. Stage 3 (#3477) deleted Yves' 1168-LoC third-party driver, clearing one obstacle. Stage 4 rewrites the peripheral impl to drop `driver/i2s.h` — the ecosystem `driver_ng` conflict no longer fires, and the real-hw TU is now linked into the classic-ESP32 build.

Ref #3474.

What changes

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. Only the impl bodies change: they now use `esp_heap_caps.h`, `driver/gpio.h`, standard FreeRTOS + `esp_err` (all `driver_ng`-neutral).

Runtime behaviour at Stage 4 v1:

  • `initialize()` stashes the config, 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 exactly like it does against the mock.

Verification on WROOM

Flashed to COM11:

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

Test plan

  • `bash compile esp32dev --examples AutoResearch` — succeeds.
  • WROOM boot + RPC + GPIO detection — clean.
  • `bash test --cpp --clean` — 344/344 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.

Stage 5 scope

  • Real `I2S1` register bring-up (clock, TX FIFO, GPIO matrix routing).
  • DMA descriptor chain construction.
  • ISR install on `ETS_I2S1_INTR_SOURCE` for true async completion.
  • Real wave8 parallel bit-transpose in `packScratchBuffer()`.
  • `BusTraits<Bus::FLEX_IO, 0>` switch on classic ESP32.
  • 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 bodies in `i2s_peripheral_esp32dev_esp.cpp.hpp` change.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Restored ESP32 classic audio support in the build so the real device implementation is included again.
    • Improved transmit handling so output completes cleanly without getting stuck during startup or busy-state checks.
  • Refactor

    • Streamlined low-level audio initialization to defer hardware setup to a later stage.

…uild (#3474)

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]>
@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: 41d6edfe-86e3-4ace-b9bc-8b50dd0f2a43

📥 Commits

Reviewing files that changed from the base of the PR and between c38172c and dff3b66.

📒 Files selected for processing (2)
  • src/platforms/esp/32/drivers/i2s/_build.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp

📝 Walkthrough

Walkthrough

This PR re-enables linking of the real ESP32-dev I2S peripheral implementation into the classic ESP32 unity build, alongside its mock. The peripheral implementation is refactored to a "Stage 4" model that removes direct driver/i2s.h usage, deferring register-level bring-up, DMA descriptor chains, and ISR install to a later stage; initialize()/deinitialize() now only track config/state, and transmit() uses a synchronous fake-async completion instead of the IDF driver write path.

Changes

Stage 4 I2S Peripheral Rework

Layer / File(s) Summary
Unity build include wiring
src/platforms/esp/32/drivers/i2s/_build.cpp.hpp
Includes both the real ESP32-dev I2S peripheral implementation and its mock, replacing the prior exclusion comment with documentation of why the TU now links (driver/i2s.h no longer conflicts with legacy adc.h init).
Stage 4 scope documentation and include removal
src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp
File comment expanded to describe Stage 4 scope versus Stage 5 deferred work; driver/i2s.h include removed from the extern "C" block.
initialize/deinitialize deferred bring-up
src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp
initialize() only stores the provided config instead of building i2s_config_t and calling i2s_driver_install; deinitialize() no longer uninstalls the driver, just resets state flags.
Buffer allocation and fake-async transmit
src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp
allocateBuffer() gains DMA-capable alignment documentation; transmit() drops i2s_write and instead marks not-busy and invokes the completion callback synchronously, keeping existing validation checks; waitTransmitDone() logic unchanged aside from a removed comment.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

Poem

A rabbit hops through I2S lanes,
Where driver/i2s.h no longer reigns,
Stage four whispers "not yet, not now,"
Buffers wait, DMA takes a bow,
Synchronous nods where hardware once spoke —
🐰 hop, hop, another stage awoke!

✨ 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-stage4

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.

@zackees
zackees merged commit e6fb6d8 into master Jul 1, 2026
6 of 9 checks passed
zackees added a commit that referenced this pull request Jul 1, 2026
…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 added a commit that referenced this pull request Jul 1, 2026
… 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]>
@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
zackees deleted the feat/3474-i2s-stage4 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