Skip to content

lpc: move bare-metal support into platform code - #2989

Merged
zackees merged 1 commit into
masterfrom
codex/nxplpc-fastled-cleanup
Jun 9, 2026
Merged

zackees merged 1 commit into
masterfrom
codex/nxplpc-fastled-cleanup

Conversation

@zackees

@zackees zackees commented Jun 8, 2026 •

Copy link
Copy Markdown
Member

Summary

  • move the LPC-specific FastLED runtime/time/IO glue into src/platforms/arm/lpc instead of keeping board-support files under an example
  • wire LPC into the ARM platform build aggregation and use the shared no-op pin map path
  • qualify FastLED's internal yield call as fl::yield() so Arduino global yield() stubs do not collide
  • keep Arduino-owned typedefs and timing out of the bare-metal LPC fallback path

This intentionally does not bring over the misplaced examples/BlinkLPC845 include tree or generated build-info JSON from external PR #2988. Those fbuild-owned pieces are in the companion PR: FastLED/fbuild#512.

Validation

  • git diff --check master..HEAD
  • with scratch-only examples/Blink/platformio.ini: ..\fbuild\target\debug\fbuild.exe ci --board lpc845 examples\Blink\Blink.ino --lib . --quick -v
  • with scratch-only examples/Blink/platformio.ini: ..\fbuild\target\debug\fbuild.exe ci --board lpc804 examples\Blink\Blink.ino --lib . --quick -v

Summary by CodeRabbit

  • New Features

    • Added support for ARM LPC microcontroller platform with timing, I/O operations, and runtime management
  • Bug Fixes

    • Fixed delay implementation to use correct function namespace resolution
  • Refactor

    • Enhanced platform architecture to integrate new ARM LPC platform support

@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces complete ARM LPC platform support to FastLED by implementing LPC-specific timing via SysTick, I/O stubs, runtime symbols, and platform configuration. It also refactors the core delay loop to consistently use the namespaced fl::yield() function instead of an unqualified yield() call.

Changes

LPC Platform Support

Layer / File(s) Summary
Core yield refactoring
src/FastLED.cpp.hpp
Includes fl/system/yield.h and updates CFastLED::delay() to call fl::yield() instead of unqualified yield().
LPC platform infrastructure
src/platforms/arm/lpc/led_sysdefs_arm_lpc.h, src/platforms/pin.h, src/platforms/arm/_build.cpp.hpp, src/platforms/arm/lpc/_build.cpp.hpp
Defines FASTLED_NO_PINMAP, conditionalizes the boolean typedef on Arduino, integrates LPC into the ARM platform build unity header, and adds LPC platform selection branch to pin mapping.
LPC SysTick-based timing
src/platforms/arm/lpc/platform_time_lpc.cpp.hpp
Implements millisecond and microsecond timing using Cortex SysTick, including internal state (g_millis, g_systick_started), lazy initialization, SysTick_Handler ISR, and public delay, delayMicroseconds, millis, and micros functions with atomic snapshot logic in micros().
LPC I/O and runtime support
src/platforms/arm/lpc/io_lpc.cpp.hpp, src/platforms/arm/lpc/runtime_lpc.cpp.hpp, src/platforms/arm/lpc/spi_arm_lpc.h
Provides LPC platform I/O stubs (serial begin/print/read functions returning stub values), weak linker symbols (__dso_handle, end, _end), weak operator delete/delete[] overloads, and SPI type header dependencies.
LPC clockless controller delay dependencies
src/platforms/arm/lpc/clockless_arm_lpc.h, src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h
Adds fastled_delay.h includes to LPC clockless controller headers to provide delay-related symbols.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • FastLED/FastLED#2841: Main changes add LPC platform infrastructure and clockless controller support headers that are preparatory for the LPC804 PLU clockless driver.
  • FastLED/FastLED#2990: Main changes implement LPC platform support (timing, I/O, runtime, pin mapping, build integration) enabling in-tree LPC platform dispatch.
  • FastLED/FastLED#2836: Main changes add complete LPC platform port infrastructure including timing, I/O stubs, runtime, and system definitions.
  • FastLED/fbuild#487: Main changes implement LPC platform pieces (SysTick timing, I/O, pin mapping, platform wiring) tracked by the LPC8xx end-to-end support meta-issue.
  • FastLED/FastLED#2865: Main changes modify LPC platform driver headers and add platform selection infrastructure in the same LPC driver area.

Possibly related PRs

  • FastLED/FastLED#2850: Adds fastled_delay.h to src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h, which directly integrates with the new LPC845 PWM+DMA clockless driver.
  • FastLED/FastLED#2866: Both PRs touch src/platforms/arm/lpc/clockless_arm_lpc.h, with the retrieved PR refining LPC8xx guards while this PR adds delay header dependency.
  • FastLED/FastLED#2849: Extends LPC11 detection to enable FL_IS_ARM_LPC, which directly activates the new LPC-only headers and platform branches introduced in this PR.

Poem

🐰 A rabbit hops through ARM LPC lands,
With SysTick ticking in its tiny hands,
Timing precise, and I/O so stout,
FastLED's yield now knows what's about! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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: moving LPC bare-metal support implementation files into the platform code directory structure.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/nxplpc-fastled-cleanup

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.

