From 001d01f93acf03afe8a12dc05c133e4696bf52da Mon Sep 17 00:00:00 2001 From: "C.S.M" Date: Mon, 14 Jul 2025 13:28:44 +0800 Subject: [PATCH] refactor(gpio): Move valid gpio_caps macro from driver layer to hal --- .../esp_driver_gpio/include/driver/gpio.h | 11 ------ components/esp_hw_support/usb_phy/usb_phy.c | 7 ---- components/hal/include/hal/gpio_types.h | 11 ++++++ components/spi_flash/CMakeLists.txt | 4 +- components/spi_flash/esp_flash_spi_init.c | 1 - .../g1_components/check_dependencies.py | 37 ++++++++++++++----- 6 files changed, 40 insertions(+), 31 deletions(-) diff --git a/components/esp_driver_gpio/include/driver/gpio.h b/components/esp_driver_gpio/include/driver/gpio.h index a15bf533f0..a46f5996ce 100644 --- a/components/esp_driver_gpio/include/driver/gpio.h +++ b/components/esp_driver_gpio/include/driver/gpio.h @@ -20,17 +20,6 @@ extern "C" { #endif -#define GPIO_PIN_COUNT (SOC_GPIO_PIN_COUNT) -/// Check whether it is a valid GPIO number -#define GPIO_IS_VALID_GPIO(gpio_num) ((gpio_num >= 0) && \ - (((1ULL << (gpio_num)) & SOC_GPIO_VALID_GPIO_MASK) != 0)) -/// Check whether it can be a valid GPIO number of output mode -#define GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) ((gpio_num >= 0) && \ - (((1ULL << (gpio_num)) & SOC_GPIO_VALID_OUTPUT_GPIO_MASK) != 0)) -/// Check whether it can be a valid digital I/O pad -#define GPIO_IS_VALID_DIGITAL_IO_PAD(gpio_num) ((gpio_num >= 0) && \ - (((1ULL << (gpio_num)) & SOC_GPIO_VALID_DIGITAL_IO_PAD_MASK) != 0)) - typedef intr_handle_t gpio_isr_handle_t; /** diff --git a/components/esp_hw_support/usb_phy/usb_phy.c b/components/esp_hw_support/usb_phy/usb_phy.c index 01c29dbdd1..f67d470685 100644 --- a/components/esp_hw_support/usb_phy/usb_phy.c +++ b/components/esp_hw_support/usb_phy/usb_phy.c @@ -20,13 +20,6 @@ #include "hal/gpio_ll.h" #include "soc/soc_caps.h" -/// Check whether it is a valid GPIO number -#define GPIO_IS_VALID_GPIO(gpio_num) ((gpio_num >= 0) && \ - (((1ULL << (gpio_num)) & SOC_GPIO_VALID_GPIO_MASK) != 0)) -/// Check whether it can be a valid GPIO number of output mode -#define GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) ((gpio_num >= 0) && \ - (((1ULL << (gpio_num)) & SOC_GPIO_VALID_OUTPUT_GPIO_MASK) != 0)) - #if SOC_USB_UTMI_PHY_NO_POWER_OFF_ISO #include "esp_private/sleep_usb.h" #include "esp_sleep.h" diff --git a/components/hal/include/hal/gpio_types.h b/components/hal/include/hal/gpio_types.h index d98ee5a03b..d60bb6e4e3 100644 --- a/components/hal/include/hal/gpio_types.h +++ b/components/hal/include/hal/gpio_types.h @@ -16,6 +16,17 @@ extern "C" { #endif +#define GPIO_PIN_COUNT (SOC_GPIO_PIN_COUNT) +/// Check whether it is a valid GPIO number +#define GPIO_IS_VALID_GPIO(gpio_num) ((gpio_num >= 0) && \ + (((1ULL << (gpio_num)) & SOC_GPIO_VALID_GPIO_MASK) != 0)) +/// Check whether it can be a valid GPIO number of output mode +#define GPIO_IS_VALID_OUTPUT_GPIO(gpio_num) ((gpio_num >= 0) && \ + (((1ULL << (gpio_num)) & SOC_GPIO_VALID_OUTPUT_GPIO_MASK) != 0)) +/// Check whether it can be a valid digital I/O pad +#define GPIO_IS_VALID_DIGITAL_IO_PAD(gpio_num) ((gpio_num >= 0) && \ + (((1ULL << (gpio_num)) & SOC_GPIO_VALID_DIGITAL_IO_PAD_MASK) != 0)) + typedef enum { GPIO_PORT_0 = 0, GPIO_PORT_MAX, diff --git a/components/spi_flash/CMakeLists.txt b/components/spi_flash/CMakeLists.txt index 024f0a0a6c..1cd7c874fe 100644 --- a/components/spi_flash/CMakeLists.txt +++ b/components/spi_flash/CMakeLists.txt @@ -52,9 +52,7 @@ else() "spi_flash_os_func_noos.c") list(APPEND srcs ${cache_srcs}) - set(priv_requires bootloader_support app_update soc esp_mm - esp_driver_gpio - ) + set(priv_requires bootloader_support soc esp_mm) endif() idf_component_register(SRCS "${srcs}" diff --git a/components/spi_flash/esp_flash_spi_init.c b/components/spi_flash/esp_flash_spi_init.c index d16506d391..8a63a3bbcd 100644 --- a/components/spi_flash/esp_flash_spi_init.c +++ b/components/spi_flash/esp_flash_spi_init.c @@ -8,7 +8,6 @@ #include "esp_flash.h" #include "memspi_host_driver.h" #include "esp_flash_spi_init.h" -#include "driver/gpio.h" #include "esp_rom_gpio.h" #include "esp_rom_efuse.h" #include "esp_log.h" diff --git a/tools/test_apps/system/g1_components/check_dependencies.py b/tools/test_apps/system/g1_components/check_dependencies.py index 3f0e8e7c1b..eb156e1729 100644 --- a/tools/test_apps/system/g1_components/check_dependencies.py +++ b/tools/test_apps/system/g1_components/check_dependencies.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Unlicense OR CC0-1.0 import argparse import logging @@ -6,13 +6,30 @@ from typing import Dict from typing import List from typing import Tuple -g1_g0_components = ['hal', 'cxx', 'newlib', 'freertos', 'esp_hw_support', 'heap', 'log', 'soc', 'esp_rom', - 'esp_common', 'esp_system', 'xtensa', 'riscv', 'spi_flash', 'esp_mm'] +g1_g0_components = [ + 'hal', + 'cxx', + 'newlib', + 'freertos', + 'esp_hw_support', + 'heap', + 'log', + 'soc', + 'esp_rom', + 'esp_common', + 'esp_system', + 'xtensa', + 'riscv', + 'spi_flash', + 'esp_mm', +] -expected_dep_violations = {'esp_system': ['esp_timer', 'bootloader_support', 'esp_pm'], - 'spi_flash': ['bootloader_support', 'app_update', 'esp_driver_gpio'], - 'esp_hw_support': ['efuse', 'bootloader_support', 'esp_driver_gpio', 'esp_timer', 'esp_pm', 'esp_security'], - 'cxx': ['pthread']} +expected_dep_violations = { + 'esp_system': ['esp_timer', 'bootloader_support', 'esp_pm'], + 'spi_flash': ['bootloader_support'], + 'esp_hw_support': ['efuse', 'bootloader_support', 'esp_driver_gpio', 'esp_timer', 'esp_pm', 'esp_security'], + 'cxx': ['pthread'], +} def parse_dependencies(file_path: str) -> Tuple[Dict[str, List[str]], List[str]]: @@ -25,7 +42,7 @@ def parse_dependencies(file_path: str) -> Tuple[Dict[str, List[str]], List[str]] if line: parts = line.split(' -> ') - if (len(parts) >= 2): + if len(parts) >= 2: source = parts[0] target = parts[1].split()[0] # Extracting the target component logging.debug(f'Parsed dependency: {source} -> {target}') @@ -48,7 +65,9 @@ def parse_dependencies(file_path: str) -> Tuple[Dict[str, List[str]], List[str]] if __name__ == '__main__': parser = argparse.ArgumentParser(description='Check G1 dependencies') - parser.add_argument('--component_deps_file', required=True, type=str, help='The path to the component_deps.dot file') + parser.add_argument( + '--component_deps_file', required=True, type=str, help='The path to the component_deps.dot file' + ) args = parser.parse_args()