Skip to content

feat(i2s): Phase 2b step B — DMA descriptor + esp_intr_alloc ISR (#3526) - #3557

Merged
zackees merged 6 commits into
masterfrom
feat/i2s-phase-2b-step-b-dma-isr-3526
Jul 1, 2026
Merged

zackees merged 6 commits into
masterfrom
feat/i2s-phase-2b-step-b-dma-isr-3526

Conversation

@zackees

@zackees zackees commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Summary

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 finishTransmitFromIsr() which flips mBusy = false and dispatches the registered completion callback (channel-engine trampoline).

waitTransmitDone(timeout_ms) is now a real deadline-bounded spin (yields via vTaskDelay(1) while mBusy).

Scope limits (deferred to follow-up)

  • Single descriptor, one-shot only: buffers >4092 bytes rejected (lldesc length is 12-bit). Streaming refill is a follow-up.
  • No GPIO mux routing: peripheral is configured for parallel-out but 16 lane pins not yet mapped via gpio_matrix_out. That's Phase 2b step C (needs configureTiming + per-channel GPIO plumbing on engine side).

Test plan

  • 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. 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.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added support for an additional waveform encoding path for compatible ESP32 I2S output.
    • Expanded channel encoding support so more output modes can share the same high-performance pipeline.
  • Bug Fixes

    • Improved startup reliability by keeping the watchdog serviced during the serial-connection wait, reducing unexpected resets before a host attaches.
    • Made I2S transmission handling more robust with real completion tracking and safer resource cleanup.

zackees and others added 5 commits July 1, 2026 13:50
…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]>
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 83a096c9-c332-4585-8425-32ab9c613e55

📥 Commits

Reviewing files that changed from the base of the PR and between 02956b3 and 5728449.

📒 Files selected for processing (27)
  • examples/AutoResearch/AutoResearch.ino
  • examples/AutoResearch/AutoResearchParlioEncode.h
  • examples/AutoResearch/AutoResearchWave8Expand.h
  • src/fl/channels/detail/_build.cpp.hpp
  • src/fl/channels/detail/wave3.cpp.hpp
  • src/fl/channels/detail/wave3.h
  • src/fl/channels/detail/wave3.hpp
  • src/fl/channels/detail/wave8.cpp.hpp
  • src/fl/channels/detail/wave8.h
  • src/fl/channels/detail/wave8.hpp
  • src/fl/channels/wave3.cpp.hpp
  • src/fl/channels/wave3.h
  • src/fl/channels/wave8.cpp.hpp
  • src/fl/channels/wave8.h
  • src/platforms/esp/32/drivers/i2s/channel_driver_i2s.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.h
  • src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.h
  • src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp
  • src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp
  • src/platforms/esp/32/drivers/spi/wave8_encoder_spi.h
  • tests/fl/channels/wave3.cpp
  • tests/fl/channels/wave8.cpp
  • tests/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp
  • tests/platforms/esp/32/drivers/parlio/parlio_driver.cpp
💤 Files with no reviewable changes (2)
  • src/fl/channels/detail/wave3.hpp
  • src/fl/channels/detail/wave8.hpp

📝 Walkthrough

Walkthrough

This PR splits Wave3/Wave8 force-inlined "detail" headers into public declaration headers with out-of-line, unity-compiled implementations, updating all call sites accordingly. It adds a Wave3 encoder sibling for the classic ESP32 I2S1 driver, rewrites the I2S1 peripheral to use real DMA/ISR-driven transmission, and adjusts AutoResearch watchdog arming during setup.

Changes

AutoResearch Watchdog Setup

Layer / File(s) Summary
Setup-phase watchdog arming and serial wait loop
examples/AutoResearch/AutoResearch.ino
Adds a longer setup-scoped watchdog timeout, explicitly arms the watchdog at the top of `setup()`, and replaces the blocking serial-ready wait with a polling loop that feeds the watchdog while waiting for `fl::serial_ready()`.

Estimated code review effort: 2 (Simple) | ~10 minutes

Wave3/Wave8 Header Split and New Wave3 I2S1 Encoder

