Skip to content

feat(platform): LPC804 PLU clockless driver (#2841) - #2848

Merged
zackees merged 1 commit into
masterfrom
feat/2841-lpc804-plu-driver
Jun 6, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/2841-lpc804-plu-driver

Conversation

@zackees

@zackees zackees commented Jun 6, 2026 •

Copy link
Copy Markdown
Member

Closes #2841.

Stage 2b follow-up to #2836 / #2837. Adds an opt-in WS2812 driver for the NXP LPC804 that offloads bit-timing to its on-chip Programmable Logic Unit (PLU), freeing the 15 MHz Cortex-M0+ from cycle-counted bit-banging.

Summary

  • New header src/platforms/arm/lpc/clockless_arm_lpc_plu.h implementing fl::ClocklessController<DATA_PIN, TIMING, RGB_ORDER, ...> against the LPC804 PLU.
  • Build-time opt-in: -DFASTLED_LPC_PLU=1 (only honoured when FL_LPC804 is also defined).
  • The existing bit-banged driver (clockless_arm_lpc.h) compiles itself out under the same gate so we don't double-define the template.
  • fastled_arm_lpc.h now pulls in the PLU header after the bit-bang header; both self-gate, so LPC845 builds are unchanged.

PLU graph

Three LUTs synthesise the WS2812 bit waveform:

LUT Function UM11065 ref
LUT0 out = !CNT1 — T0H window (high for first half of bit) §12.6.2 Table 96
LUT1 out = !(CNT0 & CNT1) — T1H window (high for ~75% of bit) §12.6.2 Table 96
LUT2 out = DATA ? LUT1 : LUT0 — bit mux §12.6.2 Table 96

Routing:

  • LUTn_INP_MUX[m] (UM11065 §12.6.1) wires PLU_IN0..2 + LUT cross-feeds.
  • OUTPUT0_MUX (UM11065 §12.6.3) routes LUT2 to PLU_OUT0.
  • PLU clock enabled by SYSCON->SYSAHBCLKCTRL0 bit 18 (UM11065 §4.6.13).

Result: DATA=0 produces a ~T0H high pulse, DATA=1 produces a ~T0H+T1H high pulse — the WS2812 NRZ encoding.

Open TODO(2841)s left in code

Documented and grep-able as TODO(2841):

  1. SCT/MRT-based timing source feeding PLU_IN1 / PLU_IN2 (the bit-period counter). Currently left as a board-integrator responsibility — the integrator's init_timing_source() must run before FastLED.show().
  2. SWM PINASSIGN_PLU_IN[n] / PINASSIGN_PLU_OUT[n] programming helper. The SWM is fully crossbar-routable per UM11065 Table 88, so no compile-time pin validation is feasible without per-package constraints.
  3. Confirm SYSCON->SYSAHBCLKCTRL0 PLU clock bit position against the LPC804.h CMSIS enum once the device header is available in CI.
  4. Regenerate the LUT2 bit-mux truth-table constant via a unit test that enumerates the boolean expression, to defend against bit-ordering surprises in UM11065 §12.6.2 Table 96.
  5. Calibrate sendByte() NOP padding once the SCT counter rate is locked.

These are all hardware-bringup tasks; none can be resolved without a real LPC804 board.

Files changed

  • src/platforms/arm/lpc/clockless_arm_lpc_plu.h — new (405 lines)
  • src/platforms/arm/lpc/clockless_arm_lpc.h — add gate so bit-bang compiles out when PLU is selected
  • src/platforms/arm/lpc/fastled_arm_lpc.h — include the new PLU header

CI / hardware status

  • Host bash lint --cpp green.
  • Host C++ tests are unaffected because both LPC drivers are gated by FL_IS_ARM_LPC (unset on host).
  • The build-lpc804.yml workflow is hardware-gated and may stay red until Stage 3 (per feat(platform): LPC804 PLU clockless driver (Stage 2b of #2836) #2841 acceptance criteria); per maintainer direction the user has accepted this.

Draft because

No hardware available in this PR to scope-trace the WS2812 waveform. Marked draft pending Stage 3 hardware verification, after which the workflow can drop continue-on-error: true and this PR can be marked ready.

Summary by CodeRabbit

  • New Features

    • Added optional hardware-accelerated driver for LPC804 microcontrollers using on-chip programmable logic, enabling more efficient WS2812 LED control. Enable via FASTLED_LPC_PLU macro.
  • Bug Fixes

    • Fixed conditional compilation conflict in existing LPC driver to prevent double-definition when using the new PLU-based implementation.

Adds a Programmable Logic Unit (PLU) clockless WS2812 driver for the NXP
LPC804 at 15 MHz, where the shared M0+ bit-banged path has ~1 cycle of
margin on T1 and is marginal.

The PLU is configured as a 3-LUT graph that synthesises the WS2812 bit
pulse-shape in hardware (LUT0 = T0H window, LUT1 = T1H window, LUT2 =
DATA-selected bit mux), routed via OUTPUT0_MUX to a SWM-assigned GPIO.
The CPU only has to push the next data bit per WS2812 bit interval.

Architecturally mirrors the RP2040 PIO driver:
  - ClocklessController<DATA_PIN, TIMING, RGB_ORDER, XTRA0, FLIP, WAIT>
  - CMinWait<WAIT_TIME> for reset-gap enforcement
  - showPixels() disables interrupts and feeds bytes MSB-first

Build-time opt-in via -DFASTLED_LPC_PLU=1 (only honoured when FL_LPC804
is also defined). The existing bit-bang driver compiles itself out under
the same gate, so LPC845 builds are unaffected.

Register layout cited inline against NXP UM11065 chapter 12 (PLU) and
chapter 4 (SYSCON clock-gating). Timing-counter source for PLU_IN1/IN2
and SWM PINASSIGN_PLU_IN/OUT pin routing are left as documented
TODO(2841) for the hardware-bringup pass; no hex was fabricated.

Stage 2b of #2836. Hardware validation is Stage 3.

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

coderabbitai Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

Too many files changed? Review this PR in Change Stack to see how the pieces fit before you dive in.

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: cfa233dd-aabd-45d4-b4ce-f828d6057c64

📥 Commits

Reviewing files that changed from the base of the PR and between 73ac19d and eda50a1.

📒 Files selected for processing (3)
  • src/platforms/arm/lpc/clockless_arm_lpc.h
  • src/platforms/arm/lpc/clockless_arm_lpc_plu.h
  • src/platforms/arm/lpc/fastled_arm_lpc.h

📝 Walkthrough

Walkthrough

This PR implements a hardware-accelerated WS2812 LED driver for LPC804 microcontrollers using the Programmable Logic Unit (PLU) to generate pulse timing in silicon. The PLU-based driver replaces the software-based approach under a build-time opt-in flag, with conditional compilation preventing double-definition of the ClocklessController template.

Changes

LPC804 PLU Clockless Driver

Layer / File(s) Summary
PLU Hardware Driver Implementation
src/platforms/arm/lpc/clockless_arm_lpc_plu.h
Defines PLU register layout, LUT truth tables implementing WS2812 NRZ pulse shaping, and a ClocklessController template that initializes the PLU graph, streams pixel bits via the data pin in an 8-bit loop (sendByte), and relies on hardware timing instead of software-generated delays.
Build-time Conditional Compilation
src/platforms/arm/lpc/clockless_arm_lpc.h
Updates the standard LPC clockless controller header guard from #if FL_IS_ARM_LPC to #if FL_IS_ARM_LPC && !(FL_LPC804 && FASTLED_LPC_PLU) to prevent template double-definition when the PLU opt-in is enabled.
Platform Header Integration
src/platforms/arm/lpc/fastled_arm_lpc.h
Adds include of the PLU-based clockless driver header and build-time documentation explaining the opt-in macro gating.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Poem

🐰 A rabbit's hop through logic gates,
Where PLU timing generates fates—
No software delay, just silicon song,
LEDs dance at fifteen MHz strong! ✨

✨ 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/2841-lpc804-plu-driver

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 and usage tips.

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.

feat(platform): LPC804 PLU clockless driver (Stage 2b of #2836)

1 participant