Skip to content

Replace padded LPC GPIO fallback accessors - #3221

Merged
zackees merged 1 commit into
masterfrom
feat/lpc-gpio-accessors
Jun 18, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/lpc-gpio-accessors

Conversation

@zackees

@zackees zackees commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

Summary

  • replace the padded fallback FL_LPC_GPIO_Type mirror with explicit LPC GPIO offset accessors
  • prefer vendor/CMSIS LPC_GPIO or GPIO definitions when a board package provides them
  • keep the FastPin PIN/SET/CLR relative offsets asserted for the clockless driver

Context

Fixes #3218.
Refs #3212.

This keeps the fallback from implying that padding consumes target RAM. The old padded struct was a compile-time MMIO layout only, but the direct offset form is clearer and avoids carrying a large fake register map just to reach PIN, SET, CLR, NOT, DIRSET, and DIRCLR.

Verification

  • uv run python -m ci.autoresearch lpc845brk --pin-toggle-rx --upload-port COM10 --quiet --skip-schema --timeout 120s
    • build/flash/reset succeeded
    • firmware built at 62.49 KB / 64 KB flash, 10.99 KB / 16 KB RAM
    • RPC echo succeeded
    • pin-toggle capture failed with 0 edges at 1 kHz, 10 kHz, and 100 kHz; runner reports likely missing/incorrect P0_10 -> P0_11 jumper
  • uv run fbuild .build\pio\lpc845brk build -e lpc845brk --shrink=safe -v
    • succeeded after starting zccache explicitly
  • uv run ci/ci-compile.py lpc845brk --examples AutoResearch --backend platformio --max-failures 1 --log-failures .compile-failures-pio
    • source compile completed; link overflowed by 2192 bytes on PlatformIO/GCC 8.2.1, matching the target's tight flash budget rather than a source error

Summary by CodeRabbit

  • Refactor
    • Restructured internal GPIO hardware access layer for ARM LPC platforms to improve register handling and hardware compatibility.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 82d722d7-bebb-4d4e-ad0a-36e1810763ae

📥 Commits

Reviewing files that changed from the base of the PR and between 903f589 and 7d3c598.

📒 Files selected for processing (1)
  • src/platforms/arm/lpc/fastpin_arm_lpc.h

📝 Walkthrough

Walkthrough

fastpin_arm_lpc.h removes the fallback FL_LPC_GPIO_Type sparse struct and its LPC_GPIO cast macro, replacing them with a lpc_detail namespace containing compile-time offset constants, static assertions, and typed volatile u32* accessor helpers. All _ARMPIN GPIO operations are updated to call these helpers, and FL_LPC_GPIO_HW is #undef'd at the end of the header.

Changes

LPC GPIO offset-based register accessor refactor

Layer / File(s) Summary
lpc_detail offset constants and accessor helpers
src/platforms/arm/lpc/fastpin_arm_lpc.h
Removes FL_LPC_GPIO_Type struct and fallback #define LPC_GPIO cast. Adds FL_LPC_GPIO_HW macro selected from existing LPC_GPIO or GPIO. Defines lpc_detail namespace with constexpr offset constants (with static assertions), lpc_gpio_reg base+offset pointer computation, and typed lpc_gpio_pin/set/clr/not/dirset/dirclr helpers that either dereference the hardware struct or compute from FL_LPC_GPIO_BASE + offset.
_ARMPIN methods rewritten to use lpc_detail helpers
src/platforms/arm/lpc/fastpin_arm_lpc.h
Replaces all direct LPC_GPIO->DIRSET/DIRCLR/SET/CLR/NOT/PIN member accesses in setOutput, setInput, hi, lo, toggle, isset, port, sport, cport with calls to the corresponding lpc_detail::lpc_gpio_* helpers. Adds #undef FL_LPC_GPIO_HW cleanup at end of header.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3212: Directly precedes this PR — fixed FL_LPC_GPIO_Type padding offsets; this PR supersedes that struct entirely by switching to computed offset accessors.
  • FastLED/FastLED#2837: Introduced the original _ARMPIN/LPC_GPIO-based implementation that this PR refactors.
  • FastLED/FastLED#2866: Narrowed the preprocessor gate around the same _ARMPIN template that this PR modifies internally.

Poem

🐇 Hoppity-hop through registers aligned,
No padding gaps to leave offsets behind!
lpc_detail springs forth with offsets just right,
Static assertions keep the addresses tight.
The old struct is gone — what a cleaner delight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.13% 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 PR title 'Replace padded LPC GPIO fallback accessors' directly reflects the main change: replacing the sparse padded FL_LPC_GPIO_Type struct with explicit offset-based accessors.
Linked Issues check ✅ Passed The PR fully addresses issue #3218 acceptance criteria: replaces padded struct with direct offset accessors, covers all registers used by FastPin methods (setOutput, setInput, hi, lo, toggle, hival, loval, port, sport, cport), defers to SDK/CMSIS definitions when available, and excludes GPIO clock gating.
Out of Scope Changes check ✅ Passed All changes are scoped to fastpin_arm_lpc.h and directly implement the refactoring specified in issue #3218, with no unrelated modifications present.