@zackees
zackees force-pushed the codex/nxplpc-fastled-cleanup branch from 072e47c to 0b47521 Compare June 9, 2026 04:42
@zackees
zackees marked this pull request as ready for review June 9, 2026 04:42
@fastled-project-sync fastled-project-sync Bot moved this from In Progress to Triage in FastLED Tracker Jun 9, 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/runtime_lpc.cpp.hpp (1)

19-35: 💤 Low value

No-op delete operators assume no dynamic allocation.

The weak no-op operator delete overloads will silently leak memory if any code uses new/delete. This is acceptable for bare-metal LPC where dynamic allocation is typically avoided, but consider adding a compile-time guard or runtime assertion if dynamic allocation is attempted, or document this constraint clearly in the header comments.

🤖 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/runtime_lpc.cpp.hpp` around lines 19 - 35, The no-op
weak operator delete overloads (operator delete, operator delete[], operator
delete(void*, size_t), operator delete[](void*, size_t)) silently drop frees and
can hide use of dynamic allocation; update these overloads to either (1) add a
compile-time guard (e.g., a macro or static_assert flag like
FL_ALLOW_DYNAMIC_ALLOCAION) so the no-op definitions are only compiled for a
no-dynamic mode, or (2) insert a runtime trap/assert (e.g., call to platform
panic/assert handler) inside each operator to fail-fast when delete is used, and
add a header comment documenting that dynamic allocation is unsupported unless
the guard is enabled; reference and change the four operator delete definitions
accordingly.
src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h (1)

314-314: ⚡ Quick win

Static buffer sharing constraint is documented but not enforced.

The static sChannelBuf is shared across all ClocklessController instances, which limits the design to a single active controller. The comment on lines 312-313 documents this, but there's no runtime enforcement. If a user accidentally creates multiple LPC PWM/DMA controllers, they will silently corrupt each other's buffer state.

Consider adding a debug-mode assertion in init() or showPixels() to detect multiple concurrent instances, or document this constraint more prominently in the class documentation.

🛡️ Proposed guard to detect multiple instances

Add a debug assertion in init():

 virtual void init() FL_NOEXCEPT {
+    `#ifdef` FASTLED_DEBUG
+    static bool sInstanceActive = false;
+    if (sInstanceActive) {
+        // Multiple LPC PWM/DMA controllers detected - only one supported
+        while(1) {}  // Halt in debug builds
+    }
+    sInstanceActive = true;
+    `#endif`
+    
     FastPin<DATA_PIN>::setOutput();
🤖 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/clockless_arm_lpc_pwm_dma.h` at line 314, The static
buffer sChannelBuf is shared across all ClocklessController instances but
there's no runtime check to prevent multiple active controllers; add a
debug-only guard to detect and fail-fast when a second instance is initialized
or used—for example, introduce a static or global flag (e.g., sChannelBufInUse
or sActiveControllerCount) and assert in ClocklessController::init() (and/or
ClocklessController::showPixels()) that no other instance is active, set the
flag on successful init and clear it in the destructor or a deinit method, and
ensure the check is compiled only in debug builds so production size/perf is
unaffected.
🤖 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/clockless_arm_lpc_pwm_dma.h`:
- Line 314: The static buffer sChannelBuf is shared across all
ClocklessController instances but there's no runtime check to prevent multiple
active controllers; add a debug-only guard to detect and fail-fast when a second
instance is initialized or used—for example, introduce a static or global flag
(e.g., sChannelBufInUse or sActiveControllerCount) and assert in
ClocklessController::init() (and/or ClocklessController::showPixels()) that no
other instance is active, set the flag on successful init and clear it in the
destructor or a deinit method, and ensure the check is compiled only in debug
builds so production size/perf is unaffected.

In `@src/platforms/arm/lpc/runtime_lpc.cpp.hpp`:
- Around line 19-35: The no-op weak operator delete overloads (operator delete,
operator delete[], operator delete(void*, size_t), operator delete[](void*,
size_t)) silently drop frees and can hide use of dynamic allocation; update
these overloads to either (1) add a compile-time guard (e.g., a macro or
static_assert flag like FL_ALLOW_DYNAMIC_ALLOCAION) so the no-op definitions are
only compiled for a no-dynamic mode, or (2) insert a runtime trap/assert (e.g.,
call to platform panic/assert handler) inside each operator to fail-fast when
delete is used, and add a header comment documenting that dynamic allocation is
unsupported unless the guard is enabled; reference and change the four operator
delete definitions accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9b814fab-217a-441d-bb42-2fd88595758e

📥 Commits

Reviewing files that changed from the base of the PR and between 731d2fb and 0b47521.

📒 Files selected for processing (11)
  • src/FastLED.cpp.hpp
  • src/platforms/arm/_build.cpp.hpp
  • src/platforms/arm/lpc/_build.cpp.hpp
  • src/platforms/arm/lpc/clockless_arm_lpc.h
  • src/platforms/arm/lpc/clockless_arm_lpc_pwm_dma.h
  • src/platforms/arm/lpc/io_lpc.cpp.hpp
  • src/platforms/arm/lpc/led_sysdefs_arm_lpc.h
  • src/platforms/arm/lpc/platform_time_lpc.cpp.hpp
  • src/platforms/arm/lpc/runtime_lpc.cpp.hpp
  • src/platforms/arm/lpc/spi_arm_lpc.h
  • src/platforms/pin.h

@zackees
zackees merged commit ed860aa into master Jun 9, 2026
10 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 9, 2026
@zackees

zackees commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@zackees
zackees deleted the codex/nxplpc-fastled-cleanup 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