Skip to content

feat(platform/lpc): address CodeRabbit follow-ups on #2872 (writeBit RX-ignore, writePixels context, header-impl split, stale comments) #2875

Closed

Description

@zackees

Background

PR #2872 (Stage 4 wiring for LPC11Uxx / LPC15xx / APA102 SPI on LPC8xx) landed CodeRabbit-clean overall, but the bot posted 6 follow-up findings that were not addressed pre-merge: 2 correctness bugs in the new LPC SPI driver, 1 header-layout refactor, and 3 documentation/comment freshness items. This issue bundles them so a single follow-up PR can sweep them all.

Original CR review: #2872

Findings

Sorted by severity. Each row tracks status in this issue's checklist.

🟠 Major — correctness bugs (2)

1. src/platforms/arm/lpc/spi_arm_lpc.h:167-172 — writeBit() leaves RX capture enabled

The single-bit transmit helper is the only path in the driver that writes TXDATCTL without setting FL_LPC_SPI_TXCTL_RXIGNORE. Every call clocks data into the receive side, and the driver never drains RXDAT. Repeated writeBit calls accumulate RXOV (RX overrun), making the APA102 start-bit prefix path and any future SM16716-style bit-prefix paths unreliable on long strips.

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;
 }

Acceptance: every TXDATCTL write in the file ORs in FL_LPC_SPI_TXCTL_RXIGNORE.

2. src/platforms/arm/lpc/spi_arm_lpc.h:223-242 — writePixels() drops context argument

The function signature accepts void* context = nullptr but never forwards it. Every other SPI backend in src/platforms/*/spi_*.h calls D::postBlock(len, context) so the pixel adjuster can do context-dependent cleanup. The LPC path's D::postBlock(len) call will:

  • silently drop work that adjusters expect to execute, and
  • fail to instantiate against any user-supplied D adjuster type that only declares the 2-argument postBlock(int, void*) form.

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();
     }

Acceptance: writePixels parameter is named context (not commented out) and D::postBlock receives it.

🟠 Major — refactor (1)

3. src/platforms/arm/lpc/spi_arm_lpc.h:103-250 — Move method bodies out of the .h

Per the repo coding-guidelines (cf. CR's quote: "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.") the new ARMHardwareSPIOutput template has all method bodies (init, select, release, wait, waitFully, writeBit, writeByte, writeWord, writeBytesValueRaw, writeBytesValue, writeBytes, writePixels, finalizeTransmission) inside the .h.

Fix: split into:

  • src/platforms/arm/lpc/spi_arm_lpc.h — class declaration + method signatures.
  • src/platforms/arm/lpc/spi_arm_lpc.impl.hpp — method definitions.
  • spi_arm_lpc.h ends with #include "spi_arm_lpc.impl.hpp" so the compilation footprint is unchanged.

Match the existing platform pattern (see src/platforms/arm/k20/spi_arm_k20.h + .cpp.hpp for an analogous split if present, otherwise mirror the Teensy-LC layout).

Acceptance: grep -n "{$" src/platforms/arm/lpc/spi_arm_lpc.h shows no out-of-line bodies; all bodies live in the .impl.hpp.

🟡 Minor — documentation freshness (3)

4. src/platforms/arm/lpc/fastpin_arm_lpc.h:36 — Stale GPIO-controller comment

-// 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

5. src/platforms/arm/lpc/fastpin_arm_lpc.h:77-78 — Stale FastPin template comment

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

6. src/platforms/arm/lpc/README.md:87 — Item-count mismatch

Line 87 says "14 items" in the implementation map summary, but the table immediately below lists 15 rows (8 Stage-3 + 7 Stage-4 entries, with Stage 4.1 having been split into two rows during PR #2872). Either re-count to 15 (preferred — matches table) or merge the split rows again.

Acceptance checklist (for the follow-up PR)

  • All TXDATCTL writes OR in FL_LPC_SPI_TXCTL_RXIGNORE (Finding 1)
  • writePixels::context parameter is named and forwarded to D::postBlock (Finding 2)
  • All method bodies in spi_arm_lpc.h moved to spi_arm_lpc.impl.hpp (Finding 3)
  • fastpin_arm_lpc.h:36 comment updated for modern LPC family (Finding 4)
  • fastpin_arm_lpc.h:77-78 comment updated for modern LPC family (Finding 5)
  • README.md item-count says 15 (Finding 6)
  • bash lint --cpp clean
  • bash test --cpp 310/310 pass (host build invariant)
  • LPC845 / LPC804 fbuild CI jobs stay green

Test plan

Host-only validation is sufficient for this PR — the bug fixes are deterministic and the refactor changes layout, not behaviour:

  1. bash test --cpp — full host suite must pass.
  2. bash lint --cpp — clean.
  3. CI fbuild matrix — both LPC8xx jobs (LPC845, LPC804) compile clean on the new header layout.
  4. Hardware bring-up of the RX-ignore fix is not required for this PR — Stage 3 (meta: LPC dev roadmap — Stages 3 + 4 (port completion, family expansion) #2845) covers scope-measured timing and is explicitly maintainer-only. The Finding 1 fix is a register-flag correctness issue verifiable by inspection; the failure mode (RXOV after long writeBit sequences) is documented in the LPC8xx UM and matches CR's reasoning.

Related

🤖 Filed via Claude Code from a CodeRabbit triage pass.

Activity

  1. added a commit that references this issue on Jun 6, 2026
    2c346c9
  2. moved this from Triage to Done in FastLED Trackeron Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions