Skip to content

perf(esp32s3): link the ADC driver only when fl::analogRead is used (#4796) - #4804

Merged
zackees merged 1 commit into
masterfrom
perf/4796-adc-own-tu
Oct 9, 2026
Merged

zackees merged 1 commit into
masterfrom
perf/4796-adc-own-tu

Conversation

@zackees

@zackees zackees commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Part of #4801. Fixes #4796.

Root cause (linker map)

main.o → fl.channels+ (IChannelDriver::waitForReady) → fl.system+ (delayMicroseconds)
  fl.system+ also contains fl::analogRead → adc_oneshot_new_unit (strong ref)
  → libesp_adc.a(adc_oneshot.c.obj) → adc_common.c.obj

adc_common.c.obj carries a .ctors constructor, adc_hw_calibration. Constructors are always kept, so every ESP32-S3 sketch ran ADC self-calibration at boot and linked the efuse calibration path:

  • adc_hal_self_calibration, adc_hal_arbiter_config, read_cal_channel;
  • esp_efuse_utility_*, esp_efuse_rtc_calib_*.

Archive extraction follows any undefined symbol in an extracted object, even when fl::analogRead itself is later discarded by --gc-sections.

Fix

Move the fl::analogRead wrapper into its own unity object, fl/build/fl.system.analog+.cpp → fl/system/analog/. This is the same pattern as the #4726 Wi-Fi/OTA split. The declaration stays in fl/system/pin.h.

Evidence (dashboard protocol, fbuild 2.5.38)

flash before → after RAM before → after
esp32s3 Blink 401,876 → 397,480 (−4,396) 77,936 → 77,760 (−176)
esp32s3 APA102 409,656 → 405,244 (−4,412) 77,864 → 77,672 (−192)
esp32dev Blink / APA102 unchanged unchanged
  • A sketch calling fl::analogRead(4) still links fl::analogRead, adc_oneshot_new_unit, adc_oneshot_read and adc_hw_calibration.
  • bash test --cpp: 319/319 unit, 95/95 examples. bash lint passes, with the new unit added to the unity-build list. /code-review: no findings.

Summary by CodeRabbit

  • Bug Fixes
    • Analog input reads now compile through a separate build path rather than the general system build. This keeps analog-related compilation isolated and addresses an ESP32 ADC calibration and linking issue. The change does not alter how callers request an analog reading.

…4796)

fl::analogRead lived in the always-linked fl.system+ unity object. Its IDF
one-shot ADC reference extracted libesp_adc.a(adc_common.c.obj) even when
the function itself was discarded, and that object's .ctors constructor
(adc_hw_calibration) runs ADC self-calibration at boot and links the efuse
calibration path into every sketch.

Move the fl::analogRead wrapper into its own unity object
(fl/build/fl.system.analog+.cpp), following the #4726 net/OTA split.

esp32s3 Blink:  flash 401876 -> 397480 (-4396), RAM 77936 -> 77760 (-176)
esp32s3 APA102: flash 409656 -> 405244 (-4412), RAM 77864 -> 77672 (-192)
esp32dev unchanged. A sketch calling fl::analogRead still links
adc_oneshot_new_unit/adc_oneshot_read and adc_hw_calibration.
bash test --cpp 319/319, 95/95; bash lint clean.
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: FastLED/FastLED/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: de23e3b9-7274-4582-832b-a2f93529dcde
📥 Commits

Reviewing files that changed from the base of the PR and between 18669e6 and c24992f.

📒 Files selected for processing (6)
  • ci/lint_cpp_rs/src/checkers/unity_build.rs
  • src/fl/build/fl.system.analog+.cpp
  • src/fl/system/analog/_build.cpp.hpp
  • src/fl/system/analog/analog_read.cpp.hpp
  • src/fl/system/analog/analog_read.h
  • src/fl/system/pin.cpp.hpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The fl::analogRead(int) implementation moves to a separate analog unity-build entry point. The unity-build checker now includes that entry point in its expected build-file list.

Changes

Analog read separation

Layer / File(s) Summary
Move analogRead implementation
src/fl/system/analog/analog_read.h, src/fl/system/analog/analog_read.cpp.hpp, src/fl/system/pin.cpp.hpp
The analog header exports fl/system/pin.h. The fl::analogRead(int) wrapper delegates to platforms::analogRead(pin) in analog_read.cpp.hpp; its previous definition is removed from pin.cpp.hpp.
Wire separate unity-build entry point
src/fl/system/analog/_build.cpp.hpp, src/fl/build/fl.system.analog+.cpp, ci/lint_cpp_rs/src/checkers/unity_build.rs
A separate unity-build entry point includes the analog implementation. The unity-build checker adds that entry point to its expected build-file list.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to c2499

