Skip to content

fix(teensy-lc): implement native SPI single-bit writes used by SM16716 #5059

Closed

Description

@zackees

Context

Two-round baseline 94dab9c source review during #5024 normalization confirms a separate native Teensy LC protocol gap: src/platforms/arm/teensy/teensy_lc/fastspi_arm_kl26.h:196 declares ARMHardwareSPIOutput::writeBit<BIT>(u8) with an empty TODO body. The independently maintained legacy implementation src/platforms/arm/kl26/fastspi_arm_kl26.h:195 has the same empty method; it is not a forwarding alias.

Production call chain is concrete: FL_IS_TEENSY_LC in src/platforms/spi_output_template.h:46-47 includes teensy_lc/spi_output_template.h; its fl::SPIOutput inherits ARMHardwareSPIOutput<DATA_PIN,CLOCK_PIN,DIVIDER,0x40076000> at line 15. SM16716Controller stores that SPIOutput (src/fl/chipsets/sm16716.h:25-27), calls shared writePixelsToSPI<FLAG_START_BIT> in showPixels, then writes its header. The shared writer calls actual writeBit<0>(1) before each RGB triplet (src/platforms/shared/spi_pixel_writer.h:43-49); the header calls actual writeBit<0>(0) twice among six zero bytes (sm16716.h:29-42). The empty methods silently omit the start bit and the two extra header clocks: byte-only transfers are 24 rather than 25 bits per pixel and 48 rather than 50 header bits.

Use stock teensylc config, native SPI0 data/clock 11/13. Canonical enable_pins at 98-120 selects peripheral pin mux for those pins; normal writeByte waits for SPTEF and writes SPIX.DL at 198. A GPIO implementation cannot just write FastPin while peripheral mux owns the pins. waitFully currently checks the transmit-buffer-ready condition, so pending shifter drain must also be considered. This is source-confirmed omitted operations, not a physically measured device report.

Proposal

Implement the native single-bit contract on LC with correct selected-bit semantics and byte/bit ordering, or route affected bit-level protocols to a proven existing software writer. Use actual vendor headers and documented peripheral/mux capabilities; do not fabricate one-bit SPI frame support. Give the separately defined legacy copy an explicit synchronized-or-retired disposition.

Acceptance criteria

  • RED first executes actual production native writeBit: all BIT 0..7 and all 256 values, both zero/one results, must produce one observable clock pulse with the selected data bit. Current empty methods must fail. GREEN after implementation; restoring each empty TODO independently fails its respective test.
  • Execute the actual shared pixel writer and SM16716 header/controller path for multiple pixels with bit-aware GPIO/peripheral observation. Verify each pixel has one HIGH start bit plus 24 data bits, header is exactly 50 LOW bits, and no interleaved pending byte is truncated. Do not test a copied SPI writer or merely the policy flag.
  • Model real mux ownership and transmit-buffer versus shift-register busy state. Test byte-to-bit-to-byte handoff, idle/no-prior-byte calls, control/mux restoration and unrelated pin preservation. A fixture that counts invisible PORT writes while SPI owns the pins is insufficient.
  • Compile actual teensylc native SPIOutput/controller instantiations on pins 11/13 using repository wrappers and target vendor headers; cover selected-bit constant patterns and runtime input in emitted code. Include the legacy header's actual implementation in separate guarded coverage without redefining/copying the writer. Hardware throughput requires physical measurements and is not an acceptance claim here.

Decisions

P2 native bit-level correctness. Separate from #5039, which optimizes normal FastPin policies consumed by GenericSoftwareSPIOutput and cannot implement this native ARMHardwareSPIOutput method. Keep pure hardware byte transfers outside generic GPIO speedup claims. Root will add a distinct required evidence registry slot; this issue is discovery-only and no code/tests/builds were changed in this filing step.

Reproduction

git show 94dab9c6b:src/platforms/arm/teensy/teensy_lc/fastspi_arm_kl26.h and corresponding legacy path show the actual empty methods.
Metadata-only all-state duplicate queries KL26 writeBit and Teensy LC SM16716 found no same component/intent duplicate. Unscreened issue bodies were not ingested.

Activity

  1. added
    sanitized
    on Nov 5, 2026
  2. zackees commented on Nov 7, 2026

    @zackees
    MemberAuthor

    #5142 implements writeBit for Teensy LC and is in the merge queue. This issue stays open for: inspection of emitted code for constant and runtime inputs, and hardware or waveform evidence, since the simulator shares the fix's timing assumptions. The drain's one-bus-clock-per-read assumption and the register layout were also not checked against the KL26 reference manual or a device.

  3. moved this from Triage to Done in FastLED Trackeron Nov 22, 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