Skip to content

I2S modern driver: wave8/wave3 general clockless (like PARLIO) + SPI unified — do NOT delegate to Yves #3526

Open

Description

@zackees

Design directive

The modern classic-ESP32 I2S parallel-out driver (currently scaffolded in channel_engine_i2s_esp32dev + i2s_peripheral_esp32dev_esp) must be built as a general clockless driver in the same shape as PARLIO — using wave8 / wave3 encoding driven by a fixed pixel clock — NOT by delegating to the classic Yves i2s_esp32dev.cpp.hpp bit-pattern driver.

Origin: user directive during #3516 Phase 2 drafting session. Was going to wrap the Yves C-style API from the modern peripheral; user redirected because the two are fundamentally different architectures and the modern driver should follow the parallel-IO/wave8 pattern PARLIO established.

Why not wrap the Yves driver

The Yves classic driver at src/platforms/esp/32/drivers/i2s/i2s_esp32dev.cpp.hpp encodes each bit as a variable number of I2S pulses derived from ChipsetTiming.T1/T2/T3 (see i2s_define_bit_patterns and i2s_transpose_and_encode). It's a per-chipset bit-pattern encoder that runs the transpose from an ISR streaming refill.

That model:

  • Can't be selected per-channel at runtime — the bit patterns are set once at i2s_init time
  • Doesn't fit the modern channel-manager flow where each ChannelData carries its own ChipsetTimingConfig
  • Isn't the pattern the rest of the parallel-IO drivers use (PARLIO on ESP32-P4/C6/H2/C5 and LCD_CAM on ESP32-S3 both use wave8/wave3 expansion)

The wave8 / wave3 pattern PARLIO uses

Reference: src/platforms/esp/32/drivers/parlio/parlio_engine.h lines 68-69 include fl/channels/wave3.h + fl/channels/wave8.h. Members at lines 295-309 hold:

u32 mTimingT1Ns;
u32 mTimingT2Ns;
u32 mTimingT3Ns;
u32 mResetUs;

fl::Wave8BitExpansionLut  mWave8Lut;     // 8x expansion, always available
fl::Wave8ByteExpansionLut mWave8ByteLut;  // byte-indexed fast path (#2526)
fl::Wave3BitExpansionLut  mWave3Lut;      // 3x expansion, chipset-eligible only
bool                      mUseWave3;
u32                       mClockFreqHz;   // wave8: 8 MHz, wave3: per-chipset

Per-channel encoding path:

  1. Channel has a ChipsetTimingConfig from its ChannelData.
  2. Check if the timing is wave3-eligible (three-slot timings can use the smaller wave3 LUT — saves 2.6x memory).
  3. Expand each byte via mWave8ByteLut (or mWave3Lut) into 8 (or 3) parallel-DMA words per input bit.
  4. Feed the expanded stream to the peripheral's DMA at the fixed pixel clock.
  5. The pixel-clock rate determines the wire-side timing: at 8 MHz wave8, each output bit is 125 ns, so 8 output bits per input bit → 1 µs per input bit at 800 kHz WS2812 rate.

For classic-ESP32 I2S1 parallel-out, the same encoding fits: I2S1 supports 16 parallel data lanes clocked at a configurable rate. Set the pixel clock to 8 MHz for wave8, feed 8 expanded output bits per input bit per lane, and every WS2812-family chipset that PARLIO handles is handled by I2S1 too.

Scope

Implementation phases (do NOT delegate to Yves at any point — the two are separate):

Phase 2a — Wave8 encoder for classic-ESP32 I2S1 (SHARED CODE ONLY)

New encoder in src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s.{h,cpp.hpp} — extended if the existing file (which targets S3 LCD_CAM) can be shared, or a new sibling wave8_encoder_i2s1.h if the bit-lane layout differs. Must:

  • Accept a ChannelData (byte stream + ChipsetTimingConfig)
  • Produce wave8-expanded bytes for one bit-lane at I2S1's 32-bit-wide FIFO layout
  • Wave3-eligibility check + wave3 fallback for smaller memory footprint
  • REQUIRED — reuse shared code, do NOT duplicate. Wave encoding kernels (fl::wave8Transpose_16_bf1, fl::wave8Transpose_16x4_bf1_pipe4, fl::wave3*) live in src/fl/channels/ and are shared across every parallel-IO driver (PARLIO, LCD_CAM, FlexIO, ObjectFLED, LPUART, and now I2S1). The I2S1 encoder is a thin wrapper that calls those kernels — it MUST NOT re-implement the transpose hot loop, MUST NOT duplicate the LUT builders, MUST NOT introduce a private lookup table with the same semantics. Any driver-specific work is limited to (a) input-format adaptation from the modern channel-manager ChannelData layout to the transpose kernels expected inputs, (b) output-format adaptation to the I2S1 DMA descriptor byte layout, (c) bounds validation. This is the anti-drift rule the AutoResearchParlioEncode.h times a mirror of production hot loop, not production code (facade cheat) #3524 mirror-cheat post-mortem established: shared production code, one implementation, everyone dispatches through it

