From 6ca90bd14a7370eb38ac31c6b26df11eb69138d2 Mon Sep 17 00:00:00 2001 From: Song Ruo Jing Date: Fri, 12 Dec 2025 21:44:35 +0800 Subject: [PATCH] refactor(ledc): split ledc hal into a separate component --- components/esp_driver_ledc/CMakeLists.txt | 1 + components/esp_driver_ledc/linker.lf | 2 +- components/esp_driver_ledc/src/ledc.c | 2 +- .../test_apps/.build-test-rules.yml | 1 + .../test_apps/ledc/CMakeLists.txt | 8 ++++- .../test_apps/ledc/main/test_ledc_sleep.cpp | 2 +- components/esp_hal_ledc/CMakeLists.txt | 17 +++++++++ components/esp_hal_ledc/README.md | 35 +++++++++++++++++++ .../esp32/include/hal/ledc_ll.h | 11 +++--- .../{soc => esp_hal_ledc}/esp32/ledc_periph.c | 2 +- .../esp32c2/include/hal/ledc_ll.h | 12 +++---- .../esp32c2/ledc_periph.c | 2 +- .../esp32c3/include/hal/ledc_ll.h | 11 +++--- .../esp32c3/ledc_periph.c | 2 +- .../esp32c5/include/hal/ledc_ll.h | 15 ++++---- .../esp32c5/ledc_periph.c | 3 +- .../esp32c6/include/hal/ledc_ll.h | 9 +++-- .../esp32c6/ledc_periph.c | 3 +- .../esp32c61/include/hal/ledc_ll.h | 15 ++++---- .../esp32c61/ledc_periph.c | 3 +- .../esp32h2/include/hal/ledc_ll.h | 9 +++-- .../esp32h2/ledc_periph.c | 3 +- .../esp32h21/include/hal/ledc_ll.h | 9 +++-- .../esp32h21/ledc_periph.c | 3 +- .../esp32h4/include/hal/ledc_ll.h | 15 ++++---- .../esp32h4/ledc_periph.c | 3 +- .../esp32p4/include/hal/ledc_ll.h | 15 ++++---- .../esp32p4/ledc_periph.c | 3 +- .../esp32s2/include/hal/ledc_ll.h | 11 +++--- .../esp32s2}/ledc_periph.c | 2 +- .../esp32s3/include/hal/ledc_ll.h | 11 +++--- .../esp32s3}/ledc_periph.c | 2 +- .../include/hal/ledc_hal.h | 1 - .../include/hal}/ledc_periph.h | 4 +-- .../include/hal/ledc_types.h | 8 ++--- components/{hal => esp_hal_ledc}/ledc_hal.c | 0 .../{hal => esp_hal_ledc}/ledc_hal_iram.c | 0 components/hal/CMakeLists.txt | 4 --- components/soc/CMakeLists.txt | 4 --- docs/doxygen/Doxyfile | 2 +- examples/peripherals/.build-test-rules.yml | 5 +-- 41 files changed, 152 insertions(+), 118 deletions(-) create mode 100644 components/esp_hal_ledc/CMakeLists.txt create mode 100644 components/esp_hal_ledc/README.md rename components/{hal => esp_hal_ledc}/esp32/include/hal/ledc_ll.h (99%) rename components/{soc => esp_hal_ledc}/esp32/ledc_periph.c (93%) rename components/{hal => esp_hal_ledc}/esp32c2/include/hal/ledc_ll.h (99%) rename components/{soc => esp_hal_ledc}/esp32c2/ledc_periph.c (91%) rename components/{hal => esp_hal_ledc}/esp32c3/include/hal/ledc_ll.h (99%) rename components/{soc => esp_hal_ledc}/esp32c3/ledc_periph.c (91%) rename components/{hal => esp_hal_ledc}/esp32c5/include/hal/ledc_ll.h (99%) rename components/{soc => esp_hal_ledc}/esp32c5/ledc_periph.c (99%) rename components/{hal => esp_hal_ledc}/esp32c6/include/hal/ledc_ll.h (99%) rename components/{soc => esp_hal_ledc}/esp32c6/ledc_periph.c (99%) rename components/{hal => esp_hal_ledc}/esp32c61/include/hal/ledc_ll.h (99%) rename components/{soc => esp_hal_ledc}/esp32c61/ledc_periph.c (99%) rename components/{hal => esp_hal_ledc}/esp32h2/include/hal/ledc_ll.h (99%) rename components/{soc => esp_hal_ledc}/esp32h2/ledc_periph.c (99%) rename components/{hal => esp_hal_ledc}/esp32h21/include/hal/ledc_ll.h (99%) rename components/{soc => esp_hal_ledc}/esp32h21/ledc_periph.c (99%) rename components/{hal => esp_hal_ledc}/esp32h4/include/hal/ledc_ll.h (99%) rename components/{soc => esp_hal_ledc}/esp32h4/ledc_periph.c (99%) rename components/{hal => esp_hal_ledc}/esp32p4/include/hal/ledc_ll.h (99%) rename components/{soc => esp_hal_ledc}/esp32p4/ledc_periph.c (99%) rename components/{hal => esp_hal_ledc}/esp32s2/include/hal/ledc_ll.h (99%) rename components/{soc/esp32s3 => esp_hal_ledc/esp32s2}/ledc_periph.c (91%) rename components/{hal => esp_hal_ledc}/esp32s3/include/hal/ledc_ll.h (99%) rename components/{soc/esp32s2 => esp_hal_ledc/esp32s3}/ledc_periph.c (91%) rename components/{hal => esp_hal_ledc}/include/hal/ledc_hal.h (99%) rename components/{soc/include/soc => esp_hal_ledc/include/hal}/ledc_periph.h (94%) rename components/{hal => esp_hal_ledc}/include/hal/ledc_types.h (100%) rename components/{hal => esp_hal_ledc}/ledc_hal.c (100%) rename components/{hal => esp_hal_ledc}/ledc_hal_iram.c (100%) diff --git a/components/esp_driver_ledc/CMakeLists.txt b/components/esp_driver_ledc/CMakeLists.txt index 41b3ca9a9df..e0bf8a9f865 100644 --- a/components/esp_driver_ledc/CMakeLists.txt +++ b/components/esp_driver_ledc/CMakeLists.txt @@ -20,6 +20,7 @@ endif() idf_component_register( SRCS ${srcs} INCLUDE_DIRS ${public_include} + REQUIRES esp_hal_ledc PRIV_REQUIRES "${priv_requires}" LDFRAGMENTS "linker.lf" ) diff --git a/components/esp_driver_ledc/linker.lf b/components/esp_driver_ledc/linker.lf index c1307aebd19..cb89c6b07f3 100644 --- a/components/esp_driver_ledc/linker.lf +++ b/components/esp_driver_ledc/linker.lf @@ -7,7 +7,7 @@ entries: ledc: _ledc_update_duty (noflash) [mapping:ledc_hal] -archive: libhal.a +archive: libesp_hal_ledc.a entries: if SOC_LEDC_SUPPORTED = y: ledc_hal_iram (noflash) diff --git a/components/esp_driver_ledc/src/ledc.c b/components/esp_driver_ledc/src/ledc.c index f138504fe49..b030bf18eb4 100644 --- a/components/esp_driver_ledc/src/ledc.c +++ b/components/esp_driver_ledc/src/ledc.c @@ -12,7 +12,7 @@ #include "freertos/idf_additions.h" #include "esp_log.h" #include "esp_check.h" -#include "soc/ledc_periph.h" +#include "hal/ledc_periph.h" #include "esp_clk_tree.h" #include "soc/soc_caps.h" #include "hal/ledc_hal.h" diff --git a/components/esp_driver_ledc/test_apps/.build-test-rules.yml b/components/esp_driver_ledc/test_apps/.build-test-rules.yml index c9446e000a9..8ea94d8ef14 100644 --- a/components/esp_driver_ledc/test_apps/.build-test-rules.yml +++ b/components/esp_driver_ledc/test_apps/.build-test-rules.yml @@ -9,3 +9,4 @@ components/esp_driver_ledc/test_apps/ledc: reason: p4 rev3 migration # TODO: IDF-14398 depends_components: - esp_driver_ledc + - esp_hal_ledc diff --git a/components/esp_driver_ledc/test_apps/ledc/CMakeLists.txt b/components/esp_driver_ledc/test_apps/ledc/CMakeLists.txt index 4867adf6f5e..34cbeb70bd6 100644 --- a/components/esp_driver_ledc/test_apps/ledc/CMakeLists.txt +++ b/components/esp_driver_ledc/test_apps/ledc/CMakeLists.txt @@ -9,10 +9,16 @@ project(ledc_test) idf_build_get_property(elf EXECUTABLE) if(CONFIG_COMPILER_DUMP_RTL_FILES) + set(LEDC_RTL_DIRS + ${CMAKE_BINARY_DIR}/esp-idf/esp_driver_ledc + ${CMAKE_BINARY_DIR}/esp-idf/hal + ${CMAKE_BINARY_DIR}/esp-idf/esp_hal_ledc + ) + string(JOIN "," LEDC_RTL_DIRS_JOINED ${LEDC_RTL_DIRS}) add_custom_target( check_test_app_sections ALL COMMAND ${PYTHON} $ENV{IDF_PATH}/tools/ci/check_callgraph.py - --rtl-dirs ${CMAKE_BINARY_DIR}/esp-idf/esp_driver_ledc/,${CMAKE_BINARY_DIR}/esp-idf/hal/ + --rtl-dirs ${LEDC_RTL_DIRS_JOINED} --elf-file ${CMAKE_BINARY_DIR}/ledc_test.elf find-refs --from-sections=.iram0.text diff --git a/components/esp_driver_ledc/test_apps/ledc/main/test_ledc_sleep.cpp b/components/esp_driver_ledc/test_apps/ledc/main/test_ledc_sleep.cpp index 1a3ea5c8820..8fa8962b32b 100644 --- a/components/esp_driver_ledc/test_apps/ledc/main/test_ledc_sleep.cpp +++ b/components/esp_driver_ledc/test_apps/ledc/main/test_ledc_sleep.cpp @@ -14,7 +14,7 @@ #include "esp_private/sleep_cpu.h" #include "esp_private/esp_sleep_internal.h" #include "esp_private/esp_pmu.h" -#include "soc/ledc_periph.h" +#include "hal/ledc_periph.h" #include "esp_private/sleep_retention.h" #include "esp_rom_serial_output.h" diff --git a/components/esp_hal_ledc/CMakeLists.txt b/components/esp_hal_ledc/CMakeLists.txt new file mode 100644 index 00000000000..a19547aa97e --- /dev/null +++ b/components/esp_hal_ledc/CMakeLists.txt @@ -0,0 +1,17 @@ +idf_build_get_property(target IDF_TARGET) + +set(srcs) +set(includes "include") + +# Add target-specific include directory if it exists +if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/${target}/include") + list(APPEND includes "${target}/include") +endif() + +if(CONFIG_SOC_LEDC_SUPPORTED) + list(APPEND srcs "ledc_hal.c" "ledc_hal_iram.c" "${target}/ledc_periph.c") +endif() + +idf_component_register(SRCS ${srcs} + INCLUDE_DIRS ${includes} + REQUIRES soc hal) diff --git a/components/esp_hal_ledc/README.md b/components/esp_hal_ledc/README.md new file mode 100644 index 00000000000..f0478943e8e --- /dev/null +++ b/components/esp_hal_ledc/README.md @@ -0,0 +1,35 @@ +# ESP Hardware Abstraction Layer for LEDC Peripheral + +> [!NOTE] +> This component is currently in beta. Its API, behavior, and compatibility may change at any time and without notice; backward compatibility is not guaranteed. Use caution when integrating into production systems. + +## Overview + +The `esp_hal_ledc` component provides a **Hardware Abstraction Layer** for the LEDC (LED PWM Controller) peripheral across all ESP-IDF supported targets. + +## Architecture + +The LEDC HAL is structured in two main sub-layers: + +1. **HAL Layer (Upper)**: Defines the operational steps and data structures required to control LEDC (e.g., timer/channel configuration, duty updates, fade and low-power helpers). +2. **Low-Level Layer (Bottom)**: Serves as a translation layer between the HAL and the register files defined in the `soc` component, handling target-specific register configurations. + +## Features + +- Multi-timer and multi-channel PWM generation +- High-speed and low-speed modes (on supported chips) +- Duty cycle setting and smooth fading +- Timer resolution and frequency configuration +- Interrupt-driven operations +- Low-power helpers (on supported chips) + +## Usage + +The HAL functions primarily serve ESP-IDF peripheral drivers such as `esp_driver_ledc`. + +Advanced developers can use these interfaces directly when implementing custom drivers, with the understanding that API stability is not guaranteed. + +## Dependencies + +- `soc`: Provides chip-specific register definitions +- `hal`: Core hardware abstraction utilities and macros diff --git a/components/hal/esp32/include/hal/ledc_ll.h b/components/esp_hal_ledc/esp32/include/hal/ledc_ll.h similarity index 99% rename from components/hal/esp32/include/hal/ledc_ll.h rename to components/esp_hal_ledc/esp32/include/hal/ledc_ll.h index d1febc47086..80979435d02 100644 --- a/components/hal/esp32/include/hal/ledc_ll.h +++ b/components/esp_hal_ledc/esp32/include/hal/ledc_ll.h @@ -10,14 +10,10 @@ #pragma once #include "hal/ledc_types.h" -#include "soc/ledc_periph.h" #include "soc/ledc_struct.h" +#include "soc/ledc_reg.h" #include "soc/dport_reg.h" -#ifdef __cplusplus -extern "C" { -#endif - #define LEDC_LL_GET_HW() &LEDC #define LEDC_LL_DUTY_NUM_MAX (LEDC_DUTY_NUM_LSCH0_V) @@ -43,6 +39,10 @@ extern "C" { ((SPEED) == LEDC_HIGH_SPEED_MODE && (CLK) == LEDC_USE_APB_CLK) \ ) +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Enable peripheral register clock * @@ -580,7 +580,6 @@ static inline volatile void* ledc_ll_get_fade_end_intr_addr(ledc_dev_t *hw) return &hw->int_st.val; } - /** * @brief Clear fade end interrupt status * diff --git a/components/soc/esp32/ledc_periph.c b/components/esp_hal_ledc/esp32/ledc_periph.c similarity index 93% rename from components/soc/esp32/ledc_periph.c rename to components/esp_hal_ledc/esp32/ledc_periph.c index d3b2fca7983..1b6b63b56ef 100644 --- a/components/soc/esp32/ledc_periph.c +++ b/components/esp_hal_ledc/esp32/ledc_periph.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/ledc_periph.h" +#include "hal/ledc_periph.h" #include "soc/gpio_sig_map.h" /* diff --git a/components/hal/esp32c2/include/hal/ledc_ll.h b/components/esp_hal_ledc/esp32c2/include/hal/ledc_ll.h similarity index 99% rename from components/hal/esp32c2/include/hal/ledc_ll.h rename to components/esp_hal_ledc/esp32c2/include/hal/ledc_ll.h index 332ed2e4cbb..a7ea3023c60 100644 --- a/components/hal/esp32c2/include/hal/ledc_ll.h +++ b/components/esp_hal_ledc/esp32c2/include/hal/ledc_ll.h @@ -10,14 +10,11 @@ #pragma once #include "hal/ledc_types.h" -#include "soc/ledc_periph.h" +#include "soc/ledc_struct.h" +#include "soc/ledc_reg.h" #include "soc/system_struct.h" #include "hal/assert.h" -#ifdef __cplusplus -extern "C" { -#endif - #define LEDC_LL_GET_HW() &LEDC #define LEDC_LL_CHANNEL_SUPPORT_OVF_CNT 1 @@ -40,6 +37,10 @@ extern "C" { #define LEDC_LL_GLOBAL_CLK_NC_BY_DEFAULT 1 #define LEDC_LL_GLOBAL_CLK_DEFAULT LEDC_SLOW_CLK_RC_FAST // The temporal global clock source to set to at least make the LEDC core clock on +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Enable peripheral register clock * @@ -557,7 +558,6 @@ static inline volatile void* ledc_ll_get_fade_end_intr_addr(ledc_dev_t *hw) return &hw->int_st.val; } - /** * @brief Clear fade end interrupt status * diff --git a/components/soc/esp32c2/ledc_periph.c b/components/esp_hal_ledc/esp32c2/ledc_periph.c similarity index 91% rename from components/soc/esp32c2/ledc_periph.c rename to components/esp_hal_ledc/esp32c2/ledc_periph.c index bba8416cf49..74de14b3f66 100644 --- a/components/soc/esp32c2/ledc_periph.c +++ b/components/esp_hal_ledc/esp32c2/ledc_periph.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/ledc_periph.h" +#include "hal/ledc_periph.h" #include "soc/gpio_sig_map.h" /* diff --git a/components/hal/esp32c3/include/hal/ledc_ll.h b/components/esp_hal_ledc/esp32c3/include/hal/ledc_ll.h similarity index 99% rename from components/hal/esp32c3/include/hal/ledc_ll.h rename to components/esp_hal_ledc/esp32c3/include/hal/ledc_ll.h index f8bfa0f9bd3..6b78ae8e858 100644 --- a/components/hal/esp32c3/include/hal/ledc_ll.h +++ b/components/esp_hal_ledc/esp32c3/include/hal/ledc_ll.h @@ -10,15 +10,11 @@ #pragma once #include "hal/ledc_types.h" -#include "soc/ledc_periph.h" #include "soc/ledc_struct.h" +#include "soc/ledc_reg.h" #include "soc/system_struct.h" #include "hal/assert.h" -#ifdef __cplusplus -extern "C" { -#endif - #define LEDC_LL_GET_HW() &LEDC #define LEDC_LL_CHANNEL_SUPPORT_OVF_CNT 1 @@ -42,6 +38,10 @@ extern "C" { #define LEDC_LL_GLOBAL_CLK_NC_BY_DEFAULT 1 #define LEDC_LL_GLOBAL_CLK_DEFAULT LEDC_SLOW_CLK_RC_FAST // The temporal global clock source to set to at least make the LEDC core clock on +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Enable peripheral register clock * @@ -559,7 +559,6 @@ static inline volatile void* ledc_ll_get_fade_end_intr_addr(ledc_dev_t *hw) return &hw->int_st.val; } - /** * @brief Clear fade end interrupt status * diff --git a/components/soc/esp32c3/ledc_periph.c b/components/esp_hal_ledc/esp32c3/ledc_periph.c similarity index 91% rename from components/soc/esp32c3/ledc_periph.c rename to components/esp_hal_ledc/esp32c3/ledc_periph.c index 0ea7d06015a..4dd0b3080b1 100644 --- a/components/soc/esp32c3/ledc_periph.c +++ b/components/esp_hal_ledc/esp32c3/ledc_periph.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/ledc_periph.h" +#include "hal/ledc_periph.h" #include "soc/gpio_sig_map.h" /* diff --git a/components/hal/esp32c5/include/hal/ledc_ll.h b/components/esp_hal_ledc/esp32c5/include/hal/ledc_ll.h similarity index 99% rename from components/hal/esp32c5/include/hal/ledc_ll.h rename to components/esp_hal_ledc/esp32c5/include/hal/ledc_ll.h index a41609bd646..e3dbdc966b8 100644 --- a/components/hal/esp32c5/include/hal/ledc_ll.h +++ b/components/esp_hal_ledc/esp32c5/include/hal/ledc_ll.h @@ -18,10 +18,6 @@ #include "soc/soc_caps.h" #include "soc/soc_etm_source.h" -#ifdef __cplusplus -extern "C" { -#endif - #define LEDC_LL_GET_HW() &LEDC #define LEDC_LL_CHANNEL_SUPPORT_OVF_CNT 1 @@ -125,6 +121,10 @@ extern "C" { [LEDC_TIMER_ETM_EVENT_OVF] = BIT(LEDC_EVT_TIME_OVF_TIMER0_EN_S), \ }}[(group)][(event)] << (timer)) +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Enable peripheral register clock * @@ -205,8 +205,7 @@ static inline void ledc_ll_set_slow_clk_sel(ledc_dev_t *hw, ledc_slow_clk_sel_t { (void) hw; uint32_t clk_sel_val = 3; - switch (slow_clk_sel) - { + switch (slow_clk_sel) { case LEDC_SLOW_CLK_XTAL: clk_sel_val = 0; break; @@ -234,8 +233,7 @@ static inline void ledc_ll_set_slow_clk_sel(ledc_dev_t *hw, ledc_slow_clk_sel_t static inline void ledc_ll_get_slow_clk_sel(ledc_dev_t *hw, ledc_slow_clk_sel_t *slow_clk_sel) { (void) hw; - switch (PCR.ledc_sclk_conf.ledc_sclk_sel) - { + switch (PCR.ledc_sclk_conf.ledc_sclk_sel) { case 0: *slow_clk_sel = LEDC_SLOW_CLK_XTAL; break; @@ -646,7 +644,6 @@ static inline volatile void* ledc_ll_get_fade_end_intr_addr(ledc_dev_t *hw) return &hw->int_st.val; } - /** * @brief Clear fade end interrupt status * diff --git a/components/soc/esp32c5/ledc_periph.c b/components/esp_hal_ledc/esp32c5/ledc_periph.c similarity index 99% rename from components/soc/esp32c5/ledc_periph.c rename to components/esp_hal_ledc/esp32c5/ledc_periph.c index 5a55b87b28e..2b12ea977a3 100644 --- a/components/soc/esp32c5/ledc_periph.c +++ b/components/esp_hal_ledc/esp32c5/ledc_periph.c @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/ledc_periph.h" +#include "hal/ledc_periph.h" #include "soc/gpio_sig_map.h" +#include "soc/ledc_reg.h" /* Bunch of constants for every LEDC peripheral: GPIO signals diff --git a/components/hal/esp32c6/include/hal/ledc_ll.h b/components/esp_hal_ledc/esp32c6/include/hal/ledc_ll.h similarity index 99% rename from components/hal/esp32c6/include/hal/ledc_ll.h rename to components/esp_hal_ledc/esp32c6/include/hal/ledc_ll.h index 8627c86da07..d7d80d29841 100644 --- a/components/hal/esp32c6/include/hal/ledc_ll.h +++ b/components/esp_hal_ledc/esp32c6/include/hal/ledc_ll.h @@ -19,10 +19,6 @@ #include "soc/soc_caps.h" #include "soc/soc_etm_source.h" -#ifdef __cplusplus -extern "C" { -#endif - #define LEDC_LL_GET_HW() &LEDC #define LEDC_LL_CHANNEL_SUPPORT_OVF_CNT 1 @@ -129,6 +125,10 @@ extern "C" { [LEDC_TIMER_ETM_EVENT_OVF] = BIT(LEDC_EVT_TIME_OVF_TIMER0_EN_S), \ }}[(group)][(event)] << (timer)) +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Enable peripheral register clock * @@ -768,7 +768,6 @@ static inline volatile void* ledc_ll_get_fade_end_intr_addr(ledc_dev_t *hw) return &hw->int_st.val; } - /** * @brief Clear fade end interrupt status * diff --git a/components/soc/esp32c6/ledc_periph.c b/components/esp_hal_ledc/esp32c6/ledc_periph.c similarity index 99% rename from components/soc/esp32c6/ledc_periph.c rename to components/esp_hal_ledc/esp32c6/ledc_periph.c index 2f40e4dc762..68812a88ef7 100644 --- a/components/soc/esp32c6/ledc_periph.c +++ b/components/esp_hal_ledc/esp32c6/ledc_periph.c @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/ledc_periph.h" +#include "hal/ledc_periph.h" #include "soc/gpio_sig_map.h" +#include "soc/ledc_reg.h" /* Bunch of constants for every LEDC peripheral: GPIO signals diff --git a/components/hal/esp32c61/include/hal/ledc_ll.h b/components/esp_hal_ledc/esp32c61/include/hal/ledc_ll.h similarity index 99% rename from components/hal/esp32c61/include/hal/ledc_ll.h rename to components/esp_hal_ledc/esp32c61/include/hal/ledc_ll.h index 5e404899b03..339f82f935e 100644 --- a/components/hal/esp32c61/include/hal/ledc_ll.h +++ b/components/esp_hal_ledc/esp32c61/include/hal/ledc_ll.h @@ -18,10 +18,6 @@ #include "soc/soc_caps.h" #include "soc/soc_etm_source.h" -#ifdef __cplusplus -extern "C" { -#endif - #define LEDC_LL_GET_HW() &LEDC #define LEDC_LL_CHANNEL_SUPPORT_OVF_CNT 1 @@ -125,6 +121,10 @@ extern "C" { [LEDC_TIMER_ETM_EVENT_OVF] = BIT(LEDC_EVT_TIME_OVF_TIMER0_EN_S), \ }}[(group)][(event)] << (timer)) +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Enable peripheral register clock * @@ -205,8 +205,7 @@ static inline void ledc_ll_set_slow_clk_sel(ledc_dev_t *hw, ledc_slow_clk_sel_t { (void) hw; uint32_t clk_sel_val = 3; - switch (slow_clk_sel) - { + switch (slow_clk_sel) { case LEDC_SLOW_CLK_XTAL: clk_sel_val = 0; break; @@ -234,8 +233,7 @@ static inline void ledc_ll_set_slow_clk_sel(ledc_dev_t *hw, ledc_slow_clk_sel_t static inline void ledc_ll_get_slow_clk_sel(ledc_dev_t *hw, ledc_slow_clk_sel_t *slow_clk_sel) { (void) hw; - switch (PCR.ledc_sclk_conf.ledc_sclk_sel) - { + switch (PCR.ledc_sclk_conf.ledc_sclk_sel) { case 0: *slow_clk_sel = LEDC_SLOW_CLK_XTAL; break; @@ -646,7 +644,6 @@ static inline volatile void* ledc_ll_get_fade_end_intr_addr(ledc_dev_t *hw) return &hw->int_st.val; } - /** * @brief Clear fade end interrupt status * diff --git a/components/soc/esp32c61/ledc_periph.c b/components/esp_hal_ledc/esp32c61/ledc_periph.c similarity index 99% rename from components/soc/esp32c61/ledc_periph.c rename to components/esp_hal_ledc/esp32c61/ledc_periph.c index 7273244c17e..5c6228cced3 100644 --- a/components/soc/esp32c61/ledc_periph.c +++ b/components/esp_hal_ledc/esp32c61/ledc_periph.c @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/ledc_periph.h" +#include "hal/ledc_periph.h" #include "soc/gpio_sig_map.h" +#include "soc/ledc_reg.h" /* Bunch of constants for every LEDC peripheral: GPIO signals diff --git a/components/hal/esp32h2/include/hal/ledc_ll.h b/components/esp_hal_ledc/esp32h2/include/hal/ledc_ll.h similarity index 99% rename from components/hal/esp32h2/include/hal/ledc_ll.h rename to components/esp_hal_ledc/esp32h2/include/hal/ledc_ll.h index abf361d60d0..e2e703448f9 100644 --- a/components/hal/esp32h2/include/hal/ledc_ll.h +++ b/components/esp_hal_ledc/esp32h2/include/hal/ledc_ll.h @@ -19,10 +19,6 @@ #include "soc/soc_caps.h" #include "soc/soc_etm_source.h" -#ifdef __cplusplus -extern "C" { -#endif - #define LEDC_LL_GET_HW() &LEDC #define LEDC_LL_CHANNEL_SUPPORT_OVF_CNT 1 @@ -126,6 +122,10 @@ extern "C" { [LEDC_TIMER_ETM_EVENT_OVF] = BIT(LEDC_EVT_TIME_OVF_TIMER0_EN_S), \ }}[(group)][(event)] << (timer)) +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Enable peripheral register clock * @@ -765,7 +765,6 @@ static inline volatile void* ledc_ll_get_fade_end_intr_addr(ledc_dev_t *hw) return &hw->int_st.val; } - /** * @brief Clear fade end interrupt status * diff --git a/components/soc/esp32h2/ledc_periph.c b/components/esp_hal_ledc/esp32h2/ledc_periph.c similarity index 99% rename from components/soc/esp32h2/ledc_periph.c rename to components/esp_hal_ledc/esp32h2/ledc_periph.c index 2f40e4dc762..68812a88ef7 100644 --- a/components/soc/esp32h2/ledc_periph.c +++ b/components/esp_hal_ledc/esp32h2/ledc_periph.c @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/ledc_periph.h" +#include "hal/ledc_periph.h" #include "soc/gpio_sig_map.h" +#include "soc/ledc_reg.h" /* Bunch of constants for every LEDC peripheral: GPIO signals diff --git a/components/hal/esp32h21/include/hal/ledc_ll.h b/components/esp_hal_ledc/esp32h21/include/hal/ledc_ll.h similarity index 99% rename from components/hal/esp32h21/include/hal/ledc_ll.h rename to components/esp_hal_ledc/esp32h21/include/hal/ledc_ll.h index 2cdff6975c5..6bf9caf660b 100644 --- a/components/hal/esp32h21/include/hal/ledc_ll.h +++ b/components/esp_hal_ledc/esp32h21/include/hal/ledc_ll.h @@ -19,10 +19,6 @@ #include "soc/soc_caps.h" #include "soc/soc_etm_source.h" -#ifdef __cplusplus -extern "C" { -#endif - #define LEDC_LL_GET_HW() &LEDC #define LEDC_LL_CHANNEL_SUPPORT_OVF_CNT 1 @@ -126,6 +122,10 @@ extern "C" { [LEDC_TIMER_ETM_EVENT_OVF] = BIT(LEDC_EVT_TIME_OVF_TIMER0_EN_S), \ }}[(group)][(event)] << (timer)) +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Enable peripheral register clock * @@ -764,7 +764,6 @@ static inline volatile void* ledc_ll_get_fade_end_intr_addr(ledc_dev_t *hw) return &hw->int_st.val; } - /** * @brief Clear fade end interrupt status * diff --git a/components/soc/esp32h21/ledc_periph.c b/components/esp_hal_ledc/esp32h21/ledc_periph.c similarity index 99% rename from components/soc/esp32h21/ledc_periph.c rename to components/esp_hal_ledc/esp32h21/ledc_periph.c index 2eedbe2f59e..2deb689613d 100644 --- a/components/soc/esp32h21/ledc_periph.c +++ b/components/esp_hal_ledc/esp32h21/ledc_periph.c @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/ledc_periph.h" +#include "hal/ledc_periph.h" #include "soc/gpio_sig_map.h" +#include "soc/ledc_reg.h" /* Bunch of constants for every LEDC peripheral: GPIO signals diff --git a/components/hal/esp32h4/include/hal/ledc_ll.h b/components/esp_hal_ledc/esp32h4/include/hal/ledc_ll.h similarity index 99% rename from components/hal/esp32h4/include/hal/ledc_ll.h rename to components/esp_hal_ledc/esp32h4/include/hal/ledc_ll.h index 0da791024a6..fcb6d6417e7 100644 --- a/components/hal/esp32h4/include/hal/ledc_ll.h +++ b/components/esp_hal_ledc/esp32h4/include/hal/ledc_ll.h @@ -18,10 +18,6 @@ #include "soc/soc_caps.h" #include "soc/soc_etm_source.h" -#ifdef __cplusplus -extern "C" { -#endif - #define LEDC_LL_GET_HW() &LEDC #define LEDC_LL_CHANNEL_SUPPORT_OVF_CNT 1 @@ -125,6 +121,10 @@ extern "C" { [LEDC_TIMER_ETM_EVENT_OVF] = BIT(LEDC_EVT_TIME_OVF_TIMER0_EN_S), \ }}[(group)][(event)] << (timer)) +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Enable peripheral register clock * @@ -211,8 +211,7 @@ static inline void ledc_ll_set_slow_clk_sel(ledc_dev_t *hw, ledc_slow_clk_sel_t { (void) hw; uint32_t clk_sel_val = 3; - switch (slow_clk_sel) - { + switch (slow_clk_sel) { case LEDC_SLOW_CLK_XTAL: clk_sel_val = 0; break; @@ -240,8 +239,7 @@ static inline void ledc_ll_set_slow_clk_sel(ledc_dev_t *hw, ledc_slow_clk_sel_t static inline void ledc_ll_get_slow_clk_sel(ledc_dev_t *hw, ledc_slow_clk_sel_t *slow_clk_sel) { (void) hw; - switch (PCR.ledc_sclk_conf.ledc_sclk_sel) - { + switch (PCR.ledc_sclk_conf.ledc_sclk_sel) { case 0: *slow_clk_sel = LEDC_SLOW_CLK_XTAL; break; @@ -593,7 +591,6 @@ static inline volatile void* ledc_ll_get_fade_end_intr_addr(ledc_dev_t *hw) return &hw->int_st.val; } - /** * @brief Clear fade end interrupt status * diff --git a/components/soc/esp32h4/ledc_periph.c b/components/esp_hal_ledc/esp32h4/ledc_periph.c similarity index 99% rename from components/soc/esp32h4/ledc_periph.c rename to components/esp_hal_ledc/esp32h4/ledc_periph.c index a5dd818aa92..ecff4c90811 100644 --- a/components/soc/esp32h4/ledc_periph.c +++ b/components/esp_hal_ledc/esp32h4/ledc_periph.c @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/ledc_periph.h" +#include "hal/ledc_periph.h" #include "soc/gpio_sig_map.h" +#include "soc/ledc_reg.h" /* Bunch of constants for every LEDC peripheral: GPIO signals diff --git a/components/hal/esp32p4/include/hal/ledc_ll.h b/components/esp_hal_ledc/esp32p4/include/hal/ledc_ll.h similarity index 99% rename from components/hal/esp32p4/include/hal/ledc_ll.h rename to components/esp_hal_ledc/esp32p4/include/hal/ledc_ll.h index 5c3a65afbf6..cdcc5da36b7 100644 --- a/components/hal/esp32p4/include/hal/ledc_ll.h +++ b/components/esp_hal_ledc/esp32p4/include/hal/ledc_ll.h @@ -18,10 +18,6 @@ #include "soc/soc_caps.h" #include "soc/soc_etm_source.h" -#ifdef __cplusplus -extern "C" { -#endif - #define LEDC_LL_GET_HW() &LEDC #define LEDC_LL_CHANNEL_SUPPORT_OVF_CNT 1 @@ -125,6 +121,10 @@ extern "C" { [LEDC_TIMER_ETM_EVENT_OVF] = BIT(LEDC_EVT_TIME_OVF_TIMER0_EN_S), \ }}[(group)][(event)] << (timer)) +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Enable peripheral register clock * @@ -224,8 +224,7 @@ static inline void ledc_ll_set_slow_clk_sel(ledc_dev_t *hw, ledc_slow_clk_sel_t { (void) hw; uint32_t clk_sel_val = 3; - switch (slow_clk_sel) - { + switch (slow_clk_sel) { case LEDC_SLOW_CLK_XTAL: clk_sel_val = 0; break; @@ -260,8 +259,7 @@ static inline void ledc_ll_set_slow_clk_sel(ledc_dev_t *hw, ledc_slow_clk_sel_t static inline void ledc_ll_get_slow_clk_sel(ledc_dev_t *hw, ledc_slow_clk_sel_t *slow_clk_sel) { (void) hw; - switch (HP_SYS_CLKRST.peri_clk_ctrl22.reg_ledc_clk_src_sel) - { + switch (HP_SYS_CLKRST.peri_clk_ctrl22.reg_ledc_clk_src_sel) { case 0: *slow_clk_sel = LEDC_SLOW_CLK_XTAL; break; @@ -671,7 +669,6 @@ static inline volatile void* ledc_ll_get_fade_end_intr_addr(ledc_dev_t *hw) return &hw->int_st.val; } - /** * @brief Clear fade end interrupt status * diff --git a/components/soc/esp32p4/ledc_periph.c b/components/esp_hal_ledc/esp32p4/ledc_periph.c similarity index 99% rename from components/soc/esp32p4/ledc_periph.c rename to components/esp_hal_ledc/esp32p4/ledc_periph.c index dfce02a6095..7be6fcddc89 100644 --- a/components/soc/esp32p4/ledc_periph.c +++ b/components/esp_hal_ledc/esp32p4/ledc_periph.c @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/ledc_periph.h" +#include "hal/ledc_periph.h" #include "soc/gpio_sig_map.h" +#include "soc/ledc_reg.h" /* Bunch of constants for every LEDC peripheral: GPIO signals diff --git a/components/hal/esp32s2/include/hal/ledc_ll.h b/components/esp_hal_ledc/esp32s2/include/hal/ledc_ll.h similarity index 99% rename from components/hal/esp32s2/include/hal/ledc_ll.h rename to components/esp_hal_ledc/esp32s2/include/hal/ledc_ll.h index fac0e731c68..53f332acb45 100644 --- a/components/hal/esp32s2/include/hal/ledc_ll.h +++ b/components/esp_hal_ledc/esp32s2/include/hal/ledc_ll.h @@ -10,15 +10,11 @@ #pragma once #include "hal/ledc_types.h" -#include "soc/ledc_periph.h" #include "soc/ledc_struct.h" +#include "soc/ledc_reg.h" #include "soc/dport_reg.h" #include "hal/assert.h" -#ifdef __cplusplus -extern "C" { -#endif - #define LEDC_LL_GET_HW() &LEDC #define LEDC_LL_CHANNEL_SUPPORT_OVF_CNT 1 @@ -47,6 +43,10 @@ extern "C" { #define LEDC_LL_GLOBAL_CLK_NC_BY_DEFAULT 1 #define LEDC_LL_GLOBAL_CLK_DEFAULT LEDC_SLOW_CLK_RC_FAST // The temporal global clock source to set to at least make the LEDC core clock on +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Enable peripheral register clock * @@ -598,7 +598,6 @@ static inline volatile void* ledc_ll_get_fade_end_intr_addr(ledc_dev_t *hw) return &hw->int_st.val; } - /** * @brief Clear fade end interrupt status * diff --git a/components/soc/esp32s3/ledc_periph.c b/components/esp_hal_ledc/esp32s2/ledc_periph.c similarity index 91% rename from components/soc/esp32s3/ledc_periph.c rename to components/esp_hal_ledc/esp32s2/ledc_periph.c index d508be2a32e..b3b3922fb13 100644 --- a/components/soc/esp32s3/ledc_periph.c +++ b/components/esp_hal_ledc/esp32s2/ledc_periph.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/ledc_periph.h" +#include "hal/ledc_periph.h" #include "soc/gpio_sig_map.h" /* diff --git a/components/hal/esp32s3/include/hal/ledc_ll.h b/components/esp_hal_ledc/esp32s3/include/hal/ledc_ll.h similarity index 99% rename from components/hal/esp32s3/include/hal/ledc_ll.h rename to components/esp_hal_ledc/esp32s3/include/hal/ledc_ll.h index 873badf7fd2..ced69bd3aeb 100644 --- a/components/hal/esp32s3/include/hal/ledc_ll.h +++ b/components/esp_hal_ledc/esp32s3/include/hal/ledc_ll.h @@ -10,15 +10,11 @@ #pragma once #include "hal/ledc_types.h" -#include "soc/ledc_periph.h" #include "soc/ledc_struct.h" +#include "soc/ledc_reg.h" #include "soc/system_struct.h" #include "hal/assert.h" -#ifdef __cplusplus -extern "C" { -#endif - #define LEDC_LL_GET_HW() &LEDC #define LEDC_LL_CHANNEL_SUPPORT_OVF_CNT 1 @@ -42,6 +38,10 @@ extern "C" { #define LEDC_LL_GLOBAL_CLK_NC_BY_DEFAULT 1 #define LEDC_LL_GLOBAL_CLK_DEFAULT LEDC_SLOW_CLK_RC_FAST // The temporal global clock source to set to at least make the LEDC core clock on +#ifdef __cplusplus +extern "C" { +#endif + /** * @brief Enable peripheral register clock * @@ -559,7 +559,6 @@ static inline volatile void* ledc_ll_get_fade_end_intr_addr(ledc_dev_t *hw) return &hw->int_st.val; } - /** * @brief Clear fade end interrupt status * diff --git a/components/soc/esp32s2/ledc_periph.c b/components/esp_hal_ledc/esp32s3/ledc_periph.c similarity index 91% rename from components/soc/esp32s2/ledc_periph.c rename to components/esp_hal_ledc/esp32s3/ledc_periph.c index d508be2a32e..b3b3922fb13 100644 --- a/components/soc/esp32s2/ledc_periph.c +++ b/components/esp_hal_ledc/esp32s3/ledc_periph.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "soc/ledc_periph.h" +#include "hal/ledc_periph.h" #include "soc/gpio_sig_map.h" /* diff --git a/components/hal/include/hal/ledc_hal.h b/components/esp_hal_ledc/include/hal/ledc_hal.h similarity index 99% rename from components/hal/include/hal/ledc_hal.h rename to components/esp_hal_ledc/include/hal/ledc_hal.h index aba8a4bdbc5..e858624440d 100644 --- a/components/hal/include/hal/ledc_hal.h +++ b/components/esp_hal_ledc/include/hal/ledc_hal.h @@ -25,7 +25,6 @@ extern "C" { #endif - #if SOC_LEDC_SUPPORTED /** * Context that should be maintained by both the driver and the HAL diff --git a/components/soc/include/soc/ledc_periph.h b/components/esp_hal_ledc/include/hal/ledc_periph.h similarity index 94% rename from components/soc/include/soc/ledc_periph.h rename to components/esp_hal_ledc/include/hal/ledc_periph.h index 066dc5ca7c9..e384bafe458 100644 --- a/components/soc/include/soc/ledc_periph.h +++ b/components/esp_hal_ledc/include/hal/ledc_periph.h @@ -7,8 +7,6 @@ #pragma once #include "soc/soc_caps.h" -#include "soc/ledc_reg.h" -#include "soc/ledc_struct.h" #if SOC_PAU_SUPPORTED #include "soc/regdma.h" #include "soc/retention_periph_defs.h" @@ -22,7 +20,7 @@ extern "C" { Stores a bunch of per-ledc-peripheral data. */ typedef struct { - const uint8_t sig_out0_idx; + const int sig_out0_idx; } ledc_signal_conn_t; #if SOC_LEDC_SUPPORT_HS_MODE diff --git a/components/hal/include/hal/ledc_types.h b/components/esp_hal_ledc/include/hal/ledc_types.h similarity index 100% rename from components/hal/include/hal/ledc_types.h rename to components/esp_hal_ledc/include/hal/ledc_types.h index 116681c5682..0a1871ac21a 100644 --- a/components/hal/include/hal/ledc_types.h +++ b/components/esp_hal_ledc/include/hal/ledc_types.h @@ -6,15 +6,15 @@ #pragma once -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include "soc/soc_caps.h" #include "soc/clk_tree_defs.h" +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { #if SOC_LEDC_SUPPORT_HS_MODE LEDC_HIGH_SPEED_MODE = 0, /*!< LEDC high speed speed_mode */ diff --git a/components/hal/ledc_hal.c b/components/esp_hal_ledc/ledc_hal.c similarity index 100% rename from components/hal/ledc_hal.c rename to components/esp_hal_ledc/ledc_hal.c diff --git a/components/hal/ledc_hal_iram.c b/components/esp_hal_ledc/ledc_hal_iram.c similarity index 100% rename from components/hal/ledc_hal_iram.c rename to components/esp_hal_ledc/ledc_hal_iram.c diff --git a/components/hal/CMakeLists.txt b/components/hal/CMakeLists.txt index 001f6104e2e..cbe1dc18e1e 100644 --- a/components/hal/CMakeLists.txt +++ b/components/hal/CMakeLists.txt @@ -84,10 +84,6 @@ elseif(NOT BOOTLOADER_BUILD) list(APPEND srcs "uart_hal.c" "uart_hal_iram.c") endif() - if(CONFIG_SOC_LEDC_SUPPORTED) - list(APPEND srcs "ledc_hal.c" "ledc_hal_iram.c") - endif() - if(CONFIG_SOC_I3C_MASTER_SUPPORTED) list(APPEND srcs "i3c_master_hal.c") endif() diff --git a/components/soc/CMakeLists.txt b/components/soc/CMakeLists.txt index 418493676dd..79e399b69a6 100644 --- a/components/soc/CMakeLists.txt +++ b/components/soc/CMakeLists.txt @@ -72,10 +72,6 @@ if(CONFIG_SOC_EMAC_SUPPORTED) list(APPEND srcs "${target_folder}/emac_periph.c") endif() -if(CONFIG_SOC_LEDC_SUPPORTED) - list(APPEND srcs "${target_folder}/ledc_periph.c") -endif() - if(CONFIG_SOC_I3C_MASTER_SUPPORTED) list(APPEND srcs "${target_folder}/i3c_master_periph.c") endif() diff --git a/docs/doxygen/Doxyfile b/docs/doxygen/Doxyfile index 868562ffde4..c6bca01fa2b 100644 --- a/docs/doxygen/Doxyfile +++ b/docs/doxygen/Doxyfile @@ -173,6 +173,7 @@ INPUT = \ $(PROJECT_PATH)/components/esp_hal_i2c/include/hal/i2c_types.h \ $(PROJECT_PATH)/components/esp_hal_i2s/include/hal/i2s_types.h \ $(PROJECT_PATH)/components/esp_hal_lcd/include/hal/lcd_types.h \ + $(PROJECT_PATH)/components/esp_hal_ledc/include/hal/ledc_types.h \ $(PROJECT_PATH)/components/esp_hal_parlio/include/hal/parlio_types.h \ $(PROJECT_PATH)/components/esp_hal_mspi/include/hal/esp_flash_err.h \ $(PROJECT_PATH)/components/esp_hal_mspi/include/hal/spi_flash_types.h \ @@ -264,7 +265,6 @@ INPUT = \ $(PROJECT_PATH)/components/freertos/FreeRTOS-Kernel/include/freertos/task.h \ $(PROJECT_PATH)/components/freertos/FreeRTOS-Kernel/include/freertos/timers.h \ $(PROJECT_PATH)/components/hal/include/hal/color_types.h \ - $(PROJECT_PATH)/components/hal/include/hal/ledc_types.h \ $(PROJECT_PATH)/components/hal/include/hal/mcpwm_types.h \ $(PROJECT_PATH)/components/hal/include/hal/sdio_slave_types.h \ $(PROJECT_PATH)/components/hal/include/hal/temperature_sensor_types.h \ diff --git a/examples/peripherals/.build-test-rules.yml b/examples/peripherals/.build-test-rules.yml index 1338e9fd9ba..32b48a5f3d7 100644 --- a/examples/peripherals/.build-test-rules.yml +++ b/examples/peripherals/.build-test-rules.yml @@ -272,18 +272,15 @@ examples/peripherals/ledc: - if: SOC_LEDC_SUPPORTED != 1 depends_components: - esp_driver_ledc + - esp_hal_ledc examples/peripherals/ledc/ledc_dimmer: disable: - if: SOC_ETM_SUPPORTED != 1 or SOC_LEDC_SUPPORT_ETM != 1 - depends_components: - - esp_driver_ledc examples/peripherals/ledc/ledc_gamma_curve_fade: disable: - if: SOC_LEDC_SUPPORTED != 1 or SOC_LEDC_GAMMA_CURVE_FADE_SUPPORTED != 1 - depends_components: - - esp_driver_ledc examples/peripherals/mcpwm: disable: