Skip to content

feat(i2s): unified engine SPI path via delegate (#3526 Phase 2c) - #3544

Merged
zackees merged 1 commit into
masterfrom
feat/i2s-phase2c-spi-3526
Jul 1, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/i2s-phase2c-spi-3526

Conversation

@zackees

@zackees zackees commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

ChannelEngineI2sEsp32Dev::show() now handles SPI batches by delegating to the tested ChannelDriverI2sSpi. Mixed batches still rejected (peripheral is single-mode). poll() surfaces delegate's DRAINING/READY/ERROR states correctly. Bench: flashed clean on WROOM.

Summary by CodeRabbit

  • New Features

    • Added support for SPI batch handling on the ESP32 I2S channel engine.
    • SPI batches can now be delegated to a dedicated SPI path when available.
  • Bug Fixes

    • Improved state handling for SPI-driven output, including correct transitions during busy, draining, and error conditions.
    • Prevents the legacy I2S path from running while SPI delegation is active.
  • Tests

    • Updated coverage to verify SPI delegation behavior and mixed-batch handling.

`ChannelEngineI2sEsp32Dev::show()` now handles SPI batches — forwards
to the tested `ChannelDriverI2sSpi` via `createI2sSpiEngine()` factory
(lazy-initialised on first SPI batch so pure-clockless builds don't
link the delegate). Same I2S1 peripheral, same one-slot binding — the
modern engine is the entry point, the delegate owns the transmit
lifecycle.

## Behavior matrix (updated)

| Batch composition          | Result                                    |
|---------------------------|-------------------------------------------|
| All clockless (existing)  | Wave8 encoding → peripheral transmit ✅   |
| All SPI                   | Delegate to ChannelDriverI2sSpi ✅        |
| Mixed clockless + SPI     | ERROR (peripheral is single-mode)         |

## poll() surfaces delegate state

Delegate's `poll()` return is surfaced up:
- READY → drop to READY, release channels
- DRAINING → engine reports DRAINING (per Channel Engine DMA Wait Pattern in `agents/docs/cpp-standards.md`)
- ERROR → drop to ERROR, release channels
- BUSY → stay in current state

## Verification

- `bash test --cpp`: 345/345 pass (2 existing Phase 2c tests updated
  to allow BUSY or ERROR from SPI path — invariant is that the
  clockless peripheral is untouched by SPI batches).
- `bash lint --cpp`: clean.
- Bench: flashed to attached WROOM COM11, boot clean, ping successful.
  `flexIoDeviceInfo` reports `I2S_SPI` at `Bus::FLEX_IO, 0` (unchanged
  — the modern engine only receives channels via
  `setExclusiveDriver<>()` for the specific engine name; slot 0 stays
  with the existing driver until Phase 2d swaps it).

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

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 3387877 into master Jul 1, 2026
11 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: 935efc5e-df1e-4542-befb-8e366a4d92db

📥 Commits

Reviewing files that changed from the base of the PR and between 035c43e and 2f88b3b.

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

📝 Walkthrough

Walkthrough

ChannelEngineI2sEsp32Dev now delegates homogeneous SPI-only channel batches to a lazily-created ChannelDriverI2sSpi instance (mSpiDelegate) instead of rejecting SPI mode as an unimplemented stub. show() forwards SPI channels to the delegate and sets BUSY, or falls back to ERROR if unavailable. poll() maps delegate states (READY/DRAINING/ERROR) to engine states. Tests updated accordingly.

Changes

I2S-SPI Delegate Integration

Layer / File(s) Summary
Delegate member and header wiring
src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.h, src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp.hpp
Adds mSpiDelegate (fl::shared_ptr<IChannelDriver>) member with documentation, and conditionally includes the I2S-SPI delegate driver header under FASTLED_ESP32_HAS_I2S.
show() SPI batch dispatch
src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp.hpp
Replaces the stubbed SPI rejection with logic that lazily creates the delegate, enqueues SPI channels, calls delegate show(), and sets BUSY; falls back to releasing in-use marks and ERROR when the delegate is unavailable or unsupported.
poll() delegate state mapping
src/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp.hpp
Adds delegate-driven completion handling that polls mSpiDelegate when active and maps its READY/DRAINING/ERROR states to the engine's state, bypassing legacy peripheral completion checks.
Test updates for SPI delegation
tests/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp
Replaces the "stub rejected" pure-SPI test with a delegate-path test expecting BUSY or ERROR and zero clockless transmits; adjusts mixed clockless+SPI batch test assertions.

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

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3473: Introduces the original ChannelEngineI2sEsp32Dev stage that this PR extends with the mSpiDelegate delegation path.
  • FastLED/FastLED#3534: Modifies the same show() SPI rejection scaffolding that this PR replaces with delegate-based dispatch.
  • FastLED/FastLED#3536: Touches the same Phase 2c SPI batch dispatch code and tests in show().
✨ 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-phase2c-spi-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.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jul 1, 2026
zackees added a commit that referenced this pull request Jul 1, 2026
…3526) (#3545)

Replaces the if/else chain in `ChannelEngineI2sEsp32Dev::poll()`'s
SPI-delegate handling with an explicit `switch` over
`DriverState::Value`. Compiler now enforces coverage — if a new
DriverState enum value gets added, the missing case is a warning /
error at build time rather than a silent unhandled state.

Same behavior as the if/else version: READY / DRAINING / ERROR
surface up to callers with the appropriate cleanup; BUSY stays in
the current state.

Follow-up to #3544.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jul 1, 2026
@zackees
zackees deleted the feat/i2s-phase2c-spi-3526 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