Skip to content

feat(i2s): wave8 encoder for classic-ESP32 I2S1 (#3526 Phase 2a) - #3528

Merged
zackees merged 1 commit into
masterfrom
feat/i2s-wave8-encoder-3526-2a
Jul 1, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/i2s-wave8-encoder-3526-2a

Conversation

@zackees

@zackees zackees commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Summary

New wave8_encoder_i2s1 — general clockless byte-stream encoder for the modern classic-ESP32 I2S1 driver. First landable piece of the #3526 architectural rewrite: wave8/wave3 encoding like PARLIO, NOT delegate to Yves.

Anti-drift discipline

Deliberately avoids the mirror-cheat pattern flagged in FastLED#3524:

  • Calls the SHARED fl::wave8Transpose_16_bf1 / wave8Transpose_16x4_bf1_pipe4 kernels directly. No private transpose.
  • Uses buildWave8ByteExpansionLUT() from src/fl/channels/wave8.h. No private LUT builder.
  • Host tests compare encoder output against direct calls to those same shared kernels — if the encoder wrapper drifts, tests break immediately.

Files

  • src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.h — public API + docs
  • src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp.hpp — ~40 LoC of adaptation around shared calls
  • tests/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp — 6 test cases: input bounds rejection, one-lane byte-exact match, four-byte batch byte-exact match, inactive-lane zero-padding
  • src/platforms/esp/32/drivers/i2s/_build.cpp.hpp — unity build registration

What this does NOT do

  • Does NOT wire into I2sPeripheralEsp32DevEsp::transmit() — that's Phase 2b (needs real DMA + ISR, bench-blocked).
  • Does NOT touch the Yves `i2s_esp32dev.cpp.hpp` — untouched until Phase 2e's REQUIRED deletion.

Test plan

  • bash test --cpp: 345/345 pass (1 new test file, 6 subcases)
  • bash lint --cpp: clean

Part of #3516 meta / #3526 Phase 2a.

Summary by CodeRabbit

  • New Features
    • Added support for an ESP32 I2S1 Wave8 encoder path for clockless output.
    • Introduced frame-size helpers and a public encoder interface for building encoded output buffers.
  • Bug Fixes
    • Added validation for lane count, input size, and output buffer size to prevent invalid encoding.
    • Ensured inactive lanes are zero-padded so they do not affect encoded results.
  • Tests
    • Added coverage for valid encoding output and error handling across multiple buffer and lane configurations.

New `wave8_encoder_i2s1` — general clockless byte-stream encoder that
dispatches through the SHARED `fl::wave8Transpose_16_bf1` and
`fl::wave8Transpose_16x4_bf1_pipe4` kernels. Follows the same shape as
PARLIO's wave8 hot loop (`parlio_engine.cpp.hpp:1024-1069`). Does NOT
duplicate the transpose implementation or introduce a private LUT
builder — reuses `fl::Wave8ByteExpansionLut` via
`buildWave8ByteExpansionLUT()` from `src/fl/channels/wave8.h`.

## Rationale

Per #3526 (rolled up under #3516 meta): the modern
classic-ESP32 I2S driver is being rebuilt as a general clockless driver
in the same shape as PARLIO — using wave8/wave3 encoding, NOT
delegating to the Yves per-chipset bit-pattern driver. This is the
first landable piece of that work: a pure encoder that has no
peripheral / DMA / ISR dependencies and can be host-verified against
the shared transpose kernels for byte-exact correctness.

## Anti-drift discipline (#3524 post-mortem)

The recent #3524 issue documents the parlio_encode.h
"facade" pattern where AutoResearch measured a mirror of the
production hot loop instead of the real one — silent drift risk. This
file deliberately avoids that pattern:

- No private transpose kernel — calls
  `fl::wave8Transpose_16_bf1` / `fl::wave8Transpose_16x4_bf1_pipe4`
  directly, so this encoder can't diverge from PARLIO's production
  path.
- No private LUT builder — uses `buildWave8ByteExpansionLUT()` from
  the shared channel LUT surface.
- Host tests compare the encoder output against direct calls to those
  same shared kernels with identical inputs. If a future refactor
  introduces a subtle behavioural change in the encoder wrapper, the
  divergence surfaces immediately as a test failure.

## Files

- `src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.h` — public
  API + docs
- `src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp.hpp` —
  encoder implementation (~40 LoC of adaptation around the shared
  transpose calls)
- `tests/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp` —
  6 host test cases:
  - Rejects zero / >16 lanes
  - Rejects undersized input / output
  - One-lane one-byte byte-exact match against
    `wave8Transpose_16_bf1` direct call
  - Four-byte batch byte-exact match against
    `wave8Transpose_16x4_bf1_pipe4` direct call
  - Inactive-lane bytes ignored (garbage in lanes 1..15 doesn't
    pollute the transpose when num_lanes=1)
- `src/platforms/esp/32/drivers/i2s/_build.cpp.hpp` — added the new
  cpp.hpp to the unity build alphabetically

## What this does NOT do

- Does NOT wire the encoder into `I2sPeripheralEsp32DevEsp::transmit()`
  — that's Phase 2b (needs the real DMA descriptor ring + ISR machinery
  which requires bench validation).
- Does NOT include wave3 support — Phase 2a follow-up.
- Does NOT touch the classic Yves `i2s_esp32dev.cpp.hpp` driver — that
  stays untouched until Phase 2e's REQUIRED deletion (per #3526
  acceptance criteria).

## Verification

- `bash test --cpp`: 345/345 pass — 1 new test file with 6 subcases,
  all byte-exact against the shared transpose kernels.
