Skip to content

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

Closed

Description

@zackees

Follow-up to #3212.

Background

PR #3212 fixes a real bug in src/platforms/arm/lpc/fastpin_arm_lpc.h: the fallback FL_LPC_GPIO_Type mirror did not include the large holes in the modern LPC GPIO register map, so fields such as W, DIR, PIN, SET, CLR, NOT, DIRSET, and DIRCLR landed at the wrong byte offsets.

That PR corrects the immediate issue by adding explicit padding so the fallback mirror matches the NXP/CMSIS GPIO_Type layout:

  • B at 0x0000
  • W at 0x1000
  • DIR at 0x2000
  • PIN at 0x2100
  • SET at 0x2200
  • CLR at 0x2280
  • NOT at 0x2300
  • DIRSET at 0x2380
  • DIRCLR at 0x2400
  • DIRNOT at 0x2480

The padding does not allocate SRAM because this is a typed view over a fixed hardware address, not an instantiated object. However, it is visually bulky and easy to get wrong again.

Better fix

Replace the sparse fallback struct with one of these safer representations:

  1. Direct offset accessors/constants for the small register subset FastLED actually uses, e.g. PIN, SET, CLR, NOT, DIRSET, DIRCLR; or
  2. Keep the CMSIS-style struct mirror, but add compile-time offsetof assertions for every register FastLED touches.

Direct offsets are probably the cleaner long-term fit for FastLED because the LPC FastPin code only needs a handful of registers and the controller map has large sparse gaps.

Acceptance criteria

  • FastPin LPC fallback no longer depends on unverified sparse padding arithmetic, or every used padded-field offset is protected by static_assert(offsetof(...)).
  • Register offsets used by FastPin<>::setOutput, setInput, hi, lo, toggle, hival, loval, port, sport, and cport are covered.
  • The implementation still defers to the SDK/CMSIS LPC_GPIO / GPIO definition when available, or documents why the fallback address constants are authoritative.
  • A host-side compile/layout test covers the fallback path if practical.
  • Do not conflate this with GPIO clock gating: GPIO_PortInit(GPIO, 0) / clock ungating remains separate follow-up behavior unless this issue explicitly expands to include it.

Related work

Notes

The immediate PR #3212 is correct and should not be blocked on this cleanup. This issue is about making the fallback representation harder to break in the future.

Activity

  1. added
    type: bug
    on Jun 18, 2026
  2. added a commit that references this issue on Jun 18, 2026
  3. zackees commented on Jun 18, 2026

    @zackees
    MemberAuthor

    cc @phatpaul — this is the follow-up cleanup issue from #3212 so you can track the safer long-term fix for the LPC GPIO register-map fallback. The immediate offset fix from your PR has been merged.

  4. moved this from Triage to Done in FastLED Trackeron Jun 18, 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

    type: bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions