Skip to content

feat(i2s): engine mode-dispatch scaffolding for SPI batches (#3526 Phase 2c prep) - #3534

Merged
zackees merged 1 commit into
masterfrom
feat/i2s-engine-spi-dispatch-3526-2c
Jul 1, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/i2s-engine-spi-dispatch-3526-2c

Conversation

@zackees

@zackees zackees commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds per-channel mode dispatch in ChannelEngineI2sEsp32Dev::show() so mixed clockless+SPI batches and pure-SPI batches are refused cleanly with DriverState::ERROR instead of silently sending garbage.

Sets up Phase 2c architecture: peripheral is the dispatch boundary (parallel-IO unified-engine rule), and I2S1 can only run one mode at a time.

Once the real SPI transmit machinery lands (Phase 2c-SPI PR, bench-blocked), the two ERROR early-outs become full showSpi() calls with no other engine changes needed.

Behavior matrix

Batch Result
All clockless (existing) Wave8 encoding → peripheral transmit ✅
All SPI ERROR state (Phase 2c-SPI stub)
Mixed clockless + SPI ERROR state (mixed batches never allowed)

Test plan

  • bash test --cpp: 345/345 pass (3 new subcases inside existing test)
  • bash lint --cpp: clean
  • All 4 existing engine tests still pass — clockless path bit-identical

Part of #3516 meta / #3526 Phase 2c prep.

Summary by CodeRabbit

  • Bug Fixes

    • Improved transmit setup handling for mixed channel batches, with clearer rejection of unsupported combinations.
    • Unsupported SPI-related batch states now fail safely, leaving the engine in an error state and releasing channels properly.
    • Clockless-only batches continue to transmit normally.
  • Tests

    • Added coverage for valid clockless batches and rejected SPI-only and mixed batches to verify correct engine behavior.

…ase 2c prep)

Adds per-channel mode dispatch in `ChannelEngineI2sEsp32Dev::show()`
so mixed clockless+SPI batches and pure-SPI batches are refused
cleanly with `DriverState::ERROR` instead of silently sending garbage
through the clockless wave8 encoder.

Sets up the Phase 2c architecture: the peripheral is the dispatch
boundary (per the parallel-IO unified-engine rule in
`agents/docs/cpp-standards.md`), and I2S1 can only run one mode at a
time. The engine now recognizes each channel's mode and routes
accordingly.

## Behavior matrix

| Batch composition          | Result                                    |
|---------------------------|-------------------------------------------|
| All clockless (existing)  | Wave8 encoding → peripheral transmit ✅   |
| All SPI                   | ERROR state (Phase 2c-SPI stub)           |
| Mixed clockless + SPI     | ERROR state (mixed batches never allowed) |

The SPI-path stub is deliberate: the actual SPI transmit machinery
(FIFO width reconfigure, DMA slot, clock rate) is bench-blocked
because it needs WROOM validation. Once the Phase 2c-SPI PR lands
with real transmit code, only the two ERROR-returning early-outs
change to full `showSpi()` calls.

Clockless behavior is preserved bit-identical — all 4 existing
engine tests still pass unchanged.

## Test additions

3 new `FL_TEST_CASE`s in `channel_engine_i2s_esp32dev.cpp`:
- Pure clockless batch still succeeds (regression protection)
- Pure SPI batch rejected with ERROR + no peripheral transmit
- Mixed batch rejected with ERROR + no peripheral transmit + both
  channels released from in-use marking

New test helper `makeSpiChannelData(dataPin, clockPin, byte_count,
fill_byte)` produces a channel with `SpiChipsetConfig` so the mode
dispatch has real SPI channels to reject.

## What this does NOT do

- Does NOT implement `showSpi()` — that's the real Phase 2c PR
  (bench-blocked).
- Does NOT change the current clockless code path — pure clockless
  batches take the exact same wave8 encoding + peripheral transmit
  they did before.

## Verification

- `bash test --cpp`: 345/345 pass (3 new subcases inside existing test file)
- `bash lint --cpp`: clean

Part of #3516 meta / #3526 Phase 2c prep.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 3eff694 into master Jul 1, 2026
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: f586206a-7a0b-44a6-b841-ae6b79f6d4e4

📥 Commits

Reviewing files that changed from the base of the PR and between f83569a and 8bee239.

📒 Files selected for processing (2)
  • src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp.hpp
  • tests/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp

📝 Walkthrough

Walkthrough

Adds a dispatch check in ChannelEngineI2sEsp32Dev::show() that inspects the in-flight channel batch for clockless and SPI channels, rejecting mixed or SPI-only batches with an error state, and adds tests verifying clockless-only success versus SPI/mixed rejection.

Changes

Dispatch gate and tests

Layer / File(s) Summary
Dispatch gate in show()
src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp.hpp
Before scratch-buffer packing, scans mInFlightChannels for clockless/SPI presence, rejects mixed and SPI-only batches by clearing in-use marks, emptying the batch, and setting DriverState::ERROR; clockless-only batches proceed unchanged.
Test scaffolding and dispatch tests
tests/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp
Adds fl/channels/config.h include, a makeSpiChannelData(...) helper building APA102-encoded SPI channel data, and tests confirming clockless-only batches succeed while pure SPI and mixed batches hit the error path without peripheral transmit.

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

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3430: Introduces the unified clockless+SPI engine architecture that this dispatch check enforces.
  • FastLED/FastLED#3473: Provides the ChannelEngineI2sEsp32Dev implementation and test scaffolding that this PR extends.
✨ 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-engine-spi-dispatch-3526-2c

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: Triage

Development

Successfully merging this pull request may close these issues.

1 participant