Skip to content

feat(i2s): Phase 2b step A — inline register-level init on modern peripheral (#3526) - #3556

Merged
zackees merged 4 commits into
masterfrom
feat/i2s-phase-2b-inline-register-init-3526
Jul 1, 2026
Merged

zackees merged 4 commits into
masterfrom
feat/i2s-phase-2b-inline-register-init-3526

Conversation

@zackees

@zackees zackees commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Eliminates the modern I2S peripheral's dependency on the Yves i2s_esp32dev.h helpers. initialize() and deinitialize() now write directly to I2S0/I2S1 register blocks via soc/i2s_struct.h at a fixed 8 MHz pixel clock for wave8 output — the general-clockless architecture the #3526 meta issue mandates, NOT Yves's per-chipset bit-pattern encoder.

What changed

  • Dropped #include \"platforms/esp/32/drivers/i2s/i2s_esp32dev.h\" from the peripheral impl.
  • Replaced i2s_define_bit_patterns / i2s_init / i2s_stop with direct register writes.
  • Fixed clock divider N=10, A=1, B=0 → 80 MHz APB / 10 = 8 MHz wave8 pixel clock.
  • Ownership handshake via private static g_i2s1_hardware_claimed_by_modern — no dependency on Yves's gInitializedI2sInitialized.
  • Also fixed two AutoResearch example headers I missed in refactor(channels): split detail/wave3.hpp + wave8.hpp into .h + .cpp.hpp #3555's detail-split sweep.

What's still pending (Phase 2b step B)

transmit() is still a stub — real DMA needs:

  • lldesc_t descriptor ring (IRAM-resident)
  • esp_intr_alloc() ISR install
  • out_link.addr + out_link.start DMA kick
  • ISR-refill streaming for buffers larger than one descriptor

Phase 2b step B is a follow-up PR and can now be built directly on top of this init foundation with no Yves entanglement.

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 after WDT-driven recovery from the intermittent first-boot fl::json::json(const char*) panic (unrelated pre-existing bug)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added support for a new channel encoding path on ESP32, including frame sizing and validation.
    • Expanded hardware driver support for additional waveform handling.
  • Bug Fixes

    • Improved startup reliability by making watchdog handling more robust during early boot and serial-console waiting.
    • Reduced the chance of unexpected resets when connecting a serial monitor slowly.
    • Updated ESP32 I2S initialization and shutdown handling for more stable peripheral ownership and cleanup.

zackees and others added 4 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]>
@zackees
zackees merged commit 02956b3 into master Jul 1, 2026
11 of 12 checks passed
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a696ee80-bdb5-4c40-87f5-61c70d924549

📥 Commits

Reviewing files that changed from the base of the PR and between aa19b39 and 1db66f8.

📒 Files selected for processing (26)
  • 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/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

📝 Walkthrough

Walkthrough

This PR splits inline wave3/wave8 transpose headers into separate declaration (.h) and out-of-line definition (.cpp.hpp) files, updates all consumer includes accordingly, adds a wave3 I2S1 encoder, rewrites ESP32Dev I2S peripheral register initialization, and hardens AutoResearch's setup-time watchdog handling.

Changes

Wave3/Wave8 header split and consumers

Layer / File(s) Summary
New wave3 declaration and implementation
src/fl/channels/detail/wave3.h, src/fl/channels/detail/wave3.cpp.hpp
Adds declarations and out-of-line definitions for wave3 byte conversion and 2/4/8/16-lane transposition, plus the public wave3 wrapper.
New wave8 declaration and implementation
src/fl/channels/detail/wave8.h, src/fl/channels/detail/wave8.cpp.hpp
Adds LUTs, macros, declarations, and out-of-line definitions for wave8 byte conversion/expansion and transposition including pipelined and bf1 mask-based variants, plus the public wave8 wrapper.
Unity build wiring and include updates
src/fl/channels/detail/_build.cpp.hpp, src/fl/channels/wave3*.h/hpp, src/fl/channels/wave8*.h/hpp, src/platforms/esp/32/drivers/{i2s,lcd_spi,parlio,spi}/*, examples/AutoResearch/*, tests/fl/channels/*, tests/platforms/esp/32/drivers/parlio/*
Adds new headers to unity build and switches all consumers from removed .hpp inline headers to the new .h/.cpp.hpp split headers.
Wave3 I2S1 encoder addition
src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.h, wave8_encoder_i2s1.cpp.hpp, tests/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp
Adds encodeChannelWave3_i2s1 and sizing helper, with validation logic and byte-exact/validation tests.

ESP32Dev I2S peripheral register rewrite

Layer / File(s) Summary
Register-level initialize/deinitialize rewrite
src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_esp.cpp.hpp
Replaces classic hardware-init utilities with direct SoC register configuration, reset helpers, and an I2S1 ownership flag in initialize()/deinitialize().

AutoResearch setup watchdog hardening

Layer / File(s) Summary
Explicit watchdog arming and serial-wait feeding
examples/AutoResearch/AutoResearch.ino
Adds explicit Watchdog::instance().begin() in setup() and feeds the watchdog during the serial-ready wait loop.

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

Sequence Diagram(s)

sequenceDiagram
  participant Test
  participant encodeChannelWave3_i2s1
  participant wave3Transpose_16
  Test->>encodeChannelWave3_i2s1: input, bytes_per_lane, num_lanes, lut, output
  encodeChannelWave3_i2s1->>encodeChannelWave3_i2s1: validate lanes/sizes, zero-pad lanes
  loop each byte_offset
    encodeChannelWave3_i2s1->>wave3Transpose_16: gathered 16-lane bytes
    wave3Transpose_16-->>encodeChannelWave3_i2s1: transposed output bytes
  end
  encodeChannelWave3_i2s1-->>Test: true/false
Loading

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2532: Prior changes to the same wave3/wave8 transpose implementations that this PR migrates into out-of-line headers.
  • FastLED/FastLED#3476: Also modifies I2sPeripheralEsp32DevEsp lifecycle/register logic in the same file.
  • FastLED/FastLED#2753: Also modifies AutoResearch.ino watchdog arming/feeding behavior in setup().
✨ 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-inline-register-init-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.

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