Skip to content

perf(teensy4): adopt generic software-SPI full-port and atomic pin policies #5026

Closed

Description

@zackees

Context

Two-round audit at 94dab9c for #5024 confirms the i.MXRT1062 normal FastPin implementation at src/platforms/arm/teensy/teensy4_common/fastpin_arm_mxrt1062.h:25-51 has a 32-bit full output latch (port, fastset) and atomic write-one set/clear (sport, cport). It retains default BitbangPin policy false values (src/platforms/shared/spi_bitbang/bitbang_pin.h:34-36), missing both existing exclusive same-port two-write streaming and branchless writeBitSetClear data updates.

Production path: src/platforms/arm/fastpin_arm.h:27-29 selects the canonical header. src/platforms/arm/teensy/teensy4_common/spi_output_template.h:17-20,31-54 selects GenericSoftwareSPIOutput for non-LPSPI pairs; pins 0/1 share GPIO6, pins 0/2 are separate GPIO6/9. Public SoftwareSPIOutput also reaches it (src/fastspi.h:107). APA102 public writeByte calls (src/fl/chipsets/apa102.h:43,57-69) can benefit from atomic data updates, but do not call bulk stream APIs. src/platforms/arm/mxrt1062/fastpin_arm_mxrt1062.h is a separately retained legacy copy; canonical dispatch does not select it. LPSPI/FlexIO/ObjectFLED peripheral drivers are excluded.

Proposal

Specialize pin policy for canonical normal i.MXRT FastPin only: full-port streaming for exclusive same-port bulk calls; set/clear data updates for public-byte, separate-port and interrupt mode. Preserve forced software pins. Give the legacy copy an explicit synchronized-or-retired disposition.

Acceptance criteria

  • RED before change: production pin policy fails the desired streaming/atomic selection checks. GREEN after implementation; reverting either policy opt-in fails its check.
  • Verify MSB-first sampled data, 16 bulk stream stores per byte plus final clock-low for nonempty transactions, empty and multibyte inputs, unrelated bits, bytes/value/pixels, and public writeByte completion.
  • Separate ports and FAST_SPI_INTERRUPTS_WRITE_PINS use selected set/clear aliases and preserve simulated concurrent unrelated changes; no full-port snapshots there.
  • Compile teensy40/41 through actual dispatch for 0/1, 0/2, hardware 11/13, forced software pins and interrupt mode. Preserve LPSPI routing.
  • Correct timing units: Teensy4 SPI_SPEED is Hz with nanosecond timing (generic_software_spi.h:169-172); the shared kNeedsGpioPadding currently assumes cycles, so do not enable cycle-overhead metadata without resolving this mismatch. Keep fix(teensy4): avoid MHz truncation in software-SPI phase delays #5027 arithmetic fix separate.
  • Store-count evidence does not establish hardware speed; measure physically before making throughput claims.

Decisions

P2 optimization. Independently defined Kinetis backends get separate native sibling issues. This issue covers only i.MXRT1062. No builds/source changes during discovery; orchestrator owns RED/GREEN.

Reproduction

rg -n 'fastset|sport|cport|port_t' src/platforms/arm/teensy/teensy4_common/fastpin_arm_mxrt1062.h
rg -n 'kAtomicWrite|kTwoWriteStream|writeBitSetClear' src/platforms/shared/spi_bitbang
All-state metadata duplicate searches software SPI Teensy, two write SPI found no same optimization; #1579 and #974 concern different support/timing problems.

Activity

  1. added
    sanitized
    on Nov 5, 2026
  2. changed the title [-]perf(teensy): adopt generic software-SPI full-port and atomic pin policies[/-] [+]perf(teensy4): adopt generic software-SPI full-port and atomic pin policies[/+] on Nov 5, 2026
  3. added
    sanitized
    and removed
    sanitized
    on Nov 5, 2026
  4. moved this from Triage to Done in FastLED Trackeron Nov 6, 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