Layer / File(s) Summary
Wave3 out-of-line implementation
src/fl/channels/detail/wave3.cpp.hpp, src/fl/channels/detail/wave3.h, src/fl/channels/detail/wave3.hpp (removed), src/fl/channels/wave3.h, src/fl/channels/wave3.cpp.hpp
Byte-conversion and 2/4/8/16-lane Wave3 transpose functions plus the `fl::wave3` wrapper move from an inline header into new declaration/definition headers; comments updated accordingly.
Wave8 out-of-line implementation
src/fl/channels/detail/wave8.cpp.hpp, src/fl/channels/detail/wave8.h, src/fl/channels/detail/wave8.hpp (removed), src/fl/channels/detail/_build.cpp.hpp, src/fl/channels/wave8.h, src/fl/channels/wave8.cpp.hpp
Conversion, expansion, standard and bf1/pipelined Wave8 transpose functions and `fl::wave8` move into new declaration/definition headers wired into the unity build.
Call-site include migrations
examples/AutoResearch/..., src/platforms/esp/32/drivers/..., tests/fl/channels/*, tests/platforms/esp/32/drivers/...
Includes across examples, drivers, and tests switch from the removed `wave3.hpp`/`wave8.hpp` to the new `wave3.h`/`wave8.h` headers with no logic changes.
Wave3 sibling encoder for I2S1
src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp.hpp, wave8_encoder_i2s1.h, tests/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp
Adds `encodeChannelWave3_i2s1` with validation and per-byte-position transposition via `wave3Transpose_16`, a frame-size helper, and tests for eligibility, byte-exact output, and rejection of invalid inputs.

Estimated code review effort: 4 (Complex) | ~60 minutes

Classic ESP32 I2S1 DMA/ISR Rewrite

Layer / File(s) Summary
DMA/ISR state additions
src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.h
Forward-declares `intr_handle_t`/`lldesc_s` and adds a private `finishTransmitFromIsr()` method and `mDescriptor`/`mIsrHandle` members.
Register/DMA initialize and deinitialize rewrite
src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp
Replaces the classic init path with ownership-tracked I2S1 claiming, register/DMA/FIFO reset helpers, TX/DMA configuration, descriptor allocation, ISR installation, and matching teardown.
Interrupt-driven transmit and completion
src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp
`transmit()` arms the DMA descriptor and starts TX via interrupt instead of synchronous completion; `waitTransmitDone()` spin-waits on `mBusy` with timeout; ISR trampoline clears the interrupt and invokes the completion callback.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant I2sPeripheralEsp32DevEsp
  participant I2S1_Registers
  participant DMA_Descriptor
  participant ISR

  Caller->>I2sPeripheralEsp32DevEsp: transmit(buffer, length)
  I2sPeripheralEsp32DevEsp->>DMA_Descriptor: populate buffer/length, arm one-shot chain
  I2sPeripheralEsp32DevEsp->>I2S1_Registers: reset registers, set out_link to descriptor
  I2sPeripheralEsp32DevEsp->>I2S1_Registers: enable interrupts, start TX
  I2sPeripheralEsp32DevEsp-->>Caller: mBusy = true
  I2S1_Registers->>ISR: DMA end-of-frame interrupt
  ISR->>I2S1_Registers: clear out_eof, stop TX
  ISR->>I2sPeripheralEsp32DevEsp: finishTransmitFromIsr()
  I2sPeripheralEsp32DevEsp-->>Caller: mBusy cleared, completion callback invoked
  Caller->>I2sPeripheralEsp32DevEsp: waitTransmitDone(timeout_ms)
  I2sPeripheralEsp32DevEsp-->>Caller: returns once mBusy cleared or timeout
Loading

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2532: Both modify the same Wave3/Wave8 8/16-lane transpose kernels now moved into out-of-line `wave3.cpp.hpp`/`wave8.cpp.hpp`.
  • FastLED/FastLED#2539: Refactors the same Wave8 byte-indexed expansion/transpose implementation into the new `detail/wave8.h` + `detail/wave8.cpp.hpp` files.
  • FastLED/FastLED#2568: Both touch the Wave8 BF1 transpose implementation, moving/updating it across the `wave8.cpp.hpp`/`wave8.h` split.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding DMA descriptor support and an esp_intr_alloc-based ISR for I2S.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/i2s-phase-2b-step-b-dma-isr-3526
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feat/i2s-phase-2b-step-b-dma-isr-3526

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zackees
zackees merged commit decfe67 into master Jul 1, 2026
9 of 10 checks passed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 10

🧹 Nitpick comments (1)
src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp.hpp (1)

103-141: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract shared validation into a helper to avoid duplicating encodeChannelWave8_i2s1's bounds checks.

Lines 108-120 (num_lanes range, bytes_per_lane == 0, input-size, output-size checks) are byte-for-byte identical to the checks already present in encodeChannelWave8_i2s1 (lines 33-45) in this same file. A shared inline helper (e.g. validateWaveI2s1Args(input, bytes_per_lane, num_lanes, output_size, required_output)) would remove the duplication and keep future bound changes in one place.

♻️ Proposed shared validation helper
+namespace detail {
+inline bool validate_wave_i2s1_args(fl::size_t input_size,
+                                     fl::size_t bytes_per_lane,
+                                     fl::size_t num_lanes,
+                                     fl::size_t output_size,
+                                     fl::size_t required_output) FL_NO_EXCEPT {
+    if (num_lanes == 0 || num_lanes > 16) return false;
+    if (bytes_per_lane == 0) return false;
+    if (input_size < 16 * bytes_per_lane) return false;
+    if (output_size < required_output) return false;
+    return true;
+}
+}  // namespace detail
+
 bool encodeChannelWave3_i2s1(fl::span<const fl::u8> input,
                              fl::size_t bytes_per_lane,
                              fl::size_t num_lanes,
                              const Wave3BitExpansionLut &lut,
                              fl::span<fl::u8> output) FL_NO_EXCEPT {
-    if (num_lanes == 0 || num_lanes > 16) {
-        return false;
-    }
-    if (bytes_per_lane == 0) {
-        return false;
-    }
-    if (input.size() < 16 * bytes_per_lane) {
-        return false;
-    }
     const fl::size_t required_output = wave3I2s1EncodedFrameSize(bytes_per_lane);
-    if (output.size() < required_output) {
-        return false;
-    }
+    if (!detail::validate_wave_i2s1_args(input.size(), bytes_per_lane, num_lanes,
+                                          output.size(), required_output)) {
+        return false;
+    }
🤖 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/wave8_encoder_i2s1.cpp.hpp` around lines 103
- 141, The argument checks in encodeChannelWave3_i2s1 are duplicated from
encodeChannelWave8_i2s1, so extract them into a shared inline validation helper
and call it from both functions. Move the num_lanes, bytes_per_lane, input-size,
and output-size guards into a common helper such as validateWaveI2s1Args, then
have encodeChannelWave3_i2s1 and encodeChannelWave8_i2s1 use that helper so the
bounds logic stays consistent in one place.
🤖 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 `@examples/AutoResearch/AutoResearch.ino`:
- Around line 362-371: The serial-wait polling loop in AutoResearch.ino is
busy-spinning and only feeds FastLED.watchdog(), so it can starve the ESP32 idle
task and trip the task watchdog. Update the loop around fl::serial_ready() /
AUTORESEARCH_SERIAL_WAIT_MS to include a yield or small delay each iteration
while still feeding the watchdog, so the RTOS gets time to run and the wait
remains responsive.

In `@src/fl/channels/detail/wave3.cpp.hpp`:
- Around line 35-127: The FL_IRAM transpose APIs are using decayed array
parameters, so the compiler does not enforce the expected extents. Update the
signatures of wave3_transpose_2, wave3_transpose_4, wave3_transpose_8, and
wave3_transpose_16 to take array references instead of pointer-decayed arrays,
and make the same change in the matching detail:: declarations in wave3.h so the
definitions and declarations stay consistent.

In `@src/fl/channels/detail/wave3.h`:
- Around line 30-43: The wave3_transpose_2/4/8/16 declarations still use decayed
array parameters, so the declared extents are not enforced. Update these APIs to
use reference-to-array forms for both the lane input and output buffer, matching
the existing wave3 wrapper pattern in wave3.h, and make the same signature
changes in the corresponding definitions in wave3.cpp.hpp so the contract stays
consistent.

In `@src/fl/channels/detail/wave8.h`:
- Around line 74-124: The wave8 transpose declarations use decayed array
parameters, so the compile-time size is not enforced. Update all affected
prototypes in wave8.h — wave8_transpose_2/4/8/16, the _pipe2/_pipe4 variants,
and the _bf1 variants — to use reference-to-array parameters like the existing
wave8() wrapper pattern instead of T value[N]. Keep the same function names and
signatures otherwise, and mirror the same change in the corresponding
definitions in wave8.cpp.hpp so the declarations and implementations match.

In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp`:
- Line 66: The changed comments in the I2S peripheral header still contain
non-ASCII punctuation, so update the affected comment text to use plain ASCII
only. Review the comments around the include and the referenced blocks in the
file, especially the ones tied to fl_i2s_periph_enable and the other changed
sections, and replace em dashes or any other unicode glyphs with ASCII
equivalents without changing the meaning.
- Around line 426-438: Update I2sPeripheralEsp32DevEsp::waitTransmitDone to use
a wrap-safe timeout check instead of comparing against an absolute deadline, by
tracking elapsed ticks from start and comparing against the converted timeout
value; also replace the direct vTaskDelay(1) yield with fl::task::run(250,
fl::task::ExecFlags::SYSTEM) so the wait loop uses the unified executor
scheduling path.
- Around line 470-488: The ISR completion path is not fully IRAM-safe because
i2s_dma_isr_trampoline() calls getConfig() and then ultimately dispatches
through ChannelEngineI2sEsp32Dev::onTransmitDoneTrampoline(), which is not
marked FL_IRAM. Update the completion chain so the ISR only uses IRAM-safe data
and functions: cache any needed config before enabling interrupts or pass in
precomputed state, and move the completion callback delivery out of the ISR into
task context (or make the entire trampoline chain IRAM-safe if feasible). Focus
on i2s_dma_isr_trampoline(), finishTransmitFromIsr(), and
ChannelEngineI2sEsp32Dev::onTransmitDoneTrampoline().

In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.h`:
- Line 52: The changed comments in the ESP32 I2S peripheral header contain
non-ASCII punctuation, so update the affected comment lines in
i2s_peripheral_esp32dev_esp.h to use ASCII-only characters. Replace the em
dash-style punctuation with plain ASCII equivalents like - or -- in the comments
near the identified sections, including the related comment blocks referenced by
the review.
- Line 101: The busy flag used by the ESP32 I2S peripheral is accessed from both
ISR and task contexts, so `volatile bool mBusy` is not sufficient for
synchronization. Update the `I2SPeripheralESP32DevESP` member `mBusy` to
`fl::atomic_bool`, then adjust `finishTransmitFromIsr()`, `waitTransmitDone()`,
and `isBusy()` to use explicit acquire/release store/load semantics, or protect
all accesses with a FreeRTOS critical section if atomic use is not possible.

In `@src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.h`:
- Around line 129-143: The `encodeChannelWave3_i2s1` documentation is missing
the same ISR-safety warning already present on `encodeChannelWave8_i2s1`, even
though it uses identical input-bounds validation. Update the comment on
`encodeChannelWave3_i2s1` to explicitly say it is not safe for ISR/DMA-refill
use and should be called from the engine’s show() path, keeping the contract
consistent with the sibling encoder and the existing validation behavior.

---

Nitpick comments:
In `@src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp.hpp`:
- Around line 103-141: The argument checks in encodeChannelWave3_i2s1 are
duplicated from encodeChannelWave8_i2s1, so extract them into a shared inline
validation helper and call it from both functions. Move the num_lanes,
bytes_per_lane, input-size, and output-size guards into a common helper such as
validateWaveI2s1Args, then have encodeChannelWave3_i2s1 and
encodeChannelWave8_i2s1 use that helper so the bounds logic stays consistent in
one place.
🪄 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: 83a096c9-c332-4585-8425-32ab9c613e55

📥 Commits

Reviewing files that changed from the base of the PR and between 02956b3 and 5728449.

📒 Files selected for processing (27)
  • examples/AutoResearch/AutoResearch.ino
  • examples/AutoResearch/AutoResearchParlioEncode.h
  • examples/AutoResearch/AutoResearchWave8Expand.h
  • src/fl/channels/detail/_build.cpp.hpp
  • src/fl/channels/detail/wave3.cpp.hpp
  • src/fl/channels/detail/wave3.h
  • src/fl/channels/detail/wave3.hpp
  • src/fl/channels/detail/wave8.cpp.hpp
  • src/fl/channels/detail/wave8.h
  • src/fl/channels/detail/wave8.hpp
  • src/fl/channels/wave3.cpp.hpp
  • src/fl/channels/wave3.h
  • src/fl/channels/wave8.cpp.hpp
  • src/fl/channels/wave8.h
  • src/platforms/esp/32/drivers/i2s/channel_driver_i2s.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.h
  • src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.h
  • src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp
  • src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp
  • src/platforms/esp/32/drivers/spi/wave8_encoder_spi.h
  • tests/fl/channels/wave3.cpp
  • tests/fl/channels/wave8.cpp
  • tests/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp
  • tests/platforms/esp/32/drivers/parlio/parlio_driver.cpp
💤 Files with no reviewable changes (2)
  • src/fl/channels/detail/wave3.hpp
  • src/fl/channels/detail/wave8.hpp

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 10

🧹 Nitpick comments (1)
src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp.hpp (1)

103-141: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract shared validation into a helper to avoid duplicating encodeChannelWave8_i2s1's bounds checks.

Lines 108-120 (num_lanes range, bytes_per_lane == 0, input-size, output-size checks) are byte-for-byte identical to the checks already present in encodeChannelWave8_i2s1 (lines 33-45) in this same file. A shared inline helper (e.g. validateWaveI2s1Args(input, bytes_per_lane, num_lanes, output_size, required_output)) would remove the duplication and keep future bound changes in one place.

♻️ Proposed shared validation helper
+namespace detail {
+inline bool validate_wave_i2s1_args(fl::size_t input_size,
+                                     fl::size_t bytes_per_lane,
+                                     fl::size_t num_lanes,
+                                     fl::size_t output_size,
+                                     fl::size_t required_output) FL_NO_EXCEPT {
+    if (num_lanes == 0 || num_lanes > 16) return false;
+    if (bytes_per_lane == 0) return false;
+    if (input_size < 16 * bytes_per_lane) return false;
+    if (output_size < required_output) return false;
+    return true;
+}
+}  // namespace detail
+
 bool encodeChannelWave3_i2s1(fl::span<const fl::u8> input,
                              fl::size_t bytes_per_lane,
                              fl::size_t num_lanes,
                              const Wave3BitExpansionLut &lut,
                              fl::span<fl::u8> output) FL_NO_EXCEPT {
-    if (num_lanes == 0 || num_lanes > 16) {
-        return false;
-    }
-    if (bytes_per_lane == 0) {
-        return false;
-    }
-    if (input.size() < 16 * bytes_per_lane) {
-        return false;
-    }
     const fl::size_t required_output = wave3I2s1EncodedFrameSize(bytes_per_lane);
-    if (output.size() < required_output) {
-        return false;
-    }
+    if (!detail::validate_wave_i2s1_args(input.size(), bytes_per_lane, num_lanes,
+                                          output.size(), required_output)) {
+        return false;
+    }
🤖 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/wave8_encoder_i2s1.cpp.hpp` around lines 103
- 141, The argument checks in encodeChannelWave3_i2s1 are duplicated from
encodeChannelWave8_i2s1, so extract them into a shared inline validation helper
and call it from both functions. Move the num_lanes, bytes_per_lane, input-size,
and output-size guards into a common helper such as validateWaveI2s1Args, then
have encodeChannelWave3_i2s1 and encodeChannelWave8_i2s1 use that helper so the
bounds logic stays consistent in one place.
🤖 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 `@examples/AutoResearch/AutoResearch.ino`:
- Around line 362-371: The serial-wait polling loop in AutoResearch.ino is
busy-spinning and only feeds FastLED.watchdog(), so it can starve the ESP32 idle
task and trip the task watchdog. Update the loop around fl::serial_ready() /
AUTORESEARCH_SERIAL_WAIT_MS to include a yield or small delay each iteration
while still feeding the watchdog, so the RTOS gets time to run and the wait
remains responsive.

In `@src/fl/channels/detail/wave3.cpp.hpp`:
- Around line 35-127: The FL_IRAM transpose APIs are using decayed array
parameters, so the compiler does not enforce the expected extents. Update the
signatures of wave3_transpose_2, wave3_transpose_4, wave3_transpose_8, and
wave3_transpose_16 to take array references instead of pointer-decayed arrays,
and make the same change in the matching detail:: declarations in wave3.h so the
definitions and declarations stay consistent.

In `@src/fl/channels/detail/wave3.h`:
- Around line 30-43: The wave3_transpose_2/4/8/16 declarations still use decayed
array parameters, so the declared extents are not enforced. Update these APIs to
use reference-to-array forms for both the lane input and output buffer, matching
the existing wave3 wrapper pattern in wave3.h, and make the same signature
changes in the corresponding definitions in wave3.cpp.hpp so the contract stays
consistent.

In `@src/fl/channels/detail/wave8.h`:
- Around line 74-124: The wave8 transpose declarations use decayed array
parameters, so the compile-time size is not enforced. Update all affected
prototypes in wave8.h — wave8_transpose_2/4/8/16, the _pipe2/_pipe4 variants,
and the _bf1 variants — to use reference-to-array parameters like the existing
wave8() wrapper pattern instead of T value[N]. Keep the same function names and
signatures otherwise, and mirror the same change in the corresponding
definitions in wave8.cpp.hpp so the declarations and implementations match.

In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp`:
- Line 66: The changed comments in the I2S peripheral header still contain
non-ASCII punctuation, so update the affected comment text to use plain ASCII
only. Review the comments around the include and the referenced blocks in the
file, especially the ones tied to fl_i2s_periph_enable and the other changed
sections, and replace em dashes or any other unicode glyphs with ASCII
equivalents without changing the meaning.
- Around line 426-438: Update I2sPeripheralEsp32DevEsp::waitTransmitDone to use
a wrap-safe timeout check instead of comparing against an absolute deadline, by
tracking elapsed ticks from start and comparing against the converted timeout
value; also replace the direct vTaskDelay(1) yield with fl::task::run(250,
fl::task::ExecFlags::SYSTEM) so the wait loop uses the unified executor
scheduling path.
- Around line 470-488: The ISR completion path is not fully IRAM-safe because
i2s_dma_isr_trampoline() calls getConfig() and then ultimately dispatches
through ChannelEngineI2sEsp32Dev::onTransmitDoneTrampoline(), which is not
marked FL_IRAM. Update the completion chain so the ISR only uses IRAM-safe data
and functions: cache any needed config before enabling interrupts or pass in
precomputed state, and move the completion callback delivery out of the ISR into
task context (or make the entire trampoline chain IRAM-safe if feasible). Focus
on i2s_dma_isr_trampoline(), finishTransmitFromIsr(), and
ChannelEngineI2sEsp32Dev::onTransmitDoneTrampoline().

In `@src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.h`:
- Line 52: The changed comments in the ESP32 I2S peripheral header contain
non-ASCII punctuation, so update the affected comment lines in
i2s_peripheral_esp32dev_esp.h to use ASCII-only characters. Replace the em
dash-style punctuation with plain ASCII equivalents like - or -- in the comments
near the identified sections, including the related comment blocks referenced by
the review.
- Line 101: The busy flag used by the ESP32 I2S peripheral is accessed from both
ISR and task contexts, so `volatile bool mBusy` is not sufficient for
synchronization. Update the `I2SPeripheralESP32DevESP` member `mBusy` to
`fl::atomic_bool`, then adjust `finishTransmitFromIsr()`, `waitTransmitDone()`,
and `isBusy()` to use explicit acquire/release store/load semantics, or protect
all accesses with a FreeRTOS critical section if atomic use is not possible.

In `@src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.h`:
- Around line 129-143: The `encodeChannelWave3_i2s1` documentation is missing
the same ISR-safety warning already present on `encodeChannelWave8_i2s1`, even
though it uses identical input-bounds validation. Update the comment on
`encodeChannelWave3_i2s1` to explicitly say it is not safe for ISR/DMA-refill
use and should be called from the engine’s show() path, keeping the contract
consistent with the sibling encoder and the existing validation behavior.

---

Nitpick comments:
In `@src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp.hpp`:
- Around line 103-141: The argument checks in encodeChannelWave3_i2s1 are
duplicated from encodeChannelWave8_i2s1, so extract them into a shared inline
validation helper and call it from both functions. Move the num_lanes,
bytes_per_lane, input-size, and output-size guards into a common helper such as
validateWaveI2s1Args, then have encodeChannelWave3_i2s1 and
encodeChannelWave8_i2s1 use that helper so the bounds logic stays consistent in
one place.
🪄 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: 83a096c9-c332-4585-8425-32ab9c613e55

📥 Commits

Reviewing files that changed from the base of the PR and between 02956b3 and 5728449.

📒 Files selected for processing (27)
  • examples/AutoResearch/AutoResearch.ino
  • examples/AutoResearch/AutoResearchParlioEncode.h
  • examples/AutoResearch/AutoResearchWave8Expand.h
  • src/fl/channels/detail/_build.cpp.hpp
  • src/fl/channels/detail/wave3.cpp.hpp
  • src/fl/channels/detail/wave3.h
  • src/fl/channels/detail/wave3.hpp
  • src/fl/channels/detail/wave8.cpp.hpp
  • src/fl/channels/detail/wave8.h
  • src/fl/channels/detail/wave8.hpp
  • src/fl/channels/wave3.cpp.hpp
  • src/fl/channels/wave3.h
  • src/fl/channels/wave8.cpp.hpp
  • src/fl/channels/wave8.h
  • src/platforms/esp/32/drivers/i2s/channel_driver_i2s.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.h
  • src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.h
  • src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp
  • src/platforms/esp/32/drivers/parlio/parlio_engine.cpp.hpp
  • src/platforms/esp/32/drivers/spi/wave8_encoder_spi.h
  • tests/fl/channels/wave3.cpp
  • tests/fl/channels/wave8.cpp
  • tests/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp
  • tests/platforms/esp/32/drivers/parlio/parlio_driver.cpp
💤 Files with no reviewable changes (2)
  • src/fl/channels/detail/wave3.hpp
  • src/fl/channels/detail/wave8.hpp
🛑 Comments failed to post (10)
examples/AutoResearch/AutoResearch.ino (1)

362-371: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Busy-spin loop with no yield/delay may starve the RTOS idle task.

The polling loop only calls FastLED.watchdog().feed(), which feeds the custom fl::Watchdog, not the ESP32 idle-task/task watchdog (esp_task_wdt). Without a delay()/yield() inside the loop body, this can spin at 100% CPU for up to AUTORESEARCH_SERIAL_WAIT_MS (up to 120s per the adjacent comment), starving the idle task and potentially tripping the hardware task watchdog — the very kind of unexpected reboot this change is trying to prevent.

🛡️ Suggested fix: yield inside the poll loop
     while (!fl::serial_ready() && (millis() - serial_wait_start) < AUTORESEARCH_SERIAL_WAIT_MS) {
         // Feed the WDT while waiting for the serial monitor — on
         // classic ESP32 (non-USB-CDC) this loop can run for up to
         // AUTORESEARCH_SERIAL_WAIT_MS (120 s), far longer than the
         // setup WDT window. Without feeding here, the WDT trips and
         // the device reboots before the host ever attaches, leaving
         // the port silent.
         FastLED.watchdog().feed();
+        delay(1);  // yield to RTOS idle task / avoid starving esp_task_wdt
     }

Based on learnings from agents/docs/cpp-standards.md, wait/poll loops should yield rather than busy-spin; while that rule is scoped to C++ source files, the same starvation risk applies here on ESP32.

📝 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.

    uint32_t serial_wait_start = millis();
    while (!fl::serial_ready() && (millis() - serial_wait_start) < AUTORESEARCH_SERIAL_WAIT_MS) {
        // Feed the WDT while waiting for the serial monitor — on
        // classic ESP32 (non-USB-CDC) this loop can run for up to
        // AUTORESEARCH_SERIAL_WAIT_MS (120 s), far longer than the
        // setup WDT window. Without feeding here, the WDT trips and
        // the device reboots before the host ever attaches, leaving
        // the port silent.
        FastLED.watchdog().feed();
        delay(1);  // yield to RTOS idle task / avoid starving esp_task_wdt
    }
🤖 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 `@examples/AutoResearch/AutoResearch.ino` around lines 362 - 371, The
serial-wait polling loop in AutoResearch.ino is busy-spinning and only feeds
FastLED.watchdog(), so it can starve the ESP32 idle task and trip the task
watchdog. Update the loop around fl::serial_ready() /
AUTORESEARCH_SERIAL_WAIT_MS to include a yield or small delay each iteration
while still feeding the watchdog, so the RTOS gets time to run and the wait
remains responsive.

Source: Path instructions

src/fl/channels/detail/wave3.cpp.hpp (1)

35-127: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Decayed array parameters in FL_IRAM detail transpose functions.

wave3_transpose_2/4/8/16 are marked FL_IRAM (ISR-facing) but their parameters are spelled as decayed fixed-size arrays (const Wave3Byte lane_waves[2], u8 output[2 * sizeof(Wave3Byte)], etc.). In C++ these decay to pointers, so the declared extent is not enforced by the compiler. Per the path instructions, ISR/FL_IRAM APIs should use array references (T (&value)[N]) instead.

This matches the corresponding detail:: declarations in wave3.h, so the fix needs to update both the header declarations and these definitions together.

As per path instructions: "For ISR / FL_IRAM APIs, require an array reference: T (&value)[N]."

🛠️ Proposed fix (illustrated for `wave3_transpose_2`; apply the same pattern to `_4`/`_8`/`_16`)
-void wave3_transpose_2(const Wave3Byte lane_waves[2],
-                       u8 output[2 * sizeof(Wave3Byte)]) FL_NO_EXCEPT {
+void wave3_transpose_2(const Wave3Byte (&lane_waves)[2],
+                       u8 (&output)[2 * sizeof(Wave3Byte)]) FL_NO_EXCEPT {

And the matching declaration in detail/wave3.h:

-void wave3_transpose_2(const Wave3Byte lane_waves[2],
-                       u8 output[2 * sizeof(Wave3Byte)]) FL_NO_EXCEPT;
+void wave3_transpose_2(const Wave3Byte (&lane_waves)[2],
+                       u8 (&output)[2 * sizeof(Wave3Byte)]) FL_NO_EXCEPT;
🤖 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/fl/channels/detail/wave3.cpp.hpp` around lines 35 - 127, The FL_IRAM
transpose APIs are using decayed array parameters, so the compiler does not
enforce the expected extents. Update the signatures of wave3_transpose_2,
wave3_transpose_4, wave3_transpose_8, and wave3_transpose_16 to take array
references instead of pointer-decayed arrays, and make the same change in the
matching detail:: declarations in wave3.h so the definitions and declarations
stay consistent.

Source: Path instructions

src/fl/channels/detail/wave3.h (1)

30-43: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Decayed array parameters on all four transpose declarations.

wave3_transpose_2/4/8/16 all use T value[N] for both the lane input and the output byte buffer, which decays to a pointer and does not enforce the declared extent. The existing wave3() wrapper in this same file already uses the correct reference-to-array form (u8 (&output)[sizeof(Wave3Byte)]), so the fix is mechanical and consistent with an established pattern. Per path instructions, this is a HIGH severity rule with no grandfathering carve-out (only // ok array parameter suppression is allowed), and since this file is newly introduced by this split, it should adopt the compliant form now.

🔧 Proposed fix (repeat for _4/_8/_16)
-void wave3_transpose_2(const Wave3Byte lane_waves[2],
-                       u8 output[2 * sizeof(Wave3Byte)]) FL_NO_EXCEPT;
+void wave3_transpose_2(const Wave3Byte (&lane_waves)[2],
+                       u8 (&output)[2 * sizeof(Wave3Byte)]) FL_NO_EXCEPT;

Note: the matching definitions live in src/fl/channels/detail/wave3.cpp.hpp, which must be updated in lockstep (not included in this review's file set, but part of the same contract).

As per path instructions, "Do not allow function parameters spelled as T value[N] or T value[]... Flag these in declarations, definitions, callback signatures, and small output-buffer APIs."

🤖 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/fl/channels/detail/wave3.h` around lines 30 - 43, The
wave3_transpose_2/4/8/16 declarations still use decayed array parameters, so the
declared extents are not enforced. Update these APIs to use reference-to-array
forms for both the lane input and output buffer, matching the existing wave3
wrapper pattern in wave3.h, and make the same signature changes in the
corresponding definitions in wave3.cpp.hpp so the contract stays consistent.

Source: Path instructions

src/fl/channels/detail/wave8.h (1)

74-124: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Same decayed-array-parameter violation across all wave8 transpose declarations.

wave8_transpose_2/4/8/16, the _pipe2/_pipe4 variants, and the _bf1 variants all declare fixed-size array parameters as T value[N], which decays to a pointer and drops the compile-time size check. The public wave8() wrapper at the bottom of this file already correctly uses u8 (&output)[sizeof(Wave8Byte)], confirming the compliant pattern is already in use in this very file. Since these declarations are net-new (moved out of the old force-inline .hpp), this is the right time to fix them per the repo's HIGH severity rule.

🔧 Proposed fix (representative — apply to all listed functions)
-void wave8_transpose_2(const Wave8Byte lane_waves[2],
-                       u8 output[2 * sizeof(Wave8Byte)]) FL_NO_EXCEPT;
+void wave8_transpose_2(const Wave8Byte (&lane_waves)[2],
+                       u8 (&output)[2 * sizeof(Wave8Byte)]) FL_NO_EXCEPT;

-void wave8_transpose_16_bf1(const u8 lanes[16],
-                            u8 W0, u8 W1,
-                            u8 output[16 * sizeof(Wave8Byte)]) FL_NO_EXCEPT;
+void wave8_transpose_16_bf1(const u8 (&lanes)[16],
+                            u8 W0, u8 W1,
+                            u8 (&output)[16 * sizeof(Wave8Byte)]) FL_NO_EXCEPT;

Fanout required to the corresponding definitions in src/fl/channels/detail/wave8.cpp.hpp (flagged separately below).

As per path instructions, "Do not allow function parameters spelled as T value[N] or T value[]... the declared extent is not enforced."

🤖 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/fl/channels/detail/wave8.h` around lines 74 - 124, The wave8 transpose
declarations use decayed array parameters, so the compile-time size is not
enforced. Update all affected prototypes in wave8.h — wave8_transpose_2/4/8/16,
the _pipe2/_pipe4 variants, and the _bf1 variants — to use reference-to-array
parameters like the existing wave8() wrapper pattern instead of T value[N]. Keep
the same function names and signatures otherwise, and mirror the same change in
the corresponding definitions in wave8.cpp.hpp so the declarations and
implementations match.

Source: Path instructions

src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp (3)

66-66: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Replace non-ASCII punctuation in changed comments.

Several changed comments use em dashes; this file is covered by the ASCII-only C++ source rule. As per path instructions, “Source files must be ASCII-only (no emoji/unicode glyphs in code/comments).”

Also applies to: 90-101, 110-147, 180-180, 213-213, 271-271, 381-381, 494-496

🤖 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` at line
66, The changed comments in the I2S peripheral header still contain non-ASCII
punctuation, so update the affected comment text to use plain ASCII only. Review
the comments around the include and the referenced blocks in the file,
especially the ones tied to fl_i2s_periph_enable and the other changed sections,
and replace em dashes or any other unicode glyphs with ASCII equivalents without
changing the meaning.

Source: Path instructions


426-438: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the canonical include and existing usage pattern for fl::task::run.
rg -n "fl::task::run|ExecFlags::SYSTEM|`#include` .*task" src -g '*.h' -g '*.hpp' -g '*.cpp' -g '*.cpp.hpp'

Repository: FastLED/FastLED

Length of output: 9224


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the target function and nearby wait/poll patterns.
sed -n '400,470p' src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp

echo
echo "---- executor docs ----"
sed -n '1,220p' src/fl/task/executor.h

echo
echo "---- nearby I2S driver usage ----"
sed -n '1,240p' src/platforms/esp/32/drivers/i2s/channel_driver_i2s.cpp.hpp

Repository: FastLED/FastLED

Length of output: 17704


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Check how tick math is typically handled in the repo.
rg -n "pdMS_TO_TICKS|xTaskGetTickCount|TickType_t deadline|elapsed" src/platforms/esp/32 src/fl -g '*.h' -g '*.hpp' -g '*.cpp'

Repository: FastLED/FastLED

Length of output: 11230


Switch to wrap-safe elapsed-time checks and the unified executor yield. Replace the absolute deadline comparison with xTaskGetTickCount() - start >= timeout_ticks, and use fl::task::run(250, fl::task::ExecFlags::SYSTEM) instead of bare vTaskDelay(1).

🤖 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 426 - 438, Update I2sPeripheralEsp32DevEsp::waitTransmitDone to use a
wrap-safe timeout check instead of comparing against an absolute deadline, by
tracking elapsed ticks from start and comparing against the converted timeout
value; also replace the direct vTaskDelay(1) yield with fl::task::run(250,
fl::task::ExecFlags::SYSTEM) so the wait loop uses the unified executor
scheduling path.

Source: Path instructions


470-488: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect the ISR callback registration/call graph for IRAM annotations.
rg -n "I2sEsp32DevTxDoneCallback|registerTransmitCallback|getConfig\\(|finishTransmitFromIsr|mCallback" src/platforms/esp/32/drivers/i2s src -g '*.h' -g '*.hpp' -g '*.cpp.hpp'

Repository: FastLED/FastLED

Length of output: 40109


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the ISR implementation, the callback registration site, and the interface docs.
sed -n '430,520p' src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp
printf '\n---\n'
sed -n '1,320p' src/platforms/esp/32/drivers/i2s/ii2s_peripheral_esp32dev.h
printf '\n---\n'
sed -n '1,140p' src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp.hpp
printf '\n---\n'
sed -n '1,140p' src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.h

Repository: FastLED/FastLED

Length of output: 23703


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the channel-engine completion callback and whether it is IRAM annotated.
rg -n "onTransmitDoneTrampoline|mTransmitCompleted|registerTransmitCallback\\(" src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.* src/platforms/esp/32/drivers/i2s -g '*.h' -g '*.hpp' -g '*.cpp.hpp'

Repository: FastLED/FastLED

Length of output: 6123


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the completion trampoline definition and any IRAM annotation or unsafe calls.
sed -n '400,440p' src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp.hpp

Repository: FastLED/FastLED

Length of output: 1557


Make the ISR completion chain IRAM-safe src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp:470-500 / src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp.hpp:415-428 — i2s_dma_isr_trampoline() reaches getConfig() and then calls the registered completion callback; that callback is ChannelEngineI2sEsp32Dev::onTransmitDoneTrampoline(), which is not FL_IRAM. Cache the needed config outside the ISR or move callback delivery to task context.

🤖 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 470 - 488, The ISR completion path is not fully IRAM-safe because
i2s_dma_isr_trampoline() calls getConfig() and then ultimately dispatches
through ChannelEngineI2sEsp32Dev::onTransmitDoneTrampoline(), which is not
marked FL_IRAM. Update the completion chain so the ISR only uses IRAM-safe data
and functions: cache any needed config before enabling interrupts or pass in
precomputed state, and move the completion callback delivery out of the ISR into
task context (or make the entire trampoline chain IRAM-safe if feasible). Focus
on i2s_dma_isr_trampoline(), finishTransmitFromIsr(), and
ChannelEngineI2sEsp32Dev::onTransmitDoneTrampoline().
src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.h (2)

52-52: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Replace non-ASCII punctuation in changed comments.

These changed comment lines use em dashes; the C++ standards excerpt requires ASCII-only source/comments. Use - or -- instead. As per path instructions, “Source files must be ASCII-only (no emoji/unicode glyphs in code/comments).”

Also applies to: 91-91, 105-105

🤖 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` at line 52,
The changed comments in the ESP32 I2S peripheral header contain non-ASCII
punctuation, so update the affected comment lines in
i2s_peripheral_esp32dev_esp.h to use ASCII-only characters. Replace the em
dash-style punctuation with plain ASCII equivalents like - or -- in the comments
near the identified sections, including the related comment blocks referenced by
the review.

Source: Path instructions


101-101: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the canonical FastLED atomic header/API before patching.
rg -n "fl::atomic|template.*atomic|class atomic|`#include` .*atomic" src/fl src -g '*.h' -g '*.hpp' -g '*.cpp.hpp'

Repository: FastLED/FastLED

Length of output: 8296


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the file under review and the nearby call sites/usages of mBusy.
file='src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.h'
echo "== outline: $file =="
ast-grep outline "$file" --view expanded || true
echo
echo "== relevant lines in $file =="
sed -n '1,220p' "$file" | cat -n
echo
echo "== mBusy usages and related transmit flow =="
rg -n -A3 -B3 '\bmBusy\b|finishTransmitFromIsr|waitTransmitDone|startTransmit|transmit' \
  src/platforms/esp/32/drivers/i2s \
  -g '!*build*' -g '!*dist*'
echo
echo "== atomic header and nearby bool atomic patterns =="
rg -n 'fl::atomic<bool>|fl::atomic_bool|fl/stl/atomic.h' src/platforms/esp/32 src/fl -g '*.h' -g '*.hpp' -g '*.cpp.hpp' -g '*.impl.hpp'

Repository: FastLED/FastLED

Length of output: 50371


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate the real-hardware implementation file and inspect the busy-state flow.
fd -a 'i2s_peripheral_esp32dev_esp.*' src/platforms/esp/32/drivers/i2s

echo
echo "== implementation outline =="
impl="$(fd -a 'i2s_peripheral_esp32dev_esp.*' src/platforms/esp/32/drivers/i2s | head -n 1)"
ast-grep outline "$impl" --view expanded || true

echo
echo "== targeted mBusy / finishTransmitFromIsr / waitTransmitDone / isBusy excerpts =="
rg -n -A4 -B4 '\bmBusy\b|finishTransmitFromIsr|waitTransmitDone|isBusy|i2s_wait_tx_done|i2s_write|esp_intr_alloc|intr_alloc' "$impl"

echo
echo "== atomic helpers in the repo (focused on bool/int patterns) =="
rg -n 'fl::atomic<bool>|fl::atomic_bool|fl::atomic<.*bool.*>|fl::atomic<.*u32.*>|fl::atomic<.*int.*>' src/fl src/platforms -g '*.h' -g '*.hpp' -g '*.cpp.hpp' -g '*.impl.hpp' | head -n 120

Repository: FastLED/FastLED

Length of output: 9158


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the FastLED atomic wrapper and an existing ESP32 I2S atomic field.
sed -n '1,260p' src/fl/stl/atomic.h | cat -n
echo
sed -n '220,260p' src/platforms/esp/32/drivers/i2s/channel_driver_i2s.h | cat -n

Repository: FastLED/FastLED

Length of output: 8339


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Find how fl::atomic is accessed with explicit ordering in the repo.
rg -n '\.load\(|\.store\(|memory_order|memory_order_' src/fl src/platforms -g '*.h' -g '*.hpp' -g '*.cpp.hpp' -g '*.impl.hpp' | head -n 200

Repository: FastLED/FastLED

Length of output: 18346


Replace volatile bool mBusy with fl::atomic_bool

mBusy is written from finishTransmitFromIsr() and polled from task-side paths like waitTransmitDone()/isBusy(). volatile doesn’t provide synchronization here; use fl::atomic_bool with explicit acquire/release loads and stores, or guard the access with a FreeRTOS critical section.

🤖 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` at line 101,
The busy flag used by the ESP32 I2S peripheral is accessed from both ISR and
task contexts, so `volatile bool mBusy` is not sufficient for synchronization.
Update the `I2SPeripheralESP32DevESP` member `mBusy` to `fl::atomic_bool`, then
adjust `finishTransmitFromIsr()`, `waitTransmitDone()`, and `isBusy()` to use
explicit acquire/release store/load semantics, or protect all accesses with a
FreeRTOS critical section if atomic use is not possible.

Source: Path instructions

src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.h (1)

129-143: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Missing ISR-safety caveat on encodeChannelWave3_i2s1.

encodeChannelWave8_i2s1 documents "**Not for ISR use.** The transpose kernel is IRAM-safe but the input-bounds validation isn't; call from the engine's show() path, not the DMA-refill callback." (lines 97-99). encodeChannelWave3_i2s1 performs the identical bounds-validation pattern (lane/byte-count/output-size checks) but its doc comment (lines 129-138) omits this warning, which could mislead a caller into invoking it from an ISR/DMA-refill context.

📝 Proposed doc fix
 /// `@return` true on success. false if inputs are out of range OR the
 ///         output span is too small.
+///
+/// **Not for ISR use.** Like `encodeChannelWave8_i2s1`, the input-bounds
+/// validation isn't IRAM-safe; call from the engine's `show()` path, not
+/// the DMA-refill callback.
 bool encodeChannelWave3_i2s1(fl::span<const fl::u8> input,

Based on learnings/path instructions, contract changes require fanout across producer/validator/docs — the ISR-safety contract established for the Wave8 sibling should be mirrored here. As per path instructions: "Contract changes require fanout: update all producer/validator/tests/docs/metrics for any changed bounds/semantics; don't partially sweep."

📝 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.

/// `@brief` Encode one frame across `num_lanes` LED strips into a wave3
///        pulse-major byte stream ready for I2S1 DMA output.
///
/// Same input layout as `encodeChannelWave8_i2s1`. Wave3 eligibility is
/// the caller's responsibility — pass an LUT built via
/// `buildWave3ExpansionLUT(timing)` for a `canUseWave3(timing) == true`
/// chipset. Undefined output for wave3-ineligible timings.
///
/// `@return` true on success. false if inputs are out of range OR the
///         output span is too small.
///
/// **Not for ISR use.** Like `encodeChannelWave8_i2s1`, the input-bounds
/// validation isn't IRAM-safe; call from the engine's `show()` path, not
/// the DMA-refill callback.
bool encodeChannelWave3_i2s1(fl::span<const fl::u8> input,
                             fl::size_t bytes_per_lane,
                             fl::size_t num_lanes,
                             const Wave3BitExpansionLut &lut,
                             fl::span<fl::u8> output) FL_NO_EXCEPT;
🤖 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/wave8_encoder_i2s1.h` around lines 129 -
143, The `encodeChannelWave3_i2s1` documentation is missing the same ISR-safety
warning already present on `encodeChannelWave8_i2s1`, even though it uses
identical input-bounds validation. Update the comment on
`encodeChannelWave3_i2s1` to explicitly say it is not safe for ISR/DMA-refill
use and should be called from the engine’s show() path, keeping the contract
consistent with the sibling encoder and the existing validation behavior.

Source: Path instructions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant