Skip to content

feat(esp32): remove <esp32-hal.h> Arduino fallbacks from clock_cycles.h - #3732

Merged
zackees merged 1 commit into
masterfrom
feat/esp32-clock-cycles-idf-native
Jul 22, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/esp32-clock-cycles-idf-native

Conversation

@zackees

@zackees zackees commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

Closes #3717. Part of meta #3715 (ESP Arduino-decoupling).

Problem

clock_cycles.h had two fallback branches including the Arduino core's <esp32-hal.h> for the CPU cycle counter. Both were dead weight in practice:

  • The branch they served (Xtensa targets) already reads CCOUNT directly via inline asm in __clock_cycles() — the ifdef chain in clock_cycles.h only matters for RISC-V targets.
  • RISC-V ESP32 variants (C2/C3/C5/C6/H2) never shipped on an Arduino-ESP32 core old enough to need the removed <hal/cpu_ll.h>-predating branch, so that branch was effectively unreachable dead code.

Also channel_driver_rmt4.h had a redundant direct <esp32-hal.h> include — it already includes clock_cycles.h and uses its __clock_cycles() helper.

Fix

  • Remove both <esp32-hal.h> branches from clock_cycles.h. The IDF-native chain (hal/cpu_hal.h on IDF5+, hal/cpu_ll.h on IDF4.3+, esp_cpu.h, xtensa/hal.h) covers every real ESP32 toolchain. The final fallback now reads CCOUNT via inline asm on Xtensa or hard-errors with a clear message instead of silently depending on the Arduino core.
  • Remove the redundant <esp32-hal.h> include from channel_driver_rmt4.h.

Test plan

Summary by CodeRabbit

  • Bug Fixes
    • Improved ESP32 timing support across supported processor targets.
    • Removed reliance on an obsolete platform header, improving compatibility with newer ESP32 environments.
    • Builds now provide a clearer error when the required cycle-counter support is unavailable.

clock_cycles.h had two fallback branches that included the Arduino core's
<esp32-hal.h> for the CPU cycle counter. Both are dead weight: the branch
those served (Xtensa targets) already reads CCOUNT directly via inline
asm in __clock_cycles() (the ifdef chain in this file only matters for
RISC-V targets, which never shipped on an Arduino-ESP32 core old enough
to need the removed <hal/cpu_ll.h>-predating branch). Remove both
esp32-hal.h branches; the IDF-native chain (hal/cpu_hal.h on IDF5+,
hal/cpu_ll.h on IDF4.3+, esp_cpu.h, xtensa/hal.h) already covers every
real ESP32 toolchain. The final fallback now reads CCOUNT via inline asm
on Xtensa or hard-errors with a clear message instead of silently
depending on the Arduino core.

Also removes the redundant direct <esp32-hal.h> include from
channel_driver_rmt4.h (RMT4 driver), which already includes
clock_cycles.h and uses its __clock_cycles() helper.

Part of #3715. Closes #3717.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The ESP32 cycle-counter header removes Arduino-core fallbacks, adds direct Xtensa ccount access, and reports unsupported non-Xtensa configurations at compile time. The RMT4 driver removes its redundant <esp32-hal.h> include.

Changes

ESP32 cycle counter cleanup

Layer / File(s) Summary
Cycle counter selection and fallback
src/platforms/esp/32/core/clock_cycles.h
Removes <esp32-hal.h> selection paths, adds fl/stl/noexcept.h, uses Xtensa ccount assembly, and emits an error for unsupported non-Xtensa targets.
RMT4 header cleanup
src/platforms/esp/32/drivers/rmt/rmt_4/channel_driver_rmt4.h
Removes the redundant IWYU-guarded <esp32-hal.h> include.

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

Possibly related issues

  • #3715 — Removes the Arduino-specific cycle-counter dependencies described by the issue.
  • #3722 — Replaces Arduino-specific ESP32 header usage with capability-based cycle-counter handling.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: removing esp32-hal fallbacks from clock_cycles.h.
Linked Issues check ✅ Passed The diff removes the Arduino fallback include from clock_cycles.h and the redundant RMT4 include, aligning with #3717's requested cleanup.
Out of Scope Changes check ✅ Passed The changes are limited to the two ESP32 headers named in the issue and do not introduce unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/esp32-clock-cycles-idf-native

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/platforms/esp/32/core/clock_cycles.h`:
- Around line 46-54: Move the definition of __cpu_hal_get_cycle_count out of
clock_cycles.h, leaving only its declaration there. Add the complete
FASTLED_XTENSA/__XTENSA__ implementation and fallback error handling to the
matching implementation file, preserving the existing signature and behavior.
- Line 47: Replace the newly added FASTLED_XTENSA preprocessor check with the
repository-standard FL_IS_XTENSA platform detection, preserving the existing
Xtensa conditional behavior without introducing any new FASTLED_* defined check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9ccb6afd-a2e7-4123-ba2d-a9c15cfb8b07

📥 Commits

Reviewing files that changed from the base of the PR and between 1404736 and 20e3061.

📒 Files selected for processing (2)
  • src/platforms/esp/32/core/clock_cycles.h
  • src/platforms/esp/32/drivers/rmt/rmt_4/channel_driver_rmt4.h
💤 Files with no reviewable changes (1)
  • src/platforms/esp/32/drivers/rmt/rmt_4/channel_driver_rmt4.h

@zackees
zackees merged commit 3a20d0a into master Jul 22, 2026
22 checks passed
@zackees
zackees deleted the feat/esp32-clock-cycles-idf-native branch July 22, 2026 19:27
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jul 22, 2026
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.

esp32: remove <esp32-hal.h> Arduino fallbacks from clock_cycles.h (+ rmt4 driver cascade)

1 participant