From a0e8c4692a4fa49f60b8124cf0b660a7ae211944 Mon Sep 17 00:00:00 2001 From: morris Date: Mon, 26 Sep 2022 16:45:57 +0800 Subject: [PATCH 1/2] pcnt: rotary encoder wake up system from light sleep example --- examples/peripherals/pcnt/rotary_encoder/README.md | 2 ++ .../pcnt/rotary_encoder/main/Kconfig.projbuild | 8 ++++++++ .../rotary_encoder/main/rotary_encoder_example_main.c | 10 ++++++++++ 3 files changed, 20 insertions(+) create mode 100644 examples/peripherals/pcnt/rotary_encoder/main/Kconfig.projbuild diff --git a/examples/peripherals/pcnt/rotary_encoder/README.md b/examples/peripherals/pcnt/rotary_encoder/README.md index b358306b6f..4007b08821 100644 --- a/examples/peripherals/pcnt/rotary_encoder/README.md +++ b/examples/peripherals/pcnt/rotary_encoder/README.md @@ -53,6 +53,8 @@ The GPIO used by the example can be changed according to your board by `EXAMPLE_ ### 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. (To exit the serial monitor, type ``Ctrl-]``.) diff --git a/examples/peripherals/pcnt/rotary_encoder/main/Kconfig.projbuild b/examples/peripherals/pcnt/rotary_encoder/main/Kconfig.projbuild new file mode 100644 index 0000000000..c7e6cd1f34 --- /dev/null +++ b/examples/peripherals/pcnt/rotary_encoder/main/Kconfig.projbuild @@ -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 diff --git a/examples/peripherals/pcnt/rotary_encoder/main/rotary_encoder_example_main.c b/examples/peripherals/pcnt/rotary_encoder/main/rotary_encoder_example_main.c index 079a803520..eea9e965a5 100644 --- a/examples/peripherals/pcnt/rotary_encoder/main/rotary_encoder_example_main.c +++ b/examples/peripherals/pcnt/rotary_encoder/main/rotary_encoder_example_main.c @@ -4,11 +4,14 @@ * SPDX-License-Identifier: CC0-1.0 */ +#include "sdkconfig.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/queue.h" #include "esp_log.h" #include "driver/pulse_cnt.h" +#include "driver/gpio.h" +#include "esp_sleep.h" static const char *TAG = "example"; @@ -81,6 +84,13 @@ void app_main(void) ESP_LOGI(TAG, "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 int pulse_count = 0; int event_count = 0; From e6e1d696d25a61ae0506a12a148a697af8aad2e8 Mon Sep 17 00:00:00 2001 From: morris Date: Wed, 26 Oct 2022 16:12:53 +0800 Subject: [PATCH 2/2] doc: clarify the meaning of overflow in pcnt driver Closes https://github.com/espressif/esp-idf/issues/10039 --- docs/en/api-reference/peripherals/pcnt.rst | 2 +- docs/zh_CN/api-reference/peripherals/pcnt.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/api-reference/peripherals/pcnt.rst b/docs/en/api-reference/peripherals/pcnt.rst index 1892b5ed61..c0adc6fa9c 100644 --- a/docs/en/api-reference/peripherals/pcnt.rst +++ b/docs/en/api-reference/peripherals/pcnt.rst @@ -227,7 +227,7 @@ You can check current count value at any time by calling :cpp:func:`pcnt_unit_ge .. note:: - The returned count value is a **signed** integer, where the sign can be used to reflect the direction. The internal counter will overflow when it reaches high or low limit, but this function doesn't compensate for that loss. + The returned count value is a **signed** integer, where the sign can be used to reflect the direction. The internal counter will be cleared to zero automatically when it reaches high or low limit, but this function doesn't compensate for that loss. .. code:: c diff --git a/docs/zh_CN/api-reference/peripherals/pcnt.rst b/docs/zh_CN/api-reference/peripherals/pcnt.rst index 69e14a5fc8..c9024fbdaf 100644 --- a/docs/zh_CN/api-reference/peripherals/pcnt.rst +++ b/docs/zh_CN/api-reference/peripherals/pcnt.rst @@ -227,7 +227,7 @@ PCNT 单元的滤波器可滤除信号中的短时毛刺,:cpp:type:`pcnt_glitc .. note:: - 返回的计数器数值是一个 **带符号** 的整数,符号代表计数方向。计数器的数值大于等于最大值或小于等于最小值时,计数器会溢出。 + 返回的计数器数值是一个 **带符号** 的整数,符号代表计数方向。计数器的数值大于等于最大值或小于等于最小值时,计数器会自动清零。 .. code:: c