Skip to content

feat(i2s): streaming buffer-refill callback interface + mock impl + host tests (#3526 Phase 2b prep) - #3531

Merged
zackees merged 1 commit into
masterfrom
feat/i2s-refill-callback-interface-3526
Jul 1, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/i2s-refill-callback-interface-3526

Conversation

@zackees

@zackees zackees commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds the streaming buffer-refill callback API surface that #3526 Phase 2b (real DMA/ISR) will fill in. Ships the interface + mock impl + host tests now so:

  1. Phase 2b (bench work) has a stable, host-tested API surface to build against.
  2. The engine can be structurally exercised end-to-end on host today (transmit → refill × N → done) via mock.simulateBufferRefill(), matching how simulateTransmitDone() lets the engine test the done-signal path.

API additions

ii2s_peripheral_esp32dev.h

  • New callback type I2sEsp32DevBufferRefillCallback — void(*)(int buffer_index, bool *done, void *user_ctx). Fired per DMA-EOF interrupt. Caller sets *done = true to stop.
  • New virtual registerBufferRefillCallback(cb, user_ctx). Default returns false — impls that don't support streaming refill can leave it alone.

i2s_peripheral_esp32dev_mock.{h,cpp.hpp}

  • Real registerBufferRefillCallback impl.
  • New simulateBufferRefill(buffer_index) test hook.
  • Introspection: bufferRefillInvocationCount(), lastRefillBufferIndex(), lastRefillDone().
  • reset() clears new state.

6 new host test cases in channel_engine_i2s_esp32dev.cpp

  • Register + fire → verify buffer_index + done reporting
  • Cadence across ring with caller-driven stop
  • nullptr callback + fire is no-op
  • Register nullptr clears
  • setRegisterCallbackFailure knob respected
  • Coexistence with transmit-done callback

What this does NOT do

  • Does NOT implement the real DMA-EOF ISR in I2sPeripheralEsp32DevEsp — that's Phase 2b proper (WROOM bench required). Real impl inherits the default return false.
  • Does NOT touch Yves classic driver.

Test plan

  • bash test --cpp: 345/345 pass
  • bash lint --cpp: clean modulo 2 pre-existing violations in src/fl/remote/rpc/type_to_json.h (unrelated)

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

Summary by CodeRabbit

  • New Features

    • Added support for ESP32 I2S buffer-refill callbacks, enabling streaming-style buffer handling.
    • Expanded mock and test support to simulate buffer refills and verify callback behavior.
  • Tests

    • Added coverage for callback invocation, callback clearing, failure handling, and interaction with transmit-done events.

…e 2b prep)

Extends the II2sPeripheralEsp32Dev peripheral interface with the
streaming buffer-refill callback surface that #3526 Phase 2b
needs when it wires the real DMA-EOF ISR into
I2sPeripheralEsp32DevEsp. Ships the API surface + mock impl + host
tests now so:

1. Phase 2b (bench work) can be written against a stable, host-tested
   interface — no design churn when someone with bench access starts.
2. The engine can be structurally exercised end-to-end on host
   (transmit → refill → refill → ... → done) via the mock's
   simulateBufferRefill(), matching how simulateTransmitDone() lets
   the engine test the done-signal path.

## API additions

### `ii2s_peripheral_esp32dev.h`
- New callback signature `I2sEsp32DevBufferRefillCallback`:
  `void(*)(int buffer_index, bool *done, void *user_ctx)`. Fired
  per DMA-EOF interrupt. Caller sets `*done = true` to stop the
  refill cadence.
- New virtual `registerBufferRefillCallback(cb, user_ctx)`. Default
  implementation returns false — impls that don't support streaming
  refill (Stage-4 stub, pure done-only impls) can leave it alone.

### `i2s_peripheral_esp32dev_mock.{h,cpp.hpp}`
- Real implementation of `registerBufferRefillCallback` — stores
  callback + user_ctx.
- New mock-only test hook `simulateBufferRefill(buffer_index)` fires
  the stored callback synchronously and records the `done` return.
- New introspection accessors: `bufferRefillInvocationCount()`,
  `lastRefillBufferIndex()`, `lastRefillDone()`.
- `reset()` clears all new state.

### `channel_engine_i2s_esp32dev.cpp` (host tests)
Six new FL_TEST_CASE covering the refill surface:
- Register + single fire, verify buffer_index + done reporting.
- Cadence across a full buffer ring, verify caller-driven stop.
- nullptr callback + fire is no-op.
- Register nullptr clears the callback.
- setRegisterCallbackFailure knob respected.
- Coexistence with the transmit-done callback (both fire independently).

## What this does NOT do

- Does NOT implement the real DMA-EOF ISR wiring in
  `I2sPeripheralEsp32DevEsp` — that's Phase 2b proper (needs WROOM
  bench). The real impl inherits the default `return false` from the
  interface until it's implemented.
- Does NOT touch the Yves classic driver — that's untouched pending
  Phase 2e deletion.

## Verification

- `bash test --cpp`: 345/345 pass (6 new test cases inside the
  existing `channel_engine_i2s_esp32dev.cpp` test file).
- `bash lint --cpp`: clean modulo 2 pre-existing NoexceptAstChecker
  violations in `src/fl/remote/rpc/type_to_json.h` (unrelated to this
  PR).

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

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees merged commit 311f51b 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: bec11487-fb57-434d-8213-4b7edd6063e4

