Skip to content

feat(platform): LPC845 bit-bang clockless driver (Stage 2a of #2836) - #2837

Merged
zackees merged 1 commit into
masterfrom
feat/2836-lpc845-port
Jun 5, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/2836-lpc845-port

Conversation

@zackees

@zackees zackees commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Stage 2a of the NXP LPC8xx FastLED port (meta issue #2836).

Adds a bit-banged WS2812 clockless driver for LPC845 (Cortex-M0+ @ 30 MHz) and LPC804 (Cortex-M0+ @ 15 MHz), templated on the existing shared m0clockless driver used by Teensy LC (KL26Z) and nRF51.

New files (src/platforms/arm/lpc/)

File Purpose
is_lpc.h Detects __LPC845__ / __LPC804__ / CPU_LPC845* / CPU_LPC804* defines from the MCUXpresso CMSIS device headers; emits FL_LPC845, FL_LPC804, FL_IS_ARM_LPC.
int.h Delegates to the shared ARM 32-bit integer typedefs (src/platforms/arm/int.h).
led_sysdefs_arm_lpc.h Defines F_CPU per chip (30 MHz / 15 MHz), FL_IS_ARM_M0_PLUS, cli()/sei() via __disable_irq/__enable_irq, and includes <LPC845.h> / <LPC804.h> for LPC_GPIO.
fastpin_arm_lpc.h PIO0_0..PIO0_31 mapped onto LPC_GPIO->SET[0] / CLR[0] / DIRSET[0] / DIRCLR[0] / NOT[0] / PIN[0].
clockless_arm_lpc.h WS2812 controller; calls into the shared showLedData<HI_OFFSET, LO_OFFSET, ...> template.
fastled_arm_lpc.h Aggregator.

Dispatcher wiring

  • src/platforms/arm/is_arm.h includes lpc/is_lpc.h and adds FL_IS_ARM_LPC to the FL_IS_ARM umbrella.
  • src/led_sysdefs.h routes FL_IS_ARM_LPC to led_sysdefs_arm_lpc.h.
  • src/platforms.h routes FL_IS_ARM_LPC to fastled_arm_lpc.h (and now includes is_arm.h first so the LPC detection runs before the dispatch chain).

Design decisions

  1. Uses the portable C++ implementation of m0clockless (FASTLED_M0_USE_C_IMPLEMENTATION) instead of the inline-ASM one. The LPC8xx GPIO controller places SET[0] at +0x2200 and CLR[0] at +0x2280 from the controller base, which is beyond the 5-bit imm5*4 encoding the M0+ STR Rt, [Rn, #imm] instruction supports (max byte offset = 124). The inline-asm template's "I" constraint cannot encode those offsets in a single-instruction store. The C++ version performs an indexed store (port[off/4] = bitmask) and handles arbitrary byte offsets at zero cost.
  2. FastPin<>::port() returns &LPC_GPIO->PIN[0], with HI_OFFSET = 0x100 (relative to PIN[0], this is SET[0]) and LO_OFFSET = 0x180 (which is CLR[0]). The C++ clockless driver consumes these as compile-time template parameters.
  3. FL_LPC845 is gated via __LPC845__ or the CPU_LPC845* defines from the MCUXpresso LPC845.h CMSIS device header - that is what the NXP SDK ships.

Scope

  • Stage 2a only: bit-bang WS2812. No PLU driver (Stage 2b, LPC804) or PWM+DMA driver (Stage 2c, LPC845) here.
  • Cross-compile validation depends on Stage 1 (fbuild toolchain), which is a separate repo / separate PR. Draft until Stage 1 lands.
  • No new .ino under examples/ - per the meta issue, Blink validation goes through existing examples once Stage 1 lands. AutoResearch is the canonical scratch target for live-device testing.

What was verified from this side

  • bash lint --cpp: all checks pass on the new LPC files (and the modified dispatchers).
  • LPC code is gated by defined(FL_IS_ARM_LPC) / defined(__LPC845__) / defined(__LPC804__) so host builds are inert.
  • Host build of FastLED.h with FASTLED_STUB_IMPL (no LPC defines present) compiles cleanly with the new files on the include path.

What was NOT verified (and why)

  • No hardware bring-up: cross-compile requires Stage 1 fbuild support that does not yet exist. Once Stage 1 lands, the recommended validation sequence is examples/Blink then examples/AutoResearch on an LPC845 dev board.
  • Pre-existing master regression observed during bash test --cpp: src/fl/net/network_detector.h:50 uses namespace fl::net { (C++17 nested namespace syntax) under -Werror=c++17-extensions. The failure is identical on pristine master (verified via git stash). Out of scope for this PR; flagged here for visibility.

Test plan

  • Stage 1 (fbuild) lands and exposes an lpc845 platform target.
  • bash compile lpc845 --examples Blink compiles clean.
  • Hardware: WS2812 strip driven from PIO0_4 on an LPC845-BRK dev board renders correctly at 30 MHz CPU (T1/T2/T3 should round-trip cleanly given the shared m0clockless_c cycle math).
  • LPC804 path: same verification at 15 MHz (timing is tighter - flag any T1/T2/T3 rounding issues).

Refs #2836.

Summary by CodeRabbit

Release Notes

New Features

  • Added support for ARM LPC8xx microcontroller platforms (LPC845, LPC804)
  • FastLED can now control addressable LEDs on LPC-based boards with hardware GPIO and precise timing control
  • Includes platform-specific configuration optimized for LPC microcontrollers

Adds Stage 2a of the NXP LPC8xx FastLED port: a bit-banged WS2812
clockless driver for LPC845 (Cortex-M0+ @ 30 MHz) and LPC804
(Cortex-M0+ @ 15 MHz), templated on the existing M0+ shared driver.

New files under src/platforms/arm/lpc/:
- is_lpc.h: detects __LPC845__ / __LPC804__ / CPU_LPC845*/CPU_LPC804*
  defines from the MCUXpresso CMSIS device headers; emits FL_LPC845,
  FL_LPC804, FL_IS_ARM_LPC.
- int.h: delegates to the shared ARM 32-bit integer typedefs.
- led_sysdefs_arm_lpc.h: F_CPU per chip (30 MHz / 15 MHz), interrupt
  policy via __disable_irq / __enable_irq, FL_IS_ARM_M0_PLUS.
- fastpin_arm_lpc.h: PIO0_0..PIO0_31 mapped onto LPC_GPIO->SET[0] /
  CLR[0] / DIRSET[0] / DIRCLR[0] / NOT[0] / PIN[0].
- clockless_arm_lpc.h: WS2812 controller routing through the shared
  showLedData<HI_OFFSET, LO_OFFSET, ...> template.
- fastled_arm_lpc.h: aggregator.

Routes the new family through the existing dispatchers (is_arm.h,
led_sysdefs.h, platforms.h). All LPC code is guarded by
FL_IS_ARM_LPC so host builds are unaffected.

Drives the portable C++ implementation of m0clockless instead of the
inline-assembly one: the LPC8xx GPIO controller places SET[0] at
+0x2200 and CLR[0] at +0x2280 from the controller base, which is
beyond the 5-bit imm5*4 encoding the M0+ STR-immediate-offset
instruction supports - so the inline-asm template's "I" constraint
cannot fit those offsets in a single store. The C++ version performs
an indexed store and handles arbitrary byte offsets.

Stage 2a only: no PLU (LPC804) or PWM+DMA (LPC845) driver yet.
Cross-compile validation depends on Stage 1 (fbuild toolchain), which
is a separate PR. Draft until then.

Refs #2836
@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Looking for one thing? Review this PR in Change Stack to search files, summaries, diffs, and code without losing your place.

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: 8619e947-a3d7-482c-9f1e-5e37a597bf3d

📥 Commits

Reviewing files that changed from the base of the PR and between df207c0 and 1a6891a.

📒 Files selected for processing (9)
  • src/led_sysdefs.h
  • src/platforms.h
  • src/platforms/arm/is_arm.h
  • src/platforms/arm/lpc/clockless_arm_lpc.h
  • src/platforms/arm/lpc/fastled_arm_lpc.h
  • src/platforms/arm/lpc/fastpin_arm_lpc.h
  • src/platforms/arm/lpc/int.h
  • src/platforms/arm/lpc/is_lpc.h
  • src/platforms/arm/lpc/led_sysdefs_arm_lpc.h

📝 Walkthrough

Walkthrough

This PR adds complete ARM LPC8xx microcontroller support to FastLED by introducing platform detection, system configuration, GPIO control via FastPin, a clockless LED output controller with interrupt management, and integration into FastLED's existing platform dispatcher.

Changes

ARM LPC8xx Platform Implementation

Layer / File(s) Summary
LPC8xx platform detection and ARM integration
src/platforms/arm/lpc/is_lpc.h, src/platforms/arm/is_arm.h, src/platforms/arm/lpc/int.h
LPC8xx device detection examines CMSIS headers and compiler macros to define FL_LPC845 and FL_LPC804, signals FL_IS_ARM_LPC macro, integrates into ARM platform detection, and forwards integer types to the shared ARM int header.
LPC system configuration and initialization
src/platforms/arm/lpc/led_sysdefs_arm_lpc.h
Configures LPC8xx clock speeds (30 MHz for LPC845, 15 MHz for LPC804), forces C-based timing implementation, defines ARM M0+ CPU flag, configures interrupt and progmem behavior, provides register type aliases, and conditionally includes CMSIS device headers (LPC845.h/LPC804.h) for interrupt primitives (__disable_irq(), __enable_irq()).
Platform dispatcher integration
src/led_sysdefs.h, src/platforms.h
Inserts FL_IS_ARM_LPC conditional branches into the main platform-selection dispatcher, enabling automatic LPC platform routing when the LPC detection macros are active.
GPIO and FastPin implementation
src/platforms/arm/lpc/fastpin_arm_lpc.h
Provides memory-mapped GPIO register access through _ARMPIN template (DIRSET/DIRCLR, SET/CLR, PIN, NOT operations), includes fallback register definitions when device headers are unavailable, and instantiates FastPin specializations for pins 0–31 with hardware pin support enabled.
Clockless LED output controller
src/platforms/arm/lpc/clockless_arm_lpc.h
Implements an LPC-specific clockless LED controller template with interrupt gating, assembles pixel timing data into M0ClocklessData structures from color/controller state, computes GPIO port base and mask from FastPin, invokes showLedData with LPC-specific SET/CLR register offsets, and includes a retry mechanism with 10-microsecond delay when initial transmit fails.
Public LPC platform header
src/platforms/arm/lpc/fastled_arm_lpc.h
Groups LPC-specific FastPin and clockless controller implementations into a single public platform header with standard guards and IWYU pragmas.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Poem

🐰 The Cottage at Clock-Time's Edge

With GPIO mapped and clocks in place,
The LPC joins the ARM embrace.
Bright LED whispers, interrupt-gated,
No clock needed—their streams created.
FastLED hops to a new device's song! 🎨✨

✨ 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/2836-lpc845-port

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.

@fastled-project-sync fastled-project-sync Bot moved this to In Progress in FastLED Tracker Jun 5, 2026
@zackees
zackees marked this pull request as ready for review June 5, 2026 22:41
@zackees
zackees merged commit ebd8791 into master Jun 5, 2026
6 of 8 checks passed
@zackees
zackees deleted the feat/2836-lpc845-port branch June 5, 2026 22:41
@fastled-project-sync fastled-project-sync Bot moved this from In Progress to Triage in FastLED Tracker Jun 5, 2026
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 5, 2026
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