Skip to content

feat(platform/lpc): complete Stage 4 wiring for LPC11Uxx + LPC15xx + APA102 SPI on LPC8xx (#2845) - #2872

Merged
zackees merged 3 commits into
masterfrom
feat/2845-lpc11-lpc15-driver-wiring
Jun 6, 2026
Merged

zackees merged 3 commits into
masterfrom
feat/2845-lpc11-lpc15-driver-wiring

Conversation

@zackees

@zackees zackees commented Jun 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Single combined PR for the AI-shippable portion of meta #2845. Closes Stage 4 items 1, 2, and 3 in one shot. Stage 3 (entire stage) and Stage 4 items 4-6 are explicitly out of scope below.

What landed

Stage 4 item 1 — LPC11Uxx clockless driver wiring

Splits the previous FL_LPC11 umbrella into:

  • FL_LPC11_USB — LPC11U24 / LPC11U35 (modern GPIO at 0xA0000000, same controller layout as LPC8xx per UM10462 §9)
  • FL_LPC11_LEGACY — LPC1110 / 1112 / 1114 / 1115 (legacy GPIO at 0x50000000 with 12-bit masked-access semantics per UM10398 §12)

The USB-series chips reuse the LPC8xx fastpin + C++ clockless driver unchanged: the GPIO controllers are register-for-register identical. The CPU-class difference (M0 vs M0+) is handled in led_sysdefs_arm_lpc.h by setting FL_IS_ARM_M0 instead of FL_IS_ARM_M0_PLUS; the clockless path was already running through FASTLED_M0_USE_C_IMPLEMENTATION so the M0+-specific STR-immediate encoding limit doesn't come into play.

Legacy parts get a clear #error so users on LPC1114 / LPC1115 know they're not yet supported, instead of silently mis-encoding writes against the wrong GPIO base.

Stage 4 item 2 — LPC15xx clockless driver wiring

Same approach: UM11074 confirms LPC15xx ships the same modern 0xA0000000 GPIO controller as LPC8xx. The CPU-class gate widens to set FL_IS_ARM_M3; the fastpin + clockless headers cover this family unchanged.

Stage 4 item 3 — APA102 / SK9822 / WS2801 hardware SPI driver for LPC8xx

New src/platforms/arm/lpc/spi_arm_lpc.h — an ARMHardwareSPIOutput template targeting the LPC8xx SPI peripheral per UM11029. Master / MSB-first / mode-0 / 8-bit transfers. SPI0 default; routable to SPI1 via the pSPIX template arg. The writePixels path handles APA102's FLAG_START_BIT brightness prefix, matching the Teensy-LC SPI driver's surface.

What's NOT in this PR (and why)

Stage 3 — entire stage. The meta itself states verbatim: "Hardware required — this stage cannot be completed by AI agents alone. Needs maintainer / @phatpaul / community member with an LPCXpresso845 (or LPC824 Lite / LPC845 Breakout Board) and a scope." SystemInit at 30 MHz, scope-measured WS2812 blink, AutoResearch UART bring-up, fbuild CI continue-on-error flip — these all need physical silicon. Code-only changes here would be unverifiable and risky.

Stage 4 item 1 (legacy LPC11xx). LPC1114 / LPC1115 use the legacy GPIO controller at 0x50000000 with a different register access pattern. Wiring that needs its own fastpin layout — a separate PR with its own scoping pass.

Stage 4 item 4 (multi-strip parallel). The meta gates this on Stage 2c PWM+DMA hardware validation: "Stage 2c (#2842) needs to land first for the PWM+DMA infrastructure to exist; multi-strip is a configuration extension on top." Hardware-gated.

Stage 4 item 5 (PlatformIO upstream donation). Not a FastLED-repo deliverable.

Stage 4 item 6 (fl::set_* settings). Design-pending — the meta says "If LPC users need clock-speed overrides...". No concrete requirement from real users yet.

Files changed

File Change
src/platforms/arm/lpc/is_lpc.h Split FL_LPC11 → FL_LPC11_USB + FL_LPC11_LEGACY
src/platforms/arm/lpc/led_sysdefs_arm_lpc.h Per-family CPU class + IRC F_CPU defaults
src/platforms/arm/lpc/fastpin_arm_lpc.h Widen gate to LPC11U / LPC15; #error for legacy LPC11xx
src/platforms/arm/lpc/clockless_arm_lpc.h Widen gate to LPC11U / LPC15 (driver body unchanged)
src/platforms/arm/lpc/fastled_arm_lpc.h Drop old #error; document new wiring; include spi_arm_lpc.h
src/platforms/arm/lpc/spi_arm_lpc.h NEW — APA102/SK9822/WS2801 SPI driver
src/platforms/arm/lpc/README.md Updated support matrix + driver list

Test plan

  • bash lint --cpp — clean
  • bash test --cpp — 310/310 pass (host build)
  • CI on this PR — LPC845 / LPC804 fbuild jobs should stay green; the SPI / clockless wiring is unreferenced by the example matrix unless user code instantiates the new controllers
  • Hardware bring-up (Stage 3, not blocking this PR) — Real LPC845 / LPC11U / LPC15 board running WS2812 + APA102 examples via fbuild, scope-measured for timing correctness

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Hardware SPI output for modern LPC8xx parts (LPC845/LPC804) to drive SPI LED strips with master/MSB-first/mode-0/8-bit behavior.
    • APA102/SK9822/WS2801 pixel support via the new SPI path.
  • Compatibility

    • Broader LPC family support: expanded GPIO/clockless coverage to additional LPC11 USB and LPC15 variants while gating legacy LPC11 parts.
  • Documentation

    • Expanded platform docs: SPI configuration, pin-routing guidance, roadmap/implementation mapping, and legacy-device notes.

…on LPC8xx (#2845 Stage 4 item 3)

Closes Stage 4 item 3 of the LPC dev roadmap (#2845).

Adds src/platforms/arm/lpc/spi_arm_lpc.h — an ARMHardwareSPIOutput template
targeting the LPC8xx SPI peripheral (per NXP UM11029 / UM11065). Master
mode, MSB-first, mode 0, 8-bit transfers; SPI0 default, users can route
to SPI1 via the pSPIX template arg.

Mirrors the convention used by the Stage 2a bit-bang clockless driver:
the user's startup code is responsible for:
  - enabling the SPI clock in SYSCON->SYSAHBCLKCTRL
  - routing MOSI / SCK through the LPC Switch Matrix (SWM) to the
    requested pins

FastPin only sees raw GPIO; this driver only programs the SPI block
itself, no IOCON / SWM writes.

Pixel-controller path (writePixels) handles the optional FLAG_START_BIT
prefix for APA102's per-LED 0xFF brightness byte, matching the Teensy
LC SPI driver's surface.

Updated:
- src/platforms/arm/lpc/fastled_arm_lpc.h — include the new driver header
- src/platforms/arm/lpc/README.md — document the addition

Hardware verification gated on #2845 Stage 3 (no LPC845 board has run
FastLED-output LEDs yet on this branch). Bytes-on-the-wire correctness
follows from adherence to UM11029; AC timing on real silicon needs a
scope. SPI is forgiving on bit timing — the failure modes are at the
clock-rate / SWM-routing boundary, not within the driver itself.

Stage 4 items not addressed here (architecturally separate, deserve
their own PRs):
- Item 1: LPC11xx clockless driver (Cortex-M0, legacy GPIO at 0x50000000
  for LPC1114/LPC1115 vs modern GPIO at 0xA0000000 for LPC11Uxx — needs
  sub-family detection split before driver wiring)
- Item 2: LPC15xx clockless driver (M3 ISA, no shared M3 ASM template
  exists yet; the m0clockless.h pattern doesn't apply)
- Item 4: Multi-strip parallel output (gated on Stage 2c PWM+DMA driver
  hardware validation per the issue body)

Stage 3 (hardware-gated SystemInit / blink-on-board / AutoResearch / CI
flip) requires physical access to an LPCXpresso845 + scope and cannot
be completed by AI agents alone, as the meta issue explicitly notes.
@coderabbitai

coderabbitai Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds LPC platform-family gating and documentation (LPC11_USB vs LPC11_LEGACY), extends sysdefs and fastpin/clockless guards for modern LPC controllers, and introduces an LPC8xx hardware SPI driver (ARMHardwareSPIOutput) with SPI register definitions and pixel-streaming support for APA102/SK9822/WS2801.

Changes

LPC platform family and LPC8xx SPI driver

Layer / File(s) Summary
LPC detection macros and subfamily split
src/platforms/arm/lpc/is_lpc.h
Introduce FL_LPC11_USB and FL_LPC11_LEGACY and update FL_LPC11 to roll up from the new subfamily macros.
CPU/ISA classification and F_CPU defaults
src/platforms/arm/lpc/led_sysdefs_arm_lpc.h
Derive FL_IS_ARM_M0_PLUS/FL_IS_ARM_M0/FL_IS_ARM_M3 from FL_LPC* selection and add F_CPU defaults for FL_LPC11_USB and FL_LPC15.
FastPin and clockless gating (modern vs legacy)
src/platforms/arm/lpc/fastpin_arm_lpc.h, src/platforms/arm/lpc/clockless_arm_lpc.h
Widen modern-LPC guards to include LPC11_USB/LPC15, add #error when FL_LPC11_LEGACY would use the modern fastpin layout, and update comments/guards accordingly.
Platform header wiring & docs
src/platforms/arm/lpc/fastled_arm_lpc.h, src/platforms/arm/lpc/README.md
Replace prior #error scaffolding with documented support matrix, include spi_arm_lpc.h for LPC8xx SPI strip support, and update README entries noting LPC11Uxx vs LPC11 legacy behavior and spi_arm_lpc.h details.
SPI base macros and register typedefs
src/platforms/arm/lpc/spi_arm_lpc.h (lines 1–88)
Add FL_LPC_SPI0_BASE/FL_LPC_SPI1_BASE defaults and define FL_LPC_SPI_Type with SPI config/status/TX masks and TXDATCTL helpers.
ARMHardwareSPIOutput interface and declarations
src/platforms/arm/lpc/spi_arm_lpc.h (lines 89–105, 251–258)
Declare ARM_HARDWARE_SPI, the ARMHardwareSPIOutput template parameters, constructors, lifecycle methods, write primitives, and finalizeTransmission.
Hardware SPI implementation and pixel streaming
src/platforms/arm/lpc/spi_arm_lpc.h (lines 106–250)
Implement SPI init/divider, master/mode/8-bit/MSB-first setup, chip-select management, FIFO/idle draining, low-level bit/byte/word writes, buffered writes, and writePixels with optional start-bit prefix and channel adjuster template.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 I hop through headers, macros bright,
I split the old from new by lantern-light,
SPI hums and clocks send patterned beams,
APA pixels wake in gentle streams,
Hooray — tiny LEDs dance in my dreams!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.18% 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 and specifically describes the main changes: completing Stage 4 LPC platform wiring by adding support for LPC11Uxx and LPC15xx, plus introducing APA102 SPI driver functionality on LPC8xx.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/2845-lpc11-lpc15-driver-wiring

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.

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

Actionable comments posted: 3

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

Inline comments:
In `@src/platforms/arm/lpc/spi_arm_lpc.h`:
- Around line 103-250: The ARMHardwareSPIOutput class in the header currently
contains full method bodies (e.g., init, select, release, wait, waitFully,
writeBit, writeByte, writeWord, writeBytesValueRaw, writeBytesValue, writeBytes,
writePixels, finalizeTransmission); move all of these method definitions out of
src/.../*.h into a companion implementation include (e.g., .impl.hpp or
.cpp.hpp) and leave only the class declaration and method signatures in the .h;
ensure the header `#includes` the new implementation file at the end (or include
it where needed) so compilation is unchanged and references to symbols like
ARMHardwareSPIOutput, spi_block(), and PixelController remain valid.
- Around line 167-172: writeBit currently writes TXDATCTL without disabling RX
capture so each bit clocks unread RX data and can overflow RXOV; update
writeBit(u8) to set the SPI transmit flag that ignores/clears RX capture (the
same RX-ignore bit used by other transmit helpers) when writing to spi->TXDATCTL
so the TX write does not populate RXDAT. Locate writeBit, keep the wait() and
spi_block() usage, and OR in the RX-ignore constant (e.g. the driver’s
SPI_TXDATCTL_RXIGNORE or equivalent flag) when assigning TXDATCTL so RX is
ignored for this transmit path.
- Around line 223-242: The writePixels function accepts a context parameter but
never forwards it to the adjuster cleanup call; update the final call inside
writePixels from D::postBlock(len) to D::postBlock(len, context) so the context
is passed through to adjusters that expect the two-argument form (keep the
existing context parameter on writePixels and forward it to D::postBlock).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 416c9151-3b6c-4e7b-a456-d345d6fe3d38

📥 Commits

Reviewing files that changed from the base of the PR and between a1311af and c5f14ea.

📒 Files selected for processing (3)
  • src/platforms/arm/lpc/README.md
  • src/platforms/arm/lpc/fastled_arm_lpc.h
  • src/platforms/arm/lpc/spi_arm_lpc.h

Comment on lines +103 to +250
template <u8 _DATA_PIN, u8 _CLOCK_PIN, u32 _SPI_CLOCK_DIVIDER,
u32 pSPIX = FL_LPC_SPI0_BASE>
class ARMHardwareSPIOutput {
Selectable *mPSelect;

static inline FL_LPC_SPI_Type* spi_block() __attribute__((always_inline)) {
return reinterpret_cast<FL_LPC_SPI_Type*>(pSPIX);
}

public:
ARMHardwareSPIOutput() : mPSelect(nullptr) {}
explicit ARMHardwareSPIOutput(Selectable *pSelect) : mPSelect(pSelect) {}

void setSelect(Selectable *pSelect) FL_NOEXCEPT { mPSelect = pSelect; }

/// Initialize SPI peripheral as master, 8-bit, MSB-first, CPOL=0, CPHA=0.
/// The user's startup code is responsible for:
/// (a) enabling the SPI clock in SYSCON->SYSAHBCLKCTRL[11] / [12]
/// (SPI0 / SPI1) on LPC845, or SYSCON->SYSAHBCLKCTRL0[11] on LPC804
/// (b) routing MOSI/SCK through SWM to the requested pins
void init() FL_NOEXCEPT {
FastPin<_DATA_PIN>::setOutput();
FastPin<_CLOCK_PIN>::setOutput();

FL_LPC_SPI_Type *spi = spi_block();

// Disable before reconfig
spi->CFG = 0;

// Clock divider. LPC8xx SPI clock = peripheral clock / (DIV + 1).
// _SPI_CLOCK_DIVIDER is interpreted as the same / (DIV+1) value,
// matching the Teensy LC driver convention.
u32 div = (_SPI_CLOCK_DIVIDER > 1) ? (_SPI_CLOCK_DIVIDER - 1) : 0;
if (div > 0xFFF) div = 0xFFF; // 12-bit field
spi->DIV = div;

// Master mode, MSB first, mode 0 (CPOL=0, CPHA=0)
spi->CFG = FL_LPC_SPI_CFG_ENABLE | FL_LPC_SPI_CFG_MASTER;
}

void inline select() FL_NOEXCEPT __attribute__((always_inline)) {
if (mPSelect != nullptr) { mPSelect->select(); }
}

void inline release() FL_NOEXCEPT __attribute__((always_inline)) {
waitFully();
if (mPSelect != nullptr) { mPSelect->release(); }
}

void endTransaction() FL_NOEXCEPT { release(); }

/// Wait until TX FIFO can accept another byte.
static void wait() __attribute__((always_inline)) {
while (!(spi_block()->STAT & FL_LPC_SPI_STAT_TXRDY)) {}
}

/// Wait until the master is fully idle (transfer drained).
void waitFully() FL_NOEXCEPT {
while (!(spi_block()->STAT & FL_LPC_SPI_STAT_MSTIDLE)) {}
}

/// Per-bit write — not the most efficient but required by the SPI base
/// API used for sm16716-style strips. APA102 / SK9822 don't exercise
/// this path (start bit is part of the byte stream).
template <u8 BIT>
inline static void writeBit(u8 b) FL_NOEXCEPT {
wait();
FL_LPC_SPI_Type *spi = spi_block();
spi->TXDATCTL = (b & (1u << BIT)) ? 1 : 0;
}

/// Write a single 8-bit byte. Caller responsible for waiting on prior
/// fill; this primitive only writes the TX data register.
static void writeByte(u8 b) __attribute__((always_inline)) {
wait();
FL_LPC_SPI_Type *spi = spi_block();
// TXDATCTL with LEN=7 (8-bit transfer) and RX ignored.
spi->TXDATCTL = static_cast<u32>(b) | FL_LPC_SPI_TXCTL_LEN_8BIT |
FL_LPC_SPI_TXCTL_RXIGNORE;
}

static void writeWord(u16 w) __attribute__((always_inline)) {
writeByte(static_cast<u8>(w >> 8));
writeByte(static_cast<u8>(w & 0xFF));
}

/// Write `len` copies of `value` over SPI.
static void writeBytesValueRaw(u8 value, int len) FL_NOEXCEPT {
while (len--) { writeByte(value); }
}

/// Bracketed variant — select + write + flush + release.
void writeBytesValue(u8 value, int len) FL_NOEXCEPT {
select();
writeBytesValueRaw(value, len);
waitFully();
release();
}

/// Bracketed bulk byte write with optional per-byte adjuster D.
template <class D>
void writeBytes(FASTLED_REGISTER u8 *data, int len) FL_NOEXCEPT {
u8 *end = data + len;
select();
while (data != end) {
writeByte(D::adjust(*data++));
}
D::postBlock(len);
waitFully();
release();
}

void writeBytes(FASTLED_REGISTER u8 *data, int len) {
writeBytes<DATA_NOP>(data, len);
}

/// Bracketed pixel-controller path used for APA102 / SK9822 / WS2801.
/// Handles the optional FLAG_START_BIT prefix (APA102's 0xFF brightness
/// byte per LED) via writeBit<0>.
template <u8 FLAGS, class D, EOrder RGB_ORDER>
void writePixels(PixelController<RGB_ORDER> pixels, void* /*context*/ = nullptr) FL_NOEXCEPT {
int len = pixels.mLen;

select();
while (pixels.has(1)) {
if (FLAGS & FLAG_START_BIT) {
writeBit<0>(1);
writeByte(D::adjust(pixels.loadAndScale0()));
writeByte(D::adjust(pixels.loadAndScale1()));
writeByte(D::adjust(pixels.loadAndScale2()));
} else {
writeByte(D::adjust(pixels.loadAndScale0()));
writeByte(D::adjust(pixels.loadAndScale1()));
writeByte(D::adjust(pixels.loadAndScale2()));
}

pixels.advanceData();
pixels.stepDithering();
}
D::postBlock(len);
waitFully();
release();
}

/// Finalize transmission. The MSTIDLE wait in waitFully() already
/// drains the FIFO; no additional flush is needed.
static void finalizeTransmission() FL_NOEXCEPT {}
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy lift

Move the implementation out of this .h file.

This new src/**/*.h header contains the full method bodies for ARMHardwareSPIOutput, which violates the repository's header-layout rule. Keep the declarations here and move the definitions into a .impl.hpp or .cpp.hpp include.

As per coding guidelines, "src/**/*.h: Header file. Verify it does NOT contain function definitions... If function definitions are needed, they belong in .cpp.hpp or .impl.hpp files."

🤖 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 `@src/platforms/arm/lpc/spi_arm_lpc.h` around lines 103 - 250, The
ARMHardwareSPIOutput class in the header currently contains full method bodies
(e.g., init, select, release, wait, waitFully, writeBit, writeByte, writeWord,
writeBytesValueRaw, writeBytesValue, writeBytes, writePixels,
finalizeTransmission); move all of these method definitions out of src/.../*.h
into a companion implementation include (e.g., .impl.hpp or .cpp.hpp) and leave
only the class declaration and method signatures in the .h; ensure the header
`#includes` the new implementation file at the end (or include it where needed) so
compilation is unchanged and references to symbols like ARMHardwareSPIOutput,
spi_block(), and PixelController remain valid.

Source: Coding guidelines

Comment on lines +167 to +172
template <u8 BIT>
inline static void writeBit(u8 b) FL_NOEXCEPT {
wait();
FL_LPC_SPI_Type *spi = spi_block();
spi->TXDATCTL = (b & (1u << BIT)) ? 1 : 0;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Ignore RX on the bit-write path too.

writeBit() is the only transmit helper that leaves RX capture enabled. Every call clocks unread data into the RX side, and this driver never drains RXDAT, so repeated bit writes can accumulate RXOV and make the start-bit / SM16716 path unreliable.

Proposed fix
     template <u8 BIT>
     inline static void writeBit(u8 b) FL_NOEXCEPT {
         wait();
         FL_LPC_SPI_Type *spi = spi_block();
-        spi->TXDATCTL = (b & (1u << BIT)) ? 1 : 0;
+        spi->TXDATCTL = ((b & (1u << BIT)) ? 1u : 0u) |
+                        FL_LPC_SPI_TXCTL_RXIGNORE;
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
template <u8 BIT>
inline static void writeBit(u8 b) FL_NOEXCEPT {
wait();
FL_LPC_SPI_Type *spi = spi_block();
spi->TXDATCTL = (b & (1u << BIT)) ? 1 : 0;
}
template <u8 BIT>
inline static void writeBit(u8 b) FL_NOEXCEPT {
wait();
FL_LPC_SPI_Type *spi = spi_block();
spi->TXDATCTL = ((b & (1u << BIT)) ? 1u : 0u) |
FL_LPC_SPI_TXCTL_RXIGNORE;
}
🤖 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 `@src/platforms/arm/lpc/spi_arm_lpc.h` around lines 167 - 172, writeBit
currently writes TXDATCTL without disabling RX capture so each bit clocks unread
RX data and can overflow RXOV; update writeBit(u8) to set the SPI transmit flag
that ignores/clears RX capture (the same RX-ignore bit used by other transmit
helpers) when writing to spi->TXDATCTL so the TX write does not populate RXDAT.
Locate writeBit, keep the wait() and spi_block() usage, and OR in the RX-ignore
constant (e.g. the driver’s SPI_TXDATCTL_RXIGNORE or equivalent flag) when
assigning TXDATCTL so RX is ignored for this transmit path.

Comment on lines +223 to +242
void writePixels(PixelController<RGB_ORDER> pixels, void* /*context*/ = nullptr) FL_NOEXCEPT {
int len = pixels.mLen;

select();
while (pixels.has(1)) {
if (FLAGS & FLAG_START_BIT) {
writeBit<0>(1);
writeByte(D::adjust(pixels.loadAndScale0()));
writeByte(D::adjust(pixels.loadAndScale1()));
writeByte(D::adjust(pixels.loadAndScale2()));
} else {
writeByte(D::adjust(pixels.loadAndScale0()));
writeByte(D::adjust(pixels.loadAndScale1()));
writeByte(D::adjust(pixels.loadAndScale2()));
}

pixels.advanceData();
pixels.stepDithering();
}
D::postBlock(len);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Pass context through to D::postBlock().

This backend drops the context argument even though writePixels() exposes it. Other SPI backends forward that value to D::postBlock(len, context), so this LPC path can skip context-dependent cleanup or fail to instantiate for adjusters that only provide the 2-argument form.

Proposed fix
-    void writePixels(PixelController<RGB_ORDER> pixels, void* /*context*/ = nullptr) FL_NOEXCEPT {
+    void writePixels(PixelController<RGB_ORDER> pixels, void* context = nullptr) FL_NOEXCEPT {
         int len = pixels.mLen;
@@
-        D::postBlock(len);
+        D::postBlock(len, context);
         waitFully();
         release();
     }
🤖 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 `@src/platforms/arm/lpc/spi_arm_lpc.h` around lines 223 - 242, The writePixels
function accepts a context parameter but never forwards it to the adjuster
cleanup call; update the final call inside writePixels from D::postBlock(len) to
D::postBlock(len, context) so the context is passed through to adjusters that
expect the two-argument form (keep the existing context parameter on writePixels
and forward it to D::postBlock).

…red LPC8xx GPIO path (#2845 Stage 4 items 1 + 2)

Closes Stage 4 items 1 and 2 of #2845 by leveraging a key insight from
the NXP user manuals: LPC11Uxx (UM10462 §9) and LPC15xx (UM11074) both
ship the *same* modern GPIO controller layout as LPC8xx (UM11029) —
DIR / MASK / PIN / SET / CLR / NOT registers at 0xA0000000 with identical
offsets. The only differences are:
  - CPU class (LPC11Uxx is M0, not M0+; LPC15xx is M3)
  - Default IRC clock (both boot at 12 MHz IRC vs 30/15 MHz on LPC8xx)

That means the existing LPC8xx fastpin (`_ARMPIN` template) and the
existing LPC8xx C++ clockless driver (`clockless_arm_lpc.h`) work
unchanged on these families once the CPU-class gate is widened. The
M0 / M0+ split is purely about the `FL_IS_ARM_M0_PLUS` define vs
`FL_IS_ARM_M0`; the actual clockless code path is already routed
through `FASTLED_M0_USE_C_IMPLEMENTATION` regardless, so the
M0+-specific STR-immediate encoding limit doesn't bite us.

Changes:

* `is_lpc.h` — split `FL_LPC11` into `FL_LPC11_USB` (LPC11U24/U35 —
  modern GPIO) and `FL_LPC11_LEGACY` (LPC1110/1112/1114/1115 — legacy
  GPIO at 0x50000000, NOT supported here). The umbrella `FL_LPC11`
  stays as a roll-up.

* `led_sysdefs_arm_lpc.h` — replace the unconditional
  `#define FL_IS_ARM_M0_PLUS` with a per-family conditional:
    FL_LPC845 / FL_LPC804 → FL_IS_ARM_M0_PLUS
    FL_LPC11_USB          → FL_IS_ARM_M0
    FL_LPC15              → FL_IS_ARM_M3
  Add F_CPU defaults (12 MHz) for the new families' IRC boot clocks.

* `fastpin_arm_lpc.h` — widen the gate from `FL_LPC845 || FL_LPC804` to
  also cover `FL_LPC11_USB || FL_LPC15`. Emit a clear `#error` when
  `FL_LPC11_LEGACY` is the only LPC family detected, since the modern
  fastpin doesn't apply to those legacy parts.

* `clockless_arm_lpc.h` — widen the same gate. The existing C++ driver
  body (which uses `_ARMPIN`'s `port()` / `mask()` view + the
  HI/LO offset constants) is family-agnostic; nothing else changes.

* `fastled_arm_lpc.h` — drop the blanket `#error` for `FL_LPC11` /
  `FL_LPC15`. Replace with a status comment documenting which subset
  of the family is wired and which (legacy LPC11xx) still needs work.

* `README.md` — update the support matrix with the new rows.

Stage 4 item 3 (APA102 / SK9822 SPI driver) shipped in the earlier
commit on this branch (c5f14ea).

What's still NOT in this PR (deferred — multi-day or hardware-gated):
- Stage 3 (entire) — hardware verification required; the meta itself
  says \"this stage cannot be completed by AI agents alone.\"
- Stage 4 item 1 legacy LPC11xx parts (LPC1110/1112/1114/1115) — need
  separate fastpin targeting legacy GPIO at 0x50000000 with 12-bit
  masked-access semantics (UM10398 §12). The `#error` makes the
  unsupported case loud.
- Stage 4 item 4 (multi-strip parallel) — gated on Stage 2c hardware
  validation per the meta.
- Stage 4 items 5 (PlatformIO upstream donation) and 6 (`fl::set_*`
  settings) — design-pending, not code-blocking.

Refs #2845.
@zackees zackees changed the title feat(platform/lpc): hardware SPI driver for APA102 / SK9822 / WS2801 on LPC8xx (#2845 Stage 4 item 3) feat(platform/lpc): complete Stage 4 wiring for LPC11Uxx + LPC15xx + APA102 SPI on LPC8xx (#2845) Jun 6, 2026

@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 (2)
src/platforms/arm/lpc/fastpin_arm_lpc.h (2)

36-36: ⚡ Quick win

Update stale comment to reflect broader scope.

The comment still references "LPC8xx GPIO controller" but this struct definition now applies to the broader "modern" LPC GPIO controller family (LPC8xx, LPC11Uxx, LPC15xx) as documented in the updated header comment at lines 15-19.

📝 Suggested fix
-// Minimal LPC8xx GPIO controller view used by the FastPin templates. The
+// Minimal "modern" LPC GPIO controller view used by the FastPin templates
+// (LPC8xx/LPC11Uxx/LPC15xx share the same DIR/MASK/PIN/SET/CLR/NOT layout). The
 // MCUXpresso CMSIS device header defines an equivalent LPC_GPIO_Type; when
🤖 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 `@src/platforms/arm/lpc/fastpin_arm_lpc.h` at line 36, Update the stale comment
above the GPIO struct that currently reads "Minimal LPC8xx GPIO controller view
used by the FastPin templates." to reflect the broader scope: mention the modern
LPC GPIO controller family (LPC8xx, LPC11Uxx, LPC15xx) and that this struct is a
minimal view used by the FastPin templates; locate the comment immediately
preceding the GPIO controller struct definition in fastpin_arm_lpc.h and replace
the old LPC8xx-only text with the new inclusive wording.

77-78: ⚡ Quick win

Update stale comment to reflect broader platform scope.

The comment still references "LPC8xx pins" and "LPC845/LPC804 packages" but this template now compiles for LPC11Uxx and LPC15xx as well (per the widened guard at lines 31-32).

📝 Suggested fix
-// FastPin template for LPC8xx pins. PORT0 is the only port populated on
-// LPC845/LPC804 packages currently supported.
+// FastPin template for "modern" LPC GPIO pins (LPC8xx/LPC11Uxx/LPC15xx).
+// PORT0 is the primary port; multi-port support depends on the specific variant.
🤖 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 `@src/platforms/arm/lpc/fastpin_arm_lpc.h` around lines 77 - 78, Update the
stale header comment in fastpin_arm_lpc.h that currently says "FastPin template
for LPC8xx pins. PORT0 is the only port populated on LPC845/LPC804 packages
currently supported." to reflect the wider supported platforms (e.g., LPC8xx,
LPC11Uxx, LPC15xx or more generally "NXP LPC families") and clarify port
availability; locate the comment at the top of the file in the FastPin template
section and change the wording to indicate the template compiles for LPC8xx,
LPC11Uxx and LPC15xx (or "NXP LPC families") and keep the note about PORT0 being
the only populated port on specific packages (mention LPC845/LPC804) so readers
know scope and exceptions.
🤖 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 `@src/platforms/arm/lpc/fastpin_arm_lpc.h`:
- Line 36: Update the stale comment above the GPIO struct that currently reads
"Minimal LPC8xx GPIO controller view used by the FastPin templates." to reflect
the broader scope: mention the modern LPC GPIO controller family (LPC8xx,
LPC11Uxx, LPC15xx) and that this struct is a minimal view used by the FastPin
templates; locate the comment immediately preceding the GPIO controller struct
definition in fastpin_arm_lpc.h and replace the old LPC8xx-only text with the
new inclusive wording.
- Around line 77-78: Update the stale header comment in fastpin_arm_lpc.h that
currently says "FastPin template for LPC8xx pins. PORT0 is the only port
populated on LPC845/LPC804 packages currently supported." to reflect the wider
supported platforms (e.g., LPC8xx, LPC11Uxx, LPC15xx or more generally "NXP LPC
families") and clarify port availability; locate the comment at the top of the
file in the FastPin template section and change the wording to indicate the
template compiles for LPC8xx, LPC11Uxx and LPC15xx (or "NXP LPC families") and
keep the note about PORT0 being the only populated port on specific packages
(mention LPC845/LPC804) so readers know scope and exceptions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 721c65f4-5b8a-457d-8b2d-2bbe6ecb05f5

📥 Commits

Reviewing files that changed from the base of the PR and between c5f14ea and 33883c6.

📒 Files selected for processing (6)
  • src/platforms/arm/lpc/README.md
  • 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/is_lpc.h
  • src/platforms/arm/lpc/led_sysdefs_arm_lpc.h
✅ Files skipped from review due to trivial changes (1)
  • src/platforms/arm/lpc/README.md

The #2845 meta covers 14 items spread across THREE repositories:
  - FastLED itself (8 items, of which 3 ship in this PR via #2872)
  - FastLED/fbuild (5 items: SystemInit, vector table, mcu_config split,
    CI workflows, validate_boards.py — none of which exist in this repo)
  - platformio/* (1 item: upstream board donation, would be a new
    platform that doesn't exist yet)

Without that breakdown, the single tracking matrix in the issue obscures
which items can land in a FastLED PR vs which need a fbuild PR (or
external action), and which are blocked on hardware verification that
no AI agent can perform.

Add an "Implementation map" section to the LPC README that:
  - tags each of the 14 items with its owner repo
  - marks the 3 items that ship in #2872
  - distinguishes hardware-gated (3.5, 4.4), upstream-blocked (4.5),
    and design-pending (4.6) items
  - documents that legacy LPC11xx (1110/1112/1114/1115) needs its own
    fastpin against the 0x50000000 GPIO controller
  - recommends splitting the meta into per-repo issues once #2872 lands

This is the artifact future maintainers (and future AI sessions) need
to read first before claiming the meta is "incomplete" — half of the
work cannot land in this repo by construction.

Refs #2845. No code changes.

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

Actionable comments posted: 1

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

Inline comments:
In `@src/platforms/arm/lpc/README.md`:
- Line 87: Update the summary line that currently reads "Of the 14 items, 5 live
in `FastLED/fbuild`, 1 lives in `platformio/*`, and 8 live here." so the numeric
count matches the implementation table: either change "14" to "15" to reflect
the 15 table rows, or if the intended total is 14, collapse the duplicated Stage
4.1 rows in the table so the table contains 14 rows; locate the string in
README.md and make the corresponding edit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 266bd23a-54a8-4a1d-b7d6-80cf2264495a

📥 Commits

Reviewing files that changed from the base of the PR and between 33883c6 and 7b5cdd9.

📒 Files selected for processing (1)
  • src/platforms/arm/lpc/README.md

| **Stage 4.5** — PlatformIO upstream donation | **PlatformIO** (3rd party) | Not started | Board JSON + linker scripts donation to `platformio/platform-nxplpc` (does not exist yet — would be a new platform). |
| **Stage 4.6** — `fl::set_*` settings for LPC clock-speed / DMA-channel overrides | **FastLED** | No concrete user requirement | The existing build-time `F_CPU` override (define before `#include <FastLED.h>`) already covers the clock-speed case for users on stable boot clocks. Runtime override on `CFastLED` would need machinery to recompute per-chipset cycle counts when clock changes — out of scope until a user reports needing it. |

**Of the 14 items, 5 live in `FastLED/fbuild`, 1 lives in `platformio/*`, and 8 live here.** Of those 8: 3 shipped in this PR (#2872), 2 are explicitly hardware-gated (3.5, 3.6, 4.4), 1 is the legacy-LPC11 fastpin follow-on, 1 (4.6) has no concrete user requirement, and 1 (4.5) is upstream-PlatformIO outside FastLED's control.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix the item-count math in the implementation map summary.

Line 87 says “14 items,” but this table currently lists 15 rows (8 Stage 3 + 7 Stage 4 entries, with Stage 4.1 split into two rows). Please align the summary count with the table to avoid roadmap tracking confusion.

Suggested doc fix
-**Of the 14 items, 5 live in `FastLED/fbuild`, 1 lives in `platformio/*`, and 8 live here.** Of those 8: 3 shipped in this PR (`#2872`), 2 are explicitly hardware-gated (3.5, 3.6, 4.4), 1 is the legacy-LPC11 fastpin follow-on, 1 (4.6) has no concrete user requirement, and 1 (4.5) is upstream-PlatformIO outside FastLED's control.
+**Of the 15 rows in this table, 5 live in `FastLED/fbuild`, 1 lives in `platformio/*`, and 9 live here.** Within the 9 FastLED-owned rows: 3 shipped in this PR (`#2872`), 3 are explicitly hardware-gated (3.5, 3.6, 4.4), 1 is the legacy-LPC11 fastpin follow-on, 1 (4.6) has no concrete user requirement, and 1 (4.5) is upstream-PlatformIO outside FastLED's control.
🤖 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 `@src/platforms/arm/lpc/README.md` at line 87, Update the summary line that
currently reads "Of the 14 items, 5 live in `FastLED/fbuild`, 1 lives in
`platformio/*`, and 8 live here." so the numeric count matches the
implementation table: either change "14" to "15" to reflect the 15 table rows,
or if the intended total is 14, collapse the duplicated Stage 4.1 rows in the
table so the table contains 14 rows; locate the string in README.md and make the
corresponding edit.

@zackees
zackees merged commit ff1e888 into master Jun 6, 2026
6 of 7 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 6, 2026
zackees added a commit that referenced this pull request Jun 6, 2026
Closes #2875.

CodeRabbit posted 6 findings on PR #2872 that landed without
addressing. This PR sweeps 5 of them.

1. **spi_arm_lpc.h::writeBit() RX-ignore (correctness).** The
   single-bit transmit helper was the only path writing TXDATCTL
   without setting `FL_LPC_SPI_TXCTL_RXIGNORE`. Every call clocked
   data into RXDAT, and the driver never drained it — repeated bit
   writes (e.g. APA102 / SK9822 / SM16716 start-bit prefixes on
   long strips) would accumulate RXOV. Now ORs the flag in to match
   writeByte().

2. **spi_arm_lpc.h::writePixels() / writeBytes() context forwarding
   (correctness).** Both bracketed paths accepted a `context` arg
   but dropped it before calling `D::postBlock(len)`. Every other
   SPI backend in `src/platforms/*/spi_*.h` forwards the value as
   `D::postBlock(len, context)`. Forwarded here so context-dependent
   adjuster cleanup runs and instantiation against 2-argument-only
   adjusters works.

3. **spi_arm_lpc.h MMIO cast (drive-by clippy).** `reinterpret_cast`
   on the SPI base address was already flagged by
   `ReinterpretCastChecker` against master; converted to the
   `(volatile T*)(base)` C-style pattern the linter allows for MMIO
   (matches `clockless_arm_lpc_plu.h::reg32`).

4. **fastpin_arm_lpc.h:36 stale comment.** GPIO-controller struct
   comment now reflects the modern LPC family (LPC8xx / LPC11Uxx /
   LPC15xx all at 0xA0000000).

5. **fastpin_arm_lpc.h:77 stale comment.** FastPin template comment
   widened from "LPC8xx pins" to "modern LPC GPIO pins" with the
   PORT0-only caveat preserved.

6. **README.md item count.** Implementation map summary said "14
   items" but the table has 15 rows (Stage 4.1 split into two
   during #2872). Corrected to 15 with accurate per-owner subtotals.

## Skipped finding

CR also suggested moving the `ARMHardwareSPIOutput` method bodies
out of `spi_arm_lpc.h` into a `.impl.hpp`. That conflicts with the
repo's own `impl_hpp_includes_checker.py` lint rule: `.impl.hpp`
files may only be included from `.impl.cpp.hpp` routers (non-
template compile units). `ARMHardwareSPIOutput` is a class
template — definitions must be visible at every instantiation
point, which rules out the router pattern. This matches the other
template SPI drivers in `src/platforms/arm/*/spi_*.h`. Added an
inline comment to the header explaining the deviation. The
non-template SPI drivers (`spi_hw_*nrf52.cpp.hpp` etc.) follow the
`.cpp.hpp` convention exactly because they are non-template.

## Test plan

- [x] `bash lint --cpp` clean (also cleared a pre-existing
      ReinterpretCastChecker violation on the SPI base-address cast).
- [x] `bash test --cpp` — 310/310 host tests pass.
- [ ] CI fbuild matrix LPC845 / LPC804 jobs (validate on push).
- [ ] Hardware bring-up of the RX-ignore fix is **not** required
      for this PR — Stage 3 (#2845) covers scope-measured timing
      and is maintainer-only. The Finding 1 fix is a register-flag
      correctness issue verifiable by inspection.
zackees added a commit that referenced this pull request Jun 6, 2026
…-up links (#2881)

Closes #2845.

The Stages 3 + 4 roadmap meta has run its course:

- **3 items shipped** — Stage 4.1 (LPC11Uxx clockless), 4.2 (LPC15xx
  clockless), 4.3 (APA102 / SK9822 / WS2801 SPI). All three landed in
  #2872 with CodeRabbit follow-up fixes in #2876.
- **6 items moved to fbuild** — Stage 3.1 - 3.4 + 3.7 + 3.8 now live
  under fbuild #456 (`Meta: LPC port completion — Stage 3 fbuild-side
  items`).
- **3 items moved to hardware-gated follow-ups** — Stages 3.5 + 3.6
  consolidated at FastLED #2880 (LPC845 hardware bring-up); Stage 4.4
  at #2879 (multi-strip, blocked on Stage 2c).
- **1 item moved to a code-only follow-up** — Stage 4.1 legacy at
  #2878 (the LPC1110/1112/1114/1115 fastpin against the 0x50000000
  masked-access GPIO).
- **2 items deferred** — Stage 4.5 (PIO donation; no upstream nxplpc
  platform exists) and Stage 4.6 (`fl::set_*` clock overrides; no
  concrete user requirement). Either reopens when there is a real
  ask.

This PR is a documentation-only change to
`src/platforms/arm/lpc/README.md`:

1. Adds GitHub Actions build-status badges for the existing
   `build-lpc845.yml` and `build-lpc804.yml` workflows in fbuild,
   matching the badge style used in the root FastLED README.
2. Notes that LPC11Uxx and LPC15xx compile against the same shared
   driver headers (fbuild #456 covers dedicated CI for those
   families).
3. Rewrites the implementation map so each row points at the
   smaller follow-up issue that owns it.
4. Reorganises the References section into Meta + Shipped + Open
   follow-ups + NXP user manuals.

## Test plan

- [x] `bash lint --cpp` clean (README-only change; no source touched).
- [x] All badge URLs and issue links typed against the workflows /
      issues confirmed live via `gh` before commit.
zackees added a commit that referenced this pull request Jun 14, 2026
…ked-access GPIO (closes #2878) (#3045)

Stage 4.1 (legacy item) of FastLED #2845. The modern LPC11Uxx parts
shipped in #2872 share the 0xA0000000 GPIO controller with LPC8xx, but
the legacy LPC1110/1112/1114/1115 line uses the older 0x50000000
controller with 12-bit masked-access semantics per UM10398 sec. 9. That
controller is not register-compatible with the modern one, so the
existing fastpin emitted a `#error` for FL_IS_ARM_LPC_11_LEGACY.

This commit lands:

  * `fastpin_arm_lpc11_legacy.h` -- new fastpin header.
    `MASKED_ACCESS[mask]` writes lift hi()/lo() to single stores with
    no read-modify-write -- same property the modern controller's
    SET/CLR registers provide. Covers all four legacy ports (PIO0..3)
    via a 48-pin grid; per-package availability is enforced by hardware.
  * `fastpin_arm_lpc.h` -- the `#error` block is replaced with an
    include of the legacy header. The modern templates remain scoped
    to LPC8xx / LPC11Uxx / LPC15xx as before.
  * `fastled_arm_lpc.h` -- aggregator banner updated; the legacy
    family is now "supported via dedicated fastpin + shared M0 C++
    clockless" rather than "NOT supported".
  * `README.md` -- the supported-platforms table flips LPC11xx legacy
    from "#error if targeted" to "Compiles; hardware bring-up pending"
    so the doc tracks reality.

Hardware bring-up on real LPC1114 silicon stays as a follow-up
(explicitly out of scope per the issue body). The existing M0 C++
clockless driver in `clockless_arm_lpc.h` already provides the
WS2812 timing path and only consumes the `_ARMPIN` interface, so no
clockless changes are required.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@zackees
zackees deleted the feat/2845-lpc11-lpc15-driver-wiring 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