📥 Commits

Reviewing files that changed from the base of the PR and between 98b7884 and 98806d1.

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

📝 Walkthrough

Walkthrough

This PR introduces a "buffer refill" callback API to the classic ESP32 I2S parallel-out peripheral interface, adds a corresponding mock implementation with simulation and state-inspection helpers, and adds unit tests validating registration, invocation, clearing, failure handling, and coexistence with the existing transmit-done callback.

Changes

Buffer Refill Callback API

Layer / File(s) Summary
Interface contract
src/platforms/esp/32/drivers/i2s/ii2s_peripheral_esp32dev.h
Adds I2sEsp32DevBufferRefillCallback function-pointer type and a default no-op registerBufferRefillCallback(cb, user_ctx) virtual method on II2sPeripheralEsp32Dev.
Mock implementation
src/platforms/esp/32/drivers/i2s/i2s_peripheral_esp32dev_mock.h, i2s_peripheral_esp32dev_mock.cpp.hpp
Adds override for registerBufferRefillCallback (with failure injection via mFailRegisterCallback), synchronous simulateBufferRefill(buffer_index), inspection accessors (bufferRefillInvocationCount, lastRefillBufferIndex, lastRefillDone), new private state fields, and reset() clearing of that state.
Unit tests
tests/platforms/esp/32/drivers/i2s/channel_engine_i2s_esp32dev.cpp
Adds tests for callback invocation and state tracking, no-op behavior without registration, clearing via nullptr, registration failure handling, and coexistence with the transmit-done callback.

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

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3473: Extends the same ESP32 I2S Dev peripheral interface/mock introduced in prior work by adding this refill callback plumbing alongside the existing transmit-done callback.
✨ 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-refill-callback-interface-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
@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
)

* feat(i2s): add streaming buffer-refill callback interface (#3526 Phase 2b prep)

Extends the II2sPeripheralEsp32Dev peripheral interface with the
streaming buffer-refill callback surface that #3526 Phase 2b
needs when it wires the real DMA-EOF ISR into
I2sPeripheralEsp32DevEsp. Ships the API surface + mock impl + host
tests now so:

1. Phase 2b (bench work) can be written against a stable, host-tested
   interface — no design churn when someone with bench access starts.
2. The engine can be structurally exercised end-to-end on host
   (transmit → refill → refill → ... → done) via the mock's
   simulateBufferRefill(), matching how simulateTransmitDone() lets
   the engine test the done-signal path.

## API additions

### `ii2s_peripheral_esp32dev.h`
- New callback signature `I2sEsp32DevBufferRefillCallback`:
  `void(*)(int buffer_index, bool *done, void *user_ctx)`. Fired
  per DMA-EOF interrupt. Caller sets `*done = true` to stop the
  refill cadence.
- New virtual `registerBufferRefillCallback(cb, user_ctx)`. Default
  implementation returns false — impls that don't support streaming
  refill (Stage-4 stub, pure done-only impls) can leave it alone.

### `i2s_peripheral_esp32dev_mock.{h,cpp.hpp}`
- Real implementation of `registerBufferRefillCallback` — stores
  callback + user_ctx.
- New mock-only test hook `simulateBufferRefill(buffer_index)` fires
  the stored callback synchronously and records the `done` return.
- New introspection accessors: `bufferRefillInvocationCount()`,
  `lastRefillBufferIndex()`, `lastRefillDone()`.
- `reset()` clears all new state.

### `channel_engine_i2s_esp32dev.cpp` (host tests)
Six new FL_TEST_CASE covering the refill surface:
- Register + single fire, verify buffer_index + done reporting.
- Cadence across a full buffer ring, verify caller-driven stop.
- nullptr callback + fire is no-op.
- Register nullptr clears the callback.
- setRegisterCallbackFailure knob respected.
- Coexistence with the transmit-done callback (both fire independently).

## What this does NOT do

- Does NOT implement the real DMA-EOF ISR wiring in
  `I2sPeripheralEsp32DevEsp` — that's Phase 2b proper (needs WROOM
  bench). The real impl inherits the default `return false` from the
  interface until it's implemented.
- Does NOT touch the Yves classic driver — that's untouched pending
  Phase 2e deletion.

## Verification

- `bash test --cpp`: 345/345 pass (6 new test cases inside the
  existing `channel_engine_i2s_esp32dev.cpp` test file).
- `bash lint --cpp`: clean modulo 2 pre-existing NoexceptAstChecker
  violations in `src/fl/remote/rpc/type_to_json.h` (unrelated to this
  PR).

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

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* fix(lint): add FL_NO_EXCEPT to TypeToJson<u32> / <u16> converters

Closes the two `NoexceptAstChecker` violations in
`src/fl/remote/rpc/type_to_json.h:37,46` — the `convert(...)` overrides
on `TypeToJson<fl::u32>` and `TypeToJson<fl::u16>` were missing
`FL_NO_EXCEPT`. Every other `convert(...)` specialization in the file
that goes through primitive-type paths is trivially noexcept, so
these two just needed the annotation.

Also adds the `fl/stl/noexcept.h` include since the macro wasn't
transitively available through the existing includes.

Discovered while landing #3531 (I2S refill callback interface) —
the pre-existing violations surfaced in the lint pass and were noted
as unrelated. This fixes them so the classic-ESP32 I2S umbrella
(#3516) rollup CI is fully clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the feat/i2s-refill-callback-interface-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