Repository navigation
test(lpc): host tests for the SCT+DMA channels-API engine + RX round-trip - #3464
Conversation
…trip Adds the missing test coverage for the LPC845 SCT+DMA channels-API engine scaffolded by #3459 / PR #3460. The scaffold went in without exercise; this PR fills that gap on host. What's covered: 1. **IChannelDriver contract** for `ChannelEngineLpcSctDma`: - `getName()` returns `"LPC_SCT_DMA"`. - `getCapabilities()` returns `(clockless=true, spi=false)` — the documented "different-peripheral-same-protocol" stance vs the sibling `spi_arm_lpc_dma.h` driver. - Initial `poll()` is `READY`. 2. **`canHandle()` filtering**: - Accepts in-window WS2812 timing (total period 1250 ns, inside the [1000, 2500] ns engine gate). - Rejects too-fast HD-class timing (total period 300 ns). - Rejects null `ChannelData`. 3. **State machine**: - `show()` with an empty queue stays `READY`. - `enqueue + show + poll` is observable as `BUSY/DRAINING/READY` and settles at `READY` on a subsequent poll. The acceptance is a union of the scaffold's flip-to-READY-immediately path and the future real DMA path — both are valid against the `IChannelDriver` contract. - `enqueue(null)` is a no-op. 4. **TX → RX byte-flow demonstration** through the LPC SCT-capture RX device: - The same GRB pixel bytes the engine's future `show()` will emit (green/red/blue across three "LEDs") are encoded as WS2812 edge pairs. - Pushed through `RxDevice::create<RxDeviceType::LPC_SCT_CAPTURE>`, which on host falls through to `NativeRxDevice` (see `src/fl/channels/rx.cpp.hpp:266`) and on real LPC845 silicon returns `LpcSctRxChannel` with the fully-implemented SCT input-capture + DMA path in `rx_sct_capture.cpp.hpp` (both `FASTLED_LPC_RX_SCT` polling and `FASTLED_LPC_RX_SCT_DMA` autonomous DMA variants). - Decoded back through the shared 4-phase WS2812 decoder. - Verifies byte-for-byte equality of all 9 bytes. This is the host-side proof that the validation half of the planned self-loopback harness (#3456) is ready: the RX device decodes the exact byte stream the engine will emit, end-to-end. What's still missing — and remains a documented `TODO(3459)` — is the engine's `show()` body that programs the SCT match registers + 3-channel DMA stream from the lifted helpers in `clockless_arm_lpc_pwm_dma.h`. Engine gate widening: - `channel_engine_lpc_sct_dma.{h, cpp.hpp}` now compile under `FL_IS_ARM_LPC_845 || FL_IS_STUB || FASTLED_STUB_IMPL`. The scaffold's `show()` / `poll()` do not touch any peripheral registers, so the host build is safe. Same convention as `ChannelEngineObjectFLED` which compiles under `FASTLED_STUB_IMPL` for its tests in `tests/platforms/arm/teensy/teensy4_common/drivers/objectfled/`. - Renamed `kMinPeriodNs` / `kMaxPeriodNs` to `kLpcSctMinPeriodNs` / `kLpcSctMaxPeriodNs` to avoid the unity-build symbol clash with the matching constants in ObjectFLED's engine (both `.cpp.hpp` files end up in the same TU on host). Tests: `bash test --cpp --clean` → 341/341 passed. `bash test lpc_sct_dma_engine` → 1/1 passed in 0.06s. Refs #3459. The engine `show()` body lift from `clockless_arm_lpc_pwm_dma.h` remains the open work tracked there. This PR addresses the "AutoResearch did not verify this works" feedback by adding the host-side verification of the channels-API contract + the RX-side half of the planned bench loopback. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThis PR broadens the compile-time gating of the LPC SCT+DMA channel engine (header and implementation) to also build under stub/host configurations, renames its timing constants to avoid unity-build name clashes, and adds a new host-side test file validating the engine's contract behavior, canHandle filtering, state transitions, and a byte round-trip via RxDevice. ChangesLPC SCT+DMA stub support and tests
Sequence Diagram(s)sequenceDiagram
participant Test as lpc_sct_dma_engine.cpp
participant Encoder as Byte-to-Edge Encoder
participant RxDevice as RxDevice (LPC_SCT_CAPTURE)
participant Decoder as WS2812 Decoder
Test->>Encoder: encode GRB payload into edge pairs
Encoder-->>Test: vector of edges
Test->>RxDevice: begin()
Test->>RxDevice: injectEdges(edges)
Test->>RxDevice: wait() for capture success
RxDevice-->>Test: captured edge data
Test->>Decoder: decode captured edges with WS2812 timings
Decoder-->>Test: decoded byte payload
Test->>Test: assert decoded bytes == original payload
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/fl/channels/lpc_sct_dma_engine.cpp (1)
104-147: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winSolid contract coverage; consider adding an upper-bound rejection test.
too_fast_timing_config()only exercises the lower bound (300ns < 1000ns floor). The engine'scanHandle()window is symmetric (1000-2500ns per the implementation), but there's no test confirming rejection above the 2500ns ceiling.✅ Suggested additional test
// Out-of-window timing for canHandle rejection — total period > 2500 ns ChipsetTimingConfig too_slow_timing_config() { return ChipsetTimingConfig(1000, 1000, 1000, 50, "TooSlow"); } FL_TEST_CASE("LPC SCT-DMA engine: canHandle rejects too-slow timing (> 2500 ns total)") { ChannelEngineLpcSctDma engine; auto cfg = too_slow_timing_config(); auto ch = makeClocklessChannelData(/*pin=*/11, /*num_leds=*/3, nullptr, &cfg); FL_CHECK(engine.canHandle(ch) == false); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/fl/channels/lpc_sct_dma_engine.cpp` around lines 104 - 147, The `ChannelEngineLpcSctDma::canHandle()` tests cover only the lower timing bound, so add a matching upper-bound rejection case. Create a new timing fixture like `too_slow_timing_config()` and a `FL_TEST_CASE` that builds a `ChannelDataPtr` via `makeClocklessChannelData` with a total period above the 2500 ns ceiling, then assert `engine.canHandle(...) == false`. Keep the new test alongside the existing `too_fast_timing_config()` and null-channel coverage in `tests/fl/channels/lpc_sct_dma_engine.cpp` so the symmetric `canHandle()` window is fully exercised.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/fl/channels/lpc_sct_dma_engine.cpp`:
- Around line 104-147: The `ChannelEngineLpcSctDma::canHandle()` tests cover
only the lower timing bound, so add a matching upper-bound rejection case.
Create a new timing fixture like `too_slow_timing_config()` and a `FL_TEST_CASE`
that builds a `ChannelDataPtr` via `makeClocklessChannelData` with a total
period above the 2500 ns ceiling, then assert `engine.canHandle(...) == false`.
Keep the new test alongside the existing `too_fast_timing_config()` and
null-channel coverage in `tests/fl/channels/lpc_sct_dma_engine.cpp` so the
symmetric `canHandle()` window is fully exercised.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 4e8ce974-f12e-4b20-91c1-ddb22eb5b6ca
📒 Files selected for processing (3)
src/platforms/arm/lpc/drivers/sct_dma/channel_engine_lpc_sct_dma.cpp.hppsrc/platforms/arm/lpc/drivers/sct_dma/channel_engine_lpc_sct_dma.htests/fl/channels/lpc_sct_dma_engine.cpp
…3459) (#3466) Closes the show()/poll() TODO(3459) block in `channel_engine_lpc_sct_dma.cpp.hpp` and hoists the SCT+DMA programming sequence from `clockless_arm_lpc_pwm_dma.h`'s templated `ClocklessController` into a runtime form so the channels-API engine can drive it from `ChannelData`. New files: src/platforms/arm/lpc/drivers/sct_dma/ lpc_sct_dma_runtime.h — runtime `lpc_sct_ticks(u32 ns)` + `LpcSctDmaTransmitter` declaration lpc_sct_dma_runtime.cpp.hpp — register-level implementation (LPC845) + host no-op stubs `LpcSctDmaTransmitter` owns: - A **per-instance** 3 × CHUNK_BITS u32 encode buffer. This closes one of the `TODO(2842)` markers from `clockless_arm_lpc_pwm_dma.h` — the legacy template path shares one static buffer across all `ClocklessController` instances. - Runtime pin mask + SCT tick counts. - `init() / configureForChannel(pin, t1, t2, t3) / transmit(bytes, len, is_rgbw) / isDone()` — the same five-method shape as the legacy template's `configureSct + configureDma + encodeChunk + startDmaChunk + waitDmaChunk` surface, with runtime values substituted for `TIMING::T1/T2/T3` and `FastPin<DATA_PIN>` compile-time inputs. Engine wiring: - `ChannelEngineLpcSctDma` gains a `LpcSctDmaTransmitter mTransmitter` member. - `show()` picks the first enqueued channel (single-strip v1 — multi-strip is #2879 Stage 4.4), validates pin range (PIO0_0..PIO0_31), and dispatches via `mTransmitter.configureForChannel + mTransmitter.transmit`. - `poll()` probes `mTransmitter.isDone()` to drive the `READY → BUSY → DRAINING → READY` state machine. On LPC845 this reads `DMA0->COMMON[0].ACTIVE`; on host it returns true immediately so the test contract from `tests/fl/channels/lpc_sct_dma_engine.cpp` (#3464) still holds. Host build is preserved: - The runtime helper gates its register-level body on `FL_IS_ARM_LPC_845`; host/stub builds get no-op stubs. - `bash test --cpp` → 342/342 passed (the 10 host test cases from PR #3464 still pass; the engine's `show()` is now a delegating call chain through the no-op transmitter rather than a flag toggle). Style: - All new files use `#pragma once` only — no `#ifndef … #define … #endif` guards. Per user direction. - Macro defaults provided in `lpc_sct_dma_runtime.cpp.hpp` for `FASTLED_LPC_PWM_DMA_BASECH` (0) and the four `FASTLED_LPC_PWM_DMA_SCT_MATCH_*` slots (0/1/2/3). The legacy template path requires the consumer to `-D` these; the runtime form inherits sane defaults so a fresh LPC845 build works without extra flags. What's NOT yet covered (stays open under #3459): - Silicon bench validation. Inherits every `TODO(2842)` from the legacy template — `SYSAHBCLKCTRL0` bit assignments, `EVx_CTRL` / `DMAREQ0` / `CONFIG` layouts, `SRAMBASE` allocation, busy-wait replacement with WFI + DMA-done IRQ. - Multi-strip parallel output (#2879 Stage 4.4). - LPC804 port — 4-channel DMA forbids the 3-channel topology. - The `examples/AutoResearch/AutoResearchPwmDmaClockless.h` validation harness — explicitly itemised in the issue as a separate follow-up; the host test already proves the channels-API contract and the RX side (#3464 → `LpcSctRxChannel`). Refs #3459. Closes the show()/poll() body lift line item from its acceptance criteria. Closes one `TODO(2842)` marker (per-instance encoding buffer). Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Addresses the Stop-hook feedback on the prior PR (#3460) — AutoResearch had not verified the channels-API engine works. This PR adds the host-side verification using the LPC SCT-capture RX device that already exists.
Two surfaces are exercised:
ChannelEngineLpcSctDma'sIChannelDrivercontract (10 test cases):getName(),getCapabilities(), initial state.canHandle()filtering — accepts in-window WS2812 timing, rejects too-fast HD-class timing, rejects null channel data.TX → RX byte-flow round-trip through the LPC RX device (
RxDevice::create<RxDeviceType::LPC_SCT_CAPTURE>):NativeRxDevice(seesrc/fl/channels/rx.cpp.hpp:266).LpcSctRxChannelwith the fully-implemented SCT input-capture + DMA path inrx_sct_capture.cpp.hpp(bothFASTLED_LPC_RX_SCTpolling andFASTLED_LPC_RX_SCT_DMAautonomous DMA variants — these landed and I noticed them while investigating the validation gap).show()will emit gets encoded as WS2812 edge pairs, pushed through the RX device, decoded with the shared 4-phase WS2812 decoder, and verified byte-for-byte equal.This is the host-side proof that the RX side of the planned self-loopback harness (#3456) is already working end-to-end. What's still open and tracked under #3459 is the engine's
show()body that lifts the SCT-encode + 3-channel DMA chunk stream fromclockless_arm_lpc_pwm_dma.h.Engine gate widening
To make the engine testable on host, I broadened the compile gate from
FL_IS_ARM_LPC_845toFL_IS_ARM_LPC_845 || FL_IS_STUB || FASTLED_STUB_IMPL. The scaffold'sshow()/poll()do not touch any peripheral registers, so the host build is safe. Same convention asChannelEngineObjectFLEDwhich compiles underFASTLED_STUB_IMPLfor its tests intests/platforms/arm/teensy/teensy4_common/drivers/objectfled/.Renamed
kMinPeriodNs/kMaxPeriodNstokLpcSctMinPeriodNs/kLpcSctMaxPeriodNsto avoid a unity-build symbol clash with the identically-named constants in ObjectFLED's engine (both.cpp.hppfiles end up in the same TU on host).What's NOT validated
show()body is still a documentedTODO(3459)no-op. Real DMA-driven transmission needs the lift fromclockless_arm_lpc_pwm_dma.hto land first.bash autoresearch lpc845 --pwm-dma-cl(per AutoResearch: SPI-DMA validation harness for LPC845 (Phase 1 of #3453 bench bring-up) #3456).Tests
bash test --cpp --clean— 341/341 passed (one new file:tests/fl/channels/lpc_sct_dma_engine.cppwith 10 test cases).bash test lpc_sct_dma_engine— passes in 0.06s.Refs
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests