From d91e64cea411e65f3c96b2b2f321ba8a3e7a7c88 Mon Sep 17 00:00:00 2001 From: fuzhibo Date: Mon, 27 Apr 2020 20:30:23 +0800 Subject: [PATCH] driver(gpio): fix gpio can't wakeup light sleep --- components/driver/gpio.c | 14 ++++++-------- examples/system/light_sleep/README.md | 3 --- .../light_sleep/main/light_sleep_example_main.c | 5 ++--- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/components/driver/gpio.c b/components/driver/gpio.c index 8c00916c00..590ad0ecb6 100644 --- a/components/driver/gpio.c +++ b/components/driver/gpio.c @@ -535,11 +535,10 @@ esp_err_t gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type) if ((intr_type == GPIO_INTR_LOW_LEVEL) || (intr_type == GPIO_INTR_HIGH_LEVEL)) { if (rtc_gpio_is_valid_gpio(gpio_num)) { ret = rtc_gpio_wakeup_enable(gpio_num, intr_type); - } else { - portENTER_CRITICAL(&gpio_context.gpio_spinlock); - gpio_hal_wakeup_enable(gpio_context.gpio_hal, gpio_num, intr_type); - portEXIT_CRITICAL(&gpio_context.gpio_spinlock); } + portENTER_CRITICAL(&gpio_context.gpio_spinlock); + gpio_hal_wakeup_enable(gpio_context.gpio_hal, gpio_num, intr_type); + portEXIT_CRITICAL(&gpio_context.gpio_spinlock); } else { ESP_LOGE(GPIO_TAG, "GPIO wakeup only supports level mode, but edge mode set. gpio_num:%u", gpio_num); ret = ESP_ERR_INVALID_ARG; @@ -555,11 +554,10 @@ esp_err_t gpio_wakeup_disable(gpio_num_t gpio_num) if (rtc_gpio_is_valid_gpio(gpio_num)) { ret = rtc_gpio_wakeup_disable(gpio_num); - } else { - portENTER_CRITICAL(&gpio_context.gpio_spinlock); - gpio_hal_wakeup_disable(gpio_context.gpio_hal, gpio_num); - portEXIT_CRITICAL(&gpio_context.gpio_spinlock); } + portENTER_CRITICAL(&gpio_context.gpio_spinlock); + gpio_hal_wakeup_disable(gpio_context.gpio_hal, gpio_num); + portEXIT_CRITICAL(&gpio_context.gpio_spinlock); return ret; } diff --git a/examples/system/light_sleep/README.md b/examples/system/light_sleep/README.md index c64be0e50c..c9212067c6 100644 --- a/examples/system/light_sleep/README.md +++ b/examples/system/light_sleep/README.md @@ -1,6 +1,3 @@ -| Supported Targets | ESP32 | -| ----------------- | ----- | - # Light Sleep Example (See the README.md file in the upper level 'examples' directory for more information about examples.) diff --git a/examples/system/light_sleep/main/light_sleep_example_main.c b/examples/system/light_sleep/main/light_sleep_example_main.c index 4b8dc17115..a11a07e473 100644 --- a/examples/system/light_sleep/main/light_sleep_example_main.c +++ b/examples/system/light_sleep/main/light_sleep_example_main.c @@ -17,7 +17,6 @@ #include "esp_sleep.h" #include "esp_log.h" #include "driver/uart.h" -#include "driver/rtc_io.h" /* Most development boards have "boot" button attached to GPIO0. * You can also change this to another pin. @@ -46,11 +45,11 @@ void app_main(void) esp_sleep_enable_gpio_wakeup(); /* Wait until GPIO goes high */ - if (rtc_gpio_get_level(button_gpio_num) == wakeup_level) { + if (gpio_get_level(button_gpio_num) == wakeup_level) { printf("Waiting for GPIO%d to go high...\n", button_gpio_num); do { vTaskDelay(pdMS_TO_TICKS(10)); - } while (rtc_gpio_get_level(button_gpio_num) == wakeup_level); + } while (gpio_get_level(button_gpio_num) == wakeup_level); } printf("Entering light sleep\n");