Repository navigation
feat(i2s): Phase 2b step C — GPIO mux routing for I2S1 lanes (#3526) - #3558
Conversation
…e COM port Previously the unified WDT was armed lazily by FL_WATCHDOG_AUTO() at the top of loop(). If setup() hung (RPC bind null-deref, stalled static-init, wedged serial handshake), no WDT was armed and the COM port stayed owned by a dead sketch until manual power-cycle. Arm the WDT with a 20 s window at the very top of setup() so a hang here auto-reboots. Feed the WDT in the serial-monitor wait loop because on classic ESP32 (non-USB-CDC) that loop can span up to AUTORESEARCH_SERIAL_WAIT_MS = 120 s, well past the setup WDT window. FL_WATCHDOG_AUTO() at loop() top re-arms with the shorter loop-scoped timeout once setup() has finished. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Adds `encodeChannelWave3_i2s1` alongside the existing `encodeChannelWave8_i2s1` to satisfy the meta-issue acceptance criterion "Wave3 fallback path exercised for a three-slot chipset". Wave3 saves 2.67x memory vs wave8 for chipsets whose T1/T2/T3 timing rounds to 1/2/N ticks per 3, gated by `fl::canUseWave3(timing)`. Pixel clock is per-chipset via `fl::wave3ClockFrequencyHz(timing)` instead of the fixed 8 MHz wave8 rate. The encoder reuses the shared `fl::wave3Transpose_16` kernel from `fl/channels/wave3.h` — same anti-drift rule as the wave8 sibling. Host tests verify byte-exact output against a direct-kernel-call reference using canonical WS2812 timing (verified wave3-eligible). Drops the `fl/channels/detail/wave3.hpp` and `detail/wave8.hpp` force-inline includes from this .cpp.hpp — the unity build pulls this file across multiple TUs and the force-inline kernels would emit in each. The public `.h` declarations resolve at link time to the single out-of-line definitions in `wave3.cpp.hpp` / `wave8.cpp.hpp`, avoiding double-inline bloat. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
….hpp The former `fl/channels/detail/wave3.hpp` and `detail/wave8.hpp` were force-inline headers (`FASTLED_FORCE_INLINE FL_IRAM FL_OPTIMIZE_FUNCTION`). Every translation unit that included them emitted the full transpose kernel body. With ~10 callers across PARLIO / LCD_CAM / LCD_SPI / I2S drivers and the public wave3/wave8 wrappers, that was ~10× the transpose code in the final binary. Split into: - `detail/wave3.h` + `detail/wave8.h` — declarations, constexpr LUTs that need compile-time visibility, and the `FL_WAVE8_SPREAD_TO_16` helper macro (kept in the .h since it's a #define) - `detail/wave3.cpp.hpp` + `detail/wave8.cpp.hpp` — out-of-line definitions (dropped FASTLED_FORCE_INLINE, kept FL_IRAM + FL_OPTIMIZE_FUNCTION for perf), compiled once via the channels/detail unity build Updated 6 caller files (+2 tests) to include the new `.h` headers instead of the deleted `.hpp` files. The public API (`wave3Transpose_*` / `wave8Transpose_*` in `wave3.h` / `wave8.h`) is untouched — this is a pure implementation refactor. Perf note: dropping FASTLED_FORCE_INLINE means the transpose kernels no longer get inlined into every caller. On the in-order RV32 P4 core this could regress the encode-loop-hot-path per-frame timing measured in #2548 by a few percent (from lost cross-position ILP inside the same function scope). If bench data shows a regression, the fix is to keep the specific hot-path kernels (bf1_pipe4, etc.) FASTLED_FORCE_INLINE in the .h — the pattern here is per-function, not all-or-nothing. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…ipheral (#3526) Drops the `#include \"platforms/esp/32/drivers/i2s/i2s_esp32dev.h\"` from `I2sPeripheralEsp32DevEsp::initialize`/`deinitialize`. Replaces the calls to Yves's `i2s_define_bit_patterns` / `i2s_init` / `i2s_stop` with direct register writes on `I2S0`/`I2S1` via `soc/i2s_struct.h`. Fixed 8 MHz pixel clock for wave8 output (80 MHz APB / (10 + 0/1)) — no per-chipset clock math. This is the general-clockless architecture the meta issue mandates (PARLIO-style), NOT Yves's per-chipset bit-pattern encoder. Register-write sequence mirrors Yves's proven init sequence exactly: - reset (`lc_conf` + `conf` reset flags) - reset DMA (`lc_conf.in_rst`/`out_rst`) - reset FIFO (`conf.rx_fifo_reset`/`tx_fifo_reset`) - parallel mode (`conf2.lcd_en = 1`, 16-lane width) - 32-bit-parallel sample rate config - fixed 8 MHz clkm divider (N=10, A=1, B=0) - FIFO in DMA-serviced 32-bit mode - PCM bypass Ownership tracked via a private static `g_i2s1_hardware_claimed_by_modern` flag — no dependency on Yves's `gInitializedI2sInitialized`. During the rollout only one binding path is active at a time (Yves via `-DFASTLED_ESP32_I2S=1`, modern via `Bus::FLEX_IO, 0` after Phase 2d), so there is no cross-driver race. `deinitialize()` clears `tx_start` + resets the block directly. `transmit()` remains a stub — Phase 2b step B lands the `lldesc_t` descriptor ring, `esp_intr_alloc()` ISR install, and real DMA kick. ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` after WDT-driven recovery from the intermittent first-boot `fl::json::json(const char*)` panic (unrelated pre-existing bug tracked separately) ## Also included Updates two AutoResearch example headers I missed in the earlier detail-split sweep (#3555): - `examples/AutoResearch/AutoResearchParlioEncode.h` - `examples/AutoResearch/AutoResearchWave8Expand.h` Both now include `fl/channels/detail/wave8.h` (declarations) instead of the deleted force-inline `.hpp`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Completes the real-hardware DMA path on the modern I2S1 peripheral. `transmit()` now: 1. Points a DMA-capable `lldesc_t` at the caller's buffer 2. Resets the peripheral, arms `out_link.addr` + `out_link.start` 3. Enables the pre-installed OUT_EOF ISR 4. Flips `mBusy = true` and starts the DMA (`conf.tx_start = 1`) The ISR trampoline `i2s_dma_isr_trampoline` (FL_IRAM, ISR context) clears the interrupt, stops `tx_start`, and calls `I2sPeripheralEsp32DevEsp::finishTransmitFromIsr()` which flips `mBusy = false` and dispatches the registered completion callback (the channel-engine trampoline just flips its `mTransmitCompleted` flag — already ISR-safe). Descriptor allocated at `initialize()` time via `heap_caps_malloc` with `MALLOC_CAP_DMA` (DMA-capable DRAM). ISR handle allocated via `esp_intr_alloc(ETS_I2S1_INTR_SOURCE, ESP_INTR_FLAG_IRAM, ...)`. Both released in `deinitialize()`. `waitTransmitDone(timeout_ms)` is now a real deadline-bounded spin that yields via `vTaskDelay(1)` while `mBusy` — no more (void)timeout fake return. ## Scope limits (deferred to follow-up) - **Single descriptor, one-shot only**: buffers larger than 4092 bytes are rejected (the `lldesc_t` length field is 12 bits). Streaming refill from the ISR — for full-frame 128-byte-per-lane-per-strip wave8 output past 4 KB — is a follow-up. - **No GPIO mux routing**: the peripheral is configured for parallel- out but the 16 lane pins are not yet mapped via `gpio_matrix_out` — that's Phase 2b step C (which adds `configureTiming` + per-channel GPIO plumbing on the engine side). ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` (WDT recovery from the intermittent first-boot panic works cleanly). Modern engine is inert at runtime (not bound to `Bus::FLEX_IO, 0` yet — that's Phase 2d), so the DMA/ISR code compiles + boots but doesn't execute on this run. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Adds `II2sPeripheralEsp32Dev::routeLanePin(lane, gpio_pin)` for wiring
one parallel-out data lane to a specific GPIO pin. Called by the
engine (in a follow-up) after `initialize()` for each active channel,
before the first `transmit()`.
## Real hardware impl
`I2sPeripheralEsp32DevEsp::routeLanePin` uses the IDF v5-safe
`esp_rom_gpio_connect_out_signal(gpio_num, signal_idx, out_inv,
oen_inv)` API (replaces the legacy `gpio_matrix_out`). Signal index
computed as `I2S{n}O_DATA_OUT0_IDX + lane`, honoring the peripheral
config's per-strip invert mask so chipsets needing polarity inversion
get it "for free" through the GPIO matrix rather than in the encoder.
Pin put into output mode via `gpio_set_direction`.
## Mock
`I2sPeripheralEsp32DevMock::routeLanePin` records the (lane, pin)
pair. Two new introspection methods for tests:
- `laneRouteInvocationCount()` — call count since last `reset()`
- `lastRoutedPinForLane(lane)` — most recent pin, or -1 if unrouted
## Test coverage
New host test `Modern I2S peripheral: routeLanePin records mock mapping`:
- Uninitialised peripheral rejects the route
- Multiple lane routings recorded correctly
- Out-of-range lanes (16, 17) rejected
- Re-routing replaces the previous pin
- `reset()` clears everything
## Bench
- `bash test --cpp` — 346/346 tests pass (new test brings total up by 1)
- `bash lint --cpp` — clean
- `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS
- Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots,
RPC `ping` returns `pong, success: True, uptimeMs: 2066`
## What's still gated on Phase 2b step D
- Streaming DMA descriptor ring (current impl is single-descriptor,
4092-byte limit)
- Engine-side `configureTiming()` that plumbs per-channel GPIO pins
from `ChannelData::getPin()` down to `routeLanePin` calls
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThis PR adds ChangesESP32 I2S lane routing
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (2)
src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_mock.cpp.hpp (1)
171-173: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the I2S lane limit into a shared constant
The16lane cap is duplicated inrouteLanePin,lastRoutedPinForLane, andmLaneRoutedPin; pull it into a shared constant used by the mock and the real ESP32 implementation.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_mock.cpp.hpp` around lines 171 - 173, The I2S lane cap is hardcoded in multiple places, so replace the duplicated 16 check with a shared constant and use it consistently in routeLanePin, lastRoutedPinForLane, and mLaneRoutedPin, matching the same constant in the real ESP32 implementation as well. Update the mock and implementation to reference that shared symbol so the lane limit is defined in one place and stays in sync.src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp (1)
428-442: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win
waitTransmitDonedeadline math doesn't handleTickType_twraparound.
deadline = start + pdMS_TO_TICKS(timeout_ms)followed byxTaskGetTickCount() >= deadlinebreaks once the 32-bit tick counter wraps (every ~49.7 days at 1kHz tick rate, longer at the ESP-IDF default 100Hz). On a continuously-running LED controller this window will eventually be hit, causing either a spurious immediate timeout or an unbounded wait. Use a signed-difference comparison, the standard FreeRTOS-safe pattern.♻️ Wraparound-safe wait
bool I2sPeripheralEsp32DevEsp::waitTransmitDone(u32 timeout_ms) FL_NO_EXCEPT { const TickType_t start = xTaskGetTickCount(); - const TickType_t deadline = start + pdMS_TO_TICKS(timeout_ms); + const TickType_t timeout_ticks = pdMS_TO_TICKS(timeout_ms); while (mBusy) { - if (xTaskGetTickCount() >= deadline) { + if ((TickType_t)(xTaskGetTickCount() - start) >= timeout_ticks) { return false; } vTaskDelay(1); } return true; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp` around lines 428 - 442, `I2sPeripheralEsp32DevEsp::waitTransmitDone` uses absolute tick deadline comparison that breaks on `TickType_t` wraparound. Replace the `deadline = start + pdMS_TO_TICKS(timeout_ms)` / `xTaskGetTickCount() >= deadline` logic with the standard FreeRTOS wraparound-safe elapsed-time check using signed tick differences, and keep the loop/timeout behavior otherwise unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp`:
- Around line 383-390: The guard in the I2S DMA descriptor check is correct, but
the nearby comment is misleading because it says the descriptor can carry 4093
bytes while the code in the single-descriptor path rejects sizes above 4092.
Update the comment in the I2sPeripheralEsp32DevEsp buffer-size check to match
the actual limit used by the size_bytes validation and the FL_WARN_F message,
keeping the explanation aligned with the lldesc_t descriptor constraint.
- Around line 486-509: The I2S pin setup in I2sPeripheralEsp32DevEsp still
routes the matrix signal without first selecting the pad’s GPIO function. Update
the pin initialization flow to call the GPIO pad selection step (for example via
gpio_reset_pin(), esp_rom_gpio_pad_select_gpio(), or the equivalent
PIN_FUNC_SELECT path) before gpio_set_direction() and
esp_rom_gpio_connect_out_signal(), so pins that boot in alternate functions can
actually drive the output lane.
- Around line 461-485: The routeLanePin method in I2sPeripheralEsp32DevEsp
currently treats a negative gpio_pin as success without actually undoing the
previous mapping, so the “clear routing” path is a no-op. Update routeLanePin to
track the last routed pin per lane and, when gpio_pin is negative, disconnect
that pin using the appropriate GPIO signal detach call (for example
esp_rom_gpio_connect_out_signal with SIG_GPIO_OUT_IDX or the equivalent cleanup
path) before returning. Keep the normal routing logic for valid pins unchanged.
- Around line 524-548: Avoid calling getConfig() inside i2s_dma_isr_trampoline
because the ISR is marked FL_IRAM and getConfig() is not guaranteed to be
inlined or IRAM-safe under the ESP32 -Og debug/CI builds. Update the trampoline
to read mI2sPort directly from the I2sPeripheralEsp32DevEsp instance, or make
the accessor itself FL_IRAM-safe if it must remain in use. Use
i2s_dma_isr_trampoline and getConfig() as the key symbols when making the
change.
---
Nitpick comments:
In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp`:
- Around line 428-442: `I2sPeripheralEsp32DevEsp::waitTransmitDone` uses
absolute tick deadline comparison that breaks on `TickType_t` wraparound.
Replace the `deadline = start + pdMS_TO_TICKS(timeout_ms)` /
`xTaskGetTickCount() >= deadline` logic with the standard FreeRTOS
wraparound-safe elapsed-time check using signed tick differences, and keep the
loop/timeout behavior otherwise unchanged.
In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_mock.cpp.hpp`:
- Around line 171-173: The I2S lane cap is hardcoded in multiple places, so
replace the duplicated 16 check with a shared constant and use it consistently
in routeLanePin, lastRoutedPinForLane, and mLaneRoutedPin, matching the same
constant in the real ESP32 implementation as well. Update the mock and
implementation to reference that shared symbol so the lane limit is defined in
one place and stays in sync.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 762893e6-e534-4d1e-8b07-a82a6c6b6704
📒 Files selected for processing (6)
src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hppsrc/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.hsrc/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_mock.cpp.hppsrc/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_mock.hsrc/platforms/esp/32/drivers/i2s/ii2s_peripheral_esp32dev.htests/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp
Classic ESP32 I2S0/I2S1 each expose 24 parallel data output signals
(I2S{n}O_DATA_OUT0_IDX .. DATA_OUT23_IDX per soc/gpio_sig_map.h).
Fix per user hardware review — previous 16-lane cap in routeLanePin
was tighter than the SoC allows.
Wave8 encoder is currently 16-wide, so lanes 16..23 carry no useful
data yet, but the peripheral surface now accepts the full hardware
range so a follow-up wave8Transpose_24 (or padded-32) encoder is a
drop-in on the encoder side alone.
Test coverage extended: lanes 16 and 23 routed successfully; lane
24 and 25 rejected as out of range.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp (1)
498-501: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winUse
%dhere instead of%s.FL_WARN_Fresolves to the printf-style path for multiple arguments, so passingintvalues to%sis undefined behavior; use%dfor bothgpio_pinanderr.[src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp:498-501]
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp` around lines 498 - 501, The warning in I2sPeripheralEsp32DevEsp::gpio_set_direction error handling uses the wrong printf specifiers: replace the %s placeholders in the FL_WARN_F call with %d so the integer values from gpio_pin and err are formatted correctly. Keep the existing log message and location, but ensure both static_cast<int>(gpio_pin) and static_cast<int>(err) match the format string.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp`:
- Around line 498-501: The warning in
I2sPeripheralEsp32DevEsp::gpio_set_direction error handling uses the wrong
printf specifiers: replace the %s placeholders in the FL_WARN_F call with %d so
the integer values from gpio_pin and err are formatted correctly. Keep the
existing log message and location, but ensure both static_cast<int>(gpio_pin)
and static_cast<int>(err) match the format string.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 117c4aa6-62db-4809-8943-17bbd75420e0
📒 Files selected for processing (4)
src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hppsrc/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_mock.cpp.hppsrc/platforms/esp/32/drivers/i2s/ii2s_peripheral_esp32dev.htests/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp
🚧 Files skipped from review as they are similar to previous changes (3)
- tests/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp
- src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_mock.cpp.hpp
- src/platforms/esp/32/drivers/i2s/ii2s_peripheral_esp32dev.h
…, wraparound-safe wait, shared lane constant Reviews on PR #3558: 1. Extract lane cap into a shared `kMaxI2sLanes = 24` constant in `ii2s_peripheral_esp32dev.h`; both mock and real impl reference it. 2. `routeLanePin`: select the pad's GPIO function via `esp_rom_gpio_pad_select_gpio()` BEFORE `gpio_set_direction()` so pins booting in an alternate function (SD_CMD, etc.) can drive I2S. 3. `routeLanePin(lane, -1)`: actually detach the previously-routed pin by writing `SIG_GPIO_OUT_IDX` in its place. Requires tracking the per-lane pin on the real impl (mirror the mock's `mLaneRoutedPin`). 4. `waitTransmitDone`: wraparound-safe elapsed-time computation using `(TickType_t)(now - start)` instead of absolute `deadline`. Correct past 32-bit tick counter wrap (~49 days at 1kHz FreeRTOS tick). 5. ISR trampoline: read `mI2sPort` via a new IRAM-safe accessor `i2sPortForIsr()` instead of `getConfig()` — getConfig returns a const reference and may not be inlined into IRAM under -Og. 6. Fix stale "4093 bytes" comment on the descriptor size check to match the 4092-byte cap actually enforced. ## Bench - `bash test channel_engine_i2s_esp32dev` — passes - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — pong, uptimeMs 2066 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp`:
- Around line 497-502: The GPIO validation is happening too late in the i2s
peripheral setup path, so invalid or output-ineligible pins can reach the raw
ROM pad-select call first. In the GPIO configuration logic around
esp_rom_gpio_pad_select_gpio and gpio_set_direction, add a
GPIO_IS_VALID_OUTPUT_GPIO() guard before any pad/matrix routing helpers are
invoked, and return the same error path early for invalid pins. Keep the fix
localized to the GPIO selection/setup flow in the i2s peripheral code so the
unsafe ROM call is never reached with an invalid pin.
- Around line 518-522: Detach the currently routed GPIO for the lane before
assigning a new one in the lane-routing logic. In the I2S peripheral lane setup
code around the esp_rom_gpio_connect_out_signal call, use mLaneRoutedPin[lane]
to detect an existing mapping and clear/disconnect that old pin first, then
update mLaneRoutedPin[lane] with the new gpio_pin. Keep the fix localized to the
lane routing function so reassigning a lane does not leave the previous GPIO
still connected.
In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.h`:
- Around line 101-106: Move the non-template i2sPortForIsr() definition out of
I2sPeripheralEsp32DevEsp in the header and keep only its declaration there.
Define the FL_IRAM accessor in i2s_peripheral_esp32dev_esp.cpp.hpp so the
DMA-done ISR trampoline still calls an IRAM-safe implementation while complying
with the header policy. Ensure the out-of-line definition matches the existing
mConfig.mI2sPort return behavior and preserves FL_NO_EXCEPT.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e6284c3c-98cb-4ccf-b1dd-c7927735a40a
📒 Files selected for processing (4)
src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hppsrc/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.hsrc/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_mock.cpp.hppsrc/platforms/esp/32/drivers/i2s/ii2s_peripheral_esp32dev.h
🚧 Files skipped from review as they are similar to previous changes (2)
- src/platforms/esp/32/drivers/i2s/ii2s_peripheral_esp32dev.h
- src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_mock.cpp.hpp
| // Select the pad's GPIO function first — pins that boot into an | ||
| // alternate function (e.g. SD_CMD on GPIO11 in some board configs) | ||
| // must be switched to plain GPIO before the matrix routing takes | ||
| // effect. `esp_rom_gpio_pad_select_gpio` is the IDF v5-safe API. | ||
| esp_rom_gpio_pad_select_gpio(static_cast<u8>(gpio_pin)); | ||
|
|
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE='src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp'
nl -ba "$FILE" | sed -n '467,525p'
rg -n "GPIO_IS_VALID_OUTPUT_GPIO|esp_rom_gpio_pad_select_gpio|gpio_set_direction" src/platforms/esp/32 -SRepository: FastLED/FastLED
Length of output: 193
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE='src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp'
echo '--- relevant lines ---'
sed -n '467,525p' "$FILE" | cat -n
echo '--- nearby gpio usage in this file ---'
grep -nE 'GPIO_IS_VALID_OUTPUT_GPIO|esp_rom_gpio_pad_select_gpio|gpio_set_direction|gpio_matrix_out|gpio_pad_select_gpio' "$FILE" || true
echo '--- GPIO validation definitions / call sites in esp32 platform code ---'
grep -R -nE 'GPIO_IS_VALID_OUTPUT_GPIO|GPIO_IS_VALID_GPIO|gpio_reset_pin|gpio_pad_select_gpio|esp_rom_gpio_pad_select_gpio' src/platforms/esp/32 | head -n 80Repository: FastLED/FastLED
Length of output: 5014
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo '--- repo usages of GPIO validity helpers ---'
grep -R -nE 'GPIO_IS_VALID_OUTPUT_GPIO|GPIO_IS_VALID_GPIO|GPIO_IS_VALID_DIGITAL_IO_PAD' src . 2>/dev/null | head -n 120 || true
echo '--- search for esp_rom_gpio_pad_select_gpio declarations/usages ---'
grep -R -nE 'esp_rom_gpio_pad_select_gpio|pad_select_gpio' . 2>/dev/null | head -n 120 || true
echo '--- if ESP-IDF headers are vendored, inspect the declaration ---'
grep -R -nE 'esp_rom_gpio_pad_select_gpio|gpio_set_direction' /usr/include /usr/local/include 2>/dev/null | head -n 80 || trueRepository: FastLED/FastLED
Length of output: 612
🌐 Web query:
ESP-IDF esp_rom_gpio_pad_select_gpio invalid gpio pin behavior GPIO_IS_VALID_OUTPUT_GPIO classic ESP32
💡 Result:
The function esp_rom_gpio_pad_select_gpio(uint32_t iopad_num) is a low-level ROM API that configures an IO pad as a General Purpose IO [1][2]. Because it is a ROM function, it lacks the safety checks found in the higher-level ESP-IDF GPIO driver [3]. If you provide an invalid GPIO pin number to esp_rom_gpio_pad_select_gpio, the function will attempt to access the IO MUX register corresponding to that number. Depending on the chip architecture, passing an out-of-bounds index can cause undefined behavior, which may include silent failure, corruption of unrelated register bits, or system instability. The macro GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) is defined in the ESP-IDF GPIO HAL as a safety mechanism to verify that a pin is valid and supports output mode [4][5]. It checks the pin number against the hardware-specific maximum count and against a bitmask (SOC_GPIO_VALID_OUTPUT_GPIO_MASK) that defines which pins are capable of being used as outputs [4][5]. To ensure robust code and avoid the risks associated with raw ROM calls: 1. Always use the high-level ESP-IDF GPIO driver APIs (e.g., gpio_config()) instead of manual ROM function calls whenever possible [3]. These APIs internally use validation macros like GPIO_IS_VALID_GPIO and GPIO_IS_VALID_OUTPUT_GPIO to ensure the operation is safe. 2. If you must use esp_rom_gpio_pad_select_gpio, perform your own validation first using GPIO_IS_VALID_GPIO(gpio_num) to ensure the index is within the valid range for your target chip [4][5]. 3. Note that on some chips, certain pins have restricted functionality (e.g., input-only pins, or pins reserved for flash/PSRAM), and GPIO_IS_VALID_OUTPUT_GPIO correctly accounts for these hardware limitations by cross-referencing the pin against valid output masks [4][5]. In summary, the ROM function does not validate its input; failing to do so yourself can lead to hardware-level errors that the higher-level driver is explicitly designed to prevent [4][3][5].
Citations:
- 1: https://github.com/espressif/esp-idf/blob/master/components/esp_rom/include/esp_rom_gpio.h
- 2: https://github.com/espressif/esp-idf/blob/master/components/esp_rom/esp32/ld/esp32.rom.api.ld
- 3: https://github.com/espressif/esp-idf/blob/master/docs/en/api-reference/peripherals/gpio.rst
- 4: https://github.com/espressif/esp-idf/blob/v6.0/components/esp_hal_gpio/include/hal/gpio_types.h
- 5: https://github.com/espressif/esp-idf/blob/v5.5.3/components/esp_driver_gpio/include/driver/gpio.h
Validate the GPIO before the ROM pad-select call.
esp_rom_gpio_pad_select_gpio() is a raw ROM API and won’t reject invalid or output-ineligible pins, so the later gpio_set_direction() error path is too late. Add the GPIO_IS_VALID_OUTPUT_GPIO() check before touching the pad/matrix helpers.
Proposed fix
+ if (!GPIO_IS_VALID_OUTPUT_GPIO(gpio_pin)) {
+ FL_WARN_F("I2sPeripheralEsp32DevEsp: invalid output pin=%s",
+ static_cast<int>(gpio_pin));
+ return false;
+ }
+
// Select the pad's GPIO function first — pins that boot into an
@@
- esp_rom_gpio_pad_select_gpio(static_cast<u8>(gpio_pin));
+ esp_rom_gpio_pad_select_gpio(static_cast<u32>(gpio_pin));📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Select the pad's GPIO function first — pins that boot into an | |
| // alternate function (e.g. SD_CMD on GPIO11 in some board configs) | |
| // must be switched to plain GPIO before the matrix routing takes | |
| // effect. `esp_rom_gpio_pad_select_gpio` is the IDF v5-safe API. | |
| esp_rom_gpio_pad_select_gpio(static_cast<u8>(gpio_pin)); | |
| if (!GPIO_IS_VALID_OUTPUT_GPIO(gpio_pin)) { | |
| FL_WARN_F("I2sPeripheralEsp32DevEsp: invalid output pin=%s", | |
| static_cast<int>(gpio_pin)); | |
| return false; | |
| } | |
| // Select the pad's GPIO function first — pins that boot into an | |
| // alternate function (e.g. SD_CMD on GPIO11 in some board configs) | |
| // must be switched to plain GPIO before the matrix routing takes | |
| // effect. `esp_rom_gpio_pad_select_gpio` is the IDF v5-safe API. | |
| esp_rom_gpio_pad_select_gpio(static_cast<u32>(gpio_pin)); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp` around
lines 497 - 502, The GPIO validation is happening too late in the i2s peripheral
setup path, so invalid or output-ineligible pins can reach the raw ROM
pad-select call first. In the GPIO configuration logic around
esp_rom_gpio_pad_select_gpio and gpio_set_direction, add a
GPIO_IS_VALID_OUTPUT_GPIO() guard before any pad/matrix routing helpers are
invoked, and return the same error path early for invalid pins. Keep the fix
localized to the GPIO selection/setup flow in the i2s peripheral code so the
unsafe ROM call is never reached with an invalid pin.
| const bool invert = (mConfig.mInvertMask & (1u << lane)) != 0; | ||
| esp_rom_gpio_connect_out_signal(static_cast<u32>(gpio_pin), | ||
| static_cast<u32>(base_signal + lane), | ||
| invert, false); | ||
| mLaneRoutedPin[lane] = gpio_pin; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "routeLanePin|mLaneRoutedPin|SIG_GPIO_OUT_IDX|lastRoutedPinForLane" \
src/platforms/esp/32/drivers/i2s tests/platforms/esp/32/drivers/i2s -SRepository: FastLED/FastLED
Length of output: 5958
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '467,530p' src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp
printf '\n---\n'
sed -n '120,190p' src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.h
printf '\n---\n'
sed -n '620,675p' tests/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cppRepository: FastLED/FastLED
Length of output: 5715
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '150,210p' src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_mock.cpp.hpp
printf '\n---\n'
sed -n '70,110p' src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_mock.h
printf '\n---\n'
rg -n "routeLanePin\\([^)]*, [^)]*\\)|routeLanePin\\(.*-1" src/platforms/esp/32/drivers/i2s tests/platforms/esp/32/drivers/i2s -SRepository: FastLED/FastLED
Length of output: 6138
Detach the previously routed pin before reassigning a lane.
Re-routing a lane updates mLaneRoutedPin[lane], but the old GPIO stays connected to the I2S signal until an explicit clear. That leaves the previous pin still driven if the lane moves directly to a new GPIO.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp` around
lines 518 - 522, Detach the currently routed GPIO for the lane before assigning
a new one in the lane-routing logic. In the I2S peripheral lane setup code
around the esp_rom_gpio_connect_out_signal call, use mLaneRoutedPin[lane] to
detect an existing mapping and clear/disconnect that old pin first, then update
mLaneRoutedPin[lane] with the new gpio_pin. Keep the fix localized to the lane
routing function so reassigning a lane does not leave the previous GPIO still
connected.
| // FastLED#3526 Phase 2b step B — IRAM-safe accessor used only by | ||
| // the DMA-done ISR trampoline. Reads the u8 port field directly, no | ||
| // through-getConfig indirection (getConfig returns a reference and | ||
| // may not be inlined under -Og debug builds, which is unsafe in | ||
| // ISR context). | ||
| u8 i2sPortForIsr() const FL_NO_EXCEPT { return mConfig.mI2sPort; } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Move the ISR accessor definition out of the header.
i2sPortForIsr() is a non-template function definition in a src/**/*.h file. Keep the declaration here and define the FL_IRAM accessor in the .cpp.hpp so the ISR path stays safe without violating header policy.
Proposed adjustment
- u8 i2sPortForIsr() const FL_NO_EXCEPT { return mConfig.mI2sPort; }
+ FL_IRAM u8 i2sPortForIsr() const FL_NO_EXCEPT;Add the definition in i2s_peripheral_esp32dev_esp.cpp.hpp, before the ISR trampoline uses it:
FL_IRAM u8 I2sPeripheralEsp32DevEsp::i2sPortForIsr() const FL_NO_EXCEPT {
return mConfig.mI2sPort;
}As per path instructions, "src/**/*.h: Header file. Verify it does NOT contain function definitions ... If function definitions are needed, they belong in .cpp.hpp or .impl.hpp files."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.h` around lines
101 - 106, Move the non-template i2sPortForIsr() definition out of
I2sPeripheralEsp32DevEsp in the header and keep only its declaration there.
Define the FL_IRAM accessor in i2s_peripheral_esp32dev_esp.cpp.hpp so the
DMA-done ISR trampoline still calls an IRAM-safe implementation while complying
with the header policy. Ensure the out-of-line definition matches the existing
mConfig.mI2sPort return behavior and preserves FL_NO_EXCEPT.
Source: Path instructions
…d engine (#3526) (#3559) * fix(autoresearch): arm WDT at top of setup() so boot hangs don't wedge COM port Previously the unified WDT was armed lazily by FL_WATCHDOG_AUTO() at the top of loop(). If setup() hung (RPC bind null-deref, stalled static-init, wedged serial handshake), no WDT was armed and the COM port stayed owned by a dead sketch until manual power-cycle. Arm the WDT with a 20 s window at the very top of setup() so a hang here auto-reboots. Feed the WDT in the serial-monitor wait loop because on classic ESP32 (non-USB-CDC) that loop can span up to AUTORESEARCH_SERIAL_WAIT_MS = 120 s, well past the setup WDT window. FL_WATCHDOG_AUTO() at loop() top re-arms with the shorter loop-scoped timeout once setup() has finished. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): wave3 sibling encoder for I2S1 modern driver (#3526 Phase 2a) Adds `encodeChannelWave3_i2s1` alongside the existing `encodeChannelWave8_i2s1` to satisfy the meta-issue acceptance criterion "Wave3 fallback path exercised for a three-slot chipset". Wave3 saves 2.67x memory vs wave8 for chipsets whose T1/T2/T3 timing rounds to 1/2/N ticks per 3, gated by `fl::canUseWave3(timing)`. Pixel clock is per-chipset via `fl::wave3ClockFrequencyHz(timing)` instead of the fixed 8 MHz wave8 rate. The encoder reuses the shared `fl::wave3Transpose_16` kernel from `fl/channels/wave3.h` — same anti-drift rule as the wave8 sibling. Host tests verify byte-exact output against a direct-kernel-call reference using canonical WS2812 timing (verified wave3-eligible). Drops the `fl/channels/detail/wave3.hpp` and `detail/wave8.hpp` force-inline includes from this .cpp.hpp — the unity build pulls this file across multiple TUs and the force-inline kernels would emit in each. The public `.h` declarations resolve at link time to the single out-of-line definitions in `wave3.cpp.hpp` / `wave8.cpp.hpp`, avoiding double-inline bloat. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(channels): split detail/wave3.hpp + wave8.hpp into .h + .cpp.hpp The former `fl/channels/detail/wave3.hpp` and `detail/wave8.hpp` were force-inline headers (`FASTLED_FORCE_INLINE FL_IRAM FL_OPTIMIZE_FUNCTION`). Every translation unit that included them emitted the full transpose kernel body. With ~10 callers across PARLIO / LCD_CAM / LCD_SPI / I2S drivers and the public wave3/wave8 wrappers, that was ~10× the transpose code in the final binary. Split into: - `detail/wave3.h` + `detail/wave8.h` — declarations, constexpr LUTs that need compile-time visibility, and the `FL_WAVE8_SPREAD_TO_16` helper macro (kept in the .h since it's a #define) - `detail/wave3.cpp.hpp` + `detail/wave8.cpp.hpp` — out-of-line definitions (dropped FASTLED_FORCE_INLINE, kept FL_IRAM + FL_OPTIMIZE_FUNCTION for perf), compiled once via the channels/detail unity build Updated 6 caller files (+2 tests) to include the new `.h` headers instead of the deleted `.hpp` files. The public API (`wave3Transpose_*` / `wave8Transpose_*` in `wave3.h` / `wave8.h`) is untouched — this is a pure implementation refactor. Perf note: dropping FASTLED_FORCE_INLINE means the transpose kernels no longer get inlined into every caller. On the in-order RV32 P4 core this could regress the encode-loop-hot-path per-frame timing measured in #2548 by a few percent (from lost cross-position ILP inside the same function scope). If bench data shows a regression, the fix is to keep the specific hot-path kernels (bf1_pipe4, etc.) FASTLED_FORCE_INLINE in the .h — the pattern here is per-function, not all-or-nothing. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step A — inline register-level init on modern peripheral (#3526) Drops the `#include \"platforms/esp/32/drivers/i2s/i2s_esp32dev.h\"` from `I2sPeripheralEsp32DevEsp::initialize`/`deinitialize`. Replaces the calls to Yves's `i2s_define_bit_patterns` / `i2s_init` / `i2s_stop` with direct register writes on `I2S0`/`I2S1` via `soc/i2s_struct.h`. Fixed 8 MHz pixel clock for wave8 output (80 MHz APB / (10 + 0/1)) — no per-chipset clock math. This is the general-clockless architecture the meta issue mandates (PARLIO-style), NOT Yves's per-chipset bit-pattern encoder. Register-write sequence mirrors Yves's proven init sequence exactly: - reset (`lc_conf` + `conf` reset flags) - reset DMA (`lc_conf.in_rst`/`out_rst`) - reset FIFO (`conf.rx_fifo_reset`/`tx_fifo_reset`) - parallel mode (`conf2.lcd_en = 1`, 16-lane width) - 32-bit-parallel sample rate config - fixed 8 MHz clkm divider (N=10, A=1, B=0) - FIFO in DMA-serviced 32-bit mode - PCM bypass Ownership tracked via a private static `g_i2s1_hardware_claimed_by_modern` flag — no dependency on Yves's `gInitializedI2sInitialized`. During the rollout only one binding path is active at a time (Yves via `-DFASTLED_ESP32_I2S=1`, modern via `Bus::FLEX_IO, 0` after Phase 2d), so there is no cross-driver race. `deinitialize()` clears `tx_start` + resets the block directly. `transmit()` remains a stub — Phase 2b step B lands the `lldesc_t` descriptor ring, `esp_intr_alloc()` ISR install, and real DMA kick. ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` after WDT-driven recovery from the intermittent first-boot `fl::json::json(const char*)` panic (unrelated pre-existing bug tracked separately) ## Also included Updates two AutoResearch example headers I missed in the earlier detail-split sweep (#3555): - `examples/AutoResearch/AutoResearchParlioEncode.h` - `examples/AutoResearch/AutoResearchWave8Expand.h` Both now include `fl/channels/detail/wave8.h` (declarations) instead of the deleted force-inline `.hpp`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step B — DMA descriptor + esp_intr_alloc ISR (#3526) Completes the real-hardware DMA path on the modern I2S1 peripheral. `transmit()` now: 1. Points a DMA-capable `lldesc_t` at the caller's buffer 2. Resets the peripheral, arms `out_link.addr` + `out_link.start` 3. Enables the pre-installed OUT_EOF ISR 4. Flips `mBusy = true` and starts the DMA (`conf.tx_start = 1`) The ISR trampoline `i2s_dma_isr_trampoline` (FL_IRAM, ISR context) clears the interrupt, stops `tx_start`, and calls `I2sPeripheralEsp32DevEsp::finishTransmitFromIsr()` which flips `mBusy = false` and dispatches the registered completion callback (the channel-engine trampoline just flips its `mTransmitCompleted` flag — already ISR-safe). Descriptor allocated at `initialize()` time via `heap_caps_malloc` with `MALLOC_CAP_DMA` (DMA-capable DRAM). ISR handle allocated via `esp_intr_alloc(ETS_I2S1_INTR_SOURCE, ESP_INTR_FLAG_IRAM, ...)`. Both released in `deinitialize()`. `waitTransmitDone(timeout_ms)` is now a real deadline-bounded spin that yields via `vTaskDelay(1)` while `mBusy` — no more (void)timeout fake return. ## Scope limits (deferred to follow-up) - **Single descriptor, one-shot only**: buffers larger than 4092 bytes are rejected (the `lldesc_t` length field is 12 bits). Streaming refill from the ISR — for full-frame 128-byte-per-lane-per-strip wave8 output past 4 KB — is a follow-up. - **No GPIO mux routing**: the peripheral is configured for parallel- out but the 16 lane pins are not yet mapped via `gpio_matrix_out` — that's Phase 2b step C (which adds `configureTiming` + per-channel GPIO plumbing on the engine side). ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` (WDT recovery from the intermittent first-boot panic works cleanly). Modern engine is inert at runtime (not bound to `Bus::FLEX_IO, 0` yet — that's Phase 2d), so the DMA/ISR code compiles + boots but doesn't execute on this run. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step C — GPIO mux routing for I2S1 lanes (#3526) Adds `II2sPeripheralEsp32Dev::routeLanePin(lane, gpio_pin)` for wiring one parallel-out data lane to a specific GPIO pin. Called by the engine (in a follow-up) after `initialize()` for each active channel, before the first `transmit()`. ## Real hardware impl `I2sPeripheralEsp32DevEsp::routeLanePin` uses the IDF v5-safe `esp_rom_gpio_connect_out_signal(gpio_num, signal_idx, out_inv, oen_inv)` API (replaces the legacy `gpio_matrix_out`). Signal index computed as `I2S{n}O_DATA_OUT0_IDX + lane`, honoring the peripheral config's per-strip invert mask so chipsets needing polarity inversion get it "for free" through the GPIO matrix rather than in the encoder. Pin put into output mode via `gpio_set_direction`. ## Mock `I2sPeripheralEsp32DevMock::routeLanePin` records the (lane, pin) pair. Two new introspection methods for tests: - `laneRouteInvocationCount()` — call count since last `reset()` - `lastRoutedPinForLane(lane)` — most recent pin, or -1 if unrouted ## Test coverage New host test `Modern I2S peripheral: routeLanePin records mock mapping`: - Uninitialised peripheral rejects the route - Multiple lane routings recorded correctly - Out-of-range lanes (16, 17) rejected - Re-routing replaces the previous pin - `reset()` clears everything ## Bench - `bash test --cpp` — 346/346 tests pass (new test brings total up by 1) - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` ## What's still gated on Phase 2b step D - Streaming DMA descriptor ring (current impl is single-descriptor, 4092-byte limit) - Engine-side `configureTiming()` that plumbs per-channel GPIO pins from `ChannelData::getPin()` down to `routeLanePin` calls Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * address CodeRabbit review: pad-select, real clear path, IRAM-safe ISR, wraparound-safe wait, shared lane constant Reviews on PR #3558: 1. Extract lane cap into a shared `kMaxI2sLanes = 24` constant in `ii2s_peripheral_esp32dev.h`; both mock and real impl reference it. 2. `routeLanePin`: select the pad's GPIO function via `esp_rom_gpio_pad_select_gpio()` BEFORE `gpio_set_direction()` so pins booting in an alternate function (SD_CMD, etc.) can drive I2S. 3. `routeLanePin(lane, -1)`: actually detach the previously-routed pin by writing `SIG_GPIO_OUT_IDX` in its place. Requires tracking the per-lane pin on the real impl (mirror the mock's `mLaneRoutedPin`). 4. `waitTransmitDone`: wraparound-safe elapsed-time computation using `(TickType_t)(now - start)` instead of absolute `deadline`. Correct past 32-bit tick counter wrap (~49 days at 1kHz FreeRTOS tick). 5. ISR trampoline: read `mI2sPort` via a new IRAM-safe accessor `i2sPortForIsr()` instead of `getConfig()` — getConfig returns a const reference and may not be inlined into IRAM under -Og. 6. Fix stale "4093 bytes" comment on the descriptor size check to match the 4092-byte cap actually enforced. ## Bench - `bash test channel_engine_i2s_esp32dev` — passes - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — pong, uptimeMs 2066 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2d slot swap — BusTraits<FLEX_IO, 0> → modern unified engine (#3526) Flips `Bus::FLEX_IO, 0` on classic ESP32 from the standalone `createI2sSpiEngine()` to the modern unified `createI2sEsp32DevEngine()`. The modern engine handles BOTH clockless and SPI batches on the same I2S1 peripheral per the parallel-IO unified-engine rule (`agents/docs/cpp-standards.md` -> \"Parallel-IO Driver: Unified Clockless + SPI Engine\"). SPI batches delegate to the tested `ChannelDriverI2sSpi` internally, so SPI users see no behavioral change — only the dispatch entry point moves. ## Prerequisite fix (same PR) `ChannelEngineI2sEsp32Dev::show()` used to `initialize()` the modern peripheral BEFORE checking whether the batch is clockless or SPI. That raced with the SPI delegate's own I2S1 claim on a SPI-only batch. Fix: postpone modern peripheral init to AFTER the SPI/clockless branch. SPI paths never touch modern's peripheral; only the clockless path initializes I2S1 for wave8 output. ## Impact - **Clockless on classic ESP32 (default)**: still routes through RMT (unaffected — RMT slot binding is separate). Only opt-in `-DFASTLED_ESP32_I2S=1` Yves binding is orthogonal to this swap. - **SPI (APA102/SK9822/HD108) on classic ESP32**: now dispatches through the modern engine's `show()` which delegates to `createI2sSpiEngine()`. Extra function-call layer only. - **`BusSupports<Bus::FLEX_IO, SpiChipsetConfig, 0>`**: still `true_type` — SPI still supported on the slot. ## Phase 2e teaser `drivers/i2s_spi/bus_traits.h` is now the ONE place returning the modern factory. The whole `drivers/i2s_spi/` directory is scheduled for deletion at Phase 2e once the delegate call inside the modern engine gets folded into a direct SPI-mode transmit path. This PR keeps the file location during rollout to avoid churning the `_build.cpp.hpp` wiring on the same PR that flips the binding. ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — pong, uptimeMs 2066 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
…ing (#3526) (#3564) * fix(autoresearch): arm WDT at top of setup() so boot hangs don't wedge COM port Previously the unified WDT was armed lazily by FL_WATCHDOG_AUTO() at the top of loop(). If setup() hung (RPC bind null-deref, stalled static-init, wedged serial handshake), no WDT was armed and the COM port stayed owned by a dead sketch until manual power-cycle. Arm the WDT with a 20 s window at the very top of setup() so a hang here auto-reboots. Feed the WDT in the serial-monitor wait loop because on classic ESP32 (non-USB-CDC) that loop can span up to AUTORESEARCH_SERIAL_WAIT_MS = 120 s, well past the setup WDT window. FL_WATCHDOG_AUTO() at loop() top re-arms with the shorter loop-scoped timeout once setup() has finished. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): wave3 sibling encoder for I2S1 modern driver (#3526 Phase 2a) Adds `encodeChannelWave3_i2s1` alongside the existing `encodeChannelWave8_i2s1` to satisfy the meta-issue acceptance criterion "Wave3 fallback path exercised for a three-slot chipset". Wave3 saves 2.67x memory vs wave8 for chipsets whose T1/T2/T3 timing rounds to 1/2/N ticks per 3, gated by `fl::canUseWave3(timing)`. Pixel clock is per-chipset via `fl::wave3ClockFrequencyHz(timing)` instead of the fixed 8 MHz wave8 rate. The encoder reuses the shared `fl::wave3Transpose_16` kernel from `fl/channels/wave3.h` — same anti-drift rule as the wave8 sibling. Host tests verify byte-exact output against a direct-kernel-call reference using canonical WS2812 timing (verified wave3-eligible). Drops the `fl/channels/detail/wave3.hpp` and `detail/wave8.hpp` force-inline includes from this .cpp.hpp — the unity build pulls this file across multiple TUs and the force-inline kernels would emit in each. The public `.h` declarations resolve at link time to the single out-of-line definitions in `wave3.cpp.hpp` / `wave8.cpp.hpp`, avoiding double-inline bloat. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(channels): split detail/wave3.hpp + wave8.hpp into .h + .cpp.hpp The former `fl/channels/detail/wave3.hpp` and `detail/wave8.hpp` were force-inline headers (`FASTLED_FORCE_INLINE FL_IRAM FL_OPTIMIZE_FUNCTION`). Every translation unit that included them emitted the full transpose kernel body. With ~10 callers across PARLIO / LCD_CAM / LCD_SPI / I2S drivers and the public wave3/wave8 wrappers, that was ~10× the transpose code in the final binary. Split into: - `detail/wave3.h` + `detail/wave8.h` — declarations, constexpr LUTs that need compile-time visibility, and the `FL_WAVE8_SPREAD_TO_16` helper macro (kept in the .h since it's a #define) - `detail/wave3.cpp.hpp` + `detail/wave8.cpp.hpp` — out-of-line definitions (dropped FASTLED_FORCE_INLINE, kept FL_IRAM + FL_OPTIMIZE_FUNCTION for perf), compiled once via the channels/detail unity build Updated 6 caller files (+2 tests) to include the new `.h` headers instead of the deleted `.hpp` files. The public API (`wave3Transpose_*` / `wave8Transpose_*` in `wave3.h` / `wave8.h`) is untouched — this is a pure implementation refactor. Perf note: dropping FASTLED_FORCE_INLINE means the transpose kernels no longer get inlined into every caller. On the in-order RV32 P4 core this could regress the encode-loop-hot-path per-frame timing measured in #2548 by a few percent (from lost cross-position ILP inside the same function scope). If bench data shows a regression, the fix is to keep the specific hot-path kernels (bf1_pipe4, etc.) FASTLED_FORCE_INLINE in the .h — the pattern here is per-function, not all-or-nothing. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step A — inline register-level init on modern peripheral (#3526) Drops the `#include \"platforms/esp/32/drivers/i2s/i2s_esp32dev.h\"` from `I2sPeripheralEsp32DevEsp::initialize`/`deinitialize`. Replaces the calls to Yves's `i2s_define_bit_patterns` / `i2s_init` / `i2s_stop` with direct register writes on `I2S0`/`I2S1` via `soc/i2s_struct.h`. Fixed 8 MHz pixel clock for wave8 output (80 MHz APB / (10 + 0/1)) — no per-chipset clock math. This is the general-clockless architecture the meta issue mandates (PARLIO-style), NOT Yves's per-chipset bit-pattern encoder. Register-write sequence mirrors Yves's proven init sequence exactly: - reset (`lc_conf` + `conf` reset flags) - reset DMA (`lc_conf.in_rst`/`out_rst`) - reset FIFO (`conf.rx_fifo_reset`/`tx_fifo_reset`) - parallel mode (`conf2.lcd_en = 1`, 16-lane width) - 32-bit-parallel sample rate config - fixed 8 MHz clkm divider (N=10, A=1, B=0) - FIFO in DMA-serviced 32-bit mode - PCM bypass Ownership tracked via a private static `g_i2s1_hardware_claimed_by_modern` flag — no dependency on Yves's `gInitializedI2sInitialized`. During the rollout only one binding path is active at a time (Yves via `-DFASTLED_ESP32_I2S=1`, modern via `Bus::FLEX_IO, 0` after Phase 2d), so there is no cross-driver race. `deinitialize()` clears `tx_start` + resets the block directly. `transmit()` remains a stub — Phase 2b step B lands the `lldesc_t` descriptor ring, `esp_intr_alloc()` ISR install, and real DMA kick. ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` after WDT-driven recovery from the intermittent first-boot `fl::json::json(const char*)` panic (unrelated pre-existing bug tracked separately) ## Also included Updates two AutoResearch example headers I missed in the earlier detail-split sweep (#3555): - `examples/AutoResearch/AutoResearchParlioEncode.h` - `examples/AutoResearch/AutoResearchWave8Expand.h` Both now include `fl/channels/detail/wave8.h` (declarations) instead of the deleted force-inline `.hpp`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step B — DMA descriptor + esp_intr_alloc ISR (#3526) Completes the real-hardware DMA path on the modern I2S1 peripheral. `transmit()` now: 1. Points a DMA-capable `lldesc_t` at the caller's buffer 2. Resets the peripheral, arms `out_link.addr` + `out_link.start` 3. Enables the pre-installed OUT_EOF ISR 4. Flips `mBusy = true` and starts the DMA (`conf.tx_start = 1`) The ISR trampoline `i2s_dma_isr_trampoline` (FL_IRAM, ISR context) clears the interrupt, stops `tx_start`, and calls `I2sPeripheralEsp32DevEsp::finishTransmitFromIsr()` which flips `mBusy = false` and dispatches the registered completion callback (the channel-engine trampoline just flips its `mTransmitCompleted` flag — already ISR-safe). Descriptor allocated at `initialize()` time via `heap_caps_malloc` with `MALLOC_CAP_DMA` (DMA-capable DRAM). ISR handle allocated via `esp_intr_alloc(ETS_I2S1_INTR_SOURCE, ESP_INTR_FLAG_IRAM, ...)`. Both released in `deinitialize()`. `waitTransmitDone(timeout_ms)` is now a real deadline-bounded spin that yields via `vTaskDelay(1)` while `mBusy` — no more (void)timeout fake return. ## Scope limits (deferred to follow-up) - **Single descriptor, one-shot only**: buffers larger than 4092 bytes are rejected (the `lldesc_t` length field is 12 bits). Streaming refill from the ISR — for full-frame 128-byte-per-lane-per-strip wave8 output past 4 KB — is a follow-up. - **No GPIO mux routing**: the peripheral is configured for parallel- out but the 16 lane pins are not yet mapped via `gpio_matrix_out` — that's Phase 2b step C (which adds `configureTiming` + per-channel GPIO plumbing on the engine side). ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` (WDT recovery from the intermittent first-boot panic works cleanly). Modern engine is inert at runtime (not bound to `Bus::FLEX_IO, 0` yet — that's Phase 2d), so the DMA/ISR code compiles + boots but doesn't execute on this run. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step C — GPIO mux routing for I2S1 lanes (#3526) Adds `II2sPeripheralEsp32Dev::routeLanePin(lane, gpio_pin)` for wiring one parallel-out data lane to a specific GPIO pin. Called by the engine (in a follow-up) after `initialize()` for each active channel, before the first `transmit()`. ## Real hardware impl `I2sPeripheralEsp32DevEsp::routeLanePin` uses the IDF v5-safe `esp_rom_gpio_connect_out_signal(gpio_num, signal_idx, out_inv, oen_inv)` API (replaces the legacy `gpio_matrix_out`). Signal index computed as `I2S{n}O_DATA_OUT0_IDX + lane`, honoring the peripheral config's per-strip invert mask so chipsets needing polarity inversion get it "for free" through the GPIO matrix rather than in the encoder. Pin put into output mode via `gpio_set_direction`. ## Mock `I2sPeripheralEsp32DevMock::routeLanePin` records the (lane, pin) pair. Two new introspection methods for tests: - `laneRouteInvocationCount()` — call count since last `reset()` - `lastRoutedPinForLane(lane)` — most recent pin, or -1 if unrouted ## Test coverage New host test `Modern I2S peripheral: routeLanePin records mock mapping`: - Uninitialised peripheral rejects the route - Multiple lane routings recorded correctly - Out-of-range lanes (16, 17) rejected - Re-routing replaces the previous pin - `reset()` clears everything ## Bench - `bash test --cpp` — 346/346 tests pass (new test brings total up by 1) - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` ## What's still gated on Phase 2b step D - Streaming DMA descriptor ring (current impl is single-descriptor, 4092-byte limit) - Engine-side `configureTiming()` that plumbs per-channel GPIO pins from `ChannelData::getPin()` down to `routeLanePin` calls Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * address CodeRabbit review: pad-select, real clear path, IRAM-safe ISR, wraparound-safe wait, shared lane constant Reviews on PR #3558: 1. Extract lane cap into a shared `kMaxI2sLanes = 24` constant in `ii2s_peripheral_esp32dev.h`; both mock and real impl reference it. 2. `routeLanePin`: select the pad's GPIO function via `esp_rom_gpio_pad_select_gpio()` BEFORE `gpio_set_direction()` so pins booting in an alternate function (SD_CMD, etc.) can drive I2S. 3. `routeLanePin(lane, -1)`: actually detach the previously-routed pin by writing `SIG_GPIO_OUT_IDX` in its place. Requires tracking the per-lane pin on the real impl (mirror the mock's `mLaneRoutedPin`). 4. `waitTransmitDone`: wraparound-safe elapsed-time computation using `(TickType_t)(now - start)` instead of absolute `deadline`. Correct past 32-bit tick counter wrap (~49 days at 1kHz FreeRTOS tick). 5. ISR trampoline: read `mI2sPort` via a new IRAM-safe accessor `i2sPortForIsr()` instead of `getConfig()` — getConfig returns a const reference and may not be inlined into IRAM under -Og. 6. Fix stale "4093 bytes" comment on the descriptor size check to match the 4092-byte cap actually enforced. ## Bench - `bash test channel_engine_i2s_esp32dev` — passes - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — pong, uptimeMs 2066 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2d slot swap — BusTraits<FLEX_IO, 0> → modern unified engine (#3526) Flips `Bus::FLEX_IO, 0` on classic ESP32 from the standalone `createI2sSpiEngine()` to the modern unified `createI2sEsp32DevEngine()`. The modern engine handles BOTH clockless and SPI batches on the same I2S1 peripheral per the parallel-IO unified-engine rule (`agents/docs/cpp-standards.md` -> \"Parallel-IO Driver: Unified Clockless + SPI Engine\"). SPI batches delegate to the tested `ChannelDriverI2sSpi` internally, so SPI users see no behavioral change — only the dispatch entry point moves. ## Prerequisite fix (same PR) `ChannelEngineI2sEsp32Dev::show()` used to `initialize()` the modern peripheral BEFORE checking whether the batch is clockless or SPI. That raced with the SPI delegate's own I2S1 claim on a SPI-only batch. Fix: postpone modern peripheral init to AFTER the SPI/clockless branch. SPI paths never touch modern's peripheral; only the clockless path initializes I2S1 for wave8 output. ## Impact - **Clockless on classic ESP32 (default)**: still routes through RMT (unaffected — RMT slot binding is separate). Only opt-in `-DFASTLED_ESP32_I2S=1` Yves binding is orthogonal to this swap. - **SPI (APA102/SK9822/HD108) on classic ESP32**: now dispatches through the modern engine's `show()` which delegates to `createI2sSpiEngine()`. Extra function-call layer only. - **`BusSupports<Bus::FLEX_IO, SpiChipsetConfig, 0>`**: still `true_type` — SPI still supported on the slot. ## Phase 2e teaser `drivers/i2s_spi/bus_traits.h` is now the ONE place returning the modern factory. The whole `drivers/i2s_spi/` directory is scheduled for deletion at Phase 2e once the delegate call inside the modern engine gets folded into a direct SPI-mode transmit path. This PR keeps the file location during rollout to avoid churning the `_build.cpp.hpp` wiring on the same PR that flips the binding. ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — pong, uptimeMs 2066 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2e — delete Yves, singleton peripheral, variable timing (#3526) Closes out #3526 Phase 2e — the modern classic-ESP32 I2S parallel-out clockless driver is now the only I2S path. ## Yves deletion (with attribution) Deleted: - `src/platforms/esp/32/drivers/i2s/clockless_i2s_esp32.{h,cpp.hpp}` - `src/platforms/esp/32/drivers/i2s/i2s_esp32dev.{h,cpp.hpp}` Updated call sites to remove `ClocklessI2S` alias: - `src/platforms/esp/clockless.h` — dropped the `#if defined(FASTLED_ESP32_I2S)` branch that aliased `ClocklessController = ClocklessI2S<>` - `src/platforms/esp/32/core/fastled_esp32.h` — removed the `#include \"clockless_i2s_esp32.h\"` guarded by `FASTLED_ESP32_HAS_I2S` - `src/platforms/esp/32/drivers/i2s/_build.cpp.hpp` — dropped the two `.cpp.hpp` includes - `src/FastLED.h` — replaced the deprecation-path warning with a hard removal message (`-DFASTLED_ESP32_I2S=1` now advises users to drop the flag and use `setExclusiveDriver<fl::Bus::FLEX_IO, 0>()` for the modern engine) Yves Bazin is credited as the original driver author in the docstrings of both `channel_engine_i2s_esp32dev.h` and `i2s_peripheral_esp32dev_esp.cpp.hpp` — every register write and DMA descriptor field in the modern impl traces its lineage to his original driver. ## Peripheral -> singleton Converted `I2sPeripheralEsp32DevEsp` to a process-lifetime `fl::Singleton<>`. The former namespace-scope `g_i2s1_hardware_claimed_by_modern` global is deleted — the singleton's `mInitialized` member is now the sole ownership record for I2S1 on classic ESP32. `createI2sEsp32DevEngine()` wraps the singleton in `fl::make_shared_no_tracking<II2sPeripheralEsp32Dev>(singleton)` — zero-overhead non-owning handle, no control block, no delete possible. ## Variable-timing waveN The peripheral's `initialize()` no longer hardcodes 8 MHz pixel clock. New `solveI2sClockDivider(target_hz, &N, &A, &B)` helper solves the classic-ESP32 fractional divider math (`80 MHz / (N + B/A)`) for any target frequency the engine picks. Config's `mPixelClockHz` field is now honored — engine can drive: - WS2812 at 800 kHz -> 8 MHz clock (N=10, A=1, B=0) - WS2811 at 400 kHz -> 3.2 MHz clock (N=25, A=1, B=0) - Any wave3-eligible chipset at its per-chipset rate via `wave3ClockFrequencyHz(timing)` Falls back to 8 MHz if `mPixelClockHz` is zero. ## Follow-up issues filed - #3561 — apply the same variable-timing pattern to PARLIO (currently uses `FL_ESP_PARLIO_CLOCK_FREQ_HZ` compile-time constant) - #3562 — hoist `solveI2sClockDivider()` to a shared `platforms/esp/32/core/` location so SPI / RMT / other drivers that open-code the same math can consume it ## Bench - `bash test --cpp --clean` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — `pong, uptimeMs: 2066` Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
…ase 8) (#3565) * fix(autoresearch): arm WDT at top of setup() so boot hangs don't wedge COM port Previously the unified WDT was armed lazily by FL_WATCHDOG_AUTO() at the top of loop(). If setup() hung (RPC bind null-deref, stalled static-init, wedged serial handshake), no WDT was armed and the COM port stayed owned by a dead sketch until manual power-cycle. Arm the WDT with a 20 s window at the very top of setup() so a hang here auto-reboots. Feed the WDT in the serial-monitor wait loop because on classic ESP32 (non-USB-CDC) that loop can span up to AUTORESEARCH_SERIAL_WAIT_MS = 120 s, well past the setup WDT window. FL_WATCHDOG_AUTO() at loop() top re-arms with the shorter loop-scoped timeout once setup() has finished. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): wave3 sibling encoder for I2S1 modern driver (#3526 Phase 2a) Adds `encodeChannelWave3_i2s1` alongside the existing `encodeChannelWave8_i2s1` to satisfy the meta-issue acceptance criterion "Wave3 fallback path exercised for a three-slot chipset". Wave3 saves 2.67x memory vs wave8 for chipsets whose T1/T2/T3 timing rounds to 1/2/N ticks per 3, gated by `fl::canUseWave3(timing)`. Pixel clock is per-chipset via `fl::wave3ClockFrequencyHz(timing)` instead of the fixed 8 MHz wave8 rate. The encoder reuses the shared `fl::wave3Transpose_16` kernel from `fl/channels/wave3.h` — same anti-drift rule as the wave8 sibling. Host tests verify byte-exact output against a direct-kernel-call reference using canonical WS2812 timing (verified wave3-eligible). Drops the `fl/channels/detail/wave3.hpp` and `detail/wave8.hpp` force-inline includes from this .cpp.hpp — the unity build pulls this file across multiple TUs and the force-inline kernels would emit in each. The public `.h` declarations resolve at link time to the single out-of-line definitions in `wave3.cpp.hpp` / `wave8.cpp.hpp`, avoiding double-inline bloat. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(channels): split detail/wave3.hpp + wave8.hpp into .h + .cpp.hpp The former `fl/channels/detail/wave3.hpp` and `detail/wave8.hpp` were force-inline headers (`FASTLED_FORCE_INLINE FL_IRAM FL_OPTIMIZE_FUNCTION`). Every translation unit that included them emitted the full transpose kernel body. With ~10 callers across PARLIO / LCD_CAM / LCD_SPI / I2S drivers and the public wave3/wave8 wrappers, that was ~10× the transpose code in the final binary. Split into: - `detail/wave3.h` + `detail/wave8.h` — declarations, constexpr LUTs that need compile-time visibility, and the `FL_WAVE8_SPREAD_TO_16` helper macro (kept in the .h since it's a #define) - `detail/wave3.cpp.hpp` + `detail/wave8.cpp.hpp` — out-of-line definitions (dropped FASTLED_FORCE_INLINE, kept FL_IRAM + FL_OPTIMIZE_FUNCTION for perf), compiled once via the channels/detail unity build Updated 6 caller files (+2 tests) to include the new `.h` headers instead of the deleted `.hpp` files. The public API (`wave3Transpose_*` / `wave8Transpose_*` in `wave3.h` / `wave8.h`) is untouched — this is a pure implementation refactor. Perf note: dropping FASTLED_FORCE_INLINE means the transpose kernels no longer get inlined into every caller. On the in-order RV32 P4 core this could regress the encode-loop-hot-path per-frame timing measured in #2548 by a few percent (from lost cross-position ILP inside the same function scope). If bench data shows a regression, the fix is to keep the specific hot-path kernels (bf1_pipe4, etc.) FASTLED_FORCE_INLINE in the .h — the pattern here is per-function, not all-or-nothing. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step A — inline register-level init on modern peripheral (#3526) Drops the `#include \"platforms/esp/32/drivers/i2s/i2s_esp32dev.h\"` from `I2sPeripheralEsp32DevEsp::initialize`/`deinitialize`. Replaces the calls to Yves's `i2s_define_bit_patterns` / `i2s_init` / `i2s_stop` with direct register writes on `I2S0`/`I2S1` via `soc/i2s_struct.h`. Fixed 8 MHz pixel clock for wave8 output (80 MHz APB / (10 + 0/1)) — no per-chipset clock math. This is the general-clockless architecture the meta issue mandates (PARLIO-style), NOT Yves's per-chipset bit-pattern encoder. Register-write sequence mirrors Yves's proven init sequence exactly: - reset (`lc_conf` + `conf` reset flags) - reset DMA (`lc_conf.in_rst`/`out_rst`) - reset FIFO (`conf.rx_fifo_reset`/`tx_fifo_reset`) - parallel mode (`conf2.lcd_en = 1`, 16-lane width) - 32-bit-parallel sample rate config - fixed 8 MHz clkm divider (N=10, A=1, B=0) - FIFO in DMA-serviced 32-bit mode - PCM bypass Ownership tracked via a private static `g_i2s1_hardware_claimed_by_modern` flag — no dependency on Yves's `gInitializedI2sInitialized`. During the rollout only one binding path is active at a time (Yves via `-DFASTLED_ESP32_I2S=1`, modern via `Bus::FLEX_IO, 0` after Phase 2d), so there is no cross-driver race. `deinitialize()` clears `tx_start` + resets the block directly. `transmit()` remains a stub — Phase 2b step B lands the `lldesc_t` descriptor ring, `esp_intr_alloc()` ISR install, and real DMA kick. ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` after WDT-driven recovery from the intermittent first-boot `fl::json::json(const char*)` panic (unrelated pre-existing bug tracked separately) ## Also included Updates two AutoResearch example headers I missed in the earlier detail-split sweep (#3555): - `examples/AutoResearch/AutoResearchParlioEncode.h` - `examples/AutoResearch/AutoResearchWave8Expand.h` Both now include `fl/channels/detail/wave8.h` (declarations) instead of the deleted force-inline `.hpp`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step B — DMA descriptor + esp_intr_alloc ISR (#3526) Completes the real-hardware DMA path on the modern I2S1 peripheral. `transmit()` now: 1. Points a DMA-capable `lldesc_t` at the caller's buffer 2. Resets the peripheral, arms `out_link.addr` + `out_link.start` 3. Enables the pre-installed OUT_EOF ISR 4. Flips `mBusy = true` and starts the DMA (`conf.tx_start = 1`) The ISR trampoline `i2s_dma_isr_trampoline` (FL_IRAM, ISR context) clears the interrupt, stops `tx_start`, and calls `I2sPeripheralEsp32DevEsp::finishTransmitFromIsr()` which flips `mBusy = false` and dispatches the registered completion callback (the channel-engine trampoline just flips its `mTransmitCompleted` flag — already ISR-safe). Descriptor allocated at `initialize()` time via `heap_caps_malloc` with `MALLOC_CAP_DMA` (DMA-capable DRAM). ISR handle allocated via `esp_intr_alloc(ETS_I2S1_INTR_SOURCE, ESP_INTR_FLAG_IRAM, ...)`. Both released in `deinitialize()`. `waitTransmitDone(timeout_ms)` is now a real deadline-bounded spin that yields via `vTaskDelay(1)` while `mBusy` — no more (void)timeout fake return. ## Scope limits (deferred to follow-up) - **Single descriptor, one-shot only**: buffers larger than 4092 bytes are rejected (the `lldesc_t` length field is 12 bits). Streaming refill from the ISR — for full-frame 128-byte-per-lane-per-strip wave8 output past 4 KB — is a follow-up. - **No GPIO mux routing**: the peripheral is configured for parallel- out but the 16 lane pins are not yet mapped via `gpio_matrix_out` — that's Phase 2b step C (which adds `configureTiming` + per-channel GPIO plumbing on the engine side). ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` (WDT recovery from the intermittent first-boot panic works cleanly). Modern engine is inert at runtime (not bound to `Bus::FLEX_IO, 0` yet — that's Phase 2d), so the DMA/ISR code compiles + boots but doesn't execute on this run. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step C — GPIO mux routing for I2S1 lanes (#3526) Adds `II2sPeripheralEsp32Dev::routeLanePin(lane, gpio_pin)` for wiring one parallel-out data lane to a specific GPIO pin. Called by the engine (in a follow-up) after `initialize()` for each active channel, before the first `transmit()`. ## Real hardware impl `I2sPeripheralEsp32DevEsp::routeLanePin` uses the IDF v5-safe `esp_rom_gpio_connect_out_signal(gpio_num, signal_idx, out_inv, oen_inv)` API (replaces the legacy `gpio_matrix_out`). Signal index computed as `I2S{n}O_DATA_OUT0_IDX + lane`, honoring the peripheral config's per-strip invert mask so chipsets needing polarity inversion get it "for free" through the GPIO matrix rather than in the encoder. Pin put into output mode via `gpio_set_direction`. ## Mock `I2sPeripheralEsp32DevMock::routeLanePin` records the (lane, pin) pair. Two new introspection methods for tests: - `laneRouteInvocationCount()` — call count since last `reset()` - `lastRoutedPinForLane(lane)` — most recent pin, or -1 if unrouted ## Test coverage New host test `Modern I2S peripheral: routeLanePin records mock mapping`: - Uninitialised peripheral rejects the route - Multiple lane routings recorded correctly - Out-of-range lanes (16, 17) rejected - Re-routing replaces the previous pin - `reset()` clears everything ## Bench - `bash test --cpp` — 346/346 tests pass (new test brings total up by 1) - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` ## What's still gated on Phase 2b step D - Streaming DMA descriptor ring (current impl is single-descriptor, 4092-byte limit) - Engine-side `configureTiming()` that plumbs per-channel GPIO pins from `ChannelData::getPin()` down to `routeLanePin` calls Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * address CodeRabbit review: pad-select, real clear path, IRAM-safe ISR, wraparound-safe wait, shared lane constant Reviews on PR #3558: 1. Extract lane cap into a shared `kMaxI2sLanes = 24` constant in `ii2s_peripheral_esp32dev.h`; both mock and real impl reference it. 2. `routeLanePin`: select the pad's GPIO function via `esp_rom_gpio_pad_select_gpio()` BEFORE `gpio_set_direction()` so pins booting in an alternate function (SD_CMD, etc.) can drive I2S. 3. `routeLanePin(lane, -1)`: actually detach the previously-routed pin by writing `SIG_GPIO_OUT_IDX` in its place. Requires tracking the per-lane pin on the real impl (mirror the mock's `mLaneRoutedPin`). 4. `waitTransmitDone`: wraparound-safe elapsed-time computation using `(TickType_t)(now - start)` instead of absolute `deadline`. Correct past 32-bit tick counter wrap (~49 days at 1kHz FreeRTOS tick). 5. ISR trampoline: read `mI2sPort` via a new IRAM-safe accessor `i2sPortForIsr()` instead of `getConfig()` — getConfig returns a const reference and may not be inlined into IRAM under -Og. 6. Fix stale "4093 bytes" comment on the descriptor size check to match the 4092-byte cap actually enforced. ## Bench - `bash test channel_engine_i2s_esp32dev` — passes - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — pong, uptimeMs 2066 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2d slot swap — BusTraits<FLEX_IO, 0> → modern unified engine (#3526) Flips `Bus::FLEX_IO, 0` on classic ESP32 from the standalone `createI2sSpiEngine()` to the modern unified `createI2sEsp32DevEngine()`. The modern engine handles BOTH clockless and SPI batches on the same I2S1 peripheral per the parallel-IO unified-engine rule (`agents/docs/cpp-standards.md` -> \"Parallel-IO Driver: Unified Clockless + SPI Engine\"). SPI batches delegate to the tested `ChannelDriverI2sSpi` internally, so SPI users see no behavioral change — only the dispatch entry point moves. ## Prerequisite fix (same PR) `ChannelEngineI2sEsp32Dev::show()` used to `initialize()` the modern peripheral BEFORE checking whether the batch is clockless or SPI. That raced with the SPI delegate's own I2S1 claim on a SPI-only batch. Fix: postpone modern peripheral init to AFTER the SPI/clockless branch. SPI paths never touch modern's peripheral; only the clockless path initializes I2S1 for wave8 output. ## Impact - **Clockless on classic ESP32 (default)**: still routes through RMT (unaffected — RMT slot binding is separate). Only opt-in `-DFASTLED_ESP32_I2S=1` Yves binding is orthogonal to this swap. - **SPI (APA102/SK9822/HD108) on classic ESP32**: now dispatches through the modern engine's `show()` which delegates to `createI2sSpiEngine()`. Extra function-call layer only. - **`BusSupports<Bus::FLEX_IO, SpiChipsetConfig, 0>`**: still `true_type` — SPI still supported on the slot. ## Phase 2e teaser `drivers/i2s_spi/bus_traits.h` is now the ONE place returning the modern factory. The whole `drivers/i2s_spi/` directory is scheduled for deletion at Phase 2e once the delegate call inside the modern engine gets folded into a direct SPI-mode transmit path. This PR keeps the file location during rollout to avoid churning the `_build.cpp.hpp` wiring on the same PR that flips the binding. ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — pong, uptimeMs 2066 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2e — delete Yves, singleton peripheral, variable timing (#3526) Closes out #3526 Phase 2e — the modern classic-ESP32 I2S parallel-out clockless driver is now the only I2S path. ## Yves deletion (with attribution) Deleted: - `src/platforms/esp/32/drivers/i2s/clockless_i2s_esp32.{h,cpp.hpp}` - `src/platforms/esp/32/drivers/i2s/i2s_esp32dev.{h,cpp.hpp}` Updated call sites to remove `ClocklessI2S` alias: - `src/platforms/esp/clockless.h` — dropped the `#if defined(FASTLED_ESP32_I2S)` branch that aliased `ClocklessController = ClocklessI2S<>` - `src/platforms/esp/32/core/fastled_esp32.h` — removed the `#include \"clockless_i2s_esp32.h\"` guarded by `FASTLED_ESP32_HAS_I2S` - `src/platforms/esp/32/drivers/i2s/_build.cpp.hpp` — dropped the two `.cpp.hpp` includes - `src/FastLED.h` — replaced the deprecation-path warning with a hard removal message (`-DFASTLED_ESP32_I2S=1` now advises users to drop the flag and use `setExclusiveDriver<fl::Bus::FLEX_IO, 0>()` for the modern engine) Yves Bazin is credited as the original driver author in the docstrings of both `channel_engine_i2s_esp32dev.h` and `i2s_peripheral_esp32dev_esp.cpp.hpp` — every register write and DMA descriptor field in the modern impl traces its lineage to his original driver. ## Peripheral -> singleton Converted `I2sPeripheralEsp32DevEsp` to a process-lifetime `fl::Singleton<>`. The former namespace-scope `g_i2s1_hardware_claimed_by_modern` global is deleted — the singleton's `mInitialized` member is now the sole ownership record for I2S1 on classic ESP32. `createI2sEsp32DevEngine()` wraps the singleton in `fl::make_shared_no_tracking<II2sPeripheralEsp32Dev>(singleton)` — zero-overhead non-owning handle, no control block, no delete possible. ## Variable-timing waveN The peripheral's `initialize()` no longer hardcodes 8 MHz pixel clock. New `solveI2sClockDivider(target_hz, &N, &A, &B)` helper solves the classic-ESP32 fractional divider math (`80 MHz / (N + B/A)`) for any target frequency the engine picks. Config's `mPixelClockHz` field is now honored — engine can drive: - WS2812 at 800 kHz -> 8 MHz clock (N=10, A=1, B=0) - WS2811 at 400 kHz -> 3.2 MHz clock (N=25, A=1, B=0) - Any wave3-eligible chipset at its per-chipset rate via `wave3ClockFrequencyHz(timing)` Falls back to 8 MHz if `mPixelClockHz` is zero. ## Follow-up issues filed - #3561 — apply the same variable-timing pattern to PARLIO (currently uses `FL_ESP_PARLIO_CLOCK_FREQ_HZ` compile-time constant) - #3562 — hoist `solveI2sClockDivider()` to a shared `platforms/esp/32/core/` location so SPI / RMT / other drivers that open-code the same math can consume it ## Bench - `bash test --cpp --clean` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — `pong, uptimeMs: 2066` Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(i2s): rewrite README for modern engine (#3526 Phase 8 / #3512 Phase 8) Rewrites `src/platforms/esp/32/drivers/i2s/README.md` to reflect the current state after #3526 Phases 2a-2e: - Yves attribution as the original I2S1 parallel-out driver author - Modern channel-manager engine + wave8/wave3 encoding architecture - `fl::Singleton<>` peripheral + `make_shared_no_tracking` wrapping - Variable-rate waveN encoding (`solveI2sClockDivider`) for non-800kHz chipsets (WS2811 at 400 kHz, etc.) - Multi-lane GPIO routing to 24 lanes via `routeLanePin` - Removed `-DFASTLED_ESP32_I2S=1` at Phase 2e — replaced with `setExclusiveDriver<fl::Bus::FLEX_IO, 0>()` runtime selection - Documented streaming ISR-refill invariant that Phase 2b step D needs to preserve (Yves's ping-pong ring pattern in git history) - Cross-referenced closed sub-issues (#3489 singleton, #1165 I2S_DEVICE=1 pin routing, #1384 async surface) Closes the "Phase 8: README" acceptance criterion of both #3526 and #3512. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
#3566) * fix(autoresearch): arm WDT at top of setup() so boot hangs don't wedge COM port Previously the unified WDT was armed lazily by FL_WATCHDOG_AUTO() at the top of loop(). If setup() hung (RPC bind null-deref, stalled static-init, wedged serial handshake), no WDT was armed and the COM port stayed owned by a dead sketch until manual power-cycle. Arm the WDT with a 20 s window at the very top of setup() so a hang here auto-reboots. Feed the WDT in the serial-monitor wait loop because on classic ESP32 (non-USB-CDC) that loop can span up to AUTORESEARCH_SERIAL_WAIT_MS = 120 s, well past the setup WDT window. FL_WATCHDOG_AUTO() at loop() top re-arms with the shorter loop-scoped timeout once setup() has finished. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): wave3 sibling encoder for I2S1 modern driver (#3526 Phase 2a) Adds `encodeChannelWave3_i2s1` alongside the existing `encodeChannelWave8_i2s1` to satisfy the meta-issue acceptance criterion "Wave3 fallback path exercised for a three-slot chipset". Wave3 saves 2.67x memory vs wave8 for chipsets whose T1/T2/T3 timing rounds to 1/2/N ticks per 3, gated by `fl::canUseWave3(timing)`. Pixel clock is per-chipset via `fl::wave3ClockFrequencyHz(timing)` instead of the fixed 8 MHz wave8 rate. The encoder reuses the shared `fl::wave3Transpose_16` kernel from `fl/channels/wave3.h` — same anti-drift rule as the wave8 sibling. Host tests verify byte-exact output against a direct-kernel-call reference using canonical WS2812 timing (verified wave3-eligible). Drops the `fl/channels/detail/wave3.hpp` and `detail/wave8.hpp` force-inline includes from this .cpp.hpp — the unity build pulls this file across multiple TUs and the force-inline kernels would emit in each. The public `.h` declarations resolve at link time to the single out-of-line definitions in `wave3.cpp.hpp` / `wave8.cpp.hpp`, avoiding double-inline bloat. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(channels): split detail/wave3.hpp + wave8.hpp into .h + .cpp.hpp The former `fl/channels/detail/wave3.hpp` and `detail/wave8.hpp` were force-inline headers (`FASTLED_FORCE_INLINE FL_IRAM FL_OPTIMIZE_FUNCTION`). Every translation unit that included them emitted the full transpose kernel body. With ~10 callers across PARLIO / LCD_CAM / LCD_SPI / I2S drivers and the public wave3/wave8 wrappers, that was ~10× the transpose code in the final binary. Split into: - `detail/wave3.h` + `detail/wave8.h` — declarations, constexpr LUTs that need compile-time visibility, and the `FL_WAVE8_SPREAD_TO_16` helper macro (kept in the .h since it's a #define) - `detail/wave3.cpp.hpp` + `detail/wave8.cpp.hpp` — out-of-line definitions (dropped FASTLED_FORCE_INLINE, kept FL_IRAM + FL_OPTIMIZE_FUNCTION for perf), compiled once via the channels/detail unity build Updated 6 caller files (+2 tests) to include the new `.h` headers instead of the deleted `.hpp` files. The public API (`wave3Transpose_*` / `wave8Transpose_*` in `wave3.h` / `wave8.h`) is untouched — this is a pure implementation refactor. Perf note: dropping FASTLED_FORCE_INLINE means the transpose kernels no longer get inlined into every caller. On the in-order RV32 P4 core this could regress the encode-loop-hot-path per-frame timing measured in #2548 by a few percent (from lost cross-position ILP inside the same function scope). If bench data shows a regression, the fix is to keep the specific hot-path kernels (bf1_pipe4, etc.) FASTLED_FORCE_INLINE in the .h — the pattern here is per-function, not all-or-nothing. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step A — inline register-level init on modern peripheral (#3526) Drops the `#include \"platforms/esp/32/drivers/i2s/i2s_esp32dev.h\"` from `I2sPeripheralEsp32DevEsp::initialize`/`deinitialize`. Replaces the calls to Yves's `i2s_define_bit_patterns` / `i2s_init` / `i2s_stop` with direct register writes on `I2S0`/`I2S1` via `soc/i2s_struct.h`. Fixed 8 MHz pixel clock for wave8 output (80 MHz APB / (10 + 0/1)) — no per-chipset clock math. This is the general-clockless architecture the meta issue mandates (PARLIO-style), NOT Yves's per-chipset bit-pattern encoder. Register-write sequence mirrors Yves's proven init sequence exactly: - reset (`lc_conf` + `conf` reset flags) - reset DMA (`lc_conf.in_rst`/`out_rst`) - reset FIFO (`conf.rx_fifo_reset`/`tx_fifo_reset`) - parallel mode (`conf2.lcd_en = 1`, 16-lane width) - 32-bit-parallel sample rate config - fixed 8 MHz clkm divider (N=10, A=1, B=0) - FIFO in DMA-serviced 32-bit mode - PCM bypass Ownership tracked via a private static `g_i2s1_hardware_claimed_by_modern` flag — no dependency on Yves's `gInitializedI2sInitialized`. During the rollout only one binding path is active at a time (Yves via `-DFASTLED_ESP32_I2S=1`, modern via `Bus::FLEX_IO, 0` after Phase 2d), so there is no cross-driver race. `deinitialize()` clears `tx_start` + resets the block directly. `transmit()` remains a stub — Phase 2b step B lands the `lldesc_t` descriptor ring, `esp_intr_alloc()` ISR install, and real DMA kick. ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` after WDT-driven recovery from the intermittent first-boot `fl::json::json(const char*)` panic (unrelated pre-existing bug tracked separately) ## Also included Updates two AutoResearch example headers I missed in the earlier detail-split sweep (#3555): - `examples/AutoResearch/AutoResearchParlioEncode.h` - `examples/AutoResearch/AutoResearchWave8Expand.h` Both now include `fl/channels/detail/wave8.h` (declarations) instead of the deleted force-inline `.hpp`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step B — DMA descriptor + esp_intr_alloc ISR (#3526) Completes the real-hardware DMA path on the modern I2S1 peripheral. `transmit()` now: 1. Points a DMA-capable `lldesc_t` at the caller's buffer 2. Resets the peripheral, arms `out_link.addr` + `out_link.start` 3. Enables the pre-installed OUT_EOF ISR 4. Flips `mBusy = true` and starts the DMA (`conf.tx_start = 1`) The ISR trampoline `i2s_dma_isr_trampoline` (FL_IRAM, ISR context) clears the interrupt, stops `tx_start`, and calls `I2sPeripheralEsp32DevEsp::finishTransmitFromIsr()` which flips `mBusy = false` and dispatches the registered completion callback (the channel-engine trampoline just flips its `mTransmitCompleted` flag — already ISR-safe). Descriptor allocated at `initialize()` time via `heap_caps_malloc` with `MALLOC_CAP_DMA` (DMA-capable DRAM). ISR handle allocated via `esp_intr_alloc(ETS_I2S1_INTR_SOURCE, ESP_INTR_FLAG_IRAM, ...)`. Both released in `deinitialize()`. `waitTransmitDone(timeout_ms)` is now a real deadline-bounded spin that yields via `vTaskDelay(1)` while `mBusy` — no more (void)timeout fake return. ## Scope limits (deferred to follow-up) - **Single descriptor, one-shot only**: buffers larger than 4092 bytes are rejected (the `lldesc_t` length field is 12 bits). Streaming refill from the ISR — for full-frame 128-byte-per-lane-per-strip wave8 output past 4 KB — is a follow-up. - **No GPIO mux routing**: the peripheral is configured for parallel- out but the 16 lane pins are not yet mapped via `gpio_matrix_out` — that's Phase 2b step C (which adds `configureTiming` + per-channel GPIO plumbing on the engine side). ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` (WDT recovery from the intermittent first-boot panic works cleanly). Modern engine is inert at runtime (not bound to `Bus::FLEX_IO, 0` yet — that's Phase 2d), so the DMA/ISR code compiles + boots but doesn't execute on this run. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step C — GPIO mux routing for I2S1 lanes (#3526) Adds `II2sPeripheralEsp32Dev::routeLanePin(lane, gpio_pin)` for wiring one parallel-out data lane to a specific GPIO pin. Called by the engine (in a follow-up) after `initialize()` for each active channel, before the first `transmit()`. ## Real hardware impl `I2sPeripheralEsp32DevEsp::routeLanePin` uses the IDF v5-safe `esp_rom_gpio_connect_out_signal(gpio_num, signal_idx, out_inv, oen_inv)` API (replaces the legacy `gpio_matrix_out`). Signal index computed as `I2S{n}O_DATA_OUT0_IDX + lane`, honoring the peripheral config's per-strip invert mask so chipsets needing polarity inversion get it "for free" through the GPIO matrix rather than in the encoder. Pin put into output mode via `gpio_set_direction`. ## Mock `I2sPeripheralEsp32DevMock::routeLanePin` records the (lane, pin) pair. Two new introspection methods for tests: - `laneRouteInvocationCount()` — call count since last `reset()` - `lastRoutedPinForLane(lane)` — most recent pin, or -1 if unrouted ## Test coverage New host test `Modern I2S peripheral: routeLanePin records mock mapping`: - Uninitialised peripheral rejects the route - Multiple lane routings recorded correctly - Out-of-range lanes (16, 17) rejected - Re-routing replaces the previous pin - `reset()` clears everything ## Bench - `bash test --cpp` — 346/346 tests pass (new test brings total up by 1) - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` ## What's still gated on Phase 2b step D - Streaming DMA descriptor ring (current impl is single-descriptor, 4092-byte limit) - Engine-side `configureTiming()` that plumbs per-channel GPIO pins from `ChannelData::getPin()` down to `routeLanePin` calls Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * address CodeRabbit review: pad-select, real clear path, IRAM-safe ISR, wraparound-safe wait, shared lane constant Reviews on PR #3558: 1. Extract lane cap into a shared `kMaxI2sLanes = 24` constant in `ii2s_peripheral_esp32dev.h`; both mock and real impl reference it. 2. `routeLanePin`: select the pad's GPIO function via `esp_rom_gpio_pad_select_gpio()` BEFORE `gpio_set_direction()` so pins booting in an alternate function (SD_CMD, etc.) can drive I2S. 3. `routeLanePin(lane, -1)`: actually detach the previously-routed pin by writing `SIG_GPIO_OUT_IDX` in its place. Requires tracking the per-lane pin on the real impl (mirror the mock's `mLaneRoutedPin`). 4. `waitTransmitDone`: wraparound-safe elapsed-time computation using `(TickType_t)(now - start)` instead of absolute `deadline`. Correct past 32-bit tick counter wrap (~49 days at 1kHz FreeRTOS tick). 5. ISR trampoline: read `mI2sPort` via a new IRAM-safe accessor `i2sPortForIsr()` instead of `getConfig()` — getConfig returns a const reference and may not be inlined into IRAM under -Og. 6. Fix stale "4093 bytes" comment on the descriptor size check to match the 4092-byte cap actually enforced. ## Bench - `bash test channel_engine_i2s_esp32dev` — passes - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — pong, uptimeMs 2066 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2d slot swap — BusTraits<FLEX_IO, 0> → modern unified engine (#3526) Flips `Bus::FLEX_IO, 0` on classic ESP32 from the standalone `createI2sSpiEngine()` to the modern unified `createI2sEsp32DevEngine()`. The modern engine handles BOTH clockless and SPI batches on the same I2S1 peripheral per the parallel-IO unified-engine rule (`agents/docs/cpp-standards.md` -> \"Parallel-IO Driver: Unified Clockless + SPI Engine\"). SPI batches delegate to the tested `ChannelDriverI2sSpi` internally, so SPI users see no behavioral change — only the dispatch entry point moves. ## Prerequisite fix (same PR) `ChannelEngineI2sEsp32Dev::show()` used to `initialize()` the modern peripheral BEFORE checking whether the batch is clockless or SPI. That raced with the SPI delegate's own I2S1 claim on a SPI-only batch. Fix: postpone modern peripheral init to AFTER the SPI/clockless branch. SPI paths never touch modern's peripheral; only the clockless path initializes I2S1 for wave8 output. ## Impact - **Clockless on classic ESP32 (default)**: still routes through RMT (unaffected — RMT slot binding is separate). Only opt-in `-DFASTLED_ESP32_I2S=1` Yves binding is orthogonal to this swap. - **SPI (APA102/SK9822/HD108) on classic ESP32**: now dispatches through the modern engine's `show()` which delegates to `createI2sSpiEngine()`. Extra function-call layer only. - **`BusSupports<Bus::FLEX_IO, SpiChipsetConfig, 0>`**: still `true_type` — SPI still supported on the slot. ## Phase 2e teaser `drivers/i2s_spi/bus_traits.h` is now the ONE place returning the modern factory. The whole `drivers/i2s_spi/` directory is scheduled for deletion at Phase 2e once the delegate call inside the modern engine gets folded into a direct SPI-mode transmit path. This PR keeps the file location during rollout to avoid churning the `_build.cpp.hpp` wiring on the same PR that flips the binding. ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — pong, uptimeMs 2066 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2e — delete Yves, singleton peripheral, variable timing (#3526) Closes out #3526 Phase 2e — the modern classic-ESP32 I2S parallel-out clockless driver is now the only I2S path. ## Yves deletion (with attribution) Deleted: - `src/platforms/esp/32/drivers/i2s/clockless_i2s_esp32.{h,cpp.hpp}` - `src/platforms/esp/32/drivers/i2s/i2s_esp32dev.{h,cpp.hpp}` Updated call sites to remove `ClocklessI2S` alias: - `src/platforms/esp/clockless.h` — dropped the `#if defined(FASTLED_ESP32_I2S)` branch that aliased `ClocklessController = ClocklessI2S<>` - `src/platforms/esp/32/core/fastled_esp32.h` — removed the `#include \"clockless_i2s_esp32.h\"` guarded by `FASTLED_ESP32_HAS_I2S` - `src/platforms/esp/32/drivers/i2s/_build.cpp.hpp` — dropped the two `.cpp.hpp` includes - `src/FastLED.h` — replaced the deprecation-path warning with a hard removal message (`-DFASTLED_ESP32_I2S=1` now advises users to drop the flag and use `setExclusiveDriver<fl::Bus::FLEX_IO, 0>()` for the modern engine) Yves Bazin is credited as the original driver author in the docstrings of both `channel_engine_i2s_esp32dev.h` and `i2s_peripheral_esp32dev_esp.cpp.hpp` — every register write and DMA descriptor field in the modern impl traces its lineage to his original driver. ## Peripheral -> singleton Converted `I2sPeripheralEsp32DevEsp` to a process-lifetime `fl::Singleton<>`. The former namespace-scope `g_i2s1_hardware_claimed_by_modern` global is deleted — the singleton's `mInitialized` member is now the sole ownership record for I2S1 on classic ESP32. `createI2sEsp32DevEngine()` wraps the singleton in `fl::make_shared_no_tracking<II2sPeripheralEsp32Dev>(singleton)` — zero-overhead non-owning handle, no control block, no delete possible. ## Variable-timing waveN The peripheral's `initialize()` no longer hardcodes 8 MHz pixel clock. New `solveI2sClockDivider(target_hz, &N, &A, &B)` helper solves the classic-ESP32 fractional divider math (`80 MHz / (N + B/A)`) for any target frequency the engine picks. Config's `mPixelClockHz` field is now honored — engine can drive: - WS2812 at 800 kHz -> 8 MHz clock (N=10, A=1, B=0) - WS2811 at 400 kHz -> 3.2 MHz clock (N=25, A=1, B=0) - Any wave3-eligible chipset at its per-chipset rate via `wave3ClockFrequencyHz(timing)` Falls back to 8 MHz if `mPixelClockHz` is zero. ## Follow-up issues filed - #3561 — apply the same variable-timing pattern to PARLIO (currently uses `FL_ESP_PARLIO_CLOCK_FREQ_HZ` compile-time constant) - #3562 — hoist `solveI2sClockDivider()` to a shared `platforms/esp/32/core/` location so SPI / RMT / other drivers that open-code the same math can consume it ## Bench - `bash test --cpp --clean` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — `pong, uptimeMs: 2066` Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(i2s): rewrite README for modern engine (#3526 Phase 8 / #3512 Phase 8) Rewrites `src/platforms/esp/32/drivers/i2s/README.md` to reflect the current state after #3526 Phases 2a-2e: - Yves attribution as the original I2S1 parallel-out driver author - Modern channel-manager engine + wave8/wave3 encoding architecture - `fl::Singleton<>` peripheral + `make_shared_no_tracking` wrapping - Variable-rate waveN encoding (`solveI2sClockDivider`) for non-800kHz chipsets (WS2811 at 400 kHz, etc.) - Multi-lane GPIO routing to 24 lanes via `routeLanePin` - Removed `-DFASTLED_ESP32_I2S=1` at Phase 2e — replaced with `setExclusiveDriver<fl::Bus::FLEX_IO, 0>()` runtime selection - Documented streaming ISR-refill invariant that Phase 2b step D needs to preserve (Yves's ping-pong ring pattern in git history) - Cross-referenced closed sub-issues (#3489 singleton, #1165 I2S_DEVICE=1 pin routing, #1384 async surface) Closes the "Phase 8: README" acceptance criterion of both #3526 and #3512. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): wire wave8 encoding into engine + routeLanePin call (#3526) Fixes the gap identified by the live-bench validation in #3515: the modern I2S engine's clockless path was not actually producing WS2812 timing on the wire because: 1. `packScratchBuffer()` was concatenating raw pixel bytes, not wave8-encoding them. DMA output at 8 MHz emits raw pixels, not the pulse-major waveform WS2812 expects. 2. The engine never called `peripheral->routeLanePin()` — the I2S1 DATA_OUT signals had no physical GPIO destination. ## Changes **Engine (`packScratchBuffer`):** now runs the wave8 pulse-major encoder (`encodeChannelWave8_i2s1`) over lane-strided input. Output size = `bytes_per_lane * 128` (16 lanes × 8 pulses per input byte). Uses in-buffer input scratch after the output region so the caller's peripheral only sees the encoded prefix. **Engine (`show`):** sizes the scratch buffer for both output + input regions via `wave8I2s1EncodedFrameSize()` + `16 * bytes_per_lane`. **Engine (`show`):** after `initialize()`, iterates in-flight channels and calls `peripheral->routeLanePin(lane_idx, data->getPin())` to route each channel's pin through the I2S1 GPIO matrix. Handles up to 16 lanes (wave8 kernel width); further lanes truncated. **Config:** switched default pixel clock from 2.4 MHz to 8 MHz to match wave8's WS2812 800kHz × 8 pulses/bit rate. **Test update:** rewrote the raw-byte-concat expectation (`0xAA`s + `0xBB`s) into a byte-exact wave8 output check against a direct `encodeChannelWave8_i2s1()` reference call. Anti-drift — if the shared kernel changes, this test inherits the change automatically. Second test's `size_bytes` assertion updated from `3u` to `3u * 128u`. ## Bench state after this PR - Modern engine runtime binding: ✅ (`driverName: "I2S"`) - FastLED.show() through modern engine: ✅ (device stays alive) - Wave8 encoder emits proper output size: ✅ (host tests byte-exact) - Physical wire edges captured via RMT RX loopback: ❌ (still `captureFailed: true, rawEdgesAfterWait: 0`) The remaining bench gap is at the peripheral register-config level: `tx_bits_mod = 32`, `fifo_conf.tx_fifo_mod = 3`, and the clkm divider math need bench-side scope validation to confirm the FIFO actually clocks the wave8 bytes out at 8 MHz through the routed GPIO. Debug work continues in follow-up. ## Test plan - [x] `bash test --cpp` — 345/345 pass (wave8 byte-exact check green) - [x] `bash lint --cpp` — clean - [x] `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - [x] Flash to ESP32-WROOM — device boots, RPC responds - [ ] Bench loopback byte-exact WS2812 output — still failing (see above) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
…3567) * fix(autoresearch): arm WDT at top of setup() so boot hangs don't wedge COM port Previously the unified WDT was armed lazily by FL_WATCHDOG_AUTO() at the top of loop(). If setup() hung (RPC bind null-deref, stalled static-init, wedged serial handshake), no WDT was armed and the COM port stayed owned by a dead sketch until manual power-cycle. Arm the WDT with a 20 s window at the very top of setup() so a hang here auto-reboots. Feed the WDT in the serial-monitor wait loop because on classic ESP32 (non-USB-CDC) that loop can span up to AUTORESEARCH_SERIAL_WAIT_MS = 120 s, well past the setup WDT window. FL_WATCHDOG_AUTO() at loop() top re-arms with the shorter loop-scoped timeout once setup() has finished. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): wave3 sibling encoder for I2S1 modern driver (#3526 Phase 2a) Adds `encodeChannelWave3_i2s1` alongside the existing `encodeChannelWave8_i2s1` to satisfy the meta-issue acceptance criterion "Wave3 fallback path exercised for a three-slot chipset". Wave3 saves 2.67x memory vs wave8 for chipsets whose T1/T2/T3 timing rounds to 1/2/N ticks per 3, gated by `fl::canUseWave3(timing)`. Pixel clock is per-chipset via `fl::wave3ClockFrequencyHz(timing)` instead of the fixed 8 MHz wave8 rate. The encoder reuses the shared `fl::wave3Transpose_16` kernel from `fl/channels/wave3.h` — same anti-drift rule as the wave8 sibling. Host tests verify byte-exact output against a direct-kernel-call reference using canonical WS2812 timing (verified wave3-eligible). Drops the `fl/channels/detail/wave3.hpp` and `detail/wave8.hpp` force-inline includes from this .cpp.hpp — the unity build pulls this file across multiple TUs and the force-inline kernels would emit in each. The public `.h` declarations resolve at link time to the single out-of-line definitions in `wave3.cpp.hpp` / `wave8.cpp.hpp`, avoiding double-inline bloat. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(channels): split detail/wave3.hpp + wave8.hpp into .h + .cpp.hpp The former `fl/channels/detail/wave3.hpp` and `detail/wave8.hpp` were force-inline headers (`FASTLED_FORCE_INLINE FL_IRAM FL_OPTIMIZE_FUNCTION`). Every translation unit that included them emitted the full transpose kernel body. With ~10 callers across PARLIO / LCD_CAM / LCD_SPI / I2S drivers and the public wave3/wave8 wrappers, that was ~10× the transpose code in the final binary. Split into: - `detail/wave3.h` + `detail/wave8.h` — declarations, constexpr LUTs that need compile-time visibility, and the `FL_WAVE8_SPREAD_TO_16` helper macro (kept in the .h since it's a #define) - `detail/wave3.cpp.hpp` + `detail/wave8.cpp.hpp` — out-of-line definitions (dropped FASTLED_FORCE_INLINE, kept FL_IRAM + FL_OPTIMIZE_FUNCTION for perf), compiled once via the channels/detail unity build Updated 6 caller files (+2 tests) to include the new `.h` headers instead of the deleted `.hpp` files. The public API (`wave3Transpose_*` / `wave8Transpose_*` in `wave3.h` / `wave8.h`) is untouched — this is a pure implementation refactor. Perf note: dropping FASTLED_FORCE_INLINE means the transpose kernels no longer get inlined into every caller. On the in-order RV32 P4 core this could regress the encode-loop-hot-path per-frame timing measured in #2548 by a few percent (from lost cross-position ILP inside the same function scope). If bench data shows a regression, the fix is to keep the specific hot-path kernels (bf1_pipe4, etc.) FASTLED_FORCE_INLINE in the .h — the pattern here is per-function, not all-or-nothing. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step A — inline register-level init on modern peripheral (#3526) Drops the `#include \"platforms/esp/32/drivers/i2s/i2s_esp32dev.h\"` from `I2sPeripheralEsp32DevEsp::initialize`/`deinitialize`. Replaces the calls to Yves's `i2s_define_bit_patterns` / `i2s_init` / `i2s_stop` with direct register writes on `I2S0`/`I2S1` via `soc/i2s_struct.h`. Fixed 8 MHz pixel clock for wave8 output (80 MHz APB / (10 + 0/1)) — no per-chipset clock math. This is the general-clockless architecture the meta issue mandates (PARLIO-style), NOT Yves's per-chipset bit-pattern encoder. Register-write sequence mirrors Yves's proven init sequence exactly: - reset (`lc_conf` + `conf` reset flags) - reset DMA (`lc_conf.in_rst`/`out_rst`) - reset FIFO (`conf.rx_fifo_reset`/`tx_fifo_reset`) - parallel mode (`conf2.lcd_en = 1`, 16-lane width) - 32-bit-parallel sample rate config - fixed 8 MHz clkm divider (N=10, A=1, B=0) - FIFO in DMA-serviced 32-bit mode - PCM bypass Ownership tracked via a private static `g_i2s1_hardware_claimed_by_modern` flag — no dependency on Yves's `gInitializedI2sInitialized`. During the rollout only one binding path is active at a time (Yves via `-DFASTLED_ESP32_I2S=1`, modern via `Bus::FLEX_IO, 0` after Phase 2d), so there is no cross-driver race. `deinitialize()` clears `tx_start` + resets the block directly. `transmit()` remains a stub — Phase 2b step B lands the `lldesc_t` descriptor ring, `esp_intr_alloc()` ISR install, and real DMA kick. ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` after WDT-driven recovery from the intermittent first-boot `fl::json::json(const char*)` panic (unrelated pre-existing bug tracked separately) ## Also included Updates two AutoResearch example headers I missed in the earlier detail-split sweep (#3555): - `examples/AutoResearch/AutoResearchParlioEncode.h` - `examples/AutoResearch/AutoResearchWave8Expand.h` Both now include `fl/channels/detail/wave8.h` (declarations) instead of the deleted force-inline `.hpp`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step B — DMA descriptor + esp_intr_alloc ISR (#3526) Completes the real-hardware DMA path on the modern I2S1 peripheral. `transmit()` now: 1. Points a DMA-capable `lldesc_t` at the caller's buffer 2. Resets the peripheral, arms `out_link.addr` + `out_link.start` 3. Enables the pre-installed OUT_EOF ISR 4. Flips `mBusy = true` and starts the DMA (`conf.tx_start = 1`) The ISR trampoline `i2s_dma_isr_trampoline` (FL_IRAM, ISR context) clears the interrupt, stops `tx_start`, and calls `I2sPeripheralEsp32DevEsp::finishTransmitFromIsr()` which flips `mBusy = false` and dispatches the registered completion callback (the channel-engine trampoline just flips its `mTransmitCompleted` flag — already ISR-safe). Descriptor allocated at `initialize()` time via `heap_caps_malloc` with `MALLOC_CAP_DMA` (DMA-capable DRAM). ISR handle allocated via `esp_intr_alloc(ETS_I2S1_INTR_SOURCE, ESP_INTR_FLAG_IRAM, ...)`. Both released in `deinitialize()`. `waitTransmitDone(timeout_ms)` is now a real deadline-bounded spin that yields via `vTaskDelay(1)` while `mBusy` — no more (void)timeout fake return. ## Scope limits (deferred to follow-up) - **Single descriptor, one-shot only**: buffers larger than 4092 bytes are rejected (the `lldesc_t` length field is 12 bits). Streaming refill from the ISR — for full-frame 128-byte-per-lane-per-strip wave8 output past 4 KB — is a follow-up. - **No GPIO mux routing**: the peripheral is configured for parallel- out but the 16 lane pins are not yet mapped via `gpio_matrix_out` — that's Phase 2b step C (which adds `configureTiming` + per-channel GPIO plumbing on the engine side). ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` (WDT recovery from the intermittent first-boot panic works cleanly). Modern engine is inert at runtime (not bound to `Bus::FLEX_IO, 0` yet — that's Phase 2d), so the DMA/ISR code compiles + boots but doesn't execute on this run. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step C — GPIO mux routing for I2S1 lanes (#3526) Adds `II2sPeripheralEsp32Dev::routeLanePin(lane, gpio_pin)` for wiring one parallel-out data lane to a specific GPIO pin. Called by the engine (in a follow-up) after `initialize()` for each active channel, before the first `transmit()`. ## Real hardware impl `I2sPeripheralEsp32DevEsp::routeLanePin` uses the IDF v5-safe `esp_rom_gpio_connect_out_signal(gpio_num, signal_idx, out_inv, oen_inv)` API (replaces the legacy `gpio_matrix_out`). Signal index computed as `I2S{n}O_DATA_OUT0_IDX + lane`, honoring the peripheral config's per-strip invert mask so chipsets needing polarity inversion get it "for free" through the GPIO matrix rather than in the encoder. Pin put into output mode via `gpio_set_direction`. ## Mock `I2sPeripheralEsp32DevMock::routeLanePin` records the (lane, pin) pair. Two new introspection methods for tests: - `laneRouteInvocationCount()` — call count since last `reset()` - `lastRoutedPinForLane(lane)` — most recent pin, or -1 if unrouted ## Test coverage New host test `Modern I2S peripheral: routeLanePin records mock mapping`: - Uninitialised peripheral rejects the route - Multiple lane routings recorded correctly - Out-of-range lanes (16, 17) rejected - Re-routing replaces the previous pin - `reset()` clears everything ## Bench - `bash test --cpp` — 346/346 tests pass (new test brings total up by 1) - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` ## What's still gated on Phase 2b step D - Streaming DMA descriptor ring (current impl is single-descriptor, 4092-byte limit) - Engine-side `configureTiming()` that plumbs per-channel GPIO pins from `ChannelData::getPin()` down to `routeLanePin` calls Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * address CodeRabbit review: pad-select, real clear path, IRAM-safe ISR, wraparound-safe wait, shared lane constant Reviews on PR #3558: 1. Extract lane cap into a shared `kMaxI2sLanes = 24` constant in `ii2s_peripheral_esp32dev.h`; both mock and real impl reference it. 2. `routeLanePin`: select the pad's GPIO function via `esp_rom_gpio_pad_select_gpio()` BEFORE `gpio_set_direction()` so pins booting in an alternate function (SD_CMD, etc.) can drive I2S. 3. `routeLanePin(lane, -1)`: actually detach the previously-routed pin by writing `SIG_GPIO_OUT_IDX` in its place. Requires tracking the per-lane pin on the real impl (mirror the mock's `mLaneRoutedPin`). 4. `waitTransmitDone`: wraparound-safe elapsed-time computation using `(TickType_t)(now - start)` instead of absolute `deadline`. Correct past 32-bit tick counter wrap (~49 days at 1kHz FreeRTOS tick). 5. ISR trampoline: read `mI2sPort` via a new IRAM-safe accessor `i2sPortForIsr()` instead of `getConfig()` — getConfig returns a const reference and may not be inlined into IRAM under -Og. 6. Fix stale "4093 bytes" comment on the descriptor size check to match the 4092-byte cap actually enforced. ## Bench - `bash test channel_engine_i2s_esp32dev` — passes - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — pong, uptimeMs 2066 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2d slot swap — BusTraits<FLEX_IO, 0> → modern unified engine (#3526) Flips `Bus::FLEX_IO, 0` on classic ESP32 from the standalone `createI2sSpiEngine()` to the modern unified `createI2sEsp32DevEngine()`. The modern engine handles BOTH clockless and SPI batches on the same I2S1 peripheral per the parallel-IO unified-engine rule (`agents/docs/cpp-standards.md` -> \"Parallel-IO Driver: Unified Clockless + SPI Engine\"). SPI batches delegate to the tested `ChannelDriverI2sSpi` internally, so SPI users see no behavioral change — only the dispatch entry point moves. ## Prerequisite fix (same PR) `ChannelEngineI2sEsp32Dev::show()` used to `initialize()` the modern peripheral BEFORE checking whether the batch is clockless or SPI. That raced with the SPI delegate's own I2S1 claim on a SPI-only batch. Fix: postpone modern peripheral init to AFTER the SPI/clockless branch. SPI paths never touch modern's peripheral; only the clockless path initializes I2S1 for wave8 output. ## Impact - **Clockless on classic ESP32 (default)**: still routes through RMT (unaffected — RMT slot binding is separate). Only opt-in `-DFASTLED_ESP32_I2S=1` Yves binding is orthogonal to this swap. - **SPI (APA102/SK9822/HD108) on classic ESP32**: now dispatches through the modern engine's `show()` which delegates to `createI2sSpiEngine()`. Extra function-call layer only. - **`BusSupports<Bus::FLEX_IO, SpiChipsetConfig, 0>`**: still `true_type` — SPI still supported on the slot. ## Phase 2e teaser `drivers/i2s_spi/bus_traits.h` is now the ONE place returning the modern factory. The whole `drivers/i2s_spi/` directory is scheduled for deletion at Phase 2e once the delegate call inside the modern engine gets folded into a direct SPI-mode transmit path. This PR keeps the file location during rollout to avoid churning the `_build.cpp.hpp` wiring on the same PR that flips the binding. ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — pong, uptimeMs 2066 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2e — delete Yves, singleton peripheral, variable timing (#3526) Closes out #3526 Phase 2e — the modern classic-ESP32 I2S parallel-out clockless driver is now the only I2S path. ## Yves deletion (with attribution) Deleted: - `src/platforms/esp/32/drivers/i2s/clockless_i2s_esp32.{h,cpp.hpp}` - `src/platforms/esp/32/drivers/i2s/i2s_esp32dev.{h,cpp.hpp}` Updated call sites to remove `ClocklessI2S` alias: - `src/platforms/esp/clockless.h` — dropped the `#if defined(FASTLED_ESP32_I2S)` branch that aliased `ClocklessController = ClocklessI2S<>` - `src/platforms/esp/32/core/fastled_esp32.h` — removed the `#include \"clockless_i2s_esp32.h\"` guarded by `FASTLED_ESP32_HAS_I2S` - `src/platforms/esp/32/drivers/i2s/_build.cpp.hpp` — dropped the two `.cpp.hpp` includes - `src/FastLED.h` — replaced the deprecation-path warning with a hard removal message (`-DFASTLED_ESP32_I2S=1` now advises users to drop the flag and use `setExclusiveDriver<fl::Bus::FLEX_IO, 0>()` for the modern engine) Yves Bazin is credited as the original driver author in the docstrings of both `channel_engine_i2s_esp32dev.h` and `i2s_peripheral_esp32dev_esp.cpp.hpp` — every register write and DMA descriptor field in the modern impl traces its lineage to his original driver. ## Peripheral -> singleton Converted `I2sPeripheralEsp32DevEsp` to a process-lifetime `fl::Singleton<>`. The former namespace-scope `g_i2s1_hardware_claimed_by_modern` global is deleted — the singleton's `mInitialized` member is now the sole ownership record for I2S1 on classic ESP32. `createI2sEsp32DevEngine()` wraps the singleton in `fl::make_shared_no_tracking<II2sPeripheralEsp32Dev>(singleton)` — zero-overhead non-owning handle, no control block, no delete possible. ## Variable-timing waveN The peripheral's `initialize()` no longer hardcodes 8 MHz pixel clock. New `solveI2sClockDivider(target_hz, &N, &A, &B)` helper solves the classic-ESP32 fractional divider math (`80 MHz / (N + B/A)`) for any target frequency the engine picks. Config's `mPixelClockHz` field is now honored — engine can drive: - WS2812 at 800 kHz -> 8 MHz clock (N=10, A=1, B=0) - WS2811 at 400 kHz -> 3.2 MHz clock (N=25, A=1, B=0) - Any wave3-eligible chipset at its per-chipset rate via `wave3ClockFrequencyHz(timing)` Falls back to 8 MHz if `mPixelClockHz` is zero. ## Follow-up issues filed - #3561 — apply the same variable-timing pattern to PARLIO (currently uses `FL_ESP_PARLIO_CLOCK_FREQ_HZ` compile-time constant) - #3562 — hoist `solveI2sClockDivider()` to a shared `platforms/esp/32/core/` location so SPI / RMT / other drivers that open-code the same math can consume it ## Bench - `bash test --cpp --clean` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — `pong, uptimeMs: 2066` Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(i2s): rewrite README for modern engine (#3526 Phase 8 / #3512 Phase 8) Rewrites `src/platforms/esp/32/drivers/i2s/README.md` to reflect the current state after #3526 Phases 2a-2e: - Yves attribution as the original I2S1 parallel-out driver author - Modern channel-manager engine + wave8/wave3 encoding architecture - `fl::Singleton<>` peripheral + `make_shared_no_tracking` wrapping - Variable-rate waveN encoding (`solveI2sClockDivider`) for non-800kHz chipsets (WS2811 at 400 kHz, etc.) - Multi-lane GPIO routing to 24 lanes via `routeLanePin` - Removed `-DFASTLED_ESP32_I2S=1` at Phase 2e — replaced with `setExclusiveDriver<fl::Bus::FLEX_IO, 0>()` runtime selection - Documented streaming ISR-refill invariant that Phase 2b step D needs to preserve (Yves's ping-pong ring pattern in git history) - Cross-referenced closed sub-issues (#3489 singleton, #1165 I2S_DEVICE=1 pin routing, #1384 async surface) Closes the "Phase 8: README" acceptance criterion of both #3526 and #3512. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): wire wave8 encoding into engine + routeLanePin call (#3526) Fixes the gap identified by the live-bench validation in #3515: the modern I2S engine's clockless path was not actually producing WS2812 timing on the wire because: 1. `packScratchBuffer()` was concatenating raw pixel bytes, not wave8-encoding them. DMA output at 8 MHz emits raw pixels, not the pulse-major waveform WS2812 expects. 2. The engine never called `peripheral->routeLanePin()` — the I2S1 DATA_OUT signals had no physical GPIO destination. ## Changes **Engine (`packScratchBuffer`):** now runs the wave8 pulse-major encoder (`encodeChannelWave8_i2s1`) over lane-strided input. Output size = `bytes_per_lane * 128` (16 lanes × 8 pulses per input byte). Uses in-buffer input scratch after the output region so the caller's peripheral only sees the encoded prefix. **Engine (`show`):** sizes the scratch buffer for both output + input regions via `wave8I2s1EncodedFrameSize()` + `16 * bytes_per_lane`. **Engine (`show`):** after `initialize()`, iterates in-flight channels and calls `peripheral->routeLanePin(lane_idx, data->getPin())` to route each channel's pin through the I2S1 GPIO matrix. Handles up to 16 lanes (wave8 kernel width); further lanes truncated. **Config:** switched default pixel clock from 2.4 MHz to 8 MHz to match wave8's WS2812 800kHz × 8 pulses/bit rate. **Test update:** rewrote the raw-byte-concat expectation (`0xAA`s + `0xBB`s) into a byte-exact wave8 output check against a direct `encodeChannelWave8_i2s1()` reference call. Anti-drift — if the shared kernel changes, this test inherits the change automatically. Second test's `size_bytes` assertion updated from `3u` to `3u * 128u`. ## Bench state after this PR - Modern engine runtime binding: ✅ (`driverName: "I2S"`) - FastLED.show() through modern engine: ✅ (device stays alive) - Wave8 encoder emits proper output size: ✅ (host tests byte-exact) - Physical wire edges captured via RMT RX loopback: ❌ (still `captureFailed: true, rawEdgesAfterWait: 0`) The remaining bench gap is at the peripheral register-config level: `tx_bits_mod = 32`, `fifo_conf.tx_fifo_mod = 3`, and the clkm divider math need bench-side scope validation to confirm the FIFO actually clocks the wave8 bytes out at 8 MHz through the routed GPIO. Debug work continues in follow-up. ## Test plan - [x] `bash test --cpp` — 345/345 pass (wave8 byte-exact check green) - [x] `bash lint --cpp` — clean - [x] `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - [x] Flash to ESP32-WROOM — device boots, RPC responds - [ ] Bench loopback byte-exact WS2812 output — still failing (see above) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(i2s): document open bench debug on tx_bits_mod (#3526 / #3515) Extends the `sample_rate_conf.tx_bits_mod = 32` register-write comment with the honest debug trail from the #3515 bench: - Wave8 output layout is 16-bit-per-pulse (`wave8Transpose_16_bf1` writes `col_lo | col_hi` = 16 lanes across 2 bytes) - Bench-tested `tx_bits_mod = 16` on ESP32-WROOM — no edges captured (`captureFailed: true, rawEdgesAfterWait: 0`) - Retained Yves's `tx_bits_mod = 32` baseline value so the register config stays identical to his known-working setup — this narrows the debug delta to encoder-output-layout mismatch, not a cascade of register changes Requires scope-level bench validation to close (per #3516's "Blockers (whole-tracker)" section: "Physical WROOM COM11 hardware required for #3515 Phase D bench validation on each IDF version. No software substitute."). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
…#3569) (#3570) * fix(autoresearch): arm WDT at top of setup() so boot hangs don't wedge COM port Previously the unified WDT was armed lazily by FL_WATCHDOG_AUTO() at the top of loop(). If setup() hung (RPC bind null-deref, stalled static-init, wedged serial handshake), no WDT was armed and the COM port stayed owned by a dead sketch until manual power-cycle. Arm the WDT with a 20 s window at the very top of setup() so a hang here auto-reboots. Feed the WDT in the serial-monitor wait loop because on classic ESP32 (non-USB-CDC) that loop can span up to AUTORESEARCH_SERIAL_WAIT_MS = 120 s, well past the setup WDT window. FL_WATCHDOG_AUTO() at loop() top re-arms with the shorter loop-scoped timeout once setup() has finished. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): wave3 sibling encoder for I2S1 modern driver (#3526 Phase 2a) Adds `encodeChannelWave3_i2s1` alongside the existing `encodeChannelWave8_i2s1` to satisfy the meta-issue acceptance criterion "Wave3 fallback path exercised for a three-slot chipset". Wave3 saves 2.67x memory vs wave8 for chipsets whose T1/T2/T3 timing rounds to 1/2/N ticks per 3, gated by `fl::canUseWave3(timing)`. Pixel clock is per-chipset via `fl::wave3ClockFrequencyHz(timing)` instead of the fixed 8 MHz wave8 rate. The encoder reuses the shared `fl::wave3Transpose_16` kernel from `fl/channels/wave3.h` — same anti-drift rule as the wave8 sibling. Host tests verify byte-exact output against a direct-kernel-call reference using canonical WS2812 timing (verified wave3-eligible). Drops the `fl/channels/detail/wave3.hpp` and `detail/wave8.hpp` force-inline includes from this .cpp.hpp — the unity build pulls this file across multiple TUs and the force-inline kernels would emit in each. The public `.h` declarations resolve at link time to the single out-of-line definitions in `wave3.cpp.hpp` / `wave8.cpp.hpp`, avoiding double-inline bloat. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(channels): split detail/wave3.hpp + wave8.hpp into .h + .cpp.hpp The former `fl/channels/detail/wave3.hpp` and `detail/wave8.hpp` were force-inline headers (`FASTLED_FORCE_INLINE FL_IRAM FL_OPTIMIZE_FUNCTION`). Every translation unit that included them emitted the full transpose kernel body. With ~10 callers across PARLIO / LCD_CAM / LCD_SPI / I2S drivers and the public wave3/wave8 wrappers, that was ~10× the transpose code in the final binary. Split into: - `detail/wave3.h` + `detail/wave8.h` — declarations, constexpr LUTs that need compile-time visibility, and the `FL_WAVE8_SPREAD_TO_16` helper macro (kept in the .h since it's a #define) - `detail/wave3.cpp.hpp` + `detail/wave8.cpp.hpp` — out-of-line definitions (dropped FASTLED_FORCE_INLINE, kept FL_IRAM + FL_OPTIMIZE_FUNCTION for perf), compiled once via the channels/detail unity build Updated 6 caller files (+2 tests) to include the new `.h` headers instead of the deleted `.hpp` files. The public API (`wave3Transpose_*` / `wave8Transpose_*` in `wave3.h` / `wave8.h`) is untouched — this is a pure implementation refactor. Perf note: dropping FASTLED_FORCE_INLINE means the transpose kernels no longer get inlined into every caller. On the in-order RV32 P4 core this could regress the encode-loop-hot-path per-frame timing measured in #2548 by a few percent (from lost cross-position ILP inside the same function scope). If bench data shows a regression, the fix is to keep the specific hot-path kernels (bf1_pipe4, etc.) FASTLED_FORCE_INLINE in the .h — the pattern here is per-function, not all-or-nothing. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step A — inline register-level init on modern peripheral (#3526) Drops the `#include \"platforms/esp/32/drivers/i2s/i2s_esp32dev.h\"` from `I2sPeripheralEsp32DevEsp::initialize`/`deinitialize`. Replaces the calls to Yves's `i2s_define_bit_patterns` / `i2s_init` / `i2s_stop` with direct register writes on `I2S0`/`I2S1` via `soc/i2s_struct.h`. Fixed 8 MHz pixel clock for wave8 output (80 MHz APB / (10 + 0/1)) — no per-chipset clock math. This is the general-clockless architecture the meta issue mandates (PARLIO-style), NOT Yves's per-chipset bit-pattern encoder. Register-write sequence mirrors Yves's proven init sequence exactly: - reset (`lc_conf` + `conf` reset flags) - reset DMA (`lc_conf.in_rst`/`out_rst`) - reset FIFO (`conf.rx_fifo_reset`/`tx_fifo_reset`) - parallel mode (`conf2.lcd_en = 1`, 16-lane width) - 32-bit-parallel sample rate config - fixed 8 MHz clkm divider (N=10, A=1, B=0) - FIFO in DMA-serviced 32-bit mode - PCM bypass Ownership tracked via a private static `g_i2s1_hardware_claimed_by_modern` flag — no dependency on Yves's `gInitializedI2sInitialized`. During the rollout only one binding path is active at a time (Yves via `-DFASTLED_ESP32_I2S=1`, modern via `Bus::FLEX_IO, 0` after Phase 2d), so there is no cross-driver race. `deinitialize()` clears `tx_start` + resets the block directly. `transmit()` remains a stub — Phase 2b step B lands the `lldesc_t` descriptor ring, `esp_intr_alloc()` ISR install, and real DMA kick. ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` after WDT-driven recovery from the intermittent first-boot `fl::json::json(const char*)` panic (unrelated pre-existing bug tracked separately) ## Also included Updates two AutoResearch example headers I missed in the earlier detail-split sweep (#3555): - `examples/AutoResearch/AutoResearchParlioEncode.h` - `examples/AutoResearch/AutoResearchWave8Expand.h` Both now include `fl/channels/detail/wave8.h` (declarations) instead of the deleted force-inline `.hpp`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step B — DMA descriptor + esp_intr_alloc ISR (#3526) Completes the real-hardware DMA path on the modern I2S1 peripheral. `transmit()` now: 1. Points a DMA-capable `lldesc_t` at the caller's buffer 2. Resets the peripheral, arms `out_link.addr` + `out_link.start` 3. Enables the pre-installed OUT_EOF ISR 4. Flips `mBusy = true` and starts the DMA (`conf.tx_start = 1`) The ISR trampoline `i2s_dma_isr_trampoline` (FL_IRAM, ISR context) clears the interrupt, stops `tx_start`, and calls `I2sPeripheralEsp32DevEsp::finishTransmitFromIsr()` which flips `mBusy = false` and dispatches the registered completion callback (the channel-engine trampoline just flips its `mTransmitCompleted` flag — already ISR-safe). Descriptor allocated at `initialize()` time via `heap_caps_malloc` with `MALLOC_CAP_DMA` (DMA-capable DRAM). ISR handle allocated via `esp_intr_alloc(ETS_I2S1_INTR_SOURCE, ESP_INTR_FLAG_IRAM, ...)`. Both released in `deinitialize()`. `waitTransmitDone(timeout_ms)` is now a real deadline-bounded spin that yields via `vTaskDelay(1)` while `mBusy` — no more (void)timeout fake return. ## Scope limits (deferred to follow-up) - **Single descriptor, one-shot only**: buffers larger than 4092 bytes are rejected (the `lldesc_t` length field is 12 bits). Streaming refill from the ISR — for full-frame 128-byte-per-lane-per-strip wave8 output past 4 KB — is a follow-up. - **No GPIO mux routing**: the peripheral is configured for parallel- out but the 16 lane pins are not yet mapped via `gpio_matrix_out` — that's Phase 2b step C (which adds `configureTiming` + per-channel GPIO plumbing on the engine side). ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` (WDT recovery from the intermittent first-boot panic works cleanly). Modern engine is inert at runtime (not bound to `Bus::FLEX_IO, 0` yet — that's Phase 2d), so the DMA/ISR code compiles + boots but doesn't execute on this run. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2b step C — GPIO mux routing for I2S1 lanes (#3526) Adds `II2sPeripheralEsp32Dev::routeLanePin(lane, gpio_pin)` for wiring one parallel-out data lane to a specific GPIO pin. Called by the engine (in a follow-up) after `initialize()` for each active channel, before the first `transmit()`. ## Real hardware impl `I2sPeripheralEsp32DevEsp::routeLanePin` uses the IDF v5-safe `esp_rom_gpio_connect_out_signal(gpio_num, signal_idx, out_inv, oen_inv)` API (replaces the legacy `gpio_matrix_out`). Signal index computed as `I2S{n}O_DATA_OUT0_IDX + lane`, honoring the peripheral config's per-strip invert mask so chipsets needing polarity inversion get it "for free" through the GPIO matrix rather than in the encoder. Pin put into output mode via `gpio_set_direction`. ## Mock `I2sPeripheralEsp32DevMock::routeLanePin` records the (lane, pin) pair. Two new introspection methods for tests: - `laneRouteInvocationCount()` — call count since last `reset()` - `lastRoutedPinForLane(lane)` — most recent pin, or -1 if unrouted ## Test coverage New host test `Modern I2S peripheral: routeLanePin records mock mapping`: - Uninitialised peripheral rejects the route - Multiple lane routings recorded correctly - Out-of-range lanes (16, 17) rejected - Re-routing replaces the previous pin - `reset()` clears everything ## Bench - `bash test --cpp` — 346/346 tests pass (new test brings total up by 1) - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM via `bash autoresearch esp32dev` — device boots, RPC `ping` returns `pong, success: True, uptimeMs: 2066` ## What's still gated on Phase 2b step D - Streaming DMA descriptor ring (current impl is single-descriptor, 4092-byte limit) - Engine-side `configureTiming()` that plumbs per-channel GPIO pins from `ChannelData::getPin()` down to `routeLanePin` calls Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * address CodeRabbit review: pad-select, real clear path, IRAM-safe ISR, wraparound-safe wait, shared lane constant Reviews on PR #3558: 1. Extract lane cap into a shared `kMaxI2sLanes = 24` constant in `ii2s_peripheral_esp32dev.h`; both mock and real impl reference it. 2. `routeLanePin`: select the pad's GPIO function via `esp_rom_gpio_pad_select_gpio()` BEFORE `gpio_set_direction()` so pins booting in an alternate function (SD_CMD, etc.) can drive I2S. 3. `routeLanePin(lane, -1)`: actually detach the previously-routed pin by writing `SIG_GPIO_OUT_IDX` in its place. Requires tracking the per-lane pin on the real impl (mirror the mock's `mLaneRoutedPin`). 4. `waitTransmitDone`: wraparound-safe elapsed-time computation using `(TickType_t)(now - start)` instead of absolute `deadline`. Correct past 32-bit tick counter wrap (~49 days at 1kHz FreeRTOS tick). 5. ISR trampoline: read `mI2sPort` via a new IRAM-safe accessor `i2sPortForIsr()` instead of `getConfig()` — getConfig returns a const reference and may not be inlined into IRAM under -Og. 6. Fix stale "4093 bytes" comment on the descriptor size check to match the 4092-byte cap actually enforced. ## Bench - `bash test channel_engine_i2s_esp32dev` — passes - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — pong, uptimeMs 2066 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2d slot swap — BusTraits<FLEX_IO, 0> → modern unified engine (#3526) Flips `Bus::FLEX_IO, 0` on classic ESP32 from the standalone `createI2sSpiEngine()` to the modern unified `createI2sEsp32DevEngine()`. The modern engine handles BOTH clockless and SPI batches on the same I2S1 peripheral per the parallel-IO unified-engine rule (`agents/docs/cpp-standards.md` -> \"Parallel-IO Driver: Unified Clockless + SPI Engine\"). SPI batches delegate to the tested `ChannelDriverI2sSpi` internally, so SPI users see no behavioral change — only the dispatch entry point moves. ## Prerequisite fix (same PR) `ChannelEngineI2sEsp32Dev::show()` used to `initialize()` the modern peripheral BEFORE checking whether the batch is clockless or SPI. That raced with the SPI delegate's own I2S1 claim on a SPI-only batch. Fix: postpone modern peripheral init to AFTER the SPI/clockless branch. SPI paths never touch modern's peripheral; only the clockless path initializes I2S1 for wave8 output. ## Impact - **Clockless on classic ESP32 (default)**: still routes through RMT (unaffected — RMT slot binding is separate). Only opt-in `-DFASTLED_ESP32_I2S=1` Yves binding is orthogonal to this swap. - **SPI (APA102/SK9822/HD108) on classic ESP32**: now dispatches through the modern engine's `show()` which delegates to `createI2sSpiEngine()`. Extra function-call layer only. - **`BusSupports<Bus::FLEX_IO, SpiChipsetConfig, 0>`**: still `true_type` — SPI still supported on the slot. ## Phase 2e teaser `drivers/i2s_spi/bus_traits.h` is now the ONE place returning the modern factory. The whole `drivers/i2s_spi/` directory is scheduled for deletion at Phase 2e once the delegate call inside the modern engine gets folded into a direct SPI-mode transmit path. This PR keeps the file location during rollout to avoid churning the `_build.cpp.hpp` wiring on the same PR that flips the binding. ## Bench - `bash test --cpp` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — pong, uptimeMs 2066 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): Phase 2e — delete Yves, singleton peripheral, variable timing (#3526) Closes out #3526 Phase 2e — the modern classic-ESP32 I2S parallel-out clockless driver is now the only I2S path. ## Yves deletion (with attribution) Deleted: - `src/platforms/esp/32/drivers/i2s/clockless_i2s_esp32.{h,cpp.hpp}` - `src/platforms/esp/32/drivers/i2s/i2s_esp32dev.{h,cpp.hpp}` Updated call sites to remove `ClocklessI2S` alias: - `src/platforms/esp/clockless.h` — dropped the `#if defined(FASTLED_ESP32_I2S)` branch that aliased `ClocklessController = ClocklessI2S<>` - `src/platforms/esp/32/core/fastled_esp32.h` — removed the `#include \"clockless_i2s_esp32.h\"` guarded by `FASTLED_ESP32_HAS_I2S` - `src/platforms/esp/32/drivers/i2s/_build.cpp.hpp` — dropped the two `.cpp.hpp` includes - `src/FastLED.h` — replaced the deprecation-path warning with a hard removal message (`-DFASTLED_ESP32_I2S=1` now advises users to drop the flag and use `setExclusiveDriver<fl::Bus::FLEX_IO, 0>()` for the modern engine) Yves Bazin is credited as the original driver author in the docstrings of both `channel_engine_i2s_esp32dev.h` and `i2s_peripheral_esp32dev_esp.cpp.hpp` — every register write and DMA descriptor field in the modern impl traces its lineage to his original driver. ## Peripheral -> singleton Converted `I2sPeripheralEsp32DevEsp` to a process-lifetime `fl::Singleton<>`. The former namespace-scope `g_i2s1_hardware_claimed_by_modern` global is deleted — the singleton's `mInitialized` member is now the sole ownership record for I2S1 on classic ESP32. `createI2sEsp32DevEngine()` wraps the singleton in `fl::make_shared_no_tracking<II2sPeripheralEsp32Dev>(singleton)` — zero-overhead non-owning handle, no control block, no delete possible. ## Variable-timing waveN The peripheral's `initialize()` no longer hardcodes 8 MHz pixel clock. New `solveI2sClockDivider(target_hz, &N, &A, &B)` helper solves the classic-ESP32 fractional divider math (`80 MHz / (N + B/A)`) for any target frequency the engine picks. Config's `mPixelClockHz` field is now honored — engine can drive: - WS2812 at 800 kHz -> 8 MHz clock (N=10, A=1, B=0) - WS2811 at 400 kHz -> 3.2 MHz clock (N=25, A=1, B=0) - Any wave3-eligible chipset at its per-chipset rate via `wave3ClockFrequencyHz(timing)` Falls back to 8 MHz if `mPixelClockHz` is zero. ## Follow-up issues filed - #3561 — apply the same variable-timing pattern to PARLIO (currently uses `FL_ESP_PARLIO_CLOCK_FREQ_HZ` compile-time constant) - #3562 — hoist `solveI2sClockDivider()` to a shared `platforms/esp/32/core/` location so SPI / RMT / other drivers that open-code the same math can consume it ## Bench - `bash test --cpp --clean` — 345/345 tests pass - `bash lint --cpp` — clean - `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - Flash to ESP32-WROOM — `pong, uptimeMs: 2066` Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(i2s): rewrite README for modern engine (#3526 Phase 8 / #3512 Phase 8) Rewrites `src/platforms/esp/32/drivers/i2s/README.md` to reflect the current state after #3526 Phases 2a-2e: - Yves attribution as the original I2S1 parallel-out driver author - Modern channel-manager engine + wave8/wave3 encoding architecture - `fl::Singleton<>` peripheral + `make_shared_no_tracking` wrapping - Variable-rate waveN encoding (`solveI2sClockDivider`) for non-800kHz chipsets (WS2811 at 400 kHz, etc.) - Multi-lane GPIO routing to 24 lanes via `routeLanePin` - Removed `-DFASTLED_ESP32_I2S=1` at Phase 2e — replaced with `setExclusiveDriver<fl::Bus::FLEX_IO, 0>()` runtime selection - Documented streaming ISR-refill invariant that Phase 2b step D needs to preserve (Yves's ping-pong ring pattern in git history) - Cross-referenced closed sub-issues (#3489 singleton, #1165 I2S_DEVICE=1 pin routing, #1384 async surface) Closes the "Phase 8: README" acceptance criterion of both #3526 and #3512. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * feat(i2s): wire wave8 encoding into engine + routeLanePin call (#3526) Fixes the gap identified by the live-bench validation in #3515: the modern I2S engine's clockless path was not actually producing WS2812 timing on the wire because: 1. `packScratchBuffer()` was concatenating raw pixel bytes, not wave8-encoding them. DMA output at 8 MHz emits raw pixels, not the pulse-major waveform WS2812 expects. 2. The engine never called `peripheral->routeLanePin()` — the I2S1 DATA_OUT signals had no physical GPIO destination. ## Changes **Engine (`packScratchBuffer`):** now runs the wave8 pulse-major encoder (`encodeChannelWave8_i2s1`) over lane-strided input. Output size = `bytes_per_lane * 128` (16 lanes × 8 pulses per input byte). Uses in-buffer input scratch after the output region so the caller's peripheral only sees the encoded prefix. **Engine (`show`):** sizes the scratch buffer for both output + input regions via `wave8I2s1EncodedFrameSize()` + `16 * bytes_per_lane`. **Engine (`show`):** after `initialize()`, iterates in-flight channels and calls `peripheral->routeLanePin(lane_idx, data->getPin())` to route each channel's pin through the I2S1 GPIO matrix. Handles up to 16 lanes (wave8 kernel width); further lanes truncated. **Config:** switched default pixel clock from 2.4 MHz to 8 MHz to match wave8's WS2812 800kHz × 8 pulses/bit rate. **Test update:** rewrote the raw-byte-concat expectation (`0xAA`s + `0xBB`s) into a byte-exact wave8 output check against a direct `encodeChannelWave8_i2s1()` reference call. Anti-drift — if the shared kernel changes, this test inherits the change automatically. Second test's `size_bytes` assertion updated from `3u` to `3u * 128u`. ## Bench state after this PR - Modern engine runtime binding: ✅ (`driverName: "I2S"`) - FastLED.show() through modern engine: ✅ (device stays alive) - Wave8 encoder emits proper output size: ✅ (host tests byte-exact) - Physical wire edges captured via RMT RX loopback: ❌ (still `captureFailed: true, rawEdgesAfterWait: 0`) The remaining bench gap is at the peripheral register-config level: `tx_bits_mod = 32`, `fifo_conf.tx_fifo_mod = 3`, and the clkm divider math need bench-side scope validation to confirm the FIFO actually clocks the wave8 bytes out at 8 MHz through the routed GPIO. Debug work continues in follow-up. ## Test plan - [x] `bash test --cpp` — 345/345 pass (wave8 byte-exact check green) - [x] `bash lint --cpp` — clean - [x] `bash compile esp32dev --examples AutoResearch --no-filter` — SUCCESS - [x] Flash to ESP32-WROOM — device boots, RPC responds - [ ] Bench loopback byte-exact WS2812 output — still failing (see above) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs(i2s): document open bench debug on tx_bits_mod (#3526 / #3515) Extends the `sample_rate_conf.tx_bits_mod = 32` register-write comment with the honest debug trail from the #3515 bench: - Wave8 output layout is 16-bit-per-pulse (`wave8Transpose_16_bf1` writes `col_lo | col_hi` = 16 lanes across 2 bytes) - Bench-tested `tx_bits_mod = 16` on ESP32-WROOM — no edges captured (`captureFailed: true, rawEdgesAfterWait: 0`) - Retained Yves's `tx_bits_mod = 32` baseline value so the register config stays identical to his known-working setup — this narrows the debug delta to encoder-output-layout mismatch, not a cascade of register changes Requires scope-level bench validation to close (per #3516's "Blockers (whole-tracker)" section: "Physical WROOM COM11 hardware required for #3515 Phase D bench validation on each IDF version. No software substitute."). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(i2s,rmt-rx): 32-bit sample encoding + classic-ESP32 capture fixes (#3569) I2S TX driver (root causes of "no wire edges" in the driver itself): - Add wave8I2s1ExpandTo32Samples: rewrite wave8's 2-byte pulse pairs into one u32 sample per pulse with lanes at bits 8..23. In Yves's proven tx_bits_mod=32 LCD config, DATA_OUT(n) presents sample bit n+8, so the raw wave8 stream put lane 0 on an invisible bit AND packed two pulse periods per sample (half pulse rate). - Engine: three-region scratch (out32 / wave8 tmp / lane input); build the 2 KB byte-LUT in place on the member via per-byte wave8() — the by-value LUT return was the stack-canary trigger. - Peripheral: linear DMA descriptor chain (4088-byte links, eof only on last) — a 32-bit-sample frame exceeds one lldesc's 4092 reach; interrupt hygiene: mask+clear before esp_intr_alloc, arm in transmit(). RMT RX (bench capture was broken for every TX driver on esp32dev): - Gate en_partial_rx on SOC_RMT_SUPPORT_RX_PINGPONG — classic ESP32 lacks it and rmt_receive() hard-rejects the flag ("partial receive not supported"), so every capture failed before arming. - Fall back to non-DMA when use_dma is requested on chips without RMT DMA (AutoResearchTest forces use_dma for non-RMT TX paths). - Classic ESP32: claim 4 mem blocks (256 symbols) for non-DMA RX so a one-shot receive covers a 10-LED frame. AutoResearch (crash pair on ESP32-WROOM): - RX capture buffer: classic ESP32 gets a 32 KB tier (was 96 KB) — heap exhaustion made fl::aligned_alloc return null inside fl::json::set (StoreProhibited at 0x400d2ece). - Loop stack 16 KB via SET_LOOP_TASK_STACK_SIZE — the RPC → show() chain is bench-measured ~8.0 KB deep; the 8 KB default tripped the stack canary on any interrupt at peak depth. Paired with the buffer reduction above. Bench (WROOM COM11): runSingleTest now completes crash-free with the receive armed. Remaining zero-edge readings were traced electrically (esptool GPIO pokes) to a disconnected GPIO18->GPIO19 jumper on the bench — not a software fault. Co-Authored-By: Claude Fable 5 <[email protected]> * fix(i2s,rmt-rx): address code-review findings on #3569 fix branch I2S peripheral: - Reorder transmit() kick: int_clr + int_ena(eof|dscr_err) + esp_intr_enable now run BEFORE out_link.start. Fixes (a) tiny frames (<=64 FIFO words) raising OUT_EOF in the window where int_clr wiped it — permanent waitTransmitDone timeout; (b) int_ena.val=0 silently disarming out_dscr_err every frame; (c) esp_intr_enable failure leaving the DMA out-link armed on the error path. - conf1.tx_stop_en = 1: auto-stop TX when the FIFO drains. One-shot chains underrun after the last descriptor; with tx_stop_en=0 the TX unit kept clocking stale FIFO samples onto every routed pin through the WS28xx latch window. - Drop dead debug scaffolding (esp_log.h include, TAG_I2S_MODERN). RMT RX: - Clamp the use_dma request BEFORE the rebuild comparison — callers that always pass use_dma=true (AutoResearchTest) were tearing down and rebuilding the channel on every begin() on non-DMA chips, and the teardown leaked the memory-manager registration. - Constructor pre-registration back to the 64-word minimum marker; begin() upgrades to kNonDmaRxSymbols (256 on classic) with graceful fallback to 64 when TX channels already hold the blocks. Prevents an RX object construction from halving classic ESP32's 512-word global RMT pool for sketches that never capture. - Directly include soc/soc_caps.h so the SOC_RMT_SUPPORT_* gates can never silently evaluate undefined-as-0. Shared wave8: - Add out-param buildWave8ByteExpansionLUT overload (canonical builder, no 2 KB stack temporary); engine now uses it instead of a hand-rolled per-byte loop that could drift from the canonical layout. Drop the engine's dead mWave8BitLut member; replace the T1/T2/T3 hash cache key with exact comparison (hash collisions would silently reuse a stale LUT once per-channel timing lands). Mock/docs: - Mock transmit() now refuses null/zero-size like the hardware impl. - README: single-descriptor 4092-byte cap note replaced with the chain description; AutoResearch comment points at the RX_BUFFER_SIZE tier correctly. Co-Authored-By: Claude Fable 5 <[email protected]> * fix: remove conflict markers missed in merge (engine .cpp.hpp — branch version supersedes) Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Adds
II2sPeripheralEsp32Dev::routeLanePin(lane, gpio_pin)for wiring one parallel-out data lane to a specific GPIO pin. Called by the engine (in a follow-up) afterinitialize()for each active channel, before the firsttransmit().Real hardware impl
I2sPeripheralEsp32DevEsp::routeLanePinuses the IDF v5-safeesp_rom_gpio_connect_out_signal(gpio_num, signal_idx, out_inv, oen_inv)API (replaces the legacygpio_matrix_out). Signal index =I2S{n}O_DATA_OUT0_IDX + lane, honoring the peripheral config's per-strip invert mask so chipsets needing polarity inversion get it "for free" via the GPIO matrix rather than in the encoder.Pin put into output mode via
gpio_set_direction.Mock
I2sPeripheralEsp32DevMock::routeLanePinrecords the (lane, pin) pair. Introspection:laneRouteInvocationCount()— call count since lastreset()lastRoutedPinForLane(lane)— most recent pin, or -1Test coverage
New host test
Modern I2S peripheral: routeLanePin records mock mapping:reset()clearsBench
bash test --cpp— 346/346 passbash lint --cpp— cleanbash compile esp32dev --examples AutoResearch --no-filter— SUCCESSpong, success: True, uptimeMs: 2066🤖 Generated with Claude Code
Summary by CodeRabbit