pcnt: rotary encoder wake up system from light sleep example

This commit is contained in:
morris
2022-09-26 16:45:57 +08:00
parent db9caf4354
commit a0e8c4692a
3 changed files with 20 additions and 0 deletions

View File

@@ -53,6 +53,8 @@ The GPIO used by the example can be changed according to your board by `EXAMPLE_
### Build and Flash ### Build and Flash
By configuring one of the EC11 GPIO (e.g. `EXAMPLE_EC11_GPIO_A`) as a wake up source, we can make the rotary encoder wake the system from light sleep. This example can illustrate this feature if you enable the `EXAMPLE_WAKE_UP_LIGHT_SLEEP` from the menuconfig.
Run `idf.py -p PORT flash monitor` to build, flash and monitor the project. Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.
(To exit the serial monitor, type ``Ctrl-]``.) (To exit the serial monitor, type ``Ctrl-]``.)

View File

@@ -0,0 +1,8 @@
menu "Example Configuration"
config EXAMPLE_WAKE_UP_LIGHT_SLEEP
bool "Configure the EC11 to wake up light sleep"
default "n"
help
Whether to use one of the EC11 channel to wake up the chip from light sleep.
The wake up is not triggered by PCNT peripheral, but by the digital GPIO.
endmenu

View File

@@ -4,11 +4,14 @@
* SPDX-License-Identifier: CC0-1.0 * SPDX-License-Identifier: CC0-1.0
*/ */
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "freertos/queue.h" #include "freertos/queue.h"
#include "esp_log.h" #include "esp_log.h"
#include "driver/pulse_cnt.h" #include "driver/pulse_cnt.h"
#include "driver/gpio.h"
#include "esp_sleep.h"
static const char *TAG = "example"; static const char *TAG = "example";
@@ -81,6 +84,13 @@ void app_main(void)
ESP_LOGI(TAG, "start pcnt unit"); ESP_LOGI(TAG, "start pcnt unit");
ESP_ERROR_CHECK(pcnt_unit_start(pcnt_unit)); ESP_ERROR_CHECK(pcnt_unit_start(pcnt_unit));
#if CONFIG_EXAMPLE_WAKE_UP_LIGHT_SLEEP
// EC11 channel output high level in normal state, so we set "low level" to wake up the chip
ESP_ERROR_CHECK(gpio_wakeup_enable(EXAMPLE_EC11_GPIO_A, GPIO_INTR_LOW_LEVEL));
ESP_ERROR_CHECK(esp_sleep_enable_gpio_wakeup());
ESP_ERROR_CHECK(esp_light_sleep_start());
#endif
// Report counter value // Report counter value
int pulse_count = 0; int pulse_count = 0;
int event_count = 0; int event_count = 0;