Skip to content

feat(i2s-esp32dev): enable IDF 6+ via i2s_ll_* compat shim (#3509 Phase 3) - #3511

Merged
zackees merged 1 commit into
masterfrom
feat/i2s-unified-3509
Jul 1, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/i2s-unified-3509

Conversation

@zackees

@zackees zackees commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Enables the classic-ESP32 I2S parallel-out clockless driver on ESP-IDF 6.x by wrapping the peripheral clock/reset calls in an IDF-version-aware compat shim. Closes #3509 Phase 3.

Users on classic ESP32 with -DFASTLED_ESP32_I2S=1 now get the driver on IDF 4.x, 5.x, AND 6.x. Previously IDF 6 silently fell back to RMT because PERIPH_I2S1_MODULE was removed.

Approach

New src/platforms/esp/32/drivers/i2s/i2s_periph_compat.h:

inline bool fl_i2s_periph_enable(int port) {
#if !ESP_IDF_VERSION_6_OR_HIGHER
    periph_module_enable(port == 0 ? PERIPH_I2S0_MODULE : PERIPH_I2S1_MODULE);
#else
    i2s_ll_enable_bus_clock(port, true);
    i2s_ll_reset_register(port);
#endif
    return true;
}

The classic driver (i2s_esp32dev.cpp.hpp) swaps its two periph_module_enable(PERIPH_I2S{0,1}_MODULE) calls for one fl::fl_i2s_periph_enable(i2s_device). The feature-flag gate (FASTLED_ESP32_HAS_I2S) and the top-level clockless selector (platforms/esp/clockless.h) both drop their !ESP_IDF_VERSION_6_OR_HIGHER exclusions.

Scope of this PR (Phase 3 only)

  • IDF 6+ LL API port for periph clock enable/reset
  • Feature flag + clockless dispatch updated
  • Host tests pass (344/344)
  • Lint clean

What's NOT in this PR (tracked separately in #3509)

  • Phase 1 — root-cause ADC: CONFLICT runtime crash. Investigation in the commit body documents the finding (the collision was driver/i2s.h in Stage 2, not driver/gpio.h in Stage 4 — current UNITY_BUILD_EXCLUDE marker is over-conservative).
  • Phase 2 — moving the ~300 LoC of DMA descriptor chain + IRAM ISR machinery from Path A (classic Yves driver) into I2sPeripheralEsp32DevEsp::transmit(). This is a careful refactor that needs WROOM bench validation to prove buffer-refill ISR behavior is preserved.
  • Phase 4 — rewiring ClocklessI2S<> template through the peripheral interface (depends on Phase 2).
  • Phase 5 — re-including the modern peripheral impl in the unity build (depends on Phase 2).
  • Phase 6 — global-state → Singleton<T> migration (singleton: migrate i2s_esp32dev driver state — 19 hits, ISR pattern (Tier 2a) #3489).
  • Phase 7 — WROOM hardware validation on IDF 4.x, 5.x, AND 6.x.
  • Phase 8 — README.

Each phase is scoped for its own PR so bench validation can be attached to each landing.

Test plan

  • bash test --cpp — 344/344 pass on host (this compat shim is compile-time only, doesn't affect the host path).
  • bash lint --cpp — clean.
  • CI: bash compile esp32dev --examples AutoResearch on IDF 5.x (existing path, should be a no-op change).
  • Bench (blocking for I2S classic-ESP32: unify Yves + modern paths and add IDF 6+ (LL API) support #3509 close, NOT for this PR merge): WROOM COM11 + bash autoresearch --i2s loopback on IDF 6.x once an IDF 6 build target is added to the CI matrix. Result is currently unverified because no IDF 6 target exists in the tree yet.

Follow-up

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added broader ESP32 I2S support across ESP-IDF versions, including newer releases.
    • Introduced compatibility handling so I2S can be enabled and reset consistently on supported devices.
  • Bug Fixes

    • Fixed ESP32 builds where I2S support could be incorrectly disabled on newer ESP-IDF versions.
    • Improved fallback behavior for invalid or unsupported I2S ports.

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
zackees merged commit 8d69069 into master Jul 1, 2026
6 of 9 checks passed
@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: d2a98bd9-6f7e-4549-a633-72dad0874f11

📥 Commits

Reviewing files that changed from the base of the PR and between 70cedf0 and c02ef73.

📒 Files selected for processing (4)
  • src/platforms/esp/32/drivers/i2s/i2s_esp32dev.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/i2s_periph_compat.h
  • src/platforms/esp/32/feature_flags/enabled.h
  • src/platforms/esp/clockless.h

📝 Walkthrough

Walkthrough

This PR introduces a new i2s_periph_compat.h compatibility header providing fl_i2s_periph_enable/fl_i2s_periph_disable functions that dispatch between classic periph_module_enable/disable (IDF 4.x/5.x) and LL HAL calls (IDF 6.x+). The classic ESP32 I2S driver and feature-flag/clockless gating are updated to use this shim, removing prior ESP-IDF 6.0+ exclusions.

Changes

ESP32 I2S peripheral compat shim

Layer / File(s) Summary
Peripheral compat shim header
src/platforms/esp/32/drivers/i2s/i2s_periph_compat.h
New header defines fl::fl_i2s_periph_enable(port)/fl::fl_i2s_periph_disable(port), validating port 0/1 and dispatching to classic periph_module_enable/disable on IDF < 6 or i2s_ll_enable_bus_clock/i2s_ll_reset_register on IDF ≥ 6.
Driver integration and gating updates
src/platforms/esp/32/drivers/i2s/i2s_esp32dev.cpp.hpp, src/platforms/esp/32/feature_flags/enabled.h, src/platforms/esp/clockless.h
i2s_init now calls fl::fl_i2s_periph_enable(i2s_device) instead of direct periph_module_enable calls; FASTLED_ESP32_HAS_I2S and clockless controller selection no longer exclude ESP-IDF 6.0+.

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

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3477: Both touch i2s_esp32dev.cpp.hpp's peripheral enable logic in i2s_init.
  • FastLED/FastLED#3479: This PR builds on the classic I2S driver restored in the referenced PR, updating its peripheral enable/reset logic.
✨ 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/i2s-unified-3509

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.

@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
…section (#3514)

The IDF 6 compat shim landed in #3511 calls `i2s_ll_enable_bus_clock` +
`i2s_ll_reset_register` directly. Verified against real ESP-IDF master
source at `components/esp_hal_i2s/esp32/include/hal/i2s_ll.h`: both
functions have macro-form wrappers in the header that require
`__DECLARE_RCC_ATOMIC_ENV` to be declared in scope, which means the
current shim would fail to compile on real IDF 6 because that variable
isn't in scope of the caller.

The correct pattern (as used by IDF 6's own `components/esp_driver_i2s/
i2s_platform.c`) is to wrap the LL calls in `PERIPH_RCC_ATOMIC() { }`
from `esp_private/periph_ctrl.h`. That macro provides the required
`__DECLARE_RCC_ATOMIC_ENV` variable and manages the peripheral RCC
critical section acquire/release.

## Symbol verification (against espressif/esp-idf@master)

Signatures confirmed to match the shim:
- `static inline void i2s_ll_enable_bus_clock(int i2s_id, bool enable)`
- `static inline void i2s_ll_reset_register(int i2s_id)`

The public-safe caller pattern from `i2s_platform.c`:
```c
PERIPH_RCC_ATOMIC() {
    i2s_ll_enable_bus_clock(id, true);
    i2s_ll_reset_register(id);
    i2s_ll_enable_core_clock(I2S_LL_GET_HW(id), true);
}
```

This shim now matches that pattern.

## Verification

- `bash test --cpp`: 344/344 pass (compat shim is IDF 6-only, host tests
  unchanged).
- Real IDF 6 silicon bench: still tracked under #3512 Phase 7 (external
  blocker — pioarduino IDF 6 platform binding not shipping yet).

Part of #3509 (which is closed) — this is a defect fix on the Phase 3
compat shim that landed in #3511.

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
zackees deleted the feat/i2s-unified-3509 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.

I2S classic-ESP32: unify Yves + modern paths and add IDF 6+ (LL API) support

1 participant