Skip to content

feat(teensy): fork optional framework subsystems into tree-shakeable FastLED platform code #3696

Closed
FastLED/fbuild
#1097

Description

@zackees

Context

FastLED's Teensy integration currently reaches the external Teensy framework libraries through broad dependencies, most notably:

  • Audio.h for Teensy audio/I2S support
  • Arduino SD.h / Teensy's SdFat compatibility layer for filesystem support
  • SerialFlash and related Audio playback dependencies
  • Framework DMA and global/static subsystem state

This causes ordinary Teensy sketches to select and retain code that they do not use. The monolithic Teensy Audio.h header exposes the complete Audio library, including SD and SerialFlash playback paths. Framework globals and static DMA state can then become linker roots or retain RAM even when the feature is unused.

The existing Teensy bloat investigation is tracked in #2656. The current Audio LDF shim also intentionally includes Audio.h so PlatformIO LDF and fbuild discover the dependency, but this solves dependency discovery by selecting too much code.

Proposal

Fork the required Teensy implementations into FastLED-owned platform code:

src/platforms/arm/teensy/
audio/
sdfat/
serialflash/

Copy only the implementations needed by FastLED, document their upstream repositories and revisions, and refactor the fork to comply with FastLED's C++ conventions and lint rules.

The migration should:

  1. Remove FastLED's dependency on Audio.h.
  2. Route the Teensy I2S audio engine through FastLED's internal audio/ implementation.
  3. Move required SD/SdFat and SerialFlash support behind FastLED-owned, feature-specific implementations.
  4. Replace framework-level global objects with fl::singleton-managed state.
  5. Avoid unconditional static constructors, registration objects, address-taken storage, and unrelated DMA buffers.
  6. Keep each subsystem in independently discardable sections so LTO and section garbage collection can remove it when unused.
  7. Use the correct Teensy/audio/filesystem feature guards.
  8. Ensure platform source files are visible to FastLED's C++ lint and review tooling.
  9. Preserve upstream provenance and make future synchronization with Teensy framework updates practical.

fl::singleton should provide lazy, function-local access to subsystem state. When a Blink sketch never requests Audio, SD, or SerialFlash state, there should be no reference path to the singleton storage, constructor, or implementation sections. This is not sufficient by itself: the fork must also avoid unconditional registration, used attributes, and cross-subsystem references that create artificial linker roots.

Acceptance criteria

  • src/platforms/arm/teensy/ldf_headers.h no longer includes Audio.h.
  • A Teensy 4.1 Blink build does not select the external Teensy Audio library.
  • Teensy 4.1 Blink's final linked Flash and RAM usage return to the expected pre-regression baseline; no budget increase is accepted as the fix.
  • A Teensy I2S/audio example still compiles through FastLED's internal implementation.
  • The internal I2S implementation preserves the existing FastLED audio API and behavior.
  • An ordinary Blink build contains no retained Audio, SD, SdFat, SerialFlash, or unrelated Audio DMA symbols.
  • A build that explicitly uses SD/SdFat, SerialFlash, or audio pulls in only the corresponding implementation.
  • PlatformIO LDF and fbuild both discover and build the internal feature implementations correctly.
  • FastLED C++ lint and the relevant Teensy build/test checks pass.
  • The forked sources include upstream provenance and any intentional FastLED changes are documented.

Related issues

  • teensy41 Apa102 binary 148KB / 88KB budget — async logger + HTTP/task pulled into SPI sketch #2656 ? Teensy APA102 binary bloat and unrelated framework code being retained.

  • Run fbuild bloat (or the Teensy-supported equivalent) on the before/after Teensy Blink ELF and document the symbol-level report, confirming Flash/RAM return to the established baseline and that the unwanted Audio, SD, SdFat, SerialFlash, and DMA symbols are absent.

  • Confirm the Teensy HydroPack I2S example compiles successfully and uses FastLED's internal Teensy I2S implementation rather than the external monolithic Audio.h dependency.

Activity

  1. zackees commented on Jul 16, 2026

    @zackees
    MemberAuthor

    Implementation progress:

    • FastLED now owns the minimal PJRC I2S capture subset under src/platforms/arm/teensy/audio/, with upstream provenance and lazy fl::Singleton state.
    • ldf_headers.h no longer includes Audio.h; the I2S adapter uses the private implementation.
    • A targeted C++ lint pass succeeds.
    • bash compile teensy41 --examples Blink succeeds at the established size baseline (100,352 B Flash; 72,544 B RAM).
    • bash compile teensy41 --examples hydropack --no-filter succeeds, proving the internal Teensy I2S path compiles.
    • FastLED's Teensy filesystem path now avoids <SD.h> and routes through a private lazy SdFat adapter.

    The final Blink symbol criterion remains blocked by fbuild LDF self-selection: a fresh fbuild lib-select selects Audio, SD, SdFat, and SerialFlash from their own framework headers/sources, and the linked Blink ELF still retains the framework SD global (1,236 B) plus DMAChannel code. Cross-repo blocker: FastLED/fbuild#1094.

  2. zackees commented on Jul 16, 2026

    @zackees
    MemberAuthor

    Validation update: FastLED now owns the imported Teensy Audio/SdFat subset and Blink + HydroPack compile successfully. The remaining external SD/SdFat/Audio symbol bloat is isolated to fbuild LDF self-selection: lib-select --explain scans 2,254 sources and selects each framework extra from its own headers/sources, despite Blink not reaching those headers. The required fix is tracked in FastLED/fbuild#1094: sketch-rooted transitive resolution, with candidate libraries excluded from nominating themselves.

  3. zackees commented on Jul 16, 2026

    @zackees
    MemberAuthor

    Cross-repo resolver fix is now in FastLED/fbuild#1097. Its live Blink selector run no longer selects Audio, SD, SdFat, or SerialFlash. This FastLED PR will remain open until #1097 lands and a fresh Teensy Blink ELF/bloat report confirms the linked symbol reduction.

  4. zackees commented on Jul 16, 2026

    @zackees
    MemberAuthor

    The root-selection PR (FastLED/fbuild#1097) is open, and the remaining inactive-conditional selector behavior is now explicitly tracked by FastLED/fbuild#1098. #3696 remains open pending both resolver fixes plus the final Blink symbol/bloat proof.

  5. zackees commented on Jul 16, 2026

    @zackees
    MemberAuthor

    Fresh fbuild-native Teensy 4.1 Blink evidence on the FastLED migration branch:

    • Link result: 100,352 B flash / 72,544 B RAM (the historical baseline).
    • bash bloat teensy41 --top 25 still reports upstream SDClass/SdFat payload, including SDClass::format, FatFile::open, and SdBase<...>::begin.

    This is the expected remaining fbuild 2.5.2 LDF false-positive: the private FastLED Teensy imports are not the source of those symbols. The linked payload will be remeasured after the sketch-rooted and active-conditional LDF fixes in fbuild #1097 and #1099 are merged/released.

  6. moved this from Triage to Done in FastLED Trackeron Jul 16, 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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions