Skip to content

fix(spi-bitbang): platform policies bypass hi()/lo() on FastPin subclasses that override them #5122

Done

Description

@zackees

Raised repeatedly by CodeRabbit on the #5024 children (for example #5115, #5118, #5121). Platform BitbangPin policies detect hardware pins by base class. A downstream FastPin that derives from a hardware pin template and overrides hi()/lo(), for example to invert polarity, has those overrides skipped for data writes.

No in-repo pin does this; found by reading the code. A fix may be possible by comparing member-function pointers, which has not been tried, and should apply to all platform policies at once, ideally through a shared helper in bitbang_pin.h. Part of #5024.

Activity

  1. added
    sanitized
    on Nov 6, 2026
  2. zackees commented on Nov 8, 2026

    @zackees
    MemberAuthor

    Tried a shared fix. I'm not opening a PR because it breaks the host test fixtures.

    What works:

    • A constexpr == on function addresses is rejected by avr-gcc 7.3, xtensa-lx106 10.3, and arm-none-eabi 9.2 and 11.3.
    • Partial specialization on function-pointer template arguments is accepted by every toolchain I tried: avr 7.3, lx106 10.3, arm 9.2/11.3/14.2/15.2, xtensa/riscv 13.2/14.2, and host gcc and clang. Pins are compared by identity:
      template <void(*A)(), void(*B)()> struct Same : false; template <void(*A)()> struct Same<A,A> : true;
    • With a helper BitbangKeepsBaseWrites<Pin, Base> in bitbang_pin.h, each isXHardwarePin can take Derived and return Keeps<Derived, Base>::value. That covers 15 ARM/AVR policies. ESP32 and ESP8266 are always true and would need their own change.
    • A RED test, a FastPin derived from _RP2350PIN that inverts hi()/lo(), failed on master and passed with the change.

    Why it isn't a PR: bash test --cpp then fails about 10 platform tests (Teensy LC same-port streaming, among others). Their TracedClock fixtures override the clock pin's hi()/lo() to record edges, and they expect the stream path to stay enabled. A tracing override and an inverting override can't be told apart, so landing this means reworking those fixtures, for example tracing at the register level. That is a design decision for this issue.

  3. zackees commented on Nov 12, 2026

    @zackees
    MemberAuthor

    The maintainer selected the documentation-only scope for this sweep: current limitation plus the existing explicit-policy workaround, keeping this issue open for a concrete downstream case instead of introducing native-method identity metadata across 20 platform policies.

    PR #5245 documents that contract. A custom generic-writer pin can provide a full BitbangPin specialization deriving from BitbangPinDefaults with kAtomicWrite=true and kTwoWriteStream=false, visible consistently before instantiation. This is an internal generic-writer workaround, not a new public API, CPU atomicity promise, or runtime-channel/virtual-pin solution.

    Automatic override detection remains unimplemented. A downstream reproducer should identify the custom pin, the selected platform policy and the affected writer path before a broader implementation is scoped. Leaving this issue OPEN; no source behavior was changed by the documentation PR.

  4. zackees commented on Nov 22, 2026

    @zackees
    MemberAuthor

    Status from the issue sweep: this stays open on purpose, following the maintainer's scope call. #5245 (merged) documents the limitation and the workaround, a full BitbangPin specialisation that derives from BitbangPinDefaults. Please restart code work only with a downstream reproducer that names the custom pin, the platform policy selected and the affected writer path. The earlier shared-fix attempt broke about 10 host tests whose tracing fixtures also override hi()/lo(), so a fix needs a design decision first.

  5. moved this from Triage to In Review in FastLED Trackeron Nov 24, 2026
  6. moved this from In Review to Done in FastLED Trackeron Nov 24, 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

    sanitized

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions