Skip to content

singleton: migrate remaining ISR-touching drivers — LPUART, RMT5 peripheral, LCD_CAM, MCPWM (Tier 2c) #3491

Closed as not planned

Description

@zackees

Part of #3481 (Tier 2c).

Task

Apply the cached-pointer-in-IRAM pattern (validated by #3489 and #3490) to the remaining ISR-touching parallel-IO drivers.

Files in scope

Approach

  • Prefer one PR per driver (LPUART, RMT5 peripheral, LCD_CAM, MCPWM — 4 PRs), not one giant PR — each driver needs its own hardware validation.
  • Piggyback these onto other PRs that already touch each driver, rather than scheduling a marathon of touch-only-Singleton PRs.
  • Each PR verified with the driver's autoresearch profile.

Pattern

Copy the pattern from #3489 verbatim. struct DriverState, IRAM cached pointer, begin() sets pointer, ISR uses cached pointer, non-ISR uses Singleton<T>::instance().

Acceptance criteria (per driver)

  • File clean of SingletonElisionChecker warnings except cached pointer.
  • Driver's autoresearch profile passes on real hardware.
  • bash bloat <board> --examples Blink shows the driver's data footprint elided.

Activity

  1. added
    type: feature
    priority: medium
    area: drivers
    on Jul 1, 2026
  2. zackees commented on Jul 28, 2026

    @zackees
    MemberAuthor

    Audited against the finding in #3754 / #3486: fl::Singleton elision pays off only for objects with dynamic initialization (those register .init_array entries that pull in a ctor and resist --gc-sections). It does nothing for constant-initialized PODs — builds already pass -ffunction-sections -fdata-sections (ci/boards.py:795), so those are already dropped when unreferenced. For PODs the wrap is a net loss: storage grows by a T*, every access gains a null-check, and constant-initialization (race-free) is replaced by Singleton<T>::instance()'s hand-rolled if (!ptr), which bypasses the C++11 magic-static guard.

    All 10 hits are constant-initialized PODs, and two of the four target paths are stale.

    • lpuart_driver.cpp.hpp:180-182,188-189 — same shape as singleton: migrate flexio_driver state (Tier 2b) #3490.
    • rmt5_peripheral_esp.cpp.hpp:140,265,268,271 — four volatile debug counters written from ISR context. Same ISR-vs-lazy-init objection as singleton: migrate flexio_driver state (Tier 2b) #3490, amplified.
    • drivers/mcpwm/mcpwm_timer.cpp.hpp is actually drivers/gpio_isr_rx/mcpwm_timer.cpp.hpp; its single hit is L76 static const char* MCPWM_TIMER_TAG = "mcpwm_timer"; — a pointer to a string literal.
    • drivers/lcd_rgb/ is actually drivers/lcd_cam/, and it has zero hits.

    Recommend closing as not-planned. See #3492.

  3. zackees commented on Aug 20, 2026

    @zackees
    MemberAuthor

    Closing as not planned after checking every named driver against current master.

    The proposed blanket migration does not produce the stated elision benefit:

    • LPUART's targeted pointer/bool/u32 fields are constant-initialized POD, several ISR-touched.
    • RMT5 already uses Singleton<Rmt5PeripheralESPImpl> for the real peripheral object. Its remaining file-scope hits are constant-initialized volatile diagnostic counters/GPIO state used from callback/ISR paths.
    • MCPWM has already been narrowed: MCPWM_TIMER_TAG is constexpr, and the actual McpwmState is already behind Singleton<McpwmState>.
    • LCD_CAM's remaining annotated s_vsync_cb_data is a zero-initialized three-pointer callback context whose address is registered with the IDF ISR callback. Moving it behind a lazy singleton plus a cached pointer would add storage and a lifetime invariant without eliminating a dynamic initializer.

    Per-data sections plus linker GC already remove these POD sections when their driver TUs are unreachable. The cached-pointer workaround would add one pointer and indirection per driver precisely to preserve ISR safety around storage that is already constant-initialized and race-free. No measurable Blink data-footprint drop can follow from that transformation.

    Parent #3481 is closed; the actually useful MCPWM constant/singleton cleanup has already landed. The remaining work should not be manufactured into four hardware PRs.

  4. moved this from Triage to Done in FastLED Trackeron Aug 20, 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

    area: driverspriority: mediumtype: feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions