From 8f74c54a8ab86e0f8fd29a057b505f9639b2fda5 Mon Sep 17 00:00:00 2001 From: Song Ruo Jing Date: Mon, 17 Mar 2025 21:04:06 +0800 Subject: [PATCH 1/2] refactor(gpio): simplified gpio_reset_pin function to not call gpio_configure Closes https://github.com/espressif/esp-idf/pull/15569 --- .../esp_driver_gpio/include/driver/gpio.h | 10 +++----- components/esp_driver_gpio/src/gpio.c | 25 +++++++++++-------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/components/esp_driver_gpio/include/driver/gpio.h b/components/esp_driver_gpio/include/driver/gpio.h index af7e801bfb..04dff3e7ab 100644 --- a/components/esp_driver_gpio/include/driver/gpio.h +++ b/components/esp_driver_gpio/include/driver/gpio.h @@ -71,15 +71,13 @@ typedef struct { esp_err_t gpio_config(const gpio_config_t *pGPIOConfig); /** - * @brief Reset an gpio to default state (select gpio function, enable pullup and disable input and output). + * @brief Reset a GPIO to a certain state (select gpio function, enable pullup and disable input and output). * * @param gpio_num GPIO number. * - * @note This function also configures the IOMUX for this pin to the GPIO - * function, and disconnects any other peripheral output configured via GPIO - * Matrix. - * - * @return Always return ESP_OK. + * @return + * - ESP_OK Success + * - ESP_ERR_INVALID_ARG Parameter error */ esp_err_t gpio_reset_pin(gpio_num_t gpio_num); diff --git a/components/esp_driver_gpio/src/gpio.c b/components/esp_driver_gpio/src/gpio.c index 69baf27b14..46787bf093 100644 --- a/components/esp_driver_gpio/src/gpio.c +++ b/components/esp_driver_gpio/src/gpio.c @@ -401,7 +401,7 @@ esp_err_t gpio_config(const gpio_config_t *pGPIOConfig) gpio_pulldown_dis(io_num); } - ESP_LOGI(GPIO_TAG, "GPIO[%"PRIu32"]| InputEn: %d| OutputEn: %d| OpenDrain: %d| Pullup: %d| Pulldown: %d| Intr:%d ", io_num, input_en, output_en, od_en, pu_en, pd_en, pGPIOConfig->intr_type); + ESP_LOGD(GPIO_TAG, "GPIO[%"PRIu32"]| InputEn: %d| OutputEn: %d| OpenDrain: %d| Pullup: %d| Pulldown: %d| Intr:%d ", io_num, input_en, output_en, od_en, pu_en, pd_en, pGPIOConfig->intr_type); gpio_set_intr_type(io_num, pGPIOConfig->intr_type); if (pGPIOConfig->intr_type) { @@ -455,16 +455,19 @@ esp_err_t gpio_config_as_analog(gpio_num_t gpio_num) esp_err_t gpio_reset_pin(gpio_num_t gpio_num) { - assert(GPIO_IS_VALID_GPIO(gpio_num)); - gpio_config_t cfg = { - .pin_bit_mask = BIT64(gpio_num), - .mode = GPIO_MODE_DISABLE, - //for powersave reasons, the GPIO should not be floating, select pullup - .pull_up_en = true, - .pull_down_en = false, - .intr_type = GPIO_INTR_DISABLE, - }; - gpio_config(&cfg); + GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG); + gpio_intr_disable(gpio_num); + // for powersave reasons, the GPIO should not be floating, select pullup + gpio_pullup_en(gpio_num); + gpio_pulldown_dis(gpio_num); + gpio_input_disable(gpio_num); + gpio_output_disable(gpio_num); +#if SOC_RTCIO_PIN_COUNT > 0 + if (rtc_gpio_is_valid_gpio(gpio_num)) { + rtc_gpio_deinit(gpio_num); + } +#endif + gpio_hal_func_sel(gpio_context.gpio_hal, gpio_num, PIN_FUNC_GPIO); return ESP_OK; } From cbf7a66030aeea188e2846da2b923ae9d9732cd2 Mon Sep 17 00:00:00 2001 From: Song Ruo Jing Date: Thu, 20 Mar 2025 14:50:44 +0800 Subject: [PATCH 2/2] feat(gpio): gpio_reset_pin should do IO reservation revoke Closes https://github.com/espressif/esp-idf/issues/15598 --- components/esp_driver_gpio/include/esp_private/gpio.h | 4 ++-- components/esp_driver_gpio/src/gpio.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/components/esp_driver_gpio/include/esp_private/gpio.h b/components/esp_driver_gpio/include/esp_private/gpio.h index ceba5342ed..1a089cf6d0 100644 --- a/components/esp_driver_gpio/include/esp_private/gpio.h +++ b/components/esp_driver_gpio/include/esp_private/gpio.h @@ -83,7 +83,7 @@ esp_err_t gpio_output_disable(gpio_num_t gpio_num); * - ESP_OK Success * - ESP_ERR_INVALID_ARG GPIO number error */ -esp_err_t gpio_od_disable(gpio_num_t gpio_num); +esp_err_t gpio_od_enable(gpio_num_t gpio_num); /** * @brief Disable open-drain for an IO @@ -94,7 +94,7 @@ esp_err_t gpio_od_disable(gpio_num_t gpio_num); * - ESP_OK Success * - ESP_ERR_INVALID_ARG GPIO number error */ -esp_err_t gpio_od_enable(gpio_num_t gpio_num); +esp_err_t gpio_od_disable(gpio_num_t gpio_num); /** * @brief Configure the pin to be used for analog purpose (such as ADC, touch, etc.) diff --git a/components/esp_driver_gpio/src/gpio.c b/components/esp_driver_gpio/src/gpio.c index 46787bf093..6def528987 100644 --- a/components/esp_driver_gpio/src/gpio.c +++ b/components/esp_driver_gpio/src/gpio.c @@ -468,6 +468,7 @@ esp_err_t gpio_reset_pin(gpio_num_t gpio_num) } #endif gpio_hal_func_sel(gpio_context.gpio_hal, gpio_num, PIN_FUNC_GPIO); + esp_gpio_revoke(BIT64(gpio_num)); return ESP_OK; }