diff --git a/components/hal/ecdsa_hal.c b/components/hal/ecdsa_hal.c index 2c7f607d7c..c15c826e49 100644 --- a/components/hal/ecdsa_hal.c +++ b/components/hal/ecdsa_hal.c @@ -10,7 +10,7 @@ #include "hal/efuse_hal.h" #include "soc/soc_caps.h" -#if HAL_CONFIG_ECDSA_GEN_SIG_CM +#if HAL_CONFIG(ECDSA_GEN_SIG_CM) #include "esp_fault.h" #include "esp_random.h" #include "soc/chip_revision.h" @@ -99,7 +99,7 @@ static void ecdsa_hal_gen_signature_inner(const uint8_t *hash, uint8_t *r_out, } } -#if HAL_CONFIG_ECDSA_GEN_SIG_CM +#if HAL_CONFIG(ECDSA_GEN_SIG_CM) __attribute__((optimize("O0"))) static void ecdsa_hal_gen_signature_with_countermeasure(const uint8_t *hash, uint8_t *r_out, uint8_t *s_out, uint16_t len) { @@ -148,7 +148,7 @@ void ecdsa_hal_gen_signature(ecdsa_hal_config_t *conf, const uint8_t *hash, configure_ecdsa_periph(conf); -#if HAL_CONFIG_ECDSA_GEN_SIG_CM +#if HAL_CONFIG(ECDSA_GEN_SIG_CM) #if SOC_IS(ESP32H2) if (!ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 102)) { ecdsa_hal_gen_signature_with_countermeasure(hash, r_out, s_out, len); diff --git a/components/hal/esp32/efuse_hal.c b/components/hal/esp32/efuse_hal.c index 365fcdacea..7a8148e5ad 100644 --- a/components/hal/esp32/efuse_hal.c +++ b/components/hal/esp32/efuse_hal.c @@ -29,7 +29,7 @@ IRAM_ATTR uint32_t efuse_hal_get_major_chip_version(void) case 3: chip_ver = 2; break; -#if HAL_CONFIG_EFUSE_ENV_FPGA +#if HAL_CONFIG(EFUSE_ENV_FPGA) case 4: /* Empty efuses, but SYSCON_DATE_REG bit is set */ chip_ver = 3; break; diff --git a/components/hal/esp32c2/clk_tree_hal.c b/components/hal/esp32c2/clk_tree_hal.c index 0d4b372828..ca8a1b27cd 100644 --- a/components/hal/esp32c2/clk_tree_hal.c +++ b/components/hal/esp32c2/clk_tree_hal.c @@ -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", HAL_CONFIG_XTAL_HINT_FREQ_MHZ); - return HAL_CONFIG_XTAL_HINT_FREQ_MHZ; + 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/include/hal/gpio_ll.h b/components/hal/esp32c5/include/hal/gpio_ll.h index 8bee5b18c2..aeb764c15f 100644 --- a/components/hal/esp32c5/include/hal/gpio_ll.h +++ b/components/hal/esp32c5/include/hal/gpio_ll.h @@ -339,7 +339,7 @@ static inline void gpio_ll_od_enable(gpio_dev_t *hw, uint32_t gpio_num) __attribute__((always_inline)) static inline void gpio_ll_set_level(gpio_dev_t *hw, uint32_t gpio_num, uint32_t level) { -#if HAL_CONFIG_GPIO_USE_ROM_API +#if HAL_CONFIG(GPIO_USE_ROM_API) gpio_set_output_level(gpio_num, level); #else if (level) { @@ -365,7 +365,7 @@ static inline void gpio_ll_set_level(gpio_dev_t *hw, uint32_t gpio_num, uint32_t __attribute__((always_inline)) static inline int gpio_ll_get_level(gpio_dev_t *hw, uint32_t gpio_num) { -#if HAL_CONFIG_GPIO_USE_ROM_API +#if HAL_CONFIG(GPIO_USE_ROM_API) return gpio_get_input_level(gpio_num); #else return (hw->in.in_data_next >> gpio_num) & 0x1; diff --git a/components/hal/esp32c61/include/hal/gpio_ll.h b/components/hal/esp32c61/include/hal/gpio_ll.h index 96370f0223..6c961bfbac 100644 --- a/components/hal/esp32c61/include/hal/gpio_ll.h +++ b/components/hal/esp32c61/include/hal/gpio_ll.h @@ -337,7 +337,7 @@ static inline void gpio_ll_od_enable(gpio_dev_t *hw, uint32_t gpio_num) __attribute__((always_inline)) static inline void gpio_ll_set_level(gpio_dev_t *hw, uint32_t gpio_num, uint32_t level) { -#if HAL_CONFIG_GPIO_USE_ROM_API +#if HAL_CONFIG(GPIO_USE_ROM_API) gpio_set_output_level(gpio_num, level); #else if (level) { @@ -363,7 +363,7 @@ static inline void gpio_ll_set_level(gpio_dev_t *hw, uint32_t gpio_num, uint32_t __attribute__((always_inline)) static inline int gpio_ll_get_level(gpio_dev_t *hw, uint32_t gpio_num) { -#if HAL_CONFIG_GPIO_USE_ROM_API +#if HAL_CONFIG(GPIO_USE_ROM_API) return gpio_get_input_level(gpio_num); #else return (hw->in.in_data_next >> gpio_num) & 0x1; diff --git a/components/hal/esp32h4/include/hal/gpio_ll.h b/components/hal/esp32h4/include/hal/gpio_ll.h index 3bfdc69b18..82d75b564e 100644 --- a/components/hal/esp32h4/include/hal/gpio_ll.h +++ b/components/hal/esp32h4/include/hal/gpio_ll.h @@ -317,7 +317,7 @@ static inline void gpio_ll_od_enable(gpio_dev_t *hw, uint32_t gpio_num) __attribute__((always_inline)) static inline void gpio_ll_set_level(gpio_dev_t *hw, uint32_t gpio_num, uint32_t level) { -#if HAL_CONFIG_GPIO_USE_ROM_API +#if HAL_CONFIG(GPIO_USE_ROM_API) gpio_set_output_level(gpio_num, level); #else if (level) { @@ -351,7 +351,7 @@ static inline void gpio_ll_set_level(gpio_dev_t *hw, uint32_t gpio_num, uint32_t __attribute__((always_inline)) static inline int gpio_ll_get_level(gpio_dev_t *hw, uint32_t gpio_num) { -#if HAL_CONFIG_GPIO_USE_ROM_API +#if HAL_CONFIG(GPIO_USE_ROM_API) return gpio_get_input_level(gpio_num); #else if (gpio_num < 32) { diff --git a/components/hal/esp32p4/include/hal/gpio_ll.h b/components/hal/esp32p4/include/hal/gpio_ll.h index ae72435ac5..e5508f6f8b 100644 --- a/components/hal/esp32p4/include/hal/gpio_ll.h +++ b/components/hal/esp32p4/include/hal/gpio_ll.h @@ -384,7 +384,7 @@ static inline void gpio_ll_od_enable(gpio_dev_t *hw, uint32_t gpio_num) __attribute__((always_inline)) static inline void gpio_ll_set_level(gpio_dev_t *hw, uint32_t gpio_num, uint32_t level) { -#if HAL_CONFIG_GPIO_USE_ROM_API +#if HAL_CONFIG(GPIO_USE_ROM_API) gpio_set_output_level(gpio_num, level); #else if (level) { @@ -418,7 +418,7 @@ static inline void gpio_ll_set_level(gpio_dev_t *hw, uint32_t gpio_num, uint32_t __attribute__((always_inline)) static inline int gpio_ll_get_level(gpio_dev_t *hw, uint32_t gpio_num) { -#if HAL_CONFIG_GPIO_USE_ROM_API +#if HAL_CONFIG(GPIO_USE_ROM_API) return gpio_get_input_level(gpio_num); #else if (gpio_num < 32) { diff --git a/components/hal/gpio_hal.c b/components/hal/gpio_hal.c index 7b1646fefc..a4f7ff754a 100644 --- a/components/hal/gpio_hal.c +++ b/components/hal/gpio_hal.c @@ -49,7 +49,7 @@ void gpio_hal_iomux_out(gpio_hal_context_t *hal, uint32_t gpio_num, int func) void gpio_hal_matrix_in(gpio_hal_context_t *hal, uint32_t gpio_num, uint32_t signal_idx, bool in_inv) { gpio_ll_input_enable(hal->dev, gpio_num); -#if HAL_CONFIG_GPIO_USE_ROM_API +#if HAL_CONFIG(GPIO_USE_ROM_API) esp_rom_gpio_connect_in_signal(gpio_num, signal_idx, in_inv); #else gpio_ll_set_input_signal_matrix_source(hal->dev, signal_idx, gpio_num, in_inv); @@ -59,7 +59,7 @@ void gpio_hal_matrix_in(gpio_hal_context_t *hal, uint32_t gpio_num, uint32_t sig void gpio_hal_matrix_out(gpio_hal_context_t *hal, uint32_t gpio_num, uint32_t signal_idx, bool out_inv, bool oen_inv) { gpio_ll_func_sel(hal->dev, gpio_num, PIN_FUNC_GPIO); -#if HAL_CONFIG_GPIO_USE_ROM_API +#if HAL_CONFIG(GPIO_USE_ROM_API) esp_rom_gpio_connect_out_signal(gpio_num, signal_idx, out_inv, oen_inv); #else gpio_ll_set_output_signal_matrix_source(hal->dev, gpio_num, signal_idx, out_inv); diff --git a/components/hal/include/hal/ecdsa_hal.h b/components/hal/include/hal/ecdsa_hal.h index 3053286a5b..ec654a0b61 100644 --- a/components/hal/include/hal/ecdsa_hal.h +++ b/components/hal/include/hal/ecdsa_hal.h @@ -22,7 +22,7 @@ extern "C" { #endif -#if HAL_CONFIG_ECDSA_GEN_SIG_CM +#if HAL_CONFIG(ECDSA_GEN_SIG_CM) #define ECDSA_SIGN_MAX_DUMMY_OP_COUNT 0x7 diff --git a/components/hal/platform_port/include/hal/config.h b/components/hal/platform_port/include/hal/config.h index f7790b8191..f91ffff1bb 100644 --- a/components/hal/platform_port/include/hal/config.h +++ b/components/hal/platform_port/include/hal/config.h @@ -11,6 +11,16 @@ extern "C" { #endif +/** + * @brief Macro to access HAL configuration options. + * + * This macro is used to access various HAL configuration options defined in config.h + * It should be used instead of directly accessing the HAL_CONFIG_ prefixed options. + * + * @param x The configuration option to access, without the HAL_CONFIG_ prefix. + */ +#define HAL_CONFIG(x) HAL_CONFIG_##x + /** * @brief Enable this to reuse ROM APIs for GPIO operations. * It will save some code size. diff --git a/components/hal/spi_flash_hal_iram.c b/components/hal/spi_flash_hal_iram.c index 97751bfb0a..2c47646b07 100644 --- a/components/hal/spi_flash_hal_iram.c +++ b/components/hal/spi_flash_hal_iram.c @@ -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 -#if !HAL_CONFIG_SPI_FLASH_USE_ROM_API +#if !HAL_CONFIG(SPI_FLASH_USE_ROM_API) #include "spi_flash_hal_common.inc" diff --git a/tools/ci/sg_rules/recommend_way_to_use_hal_config.yml b/tools/ci/sg_rules/recommend_way_to_use_hal_config.yml new file mode 100644 index 0000000000..4b212ec09d --- /dev/null +++ b/tools/ci/sg_rules/recommend_way_to_use_hal_config.yml @@ -0,0 +1,22 @@ +# Refer to https://ast-grep.github.io/guide/rule-config.html for Rule Essentials +id: recommended-way-to-use-hal-config +message: Don't expand HAL_CONFIG macro manually +severity: error # error, warning, info, hint +note: Should use HAL_CONFIG() to compute the value of the HAL_CONFIG macros +language: C +files: + - "components/**/*" + - "examples/**/*" +ignores: + - "components/hal/platform_port/include/hal/config.h" +rule: + kind: identifier + pattern: $A + regex: "^HAL_CONFIG_" +transform: + B: + substring: + source: $A + startChar: 11 +fix: + HAL_CONFIG($B)