Skip to content

fix: normalize ESP32 explicit software SPI rate units #5051

Closed

Description

@zackees

Context

Two source investigation rounds at 94dab9c for #5024; no builds/tests. src/fastspi.h:82-89 makes DATA_RATE_MHZ/KHZ return Hz for ESP32, e.g. DATA_RATE_MHZ(1) = 1000000. Its public SoftwareSPIOutput (:117-119) forwards that value unchanged to GenericSoftwareSPIOutput. Only FL_IS_TEENSY_4X gets the Hz interpretation (generic_software_spi.h:169-172); ESP32 follows cycle-divider delay macros (:174-198). Thus a documented rate macro for explicit ESP32 software SPI is consumed as a huge cycle count instead of converted to a CPU-period divider. Normal SPIOutput hardware proxy uses Hz correctly and must retain that contract.

Proposal

Normalize explicit ESP32 software-output rate units at a clear dispatch/type boundary, preserving Hz semantics for hardware SPI and documenting the public software template parameter. Keep literal-divider compatibility where it is part of the existing API contract; resolve ambiguity explicitly rather than heuristic value guessing.

Acceptance criteria

  • Capture RED compile/code-generation or production delay trace for SoftwareSPIOutput<valid_data,valid_clock,DATA_RATE_MHZ(1)> and DATA_RATE_KHZ variants on ESP32. Show GREEN requested period normalization at actual CPU clocks after the fix; exercise scalar/bulk/pixel/start-bit APIs and slow/fast boundaries.
  • Compile actual ESP32/S2/S3 and RISC-V C3/C6/P4 board configurations using vendor cores, including CPU-frequency variations; verify hardware SPIOutput still receives the unchanged Hz value and explicit software path is selected.
  • Check unsigned padding bounds, code-size growth for slow rates, tiny-delay calls and minimum pulse constraints. Generated code/host delay tracing does not imply physical timing; device measurements via AutoResearch/fbuild are required for physical rate claims.
  • Restore old raw-Hz forwarding or cycle-delay interpretation as a mutation; the focused rate test must fail and return GREEN after restoration. Changing metadata/flags without executing the software path must fail shared gate test: gate software SPI changes on exhaustive production-path and mutation evidence #5031.

Decisions

  • Separate correctness child from ESP32 atomic sequence optimization perf: optimize ESP32 explicit software SPI atomic GPIO sequence #5028; fixing fewer MMIO stores cannot correct the rate-unit mismatch.
  • Normal ESP32 hardware SPI rate contract remains Hz. The explicit SoftwareSPIOutput public path is the reproducible production entry point.
  • Duplicate metadata searches software SPI ESP32/BitbangPin found no verified screened same unit-contract issue; screened ESP32 software-SPI title query returned none.

Open questions

Clarify compatibility for downstream code supplying literal software dividers on ESP32 before changing the template contract. Next step is the focused failing production-rate repro; no physical speedup is claimed.

Activity

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

    @zackees
    MemberAuthor

    Contract decision for this fix (not in the coming release): SoftwareSPIOutput<..., RATE> on ESP32 takes Hz, matching DATA_RATE_* and the hardware path, and converts to cycles inside the wrapper. Values below 1000 are rejected at compile time, so an old literal divider fails loudly. fl::GenericSoftwareSPIOutput remains the cycle-divider path. A literal of 1000 or more would be reinterpreted, so the release notes must call that out.

  3. zackees commented on Nov 6, 2026

    @zackees
    MemberAuthor

    Note from #5028 validation: SoftwareSPIOutput<...,DATA_RATE_MHZ(1)> failed to link on ESP32 at baseline (undefined delaycycles<499991>).

  4. zackees commented on Nov 7, 2026

    @zackees
    MemberAuthor

    #5129 adds the Hz-to-divider conversion, so this stays open. Still unmet: a committed test that fails when the ESP32 branch is reverted (host builds skip it; the RED/GREEN came from a temporary sketch probe), delay traces of scalar, bulk, pixel and start-bit APIs, CPU-frequency variations, code-size and minimum-pulse checks, device timing, and gate #5031. Literal divider semantics changed on ESP32 and need maintainer confirmation; see the PR body.

  5. zackees commented on Nov 22, 2026

    @zackees
    MemberAuthor

    Closing via #5411. Host test: SoftwareSPIOutput<2,3,DATA_RATE_MHZ(1)/KHZ(250)/KHZ(100)> must derive from the bitbangDividerFromHz divider; removing the #5129 Hz branch fails 5 checks. ESP32-C6 bench (fastPinLoopback, jumper GPIO0->GPIO1): 250 kHz = 4651-4653 ns, 100 kHz = 10653-10654 ns, difference 6001-6003 ns (want 6000 +/-5%); the legacy writer gives 4550 ns, difference 5941-6068 ns. The constant ~650 ns per-bit excess is the writer's GPIO work, added on top of the requested delay.

    Not covered, left as stated limitations: ESP32/S2/S3/C3/P4 builds, CPU-frequency variation, code-size and minimum-pulse checks, scalar/pixel/start-bit delay traces, and gate #5031. The question about literal-divider semantics is open in the PR body.

  6. 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