Skip to content

fix(esp32): preserve one-bit SPI writes instead of expanding them to bytes #5060

Closed

Description

@zackees

Context

Two-round baseline 94dab9c review for #5024 confirms native ESP32 writeBit transmits eight clocks instead of one. This differs from #5028 explicit software GPIO optimization and #5051 software rate-unit correctness.

Actual production chain: src/platforms/spi_output_template.h selects ESP32 src/platforms/esp/32/drivers/spi/spi_output_template.h; its SPIOutput (line15) inherits SPIDeviceProxy. Proxy writeBit at spi_device_proxy.h:230-234 invokes writeByte with 0xff/0x00, which directly forwards to mSingleSPI or buffers a whole byte for Quad SPI. Default ESP32SPIOutput backend is native IDF; src/platforms/esp/32/core/fastspi_esp32.h:44-56 instead selects the separately implemented Arduino backend when FL_ESP32_SPI_ARDUINO=1 and ARDUINO is defined.

The native IDF method src/platforms/esp/32/core/fastspi_esp32_idf.h:588-592 also writes a full byte. The Arduino method src/platforms/arduino/spi/fastspi_esp32_arduino.h:226-230 uses SPIClass.transfer(0xff/0x00), likewise a byte. These are three actual method definitions, not interchangeable aliases. core/fastspi_esp32_arduino.h is only a forwarding include.

Named producer: SM16716Controller stores platform SPIOutput (src/fl/chipsets/sm16716.h:25-27), invokes shared writePixelsToSPI<FLAG_START_BIT> (showPixels), then writeHeader. The shared writer (src/platforms/shared/spi_pixel_writer.h:43-49) requests one HIGH bit before each 24-bit RGB triplet. The header requests two individual LOW bits among six zero bytes (sm16716.h:29-42). Expanding each requested bit into a byte produces 32 rather than 25 clocks per pixel and 64 rather than 50 header clocks. Correct selected-bit value does not fix the wrong bit count. Source proves the submitted payload width; no physical device trace is claimed.

Proposal

Provide an actual one-bit native transaction/bit-stream packing contract supported by the target SPI backend, or route the whole affected bit-level protocol through a proven software SPI writer. Preserve bit/byte order and buffered transaction boundaries. Do not use fake GPIO writes while a peripheral mux owns the pins. Handle both proxy paths and direct legacy backend APIs explicitly; compile-time unsupported configurations must fail honestly instead of silently widening bits.

Acceptance criteria

  • RED first executes actual proxy/default IDF and opt-in Arduino production paths against bit-length-aware peripheral observation: each writeBit(value) requests exactly one bit. Current byte substitution must fail; all BIT0..7 and 256 values have correct selected-bit data after GREEN.
  • Execute actual SM16716 controller/shared pixel/header sequence for multiple pixels: each start bit plus RGB is 25 bits; header is exactly50 LOW bits. Include adjacent bit calls, bit/byte/bit, select/release/finalize flush boundaries and consecutive frames.
  • Default single-SPI, Quad proxy buffering (or an explicit documented rejection/fallback), direct ESP32SPIOutput APIs, FL_ESP32_SPI_ARDUINO=1+ARDUINO, and native IDF builds receive separate dispositions. Mutate each repaired method back to full-byte transfer independently and require failure.
  • Compile real ESP32 Xtensa and RISC-V target configurations with repository wrappers and actual SDK headers (e.g. esp32dev, esp32c3/esp32c6); compile the Arduino escape hatch on a compatible Arduino core. If using a native one-bit API, validate requested transfer length in target code, not only an artificial host flag.
  • Preserve normal byte-only APA102 transfers, data order, rate and mux ownership. Any device throughput/timing claim needs physical capture; source/host coverage establishes protocol requests only.

Decisions

P2 protocol correctness. Group the proxy plus two independently implemented backends because the user-visible one-bit contract and SM16716 caller require coordinated repair; require separate method mutation gates. Keep generic software GPIO/rate findings separate. This issue does not cover the unrelated empty Arduino-core generic wrapper TODO, whose selector reachability still needs confirmation.

Reproduction

git show 94dab9c6b:src/platforms/esp/32/drivers/spi/spi_device_proxy.h
git show 94dab9c6b:src/platforms/esp/32/core/fastspi_esp32_idf.h
git show 94dab9c6b:src/platforms/arduino/spi/fastspi_esp32_arduino.h
Metadata-only all-state duplicate searches ESP32 writeBit byte and ESP32 SM16716 start found no same bit-width report; unscreened bodies were not ingested. No code/tests/builds changed during discovery.

Activity

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

    @zackees
    MemberAuthor

    #5143 fixes the native IDF path and is in the merge queue. This issue stays open for: the Arduino backend, which still sends a byte; test execution of SPIDeviceProxy, which is only build-checked; and device or waveform evidence that the peripheral clocks non-byte lengths correctly.

  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