Ver código fonte

driver(gpio): fix gpio can't wakeup light sleep

fuzhibo 5 anos atrás
pai
commit
d91e64cea4

+ 6 - 8
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 ((intr_type == GPIO_INTR_LOW_LEVEL) || (intr_type == GPIO_INTR_HIGH_LEVEL)) {
         if (rtc_gpio_is_valid_gpio(gpio_num)) {
         if (rtc_gpio_is_valid_gpio(gpio_num)) {
             ret = rtc_gpio_wakeup_enable(gpio_num, intr_type);
             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 {
     } else {
         ESP_LOGE(GPIO_TAG, "GPIO wakeup only supports level mode, but edge mode set. gpio_num:%u", gpio_num);
         ESP_LOGE(GPIO_TAG, "GPIO wakeup only supports level mode, but edge mode set. gpio_num:%u", gpio_num);
         ret = ESP_ERR_INVALID_ARG;
         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)) {
     if (rtc_gpio_is_valid_gpio(gpio_num)) {
         ret = rtc_gpio_wakeup_disable(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;
     return ret;
 }
 }
 
 

+ 0 - 3
examples/system/light_sleep/README.md

@@ -1,6 +1,3 @@
-| Supported Targets | ESP32 |
-| ----------------- | ----- |
-
 # Light Sleep Example
 # Light Sleep Example
 
 
 (See the README.md file in the upper level 'examples' directory for more information about examples.)
 (See the README.md file in the upper level 'examples' directory for more information about examples.)

+ 2 - 3
examples/system/light_sleep/main/light_sleep_example_main.c

@@ -17,7 +17,6 @@
 #include "esp_sleep.h"
 #include "esp_sleep.h"
 #include "esp_log.h"
 #include "esp_log.h"
 #include "driver/uart.h"
 #include "driver/uart.h"
-#include "driver/rtc_io.h"
 
 
 /* Most development boards have "boot" button attached to GPIO0.
 /* Most development boards have "boot" button attached to GPIO0.
  * You can also change this to another pin.
  * You can also change this to another pin.
@@ -46,11 +45,11 @@ void app_main(void)
         esp_sleep_enable_gpio_wakeup();
         esp_sleep_enable_gpio_wakeup();
 
 
         /* Wait until GPIO goes high */
         /* 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);
             printf("Waiting for GPIO%d to go high...\n", button_gpio_num);
             do {
             do {
                 vTaskDelay(pdMS_TO_TICKS(10));
                 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");
         printf("Entering light sleep\n");