[pulse_counter] Fix compilation on ESP32-C6/C5/H2/P4#14070
Conversation
SOC_MOD_CLK_APB does not exist in the soc_module_clk_t enum on ESP32-C6, C5, H2, and P4 variants. Revert to esp_clk_apb_freq() which works on all variants and is the same function the ESP-IDF PCNT driver uses internally for glitch filter calculation.
|
To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file: external_components:
- source: github://pr#14070
components: [pulse_counter]
refresh: 1h(Added by the PR bot) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #14070 +/- ##
=======================================
Coverage 74.11% 74.11%
=======================================
Files 55 55
Lines 11589 11589
Branches 1578 1578
=======================================
Hits 8589 8589
Misses 2598 2598
Partials 402 402 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Memory Impact AnalysisComponents:
This analysis runs automatically when components change. Memory usage is measured from a representative test configuration. |
There was a problem hiding this comment.
Pull request overview
Fixes ESP32-C6/C5/H2/P4 build failures in pulse_counter by avoiding use of the removed SOC_MOD_CLK_APB clock enum when computing the PCNT glitch filter timing.
Changes:
- Replace
esp_clk_tree_src_get_freq_hz(SOC_MOD_CLK_APB, ...)withesp_clk_apb_freq()for APB frequency lookup in the glitch filter calculation. - Switch the included clock header from
esp_clk_tree.htoesp_private/esp_clk.hto accessesp_clk_apb_freq().
What does this implement/fix?
Fixes compilation error on ESP32-C6 (and C5, H2, P4) where
SOC_MOD_CLK_APBdoes not exist in thesoc_module_clk_tenum. These newer variants removed the APB clock enum entry — C6 hasSOC_MOD_CLK_PLL_F80Minstead.#13908 replaced
esp_clk_apb_freq()withesp_clk_tree_src_get_freq_hz(SOC_MOD_CLK_APB, ...)for the PCNT glitch filter calculation. While theesp_clk_treemigration was correct for the RMT components (usingRMT_CLK_SRC_DEFAULT), PCNT has no equivalent portable clock source enum.This reverts the pulse_counter portion back to
esp_clk_apb_freq()fromesp_private/esp_clk.h, which is the approach introduced in #13904. Sorry @swoboda1337 — I shouldn't have pushed back on the private API usage in #13908. It turns outesp_clk_apb_freq()is what the ESP-IDF PCNT driver itself uses internally for glitch filter calculation (pulse_cnt.c:404), it works correctly on all ESP32 variants, and there's simply no public API equivalent. It's what we're stuck with until Espressif provides one.Types of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are added/changed: