Skip to content

fix(spi): establish logical idle-low clock during software-SPI init #5057

Closed

Description

@zackees

Context

Two-round source/read-back audit for #5024 confirmed a first-edge initialization defect in GenericSoftwareSPIOutput. src/platforms/shared/spi_bitbang/generic_software_spi.h:82-87 makes data/clock outputs and releases select but never establishes logical clock LOW. Public writeByte/writeBit sets clock HIGH before LOW. When the existing clock latch is HIGH and setOutput preserves it, the first HIGH write is not a rising edge, so the first byte loses its MSB edge.

APA102 and SM16716 initialization only call mSPI.init (src/fl/chipsets/apa102.h:97-98, src/fl/chipsets/sm16716.h:55-56); no caller precondition requires an already-low latch. The public init contract should establish mode-0 idle state itself.

Root observed genuine debug RED using the unchanged production GPIO trace fixture: .build/software-spi-init-clock-red.log. Existing Model4 clock pin 229 is primed HIGH, trace cleared, actual Output.init and Output::writeByte(0xa5) run, existing checkBits oracle reports seven samples rather than eight. This executes production SPI, not a copied writer or modified oracle.

Proposal

Drive the clock pin's logical lo() in init before releasing select. Use the logical pin operation to preserve inverted GPIO semantics. Do not change data or stream timing.

Acceptance criteria

  • Preserve observed RED and show GREEN for the current first-byte regression: init leaves logical clock LOW and first byte has exactly eight correctly ordered rising-edge samples.
  • Exercise normal/inverted clock mappings, scalar public writeByte, same-port snapshot/streaming and independent-port atomic paths. Prime logical HIGH before init and keep the existing edge oracle unchanged.
  • Deleting the init lo operation must restore the failure. Verify no selected transaction is required for establishing idle state and unrelated GPIO bits are preserved.
  • Repository lint and orchestrator-run debug targeted tests must pass; no measured hardware throughput claim.

Decisions

P2 correctness, separate from polarity #5044 and subsequent idle-gap timing. This is a shared initialization guarantee affecting all pin policies, not a board-specific speedup. Root owns tests/builds; delegated implementation is minimal.

Reproduction

rg -n 'void init|setOutput|release' src/platforms/shared/spi_bitbang/generic_software_spi.h
Metadata-only all-state duplicate search software SPI init clock found no identical first-edge initialization report.

Activity

  1. added
    sanitized
    on Nov 5, 2026
  2. moved this from Triage to Done in FastLED Trackeron Nov 7, 2026
  3. added a commit that references this issue on Nov 8, 2026
    ebc43cd
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