Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
NoABug
arduino-esp32
提交
7a76aded
A
arduino-esp32
项目概览
NoABug
/
arduino-esp32
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
arduino-esp32
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
7a76aded
编写于
11月 09, 2022
作者:
J
Jan Procházka
提交者:
GitHub
11月 09, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add touch sleep wakeup API (#7439)
上级
bd714499
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
85 addition
and
24 deletion
+85
-24
cores/esp32/esp32-hal-touch.c
cores/esp32/esp32-hal-touch.c
+23
-0
cores/esp32/esp32-hal-touch.h
cores/esp32/esp32-hal-touch.h
+5
-0
docs/source/api/touch.rst
docs/source/api/touch.rst
+14
-0
libraries/ESP32/examples/DeepSleep/TouchWakeUp/TouchWakeUp.ino
...ries/ESP32/examples/DeepSleep/TouchWakeUp/TouchWakeUp.ino
+43
-24
未找到文件。
cores/esp32/esp32-hal-touch.c
浏览文件 @
7a76aded
...
...
@@ -186,6 +186,7 @@ static touch_value_t __touchRead(uint8_t pin)
{
int8_t
pad
=
digitalPinToTouchChannel
(
pin
);
if
(
pad
<
0
){
log_e
(
" No touch pad on selected pin!"
);
return
0
;
}
...
...
@@ -202,6 +203,7 @@ static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Ar
{
int8_t
pad
=
digitalPinToTouchChannel
(
pin
);
if
(
pad
<
0
){
log_e
(
" No touch pad on selected pin!"
);
return
;
}
...
...
@@ -264,6 +266,27 @@ bool touchInterruptGetLastStatus(uint8_t pin) {
}
#endif
void
touchSleepWakeUpEnable
(
uint8_t
pin
,
touch_value_t
threshold
)
{
int8_t
pad
=
digitalPinToTouchChannel
(
pin
);
if
(
pad
<
0
){
log_e
(
" No touch pad on selected pin!"
);
return
;
}
__touchInit
();
__touchChannelInit
(
pad
);
#if SOC_TOUCH_VERSION_1 // Only for ESP32 SoC
touch_pad_set_thresh
(
pad
,
threshold
);
#elif SOC_TOUCH_VERSION_2
touch_pad_sleep_channel_enable
(
pad
,
true
);
touch_pad_sleep_set_threshold
(
pad
,
threshold
);
#endif
esp_sleep_enable_touchpad_wakeup
();
}
extern
touch_value_t
touchRead
(
uint8_t
)
__attribute__
((
weak
,
alias
(
"__touchRead"
)));
extern
void
touchAttachInterrupt
(
uint8_t
,
voidFuncPtr
,
touch_value_t
)
__attribute__
((
weak
,
alias
(
"__touchAttachInterrupt"
)));
extern
void
touchAttachInterruptArg
(
uint8_t
,
voidArgFuncPtr
,
void
*
,
touch_value_t
)
__attribute__
((
weak
,
alias
(
"__touchAttachArgsInterrupt"
)));
...
...
cores/esp32/esp32-hal-touch.h
浏览文件 @
7a76aded
...
...
@@ -89,6 +89,11 @@ void touchInterruptSetThresholdDirection(bool mustbeLower);
bool
touchInterruptGetLastStatus
(
uint8_t
pin
);
#endif
/*
* Setup touch pad wake up from deep sleep with given threshold.
**/
void
touchSleepWakeUpEnable
(
uint8_t
pin
,
touch_value_t
threshold
);
#endif // SOC_TOUCH_SENSOR_NUM > 0
#ifdef __cplusplus
...
...
docs/source/api/touch.rst
浏览文件 @
7a76aded
...
...
@@ -85,6 +85,20 @@ This function is used to detach interrupt from the touch pad.
* ``pin`` GPIO TOUCH pad pin.
touchSleepWakeUpEnable
^^^^^^^^^^^^^^^^^^^^^^
This function is used to setup touch pad as the wake up source from the deep sleep.
.. note:: ESP32-S2 and ESP32-S3 only support one sleep wake up touch pad.
.. code-block:: arduino
void touchSleepWakeUpEnable(uint8_t pin, touch_value_t threshold);
* ``pin`` GPIO TOUCH pad pin
* ``threshold`` Sets the threshold when to wake up
TOUCH API specific for ESP32 chip (TOUCH_V1)
********************************************
...
...
libraries/ESP32/examples/DeepSleep/TouchWakeUp/TouchWakeUp.ino
浏览文件 @
7a76aded
...
...
@@ -5,13 +5,20 @@ This code displays how to use deep sleep with
a touch as a wake up source and how to store data in
RTC memory to use it over reboots
ESP32 can have multiple touch pads enabled as wakeup source
ESP32-S2 and ESP32-S3 supports only 1 touch pad as wakeup source enabled
This code is under Public Domain License.
Author:
Pranav Cherukupalli <cherukupallip@gmail.com>
*/
#define Threshold 40
/* Greater the value, more the sensitivity */
#if CONFIG_IDF_TARGET_ESP32
#define THRESHOLD 40
/* Greater the value, more the sensitivity */
#else //ESP32-S2 and ESP32-S3 + default for other chips (to be adjusted) */
#define THRESHOLD 5000
/* Lower the value, more the sensitivity */
#endif
RTC_DATA_ATTR
int
bootCount
=
0
;
touch_pad_t
touchPin
;
...
...
@@ -42,24 +49,31 @@ has been awaken from sleep
void
print_wakeup_touchpad
(){
touchPin
=
esp_sleep_get_touchpad_wakeup_status
();
switch
(
touchPin
)
{
case
0
:
Serial
.
println
(
"Touch detected on GPIO 4"
);
break
;
case
1
:
Serial
.
println
(
"Touch detected on GPIO 0"
);
break
;
case
2
:
Serial
.
println
(
"Touch detected on GPIO 2"
);
break
;
case
3
:
Serial
.
println
(
"Touch detected on GPIO 15"
);
break
;
case
4
:
Serial
.
println
(
"Touch detected on GPIO 13"
);
break
;
case
5
:
Serial
.
println
(
"Touch detected on GPIO 12"
);
break
;
case
6
:
Serial
.
println
(
"Touch detected on GPIO 14"
);
break
;
case
7
:
Serial
.
println
(
"Touch detected on GPIO 27"
);
break
;
case
8
:
Serial
.
println
(
"Touch detected on GPIO 33"
);
break
;
case
9
:
Serial
.
println
(
"Touch detected on GPIO 32"
);
break
;
default
:
Serial
.
println
(
"Wakeup not by touchpad"
);
break
;
}
}
void
callback
(){
//placeholder callback function
#if CONFIG_IDF_TARGET_ESP32
switch
(
touchPin
)
{
case
0
:
Serial
.
println
(
"Touch detected on GPIO 4"
);
break
;
case
1
:
Serial
.
println
(
"Touch detected on GPIO 0"
);
break
;
case
2
:
Serial
.
println
(
"Touch detected on GPIO 2"
);
break
;
case
3
:
Serial
.
println
(
"Touch detected on GPIO 15"
);
break
;
case
4
:
Serial
.
println
(
"Touch detected on GPIO 13"
);
break
;
case
5
:
Serial
.
println
(
"Touch detected on GPIO 12"
);
break
;
case
6
:
Serial
.
println
(
"Touch detected on GPIO 14"
);
break
;
case
7
:
Serial
.
println
(
"Touch detected on GPIO 27"
);
break
;
case
8
:
Serial
.
println
(
"Touch detected on GPIO 33"
);
break
;
case
9
:
Serial
.
println
(
"Touch detected on GPIO 32"
);
break
;
default
:
Serial
.
println
(
"Wakeup not by touchpad"
);
break
;
}
#else
if
(
touchPin
<
TOUCH_PAD_MAX
)
{
Serial
.
printf
(
"Touch detected on GPIO %d
\n
"
,
touchPin
);
}
else
{
Serial
.
println
(
"Wakeup not by touchpad"
);
}
#endif
}
void
setup
(){
...
...
@@ -74,11 +88,16 @@ void setup(){
print_wakeup_reason
();
print_wakeup_touchpad
();
//Setup interrupt on Touch Pad 3 (GPIO15)
touchAttachInterrupt
(
T3
,
callback
,
Threshold
);
#if CONFIG_IDF_TARGET_ESP32
//Setup sleep wakeup on Touch Pad 3 + 7 (GPIO15 + GPIO 27)
touchSleepWakeUpEnable
(
T3
,
THRESHOLD
);
touchSleepWakeUpEnable
(
T7
,
THRESHOLD
);
#else //ESP32-S2 + ESP32-S3
//Setup sleep wakeup on Touch Pad 3 (GPIO3)
touchSleepWakeUpEnable
(
T3
,
THRESHOLD
);
//Configure Touchpad as wakeup source
esp_sleep_enable_touchpad_wakeup
();
#endif
//Go to sleep now
Serial
.
println
(
"Going to sleep now"
);
...
...
@@ -88,4 +107,4 @@ void setup(){
void
loop
(){
//This will never be reached
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录