✏️ 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 feat/lpc-gpio-accessors

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 merged commit ad81d40 into master Jun 18, 2026
9 checks passed
@zackees
zackees deleted the feat/lpc-gpio-accessors branch June 18, 2026 17:39
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 18, 2026
zackees added a commit that referenced this pull request Jun 18, 2026
…845 (#3224 Tier 1A) (#3226)

* fix(arm/m0clockless): forward-declare CMSIS interrupt intrinsics for gcc 15.2+

gcc 15.2+ enforces stricter `-Wtemplate-body` lookup: function templates
that reference undeclared names at parse time now error rather than
warn. `showLedData` in m0clockless_c.h uses `__get_PRIMASK`,
`__enable_irq`, `__disable_irq` directly, and the LPC8xx build of the
AutoResearch sketch (which transitively reaches this header via the
LPC SCT clockless driver) was failing master compile:

    m0clockless_c.h:484:24: error: there are no arguments to '__get_PRIMASK'
    that depend on a template parameter, so a declaration of
    '__get_PRIMASK' must be available [-Wtemplate-body]

Forward-declare the three CMSIS intrinsics with their universal Cortex-M
signatures, guarded by `#ifndef` so that platforms which already provide
them as macros (Arduino-AVR's WString.h is one such case) keep working
without redefinition errors.

Surfaced while testing #3224 Tier 1A patches on master.

* perf(json): gate float arithmetic paths on Low-memory; -4.3 KB on LPC845

#3224 Tier 1A: kill the single-precision soft-FP cascade on no-FPU
targets. Verified on LPC845-BRK with AutoResearch + RX_SCT_WS2812:

    flash 63,992 B -> 59,648 B  (-4,344 B saved)
    headroom 1,544 B -> 5,888 B (~4x growth)

Soft-FP residual drops from 4,564 B to 208 B (only `__aeabi_fcmp*` /
`__aeabi_f2iz` / `__clzsi2` remain, totalling ~210 B).

## Root cause

The integer-only RPC contract on LPC8xx never receives JSON float
values, but several float-handling overloads in the visitor surface
were still reachable from the variant dispatch table:

| Visitor (variant alternative = `float`) | What it pulls in |
|---|---|
| `JsonToIntegerVisitor<T>::operator()(float const&)` | `__aeabi_f2iz` + `__aeabi_fcmp*` + `to_string(float, 6)` -> `format_float` -> ~3 KB |
| `JsonToBoolVisitor::operator()(float const&)` | `to_string(float, 6)` warning path -> same cascade |
| `JsonToStringVisitor::operator()(float const&)` | `to_string(float, 6)` direct |
| `float_conversion_visitor<*>::operator()(fl::string const&)` | `fl::parseFloat` which does `mul/add/div/divisor *= 10.0f` -> `__aeabi_fmul/fadd/fdiv` |
| `StringConversionVisitor::operator()(float const&)` / `(double const&)` | `to_string(float, 6)` again |

All overloads stay defined (the variant dispatcher requires them) but
gated on `FL_PLATFORM_HAS_LARGE_MEMORY`:

- On Large-memory targets: unchanged behavior, full float<->int<->string
  conversion + warning strings.
- On Low-memory targets: saturate to zero / empty, set an error on
  TypeConversionResult so the RPC dispatcher reports
  `float -> int not supported on Low-memory` rather than silently
  returning garbage.

The single change with the biggest weight is `JsonToIntegerVisitor`:
its float overload was the single largest reachable consumer of
single-prec soft-FP across the LowMemory build.

## Verification

```
PLATFORMIO_SRC_DIR=examples/AutoResearch fbuild build -e lpc845brk
  -> Flash: 58.25 KB / 64.00 KB (91.0%)
     RAM:   10.99 KB / 16.00 KB (68.7%)
     build succeeded
```

LD region overflow: NONE. ~5.7 KB headroom available for new
LowMemory feature work, comfortably above the 6 KB target named in
#3224's acceptance criteria.

Refs #3224 (Tier 1A item A, "Single-precision soft-FP cascade")

* fix(lpc/fastpin): switch to FL_STATIC_ASSERT + fl::bit_cast in GPIO accessors

Pre-existing master lint failures from PR #3221 (fastpin GPIO fallback
rework):

- `static_assert` -> `FL_STATIC_ASSERT` (BannedMacrosChecker; the latter
  keeps compile-time assertions portable on old embedded toolchains).
- `reinterpret_cast<volatile u32*>(addr)` -> `fl::bit_cast<volatile
  u32*>(addr)` (ReinterpretCastChecker; FastLED-blessed alternative for
  the address-to-pointer conversion that constructs the CMSIS-style
  peripheral pointer from a numeric base + offset).

Surfaced while building #3224 Tier 1A patches on master.
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.

refactor(platform/lpc): replace sparse GPIO register padding with safer offset-based accessors

1 participant