Skip to content

perf(teensy-k66): adopt generic software-SPI GPIO pin policies #5037

Closed

Description

@zackees

Context

Two-round audit at 94dab9c for #5024 confirms K64/K66 normal _ARMPIN at src/platforms/arm/teensy/teensy36/fastpin_arm_k66.h:25-53 exposes 32-bit full output latch (port, fastset) and atomic write-one set/clear (sport, cport). It retains BitbangPin default kTwoWriteStream=false,kAtomicWrite=false (src/platforms/shared/spi_bitbang/bitbang_pin.h:34-36), missing the existing exclusive same-port stream and branchless data set/clear helper.

Actual dispatch src/platforms/arm/fastpin_arm.h selects the canonical Teensy header. src/platforms/arm/k66/fastpin_arm_k66.h is a legacy independently retained copy; give it an explicit synchronized-or-retired disposition. Public SoftwareSPIOutput (src/fastspi.h:107) is the reachable software writer. Default Teensy3/LC SPIOutput is hardware-only; hardware peripheral writes are excluded. FastPinBB bit-band aliases, where defined, have different semantics and must remain excluded; FASTLED_FORCE_SOFTWARE_PINS must retain fallback behavior.

Proposal

Opt normal K64/K66 FastPin into exclusive same-port bulk streaming and branchless set/clear data policy for public-byte/separate-port/interrupt paths. Keep CPU-cycle timing and minimum pulse guarantees. This independently defined backend gets its own child of #5024.

Acceptance criteria

  • RED before implementation: actual production policy does not select optimization. GREEN after: reverting either opt-in fails a focused policy/trace assertion.
  • Same-port (e.g. pins 0/1, GPIOB) nonempty bulk byte/value/pixel APIs perform 16 stores per byte plus final clock-low; cover empty/multibyte and 0x00/0xff/alternating patterns, MSB-first rising-edge samples and unrelated-bit preservation.
  • Separate ports (0/2, GPIOB/GPIOD) and FAST_SPI_INTERRUPTS_WRITE_PINS use selected atomic set/clear aliases, preserve concurrent unrelated-pin changes, and avoid full-latch snapshots. Cover public writeByte, not only bulk APIs.
  • Compile teensy35 and teensy36 through real dispatch with same/separate ports, forced software pins and interrupt mode, preserving default hardware SPI selection. Exclude FastPinBB from policy applicability.
  • Do not infer GPIO write cycle costs from CPU frequency; preserve delays unless supported by assembly/device evidence. Local store-count assertions do not establish hardware speed; physically measure throughput before claiming gains.

Decisions

P2 optimization. Native siblings cover other independently defined Teensy GPIO implementations; no blanket all-ARM policy. No source edits/builds during discovery; orchestrator owns RED/GREEN.

Reproduction

rg -n 'fastset|sport|cport|port_t' src/platforms/arm/teensy/teensy36/fastpin_arm_k66.h
rg -n 'kTwoWriteStream|kAtomicWrite|writeBitSetClear' src/platforms/shared/spi_bitbang
All-state metadata duplicate searches software SPI Teensy and two write SPI found no identical GPIO-policy optimization issue. Existing #974 concerns cycle-delay underflow, not this missing policy.

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