Skip to content

Commit f3625b0

Browse files
committed
Merge branch 'refactor/gpio_reset_pin' into 'master'
refactor(gpio): simplified gpio_reset_pin function to not call gpio_configure Closes IDFGH-14846 and IDFGH-14880 See merge request espressif/esp-idf!37814
2 parents 465ff85 + cbf7a66 commit f3625b0

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

components/esp_driver_gpio/include/driver/gpio.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,13 @@ typedef struct {
7171
esp_err_t gpio_config(const gpio_config_t *pGPIOConfig);
7272

7373
/**
74-
* @brief Reset an gpio to default state (select gpio function, enable pullup and disable input and output).
74+
* @brief Reset a GPIO to a certain state (select gpio function, enable pullup and disable input and output).
7575
*
7676
* @param gpio_num GPIO number.
7777
*
78-
* @note This function also configures the IOMUX for this pin to the GPIO
79-
* function, and disconnects any other peripheral output configured via GPIO
80-
* Matrix.
81-
*
82-
* @return Always return ESP_OK.
78+
* @return
79+
* - ESP_OK Success
80+
* - ESP_ERR_INVALID_ARG Parameter error
8381
*/
8482
esp_err_t gpio_reset_pin(gpio_num_t gpio_num);
8583

components/esp_driver_gpio/include/esp_private/gpio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ esp_err_t gpio_output_disable(gpio_num_t gpio_num);
8383
* - ESP_OK Success
8484
* - ESP_ERR_INVALID_ARG GPIO number error
8585
*/
86-
esp_err_t gpio_od_disable(gpio_num_t gpio_num);
86+
esp_err_t gpio_od_enable(gpio_num_t gpio_num);
8787

8888
/**
8989
* @brief Disable open-drain for an IO
@@ -94,7 +94,7 @@ esp_err_t gpio_od_disable(gpio_num_t gpio_num);
9494
* - ESP_OK Success
9595
* - ESP_ERR_INVALID_ARG GPIO number error
9696
*/
97-
esp_err_t gpio_od_enable(gpio_num_t gpio_num);
97+
esp_err_t gpio_od_disable(gpio_num_t gpio_num);
9898

9999
/**
100100
* @brief Configure the pin to be used for analog purpose (such as ADC, touch, etc.)

components/esp_driver_gpio/src/gpio.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ esp_err_t gpio_config(const gpio_config_t *pGPIOConfig)
401401
gpio_pulldown_dis(io_num);
402402
}
403403

404-
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);
404+
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);
405405
gpio_set_intr_type(io_num, pGPIOConfig->intr_type);
406406

407407
if (pGPIOConfig->intr_type) {
@@ -455,16 +455,20 @@ esp_err_t gpio_config_as_analog(gpio_num_t gpio_num)
455455

456456
esp_err_t gpio_reset_pin(gpio_num_t gpio_num)
457457
{
458-
assert(GPIO_IS_VALID_GPIO(gpio_num));
459-
gpio_config_t cfg = {
460-
.pin_bit_mask = BIT64(gpio_num),
461-
.mode = GPIO_MODE_DISABLE,
462-
//for powersave reasons, the GPIO should not be floating, select pullup
463-
.pull_up_en = true,
464-
.pull_down_en = false,
465-
.intr_type = GPIO_INTR_DISABLE,
466-
};
467-
gpio_config(&cfg);
458+
GPIO_CHECK(GPIO_IS_VALID_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
459+
gpio_intr_disable(gpio_num);
460+
// for powersave reasons, the GPIO should not be floating, select pullup
461+
gpio_pullup_en(gpio_num);
462+
gpio_pulldown_dis(gpio_num);
463+
gpio_input_disable(gpio_num);
464+
gpio_output_disable(gpio_num);
465+
#if SOC_RTCIO_PIN_COUNT > 0
466+
if (rtc_gpio_is_valid_gpio(gpio_num)) {
467+
rtc_gpio_deinit(gpio_num);
468+
}
469+
#endif
470+
gpio_hal_func_sel(gpio_context.gpio_hal, gpio_num, PIN_FUNC_GPIO);
471+
esp_gpio_revoke(BIT64(gpio_num));
468472
return ESP_OK;
469473
}
470474

0 commit comments

Comments
 (0)