Skip to content

test(lpc): host tests for the SCT+DMA channels-API engine + RX round-trip - #3464

Merged
zackees merged 1 commit into
masterfrom
feat/3459-test-lpc-sct-engine
Jun 30, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/3459-test-lpc-sct-engine

Conversation

@zackees

@zackees zackees commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

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:

  1. ChannelEngineLpcSctDma's IChannelDriver contract (10 test cases):

    • getName(), getCapabilities(), initial state.
    • canHandle() filtering — accepts in-window WS2812 timing, rejects too-fast HD-class timing, rejects null channel data.
    • State-machine transitions: empty queue stays READY, enqueue+show+poll completes back to READY, null enqueue is a no-op.
  2. TX → RX byte-flow round-trip through the LPC RX device (RxDevice::create<RxDeviceType::LPC_SCT_CAPTURE>):

    • On host, falls through to NativeRxDevice (see src/fl/channels/rx.cpp.hpp:266).
    • 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 — these landed and I noticed them while investigating the validation gap).
    • The same GRB byte stream the engine's future 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 from clockless_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_845 to 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 a unity-build symbol clash with the identically-named constants in ObjectFLED's engine (both .cpp.hpp files end up in the same TU on host).

What's NOT validated

Tests

Refs

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Expanded support so the LPC SCT+DMA channel engine can be built in host/stub test environments as well as on-device.
  • Bug Fixes

    • Improved timing checks for channel handling to use the correct LPC-specific limits.
    • Added coverage for channel setup, state transitions, and timing-based acceptance/rejection rules.
  • Tests

    • Added a new host-side test suite validating driver behavior and end-to-end byte flow for WS2812-style signals.

…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]>
@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This 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.

Changes

LPC SCT+DMA stub support and tests

Layer / File(s) Summary
Stub/host build gating and renamed timing constants
src/platforms/arm/lpc/drivers/sct_dma/channel_engine_lpc_sct_dma.h, src/platforms/arm/lpc/drivers/sct_dma/channel_engine_lpc_sct_dma.cpp.hpp
Both files add platforms/is_platform.h and broaden their top-level #if gate to FL_IS_ARM_LPC_845 || FL_IS_STUB || FASTLED_STUB_IMPL, update matching #endif comments, and rename timing constants to kLpcSctMinPeriodNs/kLpcSctMaxPeriodNs used in canHandle().
Host test setup and contract/state-machine coverage
tests/fl/channels/lpc_sct_dma_engine.cpp
New test file with includes, timing-config helpers, byte-to-edge encoders, and test cases for getName(), getCapabilities(), poll(), canHandle() filtering, and enqueue()/show() state transitions.
TX→RX byte round-trip demonstration test
tests/fl/channels/lpc_sct_dma_engine.cpp
Adds a test encoding a GRB payload into WS2812 edges, capturing via RxDevice, decoding, and asserting the decoded bytes match the original payload.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3016: The new host test feeds WS2812 edge pairs into RxDevice::create<RxDeviceType::LPC_SCT_CAPTURE>, validating the LPC_SCT_CAPTURE backend introduced there.

Poem

A rabbit hops through stub and gate,
🐇 testing edges, early and late,
Constants renamed, no clash in sight,
Bytes go in GRB, come out just right,
Hop, hop, hooray — the tests compile tight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: host-side LPC SCT+DMA engine tests plus an RX round-trip check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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/3459-test-lpc-sct-engine

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/fl/channels/lpc_sct_dma_engine.cpp (1)

104-147: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Solid contract coverage; consider adding an upper-bound rejection test.

too_fast_timing_config() only exercises the lower bound (300ns < 1000ns floor). The engine's canHandle() 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7ba7725 and 063ec41.

📒 Files selected for processing (3)
  • src/platforms/arm/lpc/drivers/sct_dma/channel_engine_lpc_sct_dma.cpp.hpp
  • src/platforms/arm/lpc/drivers/sct_dma/channel_engine_lpc_sct_dma.h
  • tests/fl/channels/lpc_sct_dma_engine.cpp

@zackees
zackees merged commit 5eddaa9 into master Jun 30, 2026
7 of 10 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 30, 2026
zackees added a commit that referenced this pull request Jul 1, 2026
…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]>
@zackees
zackees deleted the feat/3459-test-lpc-sct-engine 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