- `bash lint --cpp`: clean.

Part of #3516 meta / #3526 Phase 2a.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 1afaf37 into master Jul 1, 2026
8 of 10 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: fc42fd04-2503-4882-b09f-6ffe0697850f

📥 Commits

Reviewing files that changed from the base of the PR and between 092b448 and 2a3fd29.

📒 Files selected for processing (4)
  • src/platforms/esp/32/drivers/i2s/_build.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp.hpp
  • src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.h
  • tests/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp

📝 Walkthrough

Walkthrough

Adds a new classic-ESP32 I2S1 Wave8 encoder consisting of a public header declaring encodeChannelWave8_i2s1 and a frame-size helper, an implementation that validates shapes and dispatches to shared wave8Transpose_* kernels, unity-build wiring, and a host test suite verifying validation and byte-exact correctness.

Changes

ESP32 I2S1 Wave8 encoder

Layer / File(s) Summary
Encoder header contract and frame-size helper
src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.h
Declares kWave8I2s1BytesPerBytePosition, wave8I2s1EncodedFrameSize(bytes_per_lane), and encodeChannelWave8_i2s1(...) with documented layout, bounds, and return semantics.
Encoder implementation and unity-build wiring
src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp.hpp, src/platforms/esp/32/drivers/i2s/_build.cpp.hpp
Implements shape validation and the byte-gathering encode loop that dispatches to wave8Transpose_16x4_bf1_pipe4 or wave8Transpose_16_bf1, zero-pads inactive lanes, and returns success/failure; includes the new file into the ESP32 I2S unity build.
Host tests for encoder validation and correctness
tests/platforms/esp/32/drivers/i2s/wave8_encoder_i2s1.cpp
Builds a canonical WS2812B LUT, tests failure cases (zero/excess lanes, undersized input/output), verifies byte-exact output against direct transpose kernel calls, and confirms inactive lanes are zero-padded.

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

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant encodeChannelWave8_i2s1
  participant wave8Transpose_16x4_bf1_pipe4
  participant wave8Transpose_16_bf1

  Caller->>encodeChannelWave8_i2s1: input, bytes_per_lane, num_lanes, lut, output
  encodeChannelWave8_i2s1->>encodeChannelWave8_i2s1: validate shapes and sizes
  alt >=4 byte positions remain and output permits
    encodeChannelWave8_i2s1->>wave8Transpose_16x4_bf1_pipe4: gathered 16-lane batch
    wave8Transpose_16x4_bf1_pipe4-->>encodeChannelWave8_i2s1: encoded bytes
  else single byte position
    encodeChannelWave8_i2s1->>wave8Transpose_16_bf1: gathered 16-lane bytes
    wave8Transpose_16_bf1-->>encodeChannelWave8_i2s1: encoded bytes
  end
  encodeChannelWave8_i2s1-->>Caller: true/false
Loading

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2532: New encodeChannelWave8_i2s1 relies on wave8Transpose_16_bf1/wave8Transpose_16x4_bf1_pipe4, which this PR modifies.
  • FastLED/FastLED#2534: Encoder depends on the same wave8Transpose_* implementations altered to use spread-LUT based transpose logic.
  • FastLED/FastLED#2557: Encoder's pipelined path selection depends directly on the wave8Transpose_16x4_pipe4 functionality introduced there.
✨ 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-wave8-encoder-3526-2a

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

❤️ Share

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

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jul 1, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jul 1, 2026
zackees added a commit that referenced this pull request Jul 1, 2026
…se 2b) (#3540)

`I2sPeripheralEsp32DevEsp::initialize()` no longer stubs — it now
configures the I2S1 peripheral via the tested Yves C-style utilities
(`i2s_define_bit_patterns` + `i2s_init` from `i2s_esp32dev.h`) that
have been production since #3479.

## Hardware-ownership check

Adds `i2s_is_initialized()` guard so the modern peripheral refuses to
bind if the classic `ClocklessI2S<>` template on
`-DFASTLED_ESP32_I2S=1` already claimed I2S1. First-in-wins prevents
the two paths from racing on the shared hardware.

## Timing default

Chipset timing defaults to canonical WS2812B (`TIMING_WS2812_800KHZ`
via `to_runtime_timing<>`). Per-channel timing dispatch arrives with
the modern engine's Phase 2b-encoder integration — for now this
matches every previously-working I2S user's configuration.

## Scope

- `initialize()` now real (was stub returning true without touching
  hardware).
- `deinitialize()` still no-op — Phase 2b-deinit follow-up will free
  the ISR handle + DMA descriptors.
- `transmit()` still returns synchronous stub — Phase 2b-DMA
  follow-up wires the wave8 encoder (#3528) output through I2S1 DMA.

## Verification

- `bash test --cpp`: 345/345 pass (existing engine tests unchanged —
  no code path currently invokes `initialize()`).
- `bash lint --cpp`: file clean (unrelated pre-existing violations
  in `platforms/arm/lpc/rx_sct_capture.cpp.hpp` fixed in follow-up).
- **Bench**: `bash autoresearch esp32dev` flashes + boots clean on
  attached WROOM COM11 with new initialize() in the binary. `RESULT:
  {"type":"ready",...}` at ~2s uptime, ping successful. Since no
  code path invokes the modern peripheral in this build (`Bus::FLEX_IO, 0`
  still binds to `I2S_SPI` — Phase 2d does the swap), initialize() is
  dormant but present.

Part of #3516 meta / #3526 Phase 2b.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the feat/i2s-wave8-encoder-3526-2a branch August 21, 2026 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant