From ccd092d7dcfa33e9e5d67a677ee76cb27c2de727 Mon Sep 17 00:00:00 2001 From: morris Date: Wed, 16 Jul 2025 18:05:06 +0800 Subject: [PATCH] refactor(hal): clean up some hal file dependency on sdkconfig.h --- .../esp_rom/esp32/include/esp32/rom/sha.h | 5 +-- components/hal/adc_hal.c | 35 +++++++++--------- components/hal/apm_hal.c | 5 ++- components/hal/emac_hal.c | 6 +-- components/hal/esp32/efuse_hal.c | 9 ++--- components/hal/esp32c2/clk_tree_hal.c | 6 +-- components/hal/esp32c5/efuse_hal.c | 1 - components/hal/esp32c6/efuse_hal.c | 1 - components/hal/esp32c61/efuse_hal.c | 1 - components/hal/esp32h2/efuse_hal.c | 1 - components/hal/esp32h21/efuse_hal.c | 1 - components/hal/esp32h4/efuse_hal.c | 1 - components/hal/esp32p4/efuse_hal.c | 1 - components/hal/esp32s2/efuse_hal.c | 1 - components/hal/esp32s3/efuse_hal.c | 1 - components/hal/include/hal/adc_hal.h | 6 +-- components/hal/include/hal/adc_types.h | 9 ++--- components/hal/include/hal/apm_hal.h | 6 +-- components/hal/include/hal/emac_hal.h | 9 +++-- components/hal/include/hal/modem_clock_hal.h | 4 +- components/hal/include/hal/mpi_hal.h | 11 +++--- components/hal/include/hal/pmu_types.h | 3 +- components/hal/include/hal/rtc_hal.h | 3 +- components/hal/include/hal/sha_types.h | 8 ---- .../include/hal/touch_sensor_legacy_types.h | 9 ++--- components/hal/include/hal/twai_hal.h | 1 - components/hal/mpi_hal.c | 9 ++--- .../hal/platform_port/include/hal/config.h | 20 ++++++++++ components/hal/sha_hal.c | 8 ++-- components/hal/spi_flash_encrypt_hal_iram.c | 12 +++--- components/hal/spi_flash_hal.c | 2 +- components/hal/spi_flash_hal_iram.c | 12 +++--- components/hal/usb_dwc_hal.c | 6 +-- components/hal/wdt_hal_iram.c | 7 ++-- .../sg_rules/no_kconfig_in_hal_component.yml | 37 ------------------- 35 files changed, 108 insertions(+), 149 deletions(-) diff --git a/components/esp_rom/esp32/include/esp32/rom/sha.h b/components/esp_rom/esp32/include/esp32/rom/sha.h index 39d0578592..2c9d5623b9 100644 --- a/components/esp_rom/esp32/include/esp32/rom/sha.h +++ b/components/esp_rom/esp32/include/esp32/rom/sha.h @@ -27,15 +27,14 @@ typedef struct SHAContext { uint32_t total_input_bits[4]; } SHA_CTX; -enum SHA_TYPE { +typedef enum SHA_TYPE { SHA1 = 0, SHA2_256, SHA2_384, SHA2_512, - SHA_INVALID = -1, -}; +} SHA_TYPE; /* Do not use these function in multi core mode due to * inside they have no safe implementation (without DPORT workaround). diff --git a/components/hal/adc_hal.c b/components/hal/adc_hal.c index e71c70f1de..f5e374e9fe 100644 --- a/components/hal/adc_hal.c +++ b/components/hal/adc_hal.c @@ -5,13 +5,12 @@ */ #include -#include "sdkconfig.h" #include "hal/adc_hal.h" #include "hal/assert.h" #include "soc/lldesc.h" -#include "soc/soc_caps.h" +#include "soc/soc_caps_full.h" -#if CONFIG_IDF_TARGET_ESP32 +#if SOC_IS(ESP32) //ADC utilises I2S0 DMA on ESP32 #include "hal/i2s_hal.h" #include "hal/i2s_types.h" @@ -58,7 +57,7 @@ void adc_hal_digi_init(adc_hal_dma_ctx_t *hal) adc_ll_digi_set_clk_div(ADC_LL_DIGI_SAR_CLK_DIV_DEFAULT); adc_ll_digi_dma_set_eof_num(hal->eof_num); -#if CONFIG_IDF_TARGET_ESP32 +#if SOC_IS(ESP32) i2s_ll_rx_set_sample_bit(adc_hal_i2s_dev, SAMPLE_BITS, SAMPLE_BITS); i2s_ll_rx_enable_mono_mode(adc_hal_i2s_dev, 1); i2s_ll_rx_force_enable_fifo_mod(adc_hal_i2s_dev, 1); @@ -91,20 +90,20 @@ void adc_hal_digi_deinit() ---------------------------------------------------------------*/ static adc_ll_digi_convert_mode_t get_convert_mode(adc_digi_convert_mode_t convert_mode) { -#if CONFIG_IDF_TARGET_ESP32 || SOC_ADC_DIGI_CONTROLLER_NUM == 1 +#if SOC_IS(ESP32) || SOC_ADC_DIGI_CONTROLLER_NUM == 1 return ADC_LL_DIGI_CONV_ONLY_ADC1; #elif (SOC_ADC_DIGI_CONTROLLER_NUM >= 2) switch (convert_mode) { - case ADC_CONV_SINGLE_UNIT_1: - return ADC_LL_DIGI_CONV_ONLY_ADC1; - case ADC_CONV_SINGLE_UNIT_2: - return ADC_LL_DIGI_CONV_ONLY_ADC2; - case ADC_CONV_BOTH_UNIT: - return ADC_LL_DIGI_CONV_BOTH_UNIT; - case ADC_CONV_ALTER_UNIT: - return ADC_LL_DIGI_CONV_ALTER_UNIT; - default: - abort(); + case ADC_CONV_SINGLE_UNIT_1: + return ADC_LL_DIGI_CONV_ONLY_ADC1; + case ADC_CONV_SINGLE_UNIT_2: + return ADC_LL_DIGI_CONV_ONLY_ADC2; + case ADC_CONV_BOTH_UNIT: + return ADC_LL_DIGI_CONV_BOTH_UNIT; + case ADC_CONV_ALTER_UNIT: + return ADC_LL_DIGI_CONV_ALTER_UNIT; + default: + abort(); } #endif } @@ -118,7 +117,7 @@ static adc_ll_digi_convert_mode_t get_convert_mode(adc_digi_convert_mode_t conve */ static void adc_hal_digi_sample_freq_config(adc_hal_dma_ctx_t *hal, adc_continuous_clk_src_t clk_src, uint32_t clk_src_freq_hz, uint32_t sample_freq_hz) { -#if !CONFIG_IDF_TARGET_ESP32 +#if !SOC_IS(ESP32) uint32_t interval = clk_src_freq_hz / (ADC_LL_CLKM_DIV_NUM_DEFAULT + ADC_LL_CLKM_DIV_A_DEFAULT / ADC_LL_CLKM_DIV_B_DEFAULT + 1) / 2 / sample_freq_hz; //set sample interval adc_ll_digi_set_trigger_interval(interval); @@ -218,14 +217,14 @@ void adc_hal_digi_dma_link(adc_hal_dma_ctx_t *hal, uint8_t *data_buf) .dw0.suc_eof = 0, .dw0.owner = 1, .buffer = data_buf, - .next = &desc[n+1] + .next = &desc[n + 1] }; eof_size -= this_len; data_buf += this_len; n++; } } - desc[n-1].next = desc_head; + desc[n - 1].next = desc_head; } adc_hal_dma_desc_status_t adc_hal_get_reading_result(adc_hal_dma_ctx_t *hal, const intptr_t eof_desc_addr, uint8_t **buffer, uint32_t *len) diff --git a/components/hal/apm_hal.c b/components/hal/apm_hal.c index 1fee887fff..ee350b6e2e 100644 --- a/components/hal/apm_hal.c +++ b/components/hal/apm_hal.c @@ -5,12 +5,13 @@ */ #include +#include "soc/soc_caps.h" #include "hal/assert.h" #include "hal/apm_hal.h" #include "hal/apm_ll.h" #include "hal/log.h" -#if CONFIG_IDF_TARGET_ESP32P4 +#if SOC_IS(ESP32P4) void apm_hal_hp_peri_access_enable(apm_ll_master_id_t master_id, apm_ll_hp_peri_t hp_peri, apm_ll_secure_mode_t sec_mode, bool enable) { @@ -523,4 +524,4 @@ void apm_hal_enable_ctrl_clk_gating(apm_ctrl_module_t ctrl_mod, bool enable) } } -#endif //CONFIG_IDF_TARGET_ESP32P4 +#endif //SOC_IS(ESP32P4) diff --git a/components/hal/emac_hal.c b/components/hal/emac_hal.c index c90fb8ec5f..9f43f9e934 100644 --- a/components/hal/emac_hal.c +++ b/components/hal/emac_hal.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ #include -#include "sdkconfig.h" +#include "soc/soc_caps_full.h" #include "esp_attr.h" #include "hal/emac_hal.h" #include "hal/emac_ll.h" @@ -29,7 +29,7 @@ void emac_hal_init(emac_hal_context_t *hal) { hal->dma_regs = &EMAC_DMA; hal->mac_regs = &EMAC_MAC; -#if CONFIG_IDF_TARGET_ESP32 +#if SOC_IS(ESP32) hal->ext_regs = &EMAC_EXT; #else hal->ext_regs = NULL; @@ -137,7 +137,7 @@ void emac_hal_init_dma_default(emac_hal_context_t *hal, emac_hal_dma_config_t *h /* DMAOMR Configuration */ /* Enable Dropping of TCP/IP Checksum Error Frames */ emac_ll_drop_tcp_err_frame_enable(hal->dma_regs, true); -#if CONFIG_IDF_TARGET_ESP32P4 +#if SOC_IS(ESP32P4) /* Disable Receive Store Forward (Rx FIFO is only 256B) */ emac_ll_recv_store_forward_enable(hal->dma_regs, false); #else diff --git a/components/hal/esp32/efuse_hal.c b/components/hal/esp32/efuse_hal.c index dd3ef43afb..365fcdacea 100644 --- a/components/hal/esp32/efuse_hal.c +++ b/components/hal/esp32/efuse_hal.c @@ -1,15 +1,14 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ -#include "sdkconfig.h" #include -#include "soc/soc_caps.h" #include "hal/efuse_ll.h" #include "hal/assert.h" #include "hal/efuse_hal.h" +#include "hal/config.h" #include "soc/syscon_reg.h" #include "esp_attr.h" @@ -30,11 +29,11 @@ IRAM_ATTR uint32_t efuse_hal_get_major_chip_version(void) case 3: chip_ver = 2; break; -#if CONFIG_IDF_ENV_FPGA +#if HAL_CONFIG_EFUSE_ENV_FPGA case 4: /* Empty efuses, but SYSCON_DATE_REG bit is set */ chip_ver = 3; break; -#endif // CONFIG_IDF_ENV_FPGA +#endif // HAL_CONFIG_EFUSE_ENV_FPGA case 7: chip_ver = 3; break; diff --git a/components/hal/esp32c2/clk_tree_hal.c b/components/hal/esp32c2/clk_tree_hal.c index e7cdd87702..0d4b372828 100644 --- a/components/hal/esp32c2/clk_tree_hal.c +++ b/components/hal/esp32c2/clk_tree_hal.c @@ -4,9 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "sdkconfig.h" #include "soc/clkout_channel.h" #include "hal/assert.h" +#include "hal/config.h" #include "hal/clk_tree_hal.h" #include "hal/clk_tree_ll.h" #include "hal/gpio_ll.h" @@ -78,8 +78,8 @@ uint32_t clk_hal_xtal_get_freq_mhz(void) { uint32_t freq = clk_ll_xtal_load_freq_mhz(); if (freq == 0) { - HAL_LOGW(CLK_HAL_TAG, "invalid RTC_XTAL_FREQ_REG value, assume %dMHz", CONFIG_XTAL_FREQ); - return CONFIG_XTAL_FREQ; + HAL_LOGW(CLK_HAL_TAG, "invalid RTC_XTAL_FREQ_REG value, assume %dMHz", HAL_CONFIG_XTAL_HINT_FREQ_MHZ); + return HAL_CONFIG_XTAL_HINT_FREQ_MHZ; } return freq; } diff --git a/components/hal/esp32c5/efuse_hal.c b/components/hal/esp32c5/efuse_hal.c index 6a789c0bef..49e4a99acf 100644 --- a/components/hal/esp32c5/efuse_hal.c +++ b/components/hal/esp32c5/efuse_hal.c @@ -5,7 +5,6 @@ */ #include -#include "sdkconfig.h" #include "soc/soc_caps.h" #include "hal/assert.h" #include "hal/efuse_hal.h" diff --git a/components/hal/esp32c6/efuse_hal.c b/components/hal/esp32c6/efuse_hal.c index 94a1051713..96e6bed7ca 100644 --- a/components/hal/esp32c6/efuse_hal.c +++ b/components/hal/esp32c6/efuse_hal.c @@ -5,7 +5,6 @@ */ #include -#include "sdkconfig.h" #include "soc/soc_caps.h" #include "hal/assert.h" #include "hal/efuse_hal.h" diff --git a/components/hal/esp32c61/efuse_hal.c b/components/hal/esp32c61/efuse_hal.c index 6ba9f0fba1..de77fa0bce 100644 --- a/components/hal/esp32c61/efuse_hal.c +++ b/components/hal/esp32c61/efuse_hal.c @@ -5,7 +5,6 @@ */ #include -#include "sdkconfig.h" #include "soc/soc_caps.h" #include "hal/assert.h" #include "hal/efuse_hal.h" diff --git a/components/hal/esp32h2/efuse_hal.c b/components/hal/esp32h2/efuse_hal.c index f6d1c0f40a..a6a92728d1 100644 --- a/components/hal/esp32h2/efuse_hal.c +++ b/components/hal/esp32h2/efuse_hal.c @@ -5,7 +5,6 @@ */ #include -#include "sdkconfig.h" #include "soc/soc_caps.h" #include "soc/chip_revision.h" #include "hal/assert.h" diff --git a/components/hal/esp32h21/efuse_hal.c b/components/hal/esp32h21/efuse_hal.c index 79c58dda99..bf65022155 100644 --- a/components/hal/esp32h21/efuse_hal.c +++ b/components/hal/esp32h21/efuse_hal.c @@ -5,7 +5,6 @@ */ #include -#include "sdkconfig.h" #include "soc/soc_caps.h" #include "hal/assert.h" #include "hal/efuse_hal.h" diff --git a/components/hal/esp32h4/efuse_hal.c b/components/hal/esp32h4/efuse_hal.c index 4268d52a97..f903672e05 100644 --- a/components/hal/esp32h4/efuse_hal.c +++ b/components/hal/esp32h4/efuse_hal.c @@ -5,7 +5,6 @@ */ #include -#include "sdkconfig.h" #include "soc/soc_caps.h" #include "hal/assert.h" #include "hal/efuse_hal.h" diff --git a/components/hal/esp32p4/efuse_hal.c b/components/hal/esp32p4/efuse_hal.c index 8a0eac87f1..ba32e8126f 100644 --- a/components/hal/esp32p4/efuse_hal.c +++ b/components/hal/esp32p4/efuse_hal.c @@ -4,7 +4,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "sdkconfig.h" #include "esp_attr.h" #include #include "soc/soc_caps.h" diff --git a/components/hal/esp32s2/efuse_hal.c b/components/hal/esp32s2/efuse_hal.c index 7002ca4d5f..eefeb88a5d 100644 --- a/components/hal/esp32s2/efuse_hal.c +++ b/components/hal/esp32s2/efuse_hal.c @@ -4,7 +4,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "sdkconfig.h" #include #include "soc/soc_caps.h" #include "hal/assert.h" diff --git a/components/hal/esp32s3/efuse_hal.c b/components/hal/esp32s3/efuse_hal.c index fb11194251..1ebbfddb6f 100644 --- a/components/hal/esp32s3/efuse_hal.c +++ b/components/hal/esp32s3/efuse_hal.c @@ -4,7 +4,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "sdkconfig.h" #include #include "soc/soc_caps.h" #include "hal/assert.h" diff --git a/components/hal/include/hal/adc_hal.h b/components/hal/include/hal/adc_hal.h index 1953b31709..70f10a5a52 100644 --- a/components/hal/include/hal/adc_hal.h +++ b/components/hal/include/hal/adc_hal.h @@ -19,12 +19,12 @@ #include "hal/gdma_ll.h" #endif -#if CONFIG_IDF_TARGET_ESP32S2 +#if SOC_IS(ESP32S2) //ADC utilises SPI3 DMA on ESP32S2 #include "hal/spi_ll.h" #endif -#if CONFIG_IDF_TARGET_ESP32 +#if SOC_IS(ESP32) //ADC utilises I2S0 DMA on ESP32 #include "hal/i2s_ll.h" #endif @@ -33,7 +33,7 @@ extern "C" { #endif -#if CONFIG_IDF_TARGET_ESP32 +#if SOC_IS(ESP32) #define ADC_HAL_DMA_I2S_HOST 0 #endif diff --git a/components/hal/include/hal/adc_types.h b/components/hal/include/hal/adc_types.h index 62fd0a573c..2408980cc6 100644 --- a/components/hal/include/hal/adc_types.h +++ b/components/hal/include/hal/adc_types.h @@ -7,7 +7,6 @@ #include #include -#include "sdkconfig.h" #include "soc/soc_caps.h" #include "soc/clk_tree_defs.h" #include "esp_attr.h" @@ -159,7 +158,7 @@ typedef enum { /*--------------------------------------------------------------- Output Format ---------------------------------------------------------------*/ -#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 +#if SOC_IS(ESP32) || SOC_IS(ESP32S2) /** * @brief ADC digital controller (DMA mode) output data format. * Used to analyze the acquired ADC (DMA) data. @@ -184,7 +183,7 @@ typedef struct { }; } adc_digi_output_data_t; -#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C2 +#elif SOC_IS(ESP32C3) || SOC_IS(ESP32C2) /** * @brief ADC digital controller (DMA mode) output data format. * Used to analyze the acquired ADC (DMA) data. @@ -204,7 +203,7 @@ typedef struct { }; } adc_digi_output_data_t; -#elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32P4 +#elif SOC_IS(ESP32S3) || SOC_IS(ESP32P4) /** * @brief ADC digital controller (DMA mode) output data format. * Used to analyze the acquired ADC (DMA) data. @@ -224,7 +223,7 @@ typedef struct { }; } adc_digi_output_data_t; -#elif CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C5 || CONFIG_IDF_TARGET_ESP32C61 +#elif SOC_IS(ESP32C6) || SOC_IS(ESP32H2) || SOC_IS(ESP32C5) || SOC_IS(ESP32C61) /** * @brief ADC digital controller (DMA mode) output data format. * Used to analyze the acquired ADC (DMA) data. diff --git a/components/hal/include/hal/apm_hal.h b/components/hal/include/hal/apm_hal.h index 9e636c8a0c..7b68598b12 100644 --- a/components/hal/include/hal/apm_hal.h +++ b/components/hal/include/hal/apm_hal.h @@ -16,7 +16,7 @@ extern "C" { #include "hal/apm_ll.h" #include "hal/apm_types.h" -#if CONFIG_IDF_TARGET_ESP32P4 +#if SOC_IS(ESP32P4) /** * @brief DMA configurable region configuration data. @@ -360,11 +360,11 @@ void apm_hal_enable_reset_event_bypass(bool enable); */ void apm_hal_enable_ctrl_clk_gating(apm_ctrl_module_t ctrl_mod, bool enable); -#endif //CONFIG_IDF_TARGET_ESP32P4 +#endif //SOC_IS(ESP32P4) #elif SOC_APM_CTRL_FILTER_SUPPORTED //!SOC_APM_SUPPORTED -#if CONFIG_IDF_TARGET_ESP32H4 +#if SOC_IS(ESP32H4) #include "soc/hp_apm_reg.h" #define apm_hal_enable_ctrl_filter_all(en) \ REG_WRITE(HP_APM_FUNC_CTRL_REG, en ? 0xFFFFFFFF : 0); diff --git a/components/hal/include/hal/emac_hal.h b/components/hal/include/hal/emac_hal.h index 7787f82374..c6f2c7a9ce 100644 --- a/components/hal/include/hal/emac_hal.h +++ b/components/hal/include/hal/emac_hal.h @@ -12,6 +12,7 @@ #include "esp_err.h" #include "hal/eth_types.h" #include "soc/soc_caps.h" + #ifdef __cplusplus extern "C" { #endif @@ -25,7 +26,7 @@ extern "C" { #define TYPE_SIZE_ERR_MSG(DATATYPE, SIZE) #DATATYPE " should occupy " STR(SIZE) " bytes in memory" #define ASSERT_TYPE_SIZE(DATATYPE, SIZE) ESP_STATIC_ASSERT(sizeof(DATATYPE) == SIZE, TYPE_SIZE_ERR_MSG(DATATYPE, SIZE)) -#if CONFIG_IDF_TARGET_ESP32P4 +#if SOC_IS(ESP32P4) // Descriptor must be 64B aligned for ESP32P4 due to cache arrangement #define EMAC_HAL_DMA_DESC_SIZE (64) #else @@ -191,7 +192,7 @@ ASSERT_TYPE_SIZE(eth_dma_rx_descriptor_t, EMAC_HAL_DMA_DESC_SIZE); typedef struct emac_mac_dev_s *emac_mac_soc_regs_t; typedef struct emac_dma_dev_s *emac_dma_soc_regs_t; -#if CONFIG_IDF_TARGET_ESP32 +#if SOC_IS(ESP32) typedef struct emac_ext_dev_s *emac_ext_soc_regs_t; #else typedef void *emac_ext_soc_regs_t; @@ -236,9 +237,9 @@ void emac_hal_init(emac_hal_context_t *hal); #define emac_hal_clock_enable_rmii_input(hal) emac_ll_clock_enable_rmii_input((hal)->ext_regs) -#ifdef CONFIG_IDF_TARGET_ESP32P4 +#if SOC_IS(ESP32P4) #define emac_hal_clock_rmii_rx_tx_div(hal, div) emac_ll_clock_rmii_rx_tx_div((hal)->ext_regs, div) -#endif // CONFIG_IDF_TARGET_ESP32P4 +#endif // SOC_IS(ESP32P4) #define emac_hal_clock_enable_rmii_output(hal) emac_ll_clock_enable_rmii_output((hal)->ext_regs) diff --git a/components/hal/include/hal/modem_clock_hal.h b/components/hal/include/hal/modem_clock_hal.h index ec04d18d71..5b12545ccb 100644 --- a/components/hal/include/hal/modem_clock_hal.h +++ b/components/hal/include/hal/modem_clock_hal.h @@ -9,7 +9,7 @@ #pragma once #include "soc/soc_caps.h" -#include "sdkconfig.h" + #if SOC_MODEM_CLOCK_IS_INDEPENDENT && SOC_MODEM_CLOCK_SUPPORTED #include "hal/modem_syscon_ll.h" #include "hal/modem_lpcon_ll.h" @@ -24,7 +24,7 @@ typedef struct { modem_lpcon_dev_t *lpcon_dev; } modem_clock_hal_context_t; -#if !CONFIG_IDF_TARGET_ESP32H2 //TODO: PM-92 +#if !SOC_IS(ESP32H2) //TODO: PM-92 void modem_clock_hal_set_clock_domain_icg_bitmap(modem_clock_hal_context_t *hal, modem_clock_domain_t domain, uint32_t bitmap); uint32_t modem_clock_hal_get_clock_domain_icg_bitmap(modem_clock_hal_context_t *hal, modem_clock_domain_t domain); #endif diff --git a/components/hal/include/hal/mpi_hal.h b/components/hal/include/hal/mpi_hal.h index 5a3c7002eb..5b4f167e07 100644 --- a/components/hal/include/hal/mpi_hal.h +++ b/components/hal/include/hal/mpi_hal.h @@ -16,8 +16,7 @@ #include #include #include "hal/mpi_types.h" -#include "sdkconfig.h" - +#include "soc/soc_caps.h" #ifdef __cplusplus extern "C" { @@ -32,7 +31,7 @@ extern "C" { size_t mpi_hal_calc_hardware_words(size_t words); /** - * @brief Clear the MPI power control bit and intitialise the MPI hardware. + * @brief Clear the MPI power control bit and initialise the MPI hardware. * */ void mpi_hal_enable_hardware_hw_op(void); @@ -91,13 +90,13 @@ void mpi_hal_write_at_offset(mpi_param_t param, int offset, uint32_t value); void mpi_hal_write_m_prime(uint32_t Mprime); /** - * @brief Write first word of the parametr Rinv. + * @brief Write first word of the parameter Rinv. * * @param rinv Value of first word of rinv. */ void mpi_hal_write_rinv(uint32_t rinv); -#if !CONFIG_IDF_TARGET_ESP32 +#if !SOC_IS(ESP32) /** * @brief Enable/Disable constant time acceleration option. * @@ -118,7 +117,7 @@ void mpi_hal_enable_search(bool enable); * @param position Address to start search. */ void mpi_hal_set_search_position(size_t position); -#endif /* !CONFIG_IDF_TARGET_ESP32 */ +#endif /* !SOC_IS(ESP32) */ /** * @brief Begin an MPI operation. diff --git a/components/hal/include/hal/pmu_types.h b/components/hal/include/hal/pmu_types.h index cb1fab415e..96ec68a2ac 100644 --- a/components/hal/include/hal/pmu_types.h +++ b/components/hal/include/hal/pmu_types.h @@ -8,7 +8,6 @@ #include #include "soc/soc_caps.h" -#include "sdkconfig.h" #ifdef __cplusplus extern "C" { @@ -36,7 +35,7 @@ typedef enum { /** * @brief PMU power domain of HP system */ -#if CONFIG_IDF_TARGET_ESP32P4 +#if SOC_IS(ESP32P4) typedef enum { PMU_HP_PD_TOP = 0, /*!< Power domain of digital top */ PMU_HP_PD_CNNT = 1, /*!< Power domain of high-speed IO peripherals such as USB/SDIO/Ethernet etc.*/ diff --git a/components/hal/include/hal/rtc_hal.h b/components/hal/include/hal/rtc_hal.h index 7c1946e3a6..b8bfe29612 100644 --- a/components/hal/include/hal/rtc_hal.h +++ b/components/hal/include/hal/rtc_hal.h @@ -9,9 +9,8 @@ #include #include "soc/soc_caps.h" #include "hal/gpio_types.h" -#include "sdkconfig.h" -#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#if SOC_IS(ESP32) || SOC_IS(ESP32C2) || SOC_IS(ESP32C3) || SOC_IS(ESP32S2) || SOC_IS(ESP32S3) #include "hal/rtc_cntl_ll.h" #endif diff --git a/components/hal/include/hal/sha_types.h b/components/hal/include/hal/sha_types.h index e6e2278791..24248e58ce 100644 --- a/components/hal/include/hal/sha_types.h +++ b/components/hal/include/hal/sha_types.h @@ -6,21 +6,13 @@ #pragma once -#include "sdkconfig.h" - -/* Use enum from rom for backwards compatibility */ #include "rom/sha.h" #ifdef __cplusplus extern "C" { #endif -/* Use enum from rom for backwards compatibility */ -#if CONFIG_IDF_TARGET_ESP32 -typedef enum SHA_TYPE esp_sha_type; -#else typedef SHA_TYPE esp_sha_type; -#endif #ifdef __cplusplus } diff --git a/components/hal/include/hal/touch_sensor_legacy_types.h b/components/hal/include/hal/touch_sensor_legacy_types.h index e708aefa7b..d7e694ac3c 100644 --- a/components/hal/include/hal/touch_sensor_legacy_types.h +++ b/components/hal/include/hal/touch_sensor_legacy_types.h @@ -8,7 +8,6 @@ #include #include -#include "sdkconfig.h" #include "esp_attr.h" #include "esp_bit_defs.h" #include "soc/soc_caps.h" @@ -128,7 +127,7 @@ typedef enum { #define TOUCH_PAD_THRESHOLD_MAX (0xFFFF) /*!< If set touch threshold max value, The touch sensor can't be in touched status */ #endif -#ifdef CONFIG_IDF_TARGET_ESP32 +#if SOC_IS(ESP32) #define TOUCH_PAD_SLEEP_CYCLE_DEFAULT (0x1000) /*! #include -#include "sdkconfig.h" #include "soc/soc_caps.h" #include "hal/twai_types.h" diff --git a/components/hal/mpi_hal.c b/components/hal/mpi_hal.c index 014ab14655..42ac404522 100644 --- a/components/hal/mpi_hal.c +++ b/components/hal/mpi_hal.c @@ -5,8 +5,7 @@ */ #include "hal/mpi_hal.h" #include "hal/mpi_ll.h" -#include "sdkconfig.h" - +#include "soc/soc_caps_full.h" size_t mpi_hal_calc_hardware_words(size_t words) { @@ -19,7 +18,7 @@ void mpi_hal_enable_hardware_hw_op(void) } // Note: from enabling RSA clock to here takes about 1.3us -#if !CONFIG_IDF_TARGET_ESP32 +#if !SOC_IS(ESP32) mpi_ll_disable_interrupt(); #endif } @@ -70,7 +69,7 @@ void mpi_hal_write_rinv(uint32_t rinv) } // Acceleration options -#if !CONFIG_IDF_TARGET_ESP32 +#if !SOC_IS(ESP32) void mpi_hal_enable_constant_time(bool enable) { if (enable){ @@ -95,7 +94,7 @@ void mpi_hal_set_search_position(size_t position) { mpi_ll_set_search_position(position); } -#endif /* !CONFIG_IDF_TARGET_ESP32 */ +#endif // !SOC_IS(ESP32) /* Begin an RSA operation. */ diff --git a/components/hal/platform_port/include/hal/config.h b/components/hal/platform_port/include/hal/config.h index 99ddd712f5..4c972ced8a 100644 --- a/components/hal/platform_port/include/hal/config.h +++ b/components/hal/platform_port/include/hal/config.h @@ -11,8 +11,28 @@ extern "C" { #endif +/** + * @brief Enable this to reuse ROM APIs for GPIO operations. + * It will save some code size. + */ #define HAL_CONFIG_GPIO_USE_ROM_API CONFIG_HAL_GPIO_USE_ROM_IMPL +/** + * @brief Enable this to indicate the target is an FPGA. + */ +#define HAL_CONFIG_EFUSE_ENV_FPGA CONFIG_IDF_ENV_FPGA + +/** + * @brief When the hardware fails in measuring the XTAL frequency, use this value as a hint. + */ +#define HAL_CONFIG_XTAL_HINT_FREQ_MHZ CONFIG_XTAL_FREQ + +/** + * @brief Enable this to use ROM APIs for SPI Flash operations. + * It will save some code size. + */ +#define HAL_CONFIG_SPI_FLASH_USE_ROM_API CONFIG_SPI_FLASH_ROM_IMPL + #ifdef __cplusplus } #endif diff --git a/components/hal/sha_hal.c b/components/hal/sha_hal.c index 62f64fc6c3..c0225be393 100644 --- a/components/hal/sha_hal.c +++ b/components/hal/sha_hal.c @@ -6,19 +6,19 @@ // The HAL layer for SHA +#include +#include #include "hal/sha_hal.h" #include "hal/sha_types.h" #include "hal/sha_ll.h" -#include "soc/soc_caps.h" -#include -#include +#include "soc/soc_caps_full.h" #define SHA1_STATE_LEN_WORDS (160 / 32) #define SHA256_STATE_LEN_WORDS (256 / 32) #define SHA512_STATE_LEN_WORDS (512 / 32) -#if CONFIG_IDF_TARGET_ESP32 +#if SOC_IS(ESP32) /* Return state size (in words) for a given SHA type */ inline static size_t state_length(esp_sha_type type) diff --git a/components/hal/spi_flash_encrypt_hal_iram.c b/components/hal/spi_flash_encrypt_hal_iram.c index 7af5a981f2..6e9c4ffcc8 100644 --- a/components/hal/spi_flash_encrypt_hal_iram.c +++ b/components/hal/spi_flash_encrypt_hal_iram.c @@ -12,12 +12,12 @@ void spi_flash_encryption_hal_enable(void) { spi_flash_encrypt_ll_enable(); -#if CONFIG_IDF_TARGET_ESP32S2 +#if SOC_IS(ESP32S2) spi_flash_encrypt_ll_aes_accelerator_enable(); -#endif //CONFIG_IDF_TARGET_ESP32S2 -#if !CONFIG_IDF_TARGET_ESP32 +#endif //SOC_IS(ESP32S2) +#if !SOC_IS(ESP32) spi_flash_encrypt_ll_type(FLASH_ENCRYPTION_MANU); -#endif // !CONFIG_IDF_TARGET_ESP32 +#endif // !SOC_IS(ESP32) } void spi_flash_encryption_hal_disable(void) @@ -27,9 +27,9 @@ void spi_flash_encryption_hal_disable(void) void spi_flash_encryption_hal_prepare(uint32_t address, const uint32_t* buffer, uint32_t size) { -#if !CONFIG_IDF_TARGET_ESP32 +#if !SOC_IS(ESP32) spi_flash_encrypt_ll_buffer_length(size); -#endif // !CONFIG_IDF_TARGET_ESP32 +#endif // !SOC_IS(ESP32) spi_flash_encrypt_ll_address_save(address); spi_flash_encrypt_ll_plaintext_save(address, buffer, size); spi_flash_encrypt_ll_calculate_start(); diff --git a/components/hal/spi_flash_hal.c b/components/hal/spi_flash_hal.c index de457e1d1b..8b0f1e2fa3 100644 --- a/components/hal/spi_flash_hal.c +++ b/components/hal/spi_flash_hal.c @@ -35,7 +35,7 @@ static uint32_t get_flash_clock_divider(const spi_flash_hal_config_t *cfg) HAL_LOGE(TAG, "Target frequency %dMHz higher than src %dMHz.", cfg_freq_mhz, src_freq_mhz); abort(); } -#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32C3 +#if SOC_IS(ESP32) || SOC_IS(ESP32S2) || SOC_IS(ESP32C3) if (cfg_freq_mhz == 26 || cfg_freq_mhz == 27) { best_div = 3; } else diff --git a/components/hal/spi_flash_hal_iram.c b/components/hal/spi_flash_hal_iram.c index 611756b72e..97751bfb0a 100644 --- a/components/hal/spi_flash_hal_iram.c +++ b/components/hal/spi_flash_hal_iram.c @@ -3,9 +3,9 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include "sdkconfig.h" - +#include "hal/config.h" #include "hal/spi_flash_hal.h" +#include "soc/soc_caps.h" #if SOC_SPI_MEM_SUPPORT_AUTO_SUSPEND void spi_flash_hal_setup_auto_suspend_mode(spi_flash_host_inst_t *host); @@ -15,7 +15,7 @@ void spi_flash_hal_setup_auto_resume_mode(spi_flash_host_inst_t *host); #define SPI_FLASH_TSHSL2_SAFE_VAL_NS (30) #endif //SOC_SPI_MEM_SUPPORT_AUTO_SUSPEND -#ifndef CONFIG_SPI_FLASH_ROM_IMPL +#if !HAL_CONFIG_SPI_FLASH_USE_ROM_API #include "spi_flash_hal_common.inc" @@ -88,7 +88,7 @@ esp_err_t spi_flash_hal_set_write_protect(spi_flash_host_inst_t *host, bool wp) return ESP_OK; } -#else // defined CONFIG_SPI_FLASH_ROM_IMPL +#else static inline spi_dev_t *get_spi_dev(spi_flash_host_inst_t *host) { @@ -101,7 +101,7 @@ static inline int get_host_id(spi_flash_host_inst_t* host) return spi_flash_ll_hw_get_id(dev); } -#endif // !CONFIG_SPI_FLASH_ROM_IMPL +#endif // !HAL_CONFIG_SPI_FLASH_USE_ROM_API uint32_t spi_flash_hal_check_status(spi_flash_host_inst_t *host) { @@ -115,7 +115,7 @@ uint32_t spi_flash_hal_check_status(spi_flash_host_inst_t *host) // Not clear if this is necessary, or only necessary if // chip->spi == SPI1. But probably doesn't hurt... if ((void*) dev == spi_flash_ll_get_hw(SPI1_HOST)) { -#if CONFIG_IDF_TARGET_ESP32 +#if SOC_IS(ESP32) status &= spi_flash_ll_host_idle(&SPI0); #endif } diff --git a/components/hal/usb_dwc_hal.c b/components/hal/usb_dwc_hal.c index 1b1be60ca0..bf0fb93258 100644 --- a/components/hal/usb_dwc_hal.c +++ b/components/hal/usb_dwc_hal.c @@ -8,7 +8,7 @@ #include #include // For memset() #include // For abort() -#include "sdkconfig.h" +#include "soc/soc_caps_full.h" #include "soc/chip_revision.h" #include "soc/usb_periph.h" #include "hal/usb_dwc_hal.h" @@ -87,7 +87,7 @@ static void set_defaults(usb_dwc_hal_context_t *hal) //GAHBCFG register usb_dwc_ll_gahbcfg_en_dma_mode(hal->dev); int hbstlen = 0; //Use AHB burst SINGLE by default -#if CONFIG_IDF_TARGET_ESP32S2 && CONFIG_ESP32S2_REV_MIN_FULL < 100 +#if SOC_IS(ESP32S2) /* Hardware errata workaround for the ESP32-S2 ECO0 (see ESP32-S2 Errata Document section 4.0 for full details). @@ -105,7 +105,7 @@ static void set_defaults(usb_dwc_hal_context_t *hal) if (!ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 100)) { hbstlen = 1; //Set AHB burst to INCR to workaround hardware errata } -#endif //CONFIG_IDF_TARGET_ESP32S2 && CONFIG_ESP32S2_REV_MIN_FULL < 100 +#endif // SOC_IS(ESP32S2) usb_dwc_ll_gahbcfg_set_hbstlen(hal->dev, hbstlen); //Set AHB burst mode //GUSBCFG register usb_dwc_ll_gusbcfg_dis_hnp_cap(hal->dev); //Disable HNP diff --git a/components/hal/wdt_hal_iram.c b/components/hal/wdt_hal_iram.c index 7739326354..59cb90fe99 100644 --- a/components/hal/wdt_hal_iram.c +++ b/components/hal/wdt_hal_iram.c @@ -8,6 +8,7 @@ #include #include "hal/wdt_types.h" #include "hal/wdt_hal.h" +#include "soc/soc_caps_full.h" /* ---------------------------- Init and Config ----------------------------- */ @@ -18,7 +19,7 @@ void wdt_hal_init(wdt_hal_context_t *hal, wdt_inst_t wdt_inst, uint32_t prescale if (wdt_inst == WDT_MWDT0) { hal->mwdt_dev = &TIMERG0; } -#if SOC_TIMER_GROUPS >= 2 +#if SOC_MODULE_ATTR(TIMG, INST_NUM) >= 2 else if (wdt_inst == WDT_MWDT1) { hal->mwdt_dev = &TIMERG1; } @@ -37,7 +38,7 @@ void wdt_hal_init(wdt_hal_context_t *hal, wdt_inst_t wdt_inst, uint32_t prescale rwdt_ll_disable_stage(hal->rwdt_dev, WDT_STAGE1); rwdt_ll_disable_stage(hal->rwdt_dev, WDT_STAGE2); rwdt_ll_disable_stage(hal->rwdt_dev, WDT_STAGE3); -#ifdef CONFIG_IDF_TARGET_ESP32 +#if SOC_IS(ESP32) //Enable or disable level interrupt. Edge interrupt is always disabled. rwdt_ll_set_edge_intr(hal->rwdt_dev, false); rwdt_ll_set_level_intr(hal->rwdt_dev, enable_intr); @@ -67,7 +68,7 @@ void wdt_hal_init(wdt_hal_context_t *hal, wdt_inst_t wdt_inst, uint32_t prescale mwdt_ll_disable_stage(hal->mwdt_dev, 1); mwdt_ll_disable_stage(hal->mwdt_dev, 2); mwdt_ll_disable_stage(hal->mwdt_dev, 3); -#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 +#if SOC_IS(ESP32) || SOC_IS(ESP32S2) || SOC_IS(ESP32S3) //Enable or disable level interrupt. Edge interrupt is always disabled. mwdt_ll_set_edge_intr(hal->mwdt_dev, false); mwdt_ll_set_level_intr(hal->mwdt_dev, enable_intr); diff --git a/tools/ci/sg_rules/no_kconfig_in_hal_component.yml b/tools/ci/sg_rules/no_kconfig_in_hal_component.yml index 3b1200ea78..affb2cca3d 100644 --- a/tools/ci/sg_rules/no_kconfig_in_hal_component.yml +++ b/tools/ci/sg_rules/no_kconfig_in_hal_component.yml @@ -11,37 +11,17 @@ ignores: - "components/hal/platform_port/**/*" - "components/hal/test_apps/**/*" # the following files should be refactored to remove Kconfig macros - - "components/hal/adc_hal.c" - "components/hal/adc_oneshot_hal.c" - - "components/hal/apm_hal.c" - "components/hal/cache_hal.c" - "components/hal/ecdsa_hal.c" - - "components/hal/emac_hal.c" - "components/hal/mmu_hal.c" - - "components/hal/sha_hal.c" - - "components/hal/spi_flash_encrypt_hal_iram.c" - - "components/hal/spi_flash_hal_iram.c" - "components/hal/spi_flash_hal.c" - "components/hal/twai_hal_sja1000.c" - - "components/hal/usb_dwc_hal.c" - - "components/hal/wdt_hal_iram.c" - - "components/hal/esp32/efuse_hal.c" - "components/hal/esp32/gpio_hal_workaround.c" - "components/hal/esp32/include/hal/twai_ll.h" - "components/hal/esp32/include/hal/uart_ll.h" - - "components/hal/esp32c2/clk_tree_hal.c" - - "components/hal/*/efuse_hal.c" - - "components/hal/include/hal/adc_types.h" - - "components/hal/include/hal/adc_hal.h" - - "components/hal/include/hal/rtc_hal.h" - - "components/hal/include/hal/apm_hal.h" - "components/hal/include/hal/ecdsa_hal.h" - - "components/hal/include/hal/emac_hal.h" - "components/hal/include/hal/gpio_hal.h" - - "components/hal/include/hal/mmu_hal.h" - - "components/hal/include/hal/pmu_types.h" - - "components/hal/include/hal/sha_types.h" - - "components/hal/include/hal/touch_sensor_legacy_types.h" - "components/hal/include/hal/twai_types_deprecated.h" rule: any: @@ -73,28 +53,11 @@ ignores: - "components/hal/platform_port/**/*" - "components/hal/test_apps/**/*" # the following files should be refactored to remove sdkconfig.h - - "components/hal/adc_hal.c" - "components/hal/adc_oneshot_hal.c" - "components/hal/cache_hal.c" - - "components/hal/emac_hal.c" - "components/hal/mmu_hal.c" - - "components/hal/mpi_hal.c" - - "components/hal/spi_flash_hal_iram.c" - "components/hal/twai_hal_sja1000.c" - - "components/hal/usb_dwc_hal.c" - - "components/hal/efuse_hal.c" - - "components/hal/esp32/include/hal/twai_ll.h" - - "components/hal/esp32c2/clk_tree_hal.c" - - "components/hal/*/efuse_hal.c" - - "components/hal/include/hal/adc_types.h" - "components/hal/include/hal/ecdsa_hal.h" - - "components/hal/include/hal/modem_clock_hal.h" - - "components/hal/include/hal/mpi_hal.h" - - "components/hal/include/hal/pmu_types.h" - - "components/hal/include/hal/rtc_hal.h" - - "components/hal/include/hal/sha_types.h" - - "components/hal/include/hal/touch_sensor_legacy_types.h" - - "components/hal/include/hal/twai_hal.h" - "components/hal/include/hal/twai_types_deprecated.h" rule: kind: preproc_include