Phase 2b — I2S1 peripheral (register + DMA + ISR)

Rewrite I2sPeripheralEsp32DevEsp::initialize / transmit / waitTransmitDone to:

  • Own its own DMA descriptor ring (lldesc_t chain, IRAM-resident)
  • Configure I2S1 as a fixed-rate parallel outputter — 16-bit-wide, 8 MHz pixel clock for wave8 (or chipset-specific rate for wave3)
  • Install its own esp_intr_alloc ISR that refills the next buffer while the current one drains — streaming, matching the invariant documented in src/platforms/esp/32/drivers/i2s/README.md
  • No calls into i2s_esp32dev.cpp.hpp (Yves driver stays untouched; it's the legacy -DFASTLED_ESP32_I2S=1 path until Phase 4 exposes the new modern path)

Phase 2c — SPI mode in the same engine (parallel-IO unified rule)

Per agents/docs/cpp-standards.md → "Parallel-IO Driver: Unified Clockless + SPI Engine (REQUIRED)", the modern I2S engine MUST handle both clockless and SPI modes on the same peripheral. Existing pattern to mirror:

  • ChannelEngineI2sEsp32Dev::getCapabilities() returns Capabilities(true, true)
  • BusSupports<Bus::FLEX_IO, ClocklessChipset, 0> and BusSupports<Bus::FLEX_IO, SpiChipsetConfig, 0> both specialize to fl::true_type
  • canHandle() accepts both data->isClockless() and data->isSpi()
  • show() routes per-channel — reconfigure the peripheral (FIFO width, clock rate, DMA slots) when switching modes at show-time

Since the I2S1 peripheral can only run one mode at a time, mode switches happen AT show-time (not at engine construction), same rule the FlexIO / ObjectFLED unified engines follow.

Reference for the SPI half: src/platforms/esp/32/drivers/i2s_spi/ — the existing I2S-in-SPI-mode driver already targets Bus::FLEX_IO, 0 on classic ESP32. Its SPI encoding + DMA setup can either be folded into the new engine or reused verbatim through the engine's SPI-mode branch. The _build.cpp.hpp for drivers/i2s_spi/ is removed once the merge lands (Phase 2d cleanup).

Phase 2d — Wire into BusTraits<Bus::FLEX_IO, 0> on classic ESP32

Update channel_manager_esp32.cpp.hpp so addI2sIfPossible registers ChannelEngineI2sEsp32Dev in the FLEX_IO slot as the unified clockless+SPI engine. Retires the separate addI2sSpiIfPossible — its work is now inside the single unified engine.

Phase 2e — Delete the Yves drivers (REQUIRED)

Once Phase 2d ships and bench validation on WROOM proves the new path drives every WS2812-family chipset the Yves driver did AND every clocked chipset the I2S-SPI driver did, the Yves i2s_esp32dev.cpp.hpp + clockless_i2s_esp32.h AND drivers/i2s_spi/ MUST be deleted from the tree. Not deprecated behind a compat shim — deleted. FASTLED_ESP32_I2S opt-in is removed; the modern engine is the only I2S path. Rationale: keeping two coexisting paths on the same peripheral (Yves globals + modern instance state, both racing to claim I2S1) is exactly the maintenance-cost / silent-hardware-conflict scenario the parallel-IO unified-engine rule was written to prevent. See agents/docs/cpp-standards.md -> "Parallel-IO Driver: Unified Clockless + SPI Engine (REQUIRED)" - fork = 4x maintenance surface, no behavioral benefit.

Reference

  • PARLIO engine (implementation pattern to mirror): src/platforms/esp/32/drivers/parlio/parlio_engine.h, parlio_engine.cpp.hpp
  • Shared wave LUTs: src/fl/channels/wave8.h, src/fl/channels/wave3.h
  • Existing I2S wave8 for S3 LCD_CAM (may be reusable): src/platforms/esp/32/drivers/i2s/wave8_encoder_i2s.h
  • Yves classic driver (do NOT wrap): src/platforms/esp/32/drivers/i2s/i2s_esp32dev.cpp.hpp
  • Parallel-IO unified-engine rule: agents/docs/cpp-standards.md → "Parallel-IO Driver: Unified Clockless + SPI Engine"
  • Wave8 byte-LUT bench: examples/AutoResearch/AutoResearchParlioEncode.h (⚠️ mirror-cheat noted in AutoResearchParlioEncode.h times a mirror of production hot loop, not production code (facade cheat) #3524 — do not reuse that pattern here)

Acceptance

  • wave8_encoder_i2s1 produces byte-exact wave8 output for a fixed input pattern, verified in host test.
  • wave8_encoder_i2s1 calls the shared fl::wave8Transpose_* kernels — grep confirms no private transpose implementation, no duplicate LUT builder.
  • Wave3 fallback path exercised for a three-slot chipset.
  • I2sPeripheralEsp32DevEsp drives real DMA on I2S1 via its own descriptor ring + ISR — no calls into i2s_esp32dev.cpp.hpp.
  • ChannelEngineI2sEsp32Dev::getCapabilities() returns Capabilities(true, true) — clockless AND SPI on the same engine per the parallel-IO unified rule. Both BusSupports<Bus::FLEX_IO, ClocklessChipset, 0> and BusSupports<Bus::FLEX_IO, SpiChipsetConfig, 0> specialize to fl::true_type.
  • Mode switch works at show-time (canHandle() accepts both, show() reconfigures FIFO width / clock rate as needed).
  • BusTraits<Bus::FLEX_IO, 0> on classic ESP32 resolves to ChannelEngineI2sEsp32Dev in the clockless+SPI unified-engine slot per the parallel-IO rule.
  • WROOM bench: bash autoresearch --flex-io on classic-ESP32 build drives 4+ parallel WS2812B strips (clockless) AND drives a clocked APA102/SK9822 strip (SPI mode) in the same run, both with byte-exact RX loopback (via rmt_rx_4 capture for clockless, wire capture for SPI).
  • bash test --cpp — all host tests green.
  • Legacy -DFASTLED_ESP32_I2S=1 path retained ONLY during rollout (Phase 2a-2d landings + WROOM bench validation). At Phase 2e the flag is removed and Yves files are deleted.
  • Yves i2s_esp32dev.{h,cpp.hpp} + clockless_i2s_esp32.{h,cpp.hpp} files DELETED from tree at Phase 2e.
  • drivers/i2s_spi/ DELETED at Phase 2e.
  • -DFASTLED_ESP32_I2S flag REMOVED — the deprecation #warning in src/FastLED.h (from docs+fix: Bus::FLEX_IO runtime-selection guardrail + restore Yves opt-in #3519) is deleted; the modern engine on Bus::FLEX_IO, 0 is the only path.

Non-goals

  • Not touching PARLIO / LCD_CAM / FlexIO / ObjectFLED / LPUART. Their wave8/wave3 encoders stay as-is.
  • Not rewriting the Yves driver in place — the new engine is a fresh implementation.
  • Not keeping the Yves driver as a compat shim after Phase 2e. Delete it.

Blockers

  • WROOM COM11 hardware for bench validation.
  • Requires a design pass on whether wave8_encoder_i2s1 shares the S3 LCD_CAM wave8_encoder_i2s implementation or is a sibling. Bit-lane layout differences may force separate impls.

Activity

  1. added
    type: feature
    priority: high
    platform: esp32
    area: drivers
    on Jul 1, 2026
  2. 7 remaining items

  3. zackees commented on Jul 1, 2026

    @zackees
    MemberAuthor

    Status update (2026-07-01, after #3557)

    ✅ Completed acceptance criteria

    ⏳ Remaining

    • Phase 2b step C: GPIO mux routing — 16 lane pins → I2S1 DATA_OUT signals via gpio_matrix_out. Requires engine-side configureTiming() / per-channel GPIO plumbing so pin mapping arrives with the ChannelData batch. Small but needs bench loopback capture (RMT4 RX or scope) to verify signal integrity.
    • Phase 2b step D: streaming DMA descriptor ring — current impl is single-descriptor (4092-byte limit ≈ 10 LEDs/strip at wave8). Real deployments need a 2+-descriptor ring with ISR-driven refill. Yves proves the pattern (NUM_DMA_BUFFERS, qe.stqe_next chain).
    • Phase 2d: BusTraits<Bus::FLEX_IO, 0> swap — blocked on steps C+D. When modern claims I2S1 at init, the existing SPI delegate (createI2sSpiEngine) would race for the same peripheral. Needs a clean handoff design (SPI delegate skips its own peripheral init if modern already owns it, or SPI is folded into the modern engine outright).
    • Phase 2e: delete Yves + drivers/i2s_spi/ — blocked on Phase 2d completing cleanly. Includes removing the FASTLED_ESP32_I2S deprecation warning in src/FastLED.h.
    • WROOM bench validation matrix — 4+ parallel WS2812B strips clockless + APA102 SPI in same run, byte-exact RX loopback via rmt_rx_4 for clockless / wire capture for SPI.

    Each remaining phase is a dedicated PR with real scope. Foundation is now clean — no Yves entanglement — so follow-up work builds directly on the modern peripheral impl.

  4. zackees commented on Jul 1, 2026

    @zackees
    MemberAuthor

    Status update (2026-07-01, after #3559)

    ✅ Completed acceptance criteria

    Every merge bench-verified: device boots, RPC ping returns pong, success: True, uptimeMs: 2066.

    ⏳ Remaining

    • Phase 2b step D: streaming DMA descriptor ring — current impl is single-descriptor (4092-byte limit ≈ 10 LEDs/strip at wave8). Real deployments need a 2+-descriptor ring with ISR-driven refill.
    • Phase 2e: delete Yves + drivers/i2s_spi/ — Yves side is a straightforward file deletion + removing the FASTLED_ESP32_I2S deprecation warning in src/FastLED.h. drivers/i2s_spi/ deletion is blocked on folding I2S_SPI's transmit logic INLINE into the modern engine's SPI branch (currently the modern engine still delegates via createI2sSpiEngine()).
    • WROOM bench validation matrix — 4+ parallel WS2812B strips clockless + APA102 SPI in same run, byte-exact RX loopback.

    Supporting infra this session

    Foundation is now clean — no Yves entanglement in the modern peripheral impl — so the remaining Phase 2b step D and Phase 2e work builds directly on top.

  5. zackees commented on Jul 1, 2026

    @zackees
    MemberAuthor

    Phase completion snapshot (after #3564)

    ✅ COMPLETE

    🟡 Remaining follow-ups (not blockers on the driver-complete condition)

    Supporting infra this session

    Session totals

    9 PRs merged, ~1287 lines of Yves code retired, foundation clean for the remaining stream/loopback work.

  6. added a commit that references this issue on Jul 1, 2026
  7. zackees commented on Jul 2, 2026

    @zackees
    MemberAuthor

    🎯 Live bench verification of Phase 2d slot swap

    Direct RPC query to a running ESP32-WROOM after PR #3564 landed:

    Request: {"method":"flexIoDeviceInfo","params":[{}],"id":42}

    Response:

    {
      "id": 42,
      "result": {
        "bus": "FLEX_IO",
        "silicon": "ESP32",
        "success": true,
        "instance": 0,
        "driverName": "I2S",
        "idfVersion": "5.5.2",
        "supportedByBuild": true,
        "registeredDriverNames": [
          "I2S",
          "RMT",
          "SPI",
          "BIT_BANG",
          "UART"
        ]
      },
      "jsonrpc": "2.0"
    }

    What this proves:

    • driverName: "I2S" — the modern ChannelEngineI2sEsp32Dev engine (its getName() returns "I2S") is bound to Bus::FLEX_IO, 0. Before Phase 2d (feat(i2s): Phase 2d slot swap — BusTraits<FLEX_IO, 0> → modern unified engine (#3526) #3559) this reported "I2S_SPI" — the slot swap is live on real hardware.
    • silicon: "ESP32" — classic ESP32-WROOM (FL_IS_ESP_32DEV), not S3/P4/C-series.
    • idfVersion: "5.5.2" — real ESP-IDF 5.5.2 runtime.
    • bus: "FLEX_IO", instance: 0 — correct slot binding.
    • supportedByBuild: true — the feature-flag guard FASTLED_ESP32_HAS_I2S compiles clean and registers.
    • registeredDriverNames: ["I2S", ...] — the modern engine is registered FIRST (highest priority) in the channel-manager driver list.

    IDF 5 branch of #3515 Phase D confirmed working (partial — this validates the runtime binding + boot + RPC responsiveness, not the byte-exact WS2812 loopback which still needs physical LEDs).

    IDF 4 + IDF 6 branches: the CI workflows exist (build_esp32dev_idf6.yml, prior-session boards.py entries), compile clean on both, but need dedicated bench runs to close out this row of the acceptance matrix.

    Remaining bench: wire an actual 4-strip WS2812B jumper harness with an rmt_rx_4 capture channel — that's the true byte-exact loopback validation the meta specs. Software-side everything else in the acceptance list is closed.

  8. zackees commented on Jul 2, 2026

    @zackees
    MemberAuthor

    Final session status — wave8 wired end-to-end, register-config debug remaining

    PR #3566 just merged (11th PR in the #3526 series this session). Closes the wave8-encoding gap that live bench (#3515) exposed:

    • packScratchBuffer() now runs encodeChannelWave8_i2s1() (PARLIO pattern)
    • Engine calls peripheral->routeLanePin(lane_idx, data->getPin()) for every active channel before transmit
    • Fixed peripheral config clock rate to 8 MHz (matches wave8 output rate)
    • Host tests updated with byte-exact wave8 output check via direct kernel-call reference

    Bench state after 11 PRs

    Live-hardware run on ESP32-WROOM COM11 via runSingleTest RPC with driver: "I2S", laneSizes: [10], pattern: "ALL_ONES":

    Check Result
    Modern engine bound at runtime (driverName: "I2S") ✅
    RPC infrastructure reaches engine ✅
    success: true from test dispatcher ✅
    Device stays alive after FastLED.show() ✅ (uptime keeps ticking)
    Wave8 encoder produces correct output size ✅ (host test byte-exact)
    Route pins assigned to I2S1 DATA_OUT signals ✅ (routeLanePin called for every lane)
    Physical wire edges captured by RMT RX loopback ❌ captureFailed: true, rawEdgesAfterWait: 0

    Where the real gap is now

    Every software wiring layer is now in place and unit-test-verified. The bench evidence tells us the DMA-config-to-wire path itself has a register-level bug. Candidates for next-session debug (all inside I2sPeripheralEsp32DevEsp::initialize()):

    • tx_bits_mod = 32 (32-bit sample width) may not match wave8's byte-major output layout
    • fifo_conf.tx_fifo_mod = 3 (32-bit-single-channel) may be wrong for parallel-out lane mode
    • conf.tx_mono = 0 + conf_chan.tx_chan_mod = 1 interaction — the mono-mode-with-right-first pattern from Yves was proven correct for his encoder, may not carry over cleanly
    • clkm_conf.clka_en = 0 — no clock output — may be needed for parallel-out mode
    • Missing FIFO priming? Yves may have pre-loaded the FIFO before setting tx_start

    This isn't code review — it's register-level ESP32 hardware validation that would benefit from a scope on the target GPIO pin during a transmit attempt. Software-only debug will hit a wall.

    Sub-issue closure status

    Session totals

    The remaining bench-blocker (register-config emit) is real hardware debugging that no amount of code churn in an agent session can close. Documented here for the next session's benchmark run.

  9. zackees commented on Jul 2, 2026

    @zackees
    MemberAuthor

    Filed #3568 documenting the register-config bug that produces zero wire edges from the wave8-encoded output. #3568 has scope-verifiable candidate fixes and is the acceptance path for the remaining physical validation.

  10. zackees commented on Aug 20, 2026

    @zackees
    MemberAuthor

    Deferred under the active bug-burn-down policy. The core modern I2S engine is substantially shipped, but the issue's full acceptance still combines architecture cleanup with a physical dual-mode bench campaign.

    Shipped:

    Unmet acceptance:

    • src/platforms/esp/32/drivers/i2s_spi/ still exists; SPI remains a delegated implementation rather than fully folded into the modern engine.
    • There is no preserved same-run 4+ lane WS2812 plus real APA102/SK9822 byte-exact bench result.
    • Full host suite evidence is not a substitute for those driver-wire checks.
    • No selectable classic WROOM is attached now; the current healthy ESP target is C6 COM9.

    Completing the remainder means designing/landing a non-delegating SPI path and running the physical mixed-mode bench. That is a separate hardware-backed multi-PR effort, not a safe cleanup-only patch.

    Restart criteria:

    1. Attach classic ESP32-WROOM, 4+ clockless lanes, an APA102/SK9822 strip, and RX capture.
    2. Split inline SPI ownership/delegation removal from physical mixed-mode validation.
    3. Delete drivers/i2s_spi/ only after the inline path has byte-exact host tests and a real strip/wire pass.
    4. Preserve clockless + SPI mode-switch evidence in the same firmware run.
    5. Remove deferred when the bench and implementation owner are available.

    The issue remains open and is excluded from the actionable queue while labeled deferred.

  11. added
    deferred
    on Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: driversdeferredplatform: esp32priority: hightype: feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions