Skip to content

Commit ac0f4b5

Browse files
committed
Merge branch 'refactor/split_touch_sleep_from_system_example' into 'master'
refactor(touch): separate touch sleep example Closes IDFCI-2866 and IDF-12974 See merge request espressif/esp-idf!38662
2 parents b3de8a4 + 4fed645 commit ac0f4b5

29 files changed

+246
-300
lines changed

docs/en/api-reference/peripherals/cap_touch_sens.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ Application Examples
476476
------------------------
477477

478478
- :example:`peripherals/touch_sensor/touch_sens_basic` demonstrates how to register touch channels and read the data, including hardware requirements and project configuration instructions.
479+
- :example:`peripherals/touch_sensor/touch_sens_sleep` demonstrates how to wake up the chip from the light or deep sleep by the touch sensor.
479480

480481
Application Notes
481482
-----------------

docs/en/api-reference/peripherals/touch_element.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,6 @@ Only Touch Button can be configured as a wake-up source.
432432

433433
Light- or Deep-sleep modes are both supported to be wakened up by a touch sensor. For the Light-sleep mode, any installed touch button can wake it up. But only the sleep button can wake up from Deep-sleep mode, and the touch sensor will do a calibration immediately, the reference value will be calibrated to a wrong value if our finger does not remove timely. Though the wrong reference value recovers after the finger removes away and has no effect on the driver logic, if you do not want to see a wrong reference value while waking up from Deep-sleep mode, you can call :cpp:func:`touch_element_sleep_enable_wakeup_calibration` to disable the wakeup calibration.
434434

435-
The Touch Element Wakeup example is available in `system/light_sleep` directory.
436-
437435
.. code-block:: c
438436
439437
void app_main()

docs/en/api-reference/system/sleep_modes.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,9 @@ Application Examples
475475
:SOC_WIFI_SUPPORTED: - :example:`wifi/power_save` demonstrates the usage of Wi-Fi Modem-sleep mode and automatic Light-sleep feature to maintain Wi-Fi connections.
476476
:SOC_BT_SUPPORTED: - :example:`bluetooth/nimble/power_save` demonstrates the usage of Bluetooth Modem-sleep mode and automatic Light-sleep feature to maintain Bluetooth connections.
477477
:SOC_ULP_SUPPORTED: - :example:`system/deep_sleep` demonstrates the usage of various Deep-sleep wakeup triggers and ULP coprocessor programming.
478-
:not SOC_ULP_SUPPORTED: - :example:`system/deep_sleep` demonstrates the usage of Deep-sleep wakeup triggered by various sources, such as the RTC timer, GPIOs, EXT0, EXT1, the touch sensor, supported by {IDF_TARGET_NAME}.
479-
- :example:`system/light_sleep` demonstrates the usage of Light-sleep wakeup triggered by various sources, such as the timer, GPIOs, the touch sensor, supported by {IDF_TARGET_NAME}.
478+
:not SOC_ULP_SUPPORTED: - :example:`system/deep_sleep` demonstrates the usage of Deep-sleep wakeup triggered by various sources, such as the RTC timer, GPIOs, EXT0, EXT1, supported by {IDF_TARGET_NAME}.
479+
- :example:`system/light_sleep` demonstrates the usage of Light-sleep wakeup triggered by various sources, such as the timer, GPIOs, supported by {IDF_TARGET_NAME}.
480+
:SOC_TOUCH_SENSOR_SUPPORTED and SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP: - :example:`peripherals/touch_sensor/touch_sens_sleep` demonstrates the usage of Light-sleep and Deep-sleep wakeup triggered by the touch sensor.
480481

481482
API Reference
482483
-------------

docs/zh_CN/api-reference/peripherals/cap_touch_sens.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@
476476
--------
477477

478478
- :example:`peripherals/touch_sensor/touch_sens_basic` 演示了如何注册触摸通道并读取数据,并说明了硬件要求及项目配置。
479+
- :example:`peripherals/touch_sensor/touch_sens_sleep` 演示了如何通过触摸传感器将芯片从 Light Sleep 或 Deep Sleep 状态唤醒。
479480

480481
应用注意事项
481482
------------

docs/zh_CN/api-reference/peripherals/touch_element.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,6 @@
432432

433433
使用触摸传感器,可以唤醒从 Light-sleep 或 Deep-sleep 模式中唤醒芯片。在 Light-sleep 模式下,任何已安装的触摸按键都可以唤醒芯片。但在 Deep-sleep 模式下,只有睡眠按键可以唤醒芯片,触摸传感器还会立即进行校准。如果手指没有及时离开,可能导致校准参考值出错。尽管在手指离开后,校准参考值会自行恢复,不会影响驱动逻辑,但如果你不想在从 Deep-sleep 模式唤醒时看到错误的校准参考值,可以调用 :cpp:func:`touch_element_sleep_enable_wakeup_calibration`,禁用唤醒校准功能。
434434

435-
查看使用触摸元件唤醒芯片的示例代码,请前往 ESP-IDF 示例的 :example:`system/light_sleep` 目录。
436-
437435
.. code-block:: c
438436
439437
void app_main()

docs/zh_CN/api-reference/system/sleep_modes.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,9 @@ UART 输出处理
475475
:SOC_WIFI_SUPPORTED: - :example:`wifi/power_save` 演示如何通过 Wi-Fi Modem-sleep 模式和自动 Light-sleep 模式保持 Wi-Fi 连接。
476476
:SOC_BT_SUPPORTED: - :example:`bluetooth/nimble/power_save` 演示如何通过 Bluetooth Modem-sleep 模式和自动 Light-sleep 模式保持 Bluetooth 连接。
477477
:SOC_ULP_SUPPORTED: - :example:`system/deep_sleep` 演示如何使用 Deep-sleep 唤醒触发器和 ULP 协处理器编程。
478-
:not SOC_ULP_SUPPORTED: - :example:`system/deep_sleep` 演示如何通过 {IDF_TARGET_NAME} 的唤醒源,如 RTC 定时器, GPIO, EXT0, EXT1, 触摸传感器等,触发 Deep-sleep 唤醒。
479-
- :example:`system/light_sleep` 演示如何使用 {IDF_TARGET_NAME} 的唤醒源,如定时器,GPIO,触摸传感器等,触发 Light-sleep 唤醒。
478+
:not SOC_ULP_SUPPORTED: - :example:`system/deep_sleep` 演示如何通过 {IDF_TARGET_NAME} 的唤醒源,如 RTC 定时器, GPIO, EXT0, EXT1等,触发 Deep-sleep 唤醒。
479+
- :example:`system/light_sleep` 演示如何使用 {IDF_TARGET_NAME} 的唤醒源,如定时器,GPIO等,触发 Light-sleep 唤醒。
480+
:SOC_TOUCH_SENSOR_SUPPORTED and SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP: - :example:`peripherals/touch_sensor/touch_sens_sleep` 演示如何使用触摸传感器唤醒 Light-sleep 或 Deep-sleep。
480481

481482
API 参考
482483
-------------

examples/peripherals/.build-test-rules.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,12 @@ examples/peripherals/touch_sensor/touch_sens_basic:
479479
depends_components:
480480
- esp_driver_touch_sens
481481

482+
examples/peripherals/touch_sensor/touch_sens_sleep:
483+
disable:
484+
- if: SOC_TOUCH_SENSOR_SUPPORTED != 1 or SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP != 1
485+
depends_components:
486+
- esp_driver_touch_sens
487+
482488
examples/peripherals/twai/twai_alert_and_recovery:
483489
disable:
484490
- if: SOC_TWAI_SUPPORTED != 1 or SOC_TWAI_SUPPORT_FD == 1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# The following five lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.16)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
project(touch_sens_sleep)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
| Supported Targets | ESP32 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
2+
| ----------------- | ----- | -------- | -------- | -------- |
3+
4+
# Touch Sensor Sleep Wake up Example
5+
6+
(See the README.md file in the upper level 'examples' directory for more information about examples.)
7+
8+
This example is going to demonstrate how to wake up the chip from light/deep sleep by the touch sensor.
9+
10+
## How to Use Example
11+
12+
### Hardware Required
13+
14+
* A development board with any supported Espressif SOC chip (see `Supported Targets` table above)
15+
* A USB cable for power supply and programming
16+
* (Optional) Touch board with touch buttons on it.
17+
- If you don't have a touch board, you can connect the touch pins with male jump wires and touch it directly for testing.
18+
19+
### Configure the Project
20+
21+
You can determine the touch channel number by ``EXAMPLE_TOUCH_CHANNEL_NUM`` in the example. And adjust the active threshold by ``s_thresh2bm_ratio``.
22+
23+
You can run `idf.py menuconfig` to configure the example
24+
25+
- `Example Configuration > Touch Sensor wakeup level`: Select `Light sleep wakeup` or `Deep sleep wakeup` mode
26+
- `Example Configuration > Allow touch sensor power down during the deep sleep`: Choose whether to allow the touch sensor power down during the deep sleep. If enabled, the touch sensor will be powered down during the deep sleep, only one specified touch channel can wakeup the chip from deep sleep. If disabled, the touch sensor will keep working during the deep sleep. Any enabled touch channel can wakeup the chip from deep sleep.
27+
28+
29+
### Build and Flash
30+
31+
Build the project and flash it to the board, then run monitor tool to view serial output:
32+
33+
```
34+
idf.py -p PORT build flash monitor
35+
```
36+
37+
(To exit the serial monitor, type ``Ctrl-]``.)
38+
39+
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
40+
41+
## Example Output
42+
43+
### Light Sleep Log
44+
45+
```
46+
...
47+
Touch [CH 7] enabled on GPIO9
48+
Touch [CH 8] enabled on GPIO10
49+
Touch [CH 9] enabled on GPIO11
50+
Initial benchmark and new threshold are:
51+
Touch [CH 7] 0: 4884, 97
52+
Touch [CH 8] 0: 4993, 99
53+
Touch [CH 9] 0: 4913, 98
54+
I (399) touch_wakeup: touch wakeup source is ready
55+
Entering light sleep in:
56+
5 sec...
57+
4 sec...
58+
3 sec...
59+
2 sec...
60+
1 sec...
61+
W (5399) touch callback: ch 8 active
62+
I (5399) touch_wakeup: Wake up by touch
63+
64+
Entering light sleep in:
65+
5 sec...
66+
W (5479) touch callback: ch 8 inactive
67+
4 sec...
68+
3 sec...
69+
2 sec...
70+
1 sec...
71+
```
72+
73+
### Deep Sleep Log
74+
75+
```
76+
...
77+
Touch [CH 7] enabled on GPIO9
78+
Touch [CH 8] enabled on GPIO10
79+
Touch [CH 9] enabled on GPIO11
80+
Initial benchmark and new threshold are:
81+
Touch [CH 7] 0: 4897, 97
82+
Touch [CH 8] 0: 4879, 97
83+
Touch [CH 9] 0: 4954, 99
84+
I (405) touch_wakeup: touch wakeup source is ready
85+
Entering deep sleep in:
86+
5 sec...
87+
4 sec...
88+
3 sec...
89+
2 sec...
90+
1 sec...
91+
```
92+
93+
## Troubleshooting
94+
95+
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
idf_component_register(SRCS "touch_sens_sleep.c"
2+
PRIV_REQUIRES esp_driver_touch_sens esp_driver_uart
3+
INCLUDE_DIRS ".")

0 commit comments

Comments
 (0)