This change moves the analogRead implementation into its own build unit. Sketches that never call analogRead no longer link the ESP32 ADC calibration code, which reduces flash and RAM use. analogRead behaves the same for sketches that use it. No concrete merge risk was found.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: isolating the ESP32-S3 ADC driver so it links only when fl::analogRead is used.
Linked Issues check Passed Issue #4796 requires the ADC pull-in root cause and a reduction when the ADC path is not used. The PR identifies the chain from fl.system+ through fl::analogRead to adc_common.c.obj and its cali…
Out of Scope Changes check Passed The changes stay within issue #4796. The new unity-build entry, analog wrapper files, removal of the wrapper from pin.cpp.hpp, declaration preservation, and unity-build lint-list update all support …
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zackees
zackees merged commit 1743bbe into master Oct 9, 2026
120 checks passed
zackees added a commit that referenced this pull request Oct 9, 2026
#4797) (#4807)

* perf: yield_system() keeps the task Scheduler out of driver wait loops (#4797)

fl::task::run() dispatches on its flags at runtime, so every SYSTEM-only
wait loop (FastLED.show() refresh throttle, ChannelManager/driver
waitForReady, ESP32 RMT/SPI/I2S/LCD/PARLIO/UART drivers) linked
task::Scheduler, Executor and their singletons into every sketch.

Add fl::task::yield_system(us), the SYSTEM branch of run() with the same
budget semantics, and use it at the 15 SYSTEM-only call sites.

vs master (after #4802/#4804):
esp32dev Blink:  flash 295728 -> 293908 (-1820), RAM 24480 -> 24272 (-208)
esp32dev APA102: flash 290864 -> 289044 (-1820), RAM 23944 -> 23744 (-200)
esp32s3 Blink:   flash 397660 -> 395804 (-1856), RAM 77760 -> 77552 (-208)
esp32s3 APA102:  flash 405416 -> 403576 (-1840), RAM 77672 -> 77488 (-184)
bash test --cpp 319/319, 95/95 (new yield_system test).

* docs: prescribe fl::task::yield_system() for DMA wait loops (#4797 review)

Update the channel-engine wait rule (cpp-standards.md) and the review
checklist: yield_system(us) is the same OS yield as run(us, SYSTEM) without
linking the task Scheduler/Executor.

* docs: finish yield_system rule update; correct host yield claim (#4797 review)
zackees added a commit that referenced this pull request Oct 9, 2026
… (#4814)

* chore(deps): pin fbuild 2.5.39 for the ESP32-S3 QEMU deploy fix (#4813)

fbuild 2.5.39 skips the QEMU ADC-calibration image patch when
adc_hw_calibration is not linked (FastLED/fbuild#1665). Since #4804 the ADC
constructor is no longer linked into ordinary sketches, so 2.5.37/2.5.38
failed every esp32s3_qemu_* deploy.

Local: esp32s3 QEMU BlinkParallel and DriverTest
(QEMU_LCD_CLOCKLESS_REGISTRATION: PASS) both pass with 2.5.39.

* ci: re-run after fbuild 2.5.39 reached the PyPI index

* test(bloat): re-base ESP32-S3 budget/baseline for fbuild 2.5.39 accounting (#4813)

Same firmware, new measurement: fbuild 2.5.38+ attributes weak vtable
owners (fbuild#1663), so attributed RAM reads 40016 B (was 37844 B on
2.5.37) and the image 342099 B (was 342083 B). Section RAM over #4801 fell
77936 -> 77200 B. Re-base authorized by the maintainer.

* fix(bloat): pass --nm/--cppfilt to fbuild symbols (fbuild 2.5.39, #4813)

fbuild >= 2.5.38 matches the ELF to a build_info environment by prog_path.
Teensy records prog_path as firmware.hex, so 'fbuild symbols' failed with
'no unambiguous environment matches the ELF'. Pass the cross tools from the
single-env build_info.json explicitly, as the dashboard benchmark does.

Local: bash bloat teensy41 / esp32s3 pass; teensy41 budget passes.

* fix(bloat): name the build_info for fbuild symbols; re-base RAM budgets for 2.5.39 (#4813)

- bloat.py: pass --build-info (build_info_<example>.json, else
  build_info.json) with --nm/--cppfilt, so build dirs holding several
  build_info_<example>.json files (esp32c6, esp32dev) are not 'ambiguous'.
- Local sweep of all 11 budgets on fbuild 2.5.39: image sizes identical to
  2.5.37; four RAM budgets fail only on attribution (fbuild#1663). The same
  ELFs measured under budget on 2.5.37:
    esp32c3  24607 -> 26670   esp32c6  29027 -> 33478
    esp32dev 32618 -> 34734   rp2040    8689 ->  9474
  Re-based with the maintainer's authorization; all 11 pass locally.
@zackees
zackees deleted the perf/4796-adc-own-tu branch November 5, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

perf(esp32s3): trace ADC calibration/efuse pull-in (+3.2 KB flash, +0.5 KB RAM)

1 participant