Skip to content

Commit 0b86558

Browse files
committed
Wake: Add parameter to configure tap wake source
The CMake parameter DRIVER_WAKE can be used to use the ACC (only for SC7A20) or TOUCH sensors to generate tap to wake events. If the TOUCH sensor is used and the sensor does not support auto-sleep, then it will never sleep at all.
1 parent ba4ba98 commit 0b86558

File tree

5 files changed

+58
-44
lines changed

5 files changed

+58
-44
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ set_property(CACHE DRIVER_ACC PROPERTY STRINGS BMA421 SC7A20)
6666
set(DRIVER_TOUCH "DYNAMIC" CACHE STRING "Touch sensor driver factory configuration")
6767
set_property(CACHE DRIVER_TOUCH PROPERTY STRINGS DYNAMIC GESTURE REPORT)
6868

69+
set(DRIVER_WAKE "TOUCH" CACHE STRING "Sensor to detect taps to wake")
70+
set_property(CACHE DRIVER_WAKE PROPERTY STRINGS TOUCH ACC)
71+
6972
set(PROJECT_GIT_COMMIT_HASH "")
7073

7174
execute_process(COMMAND git rev-parse --short HEAD
@@ -113,6 +116,7 @@ message(" * Target pin mapping : " ${TARGET_DEVICE})
113116
message(" * LF clock source : " ${LF_CLK})
114117
message(" * Acceleration sensor : " ${DRIVER_ACC})
115118
message(" * Touch sensor config : " ${DRIVER_TOUCH})
119+
message(" * Wake tap event sensor : " ${DRIVER_WAKE})
116120
message("")
117121

118122
set(VERSION_EDIT_WARNING "// Do not edit this file, it is automatically generated by CMAKE!")

doc/buildAndProgram.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ CMake configures the project according to variables you specify the command line
3939
**LF_CLK**|Configures the LF clock source. Allowed: `RC, XTAL, SYNT`|`-DLF_CLK=XTAL` (Default)
4040
**DRIVER_ACC**|Acceleration sensor driver selection. Allowed: `BMA421, SC7A20`|`-DDRIVER_ACC=BMA421` (Default)
4141
**DRIVER_TOUCH**|Touch sensor driver factory configuration selection. Allowed: `DYNAMIC, GESTURE, REPORT`|`-DDRIVER_TOUCH=DYNAMIC` (Default)
42+
**DRIVER_WAKE**|Which sensor to use for tap to wake events. `ACC` is only implemented for the SC7A20. Allowed: `TOUCH, ACC`|`-DDRIVER_WAKE=TOUCH` (Default)
4243
43-
####(**) Note about **CMAKE_BUILD_TYPE**:
44+
#### (**) Note about **CMAKE_BUILD_TYPE**:
4445
By default, this variable is set to *Release*. It compiles the code with size and speed optimizations. We use this value for all the binaries we publish when we [release](https://github.com/InfiniTimeOrg/InfiniTime/releases) new versions of InfiniTime.
4546
4647
The *Debug* mode disables all optimizations, which makes the code easier to debug. However, the binary size will likely be too big to fit in the internal flash memory. If you want to build and debug a *Debug* binary, you'll need to disable some parts of the code. For example, the icons for the **Navigation** app use a lot of memory space. You can comment the content of `m_iconMap` in the [Navigation](https://github.com/InfiniTimeOrg/InfiniTime/blob/develop/src/displayapp/screens/Navigation.h#L148) application to free some memory.
4748
48-
####(**) Note about **BUILD_DFU**:
49+
#### (**) Note about **BUILD_DFU**:
4950
DFU files are the files you'll need to install your build of InfiniTime using OTA (over-the-air) mecanism. To generate the DFU file, the Python tool [adafruit-nrfutil](https://github.com/adafruit/Adafruit_nRF52_nrfutil) is needed on your system. Check that this tool is properly installed before enabling this option.
5051
5152
#### CMake command line for JLink

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ else()
843843
endif()
844844
add_definitions(-DDRIVER_ACC_${DRIVER_ACC})
845845
add_definitions(-DDRIVER_TOUCH_${DRIVER_TOUCH})
846+
add_definitions(-DDRIVER_WAKE_${DRIVER_WAKE})
846847

847848
# Debug configuration
848849
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")

src/drivers/Cst816s.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,16 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() {
9696
void Cst816S::Sleep() {
9797
// This only controls the CST716, the CST816S will ignore this register.
9898
// The CST816S power state is managed using auto-sleep.
99-
100-
static constexpr uint8_t sleepValue = PWR_MODE_DEEP_SLEEP;
101-
twiMaster.Write(twiAddress, PWR_MODE_CST716, &sleepValue, 1);
102-
99+
#if !defined(DRIVER_WAKE_TOUCH)
100+
static constexpr uint8_t sleepValue = PWR_MODE_DEEP_SLEEP;
101+
twiMaster.Write(twiAddress, PWR_MODE_CST716, &sleepValue, 1);
102+
#endif
103103
NRF_LOG_INFO("[TOUCHPANEL] Sleep");
104104
}
105105

106106
void Cst816S::Wakeup() {
107-
Init();
107+
#if !defined(DRIVER_WAKE_TOUCH)
108+
Init();
109+
#endif
108110
NRF_LOG_INFO("[TOUCHPANEL] Wakeup");
109111
}

src/drivers/SC7A20.cpp

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,29 @@ void SC7A20::Init() {
3232
data = CTRL_REG4_FS_2G;
3333
Write(CTRL_REG4, &data, 1);
3434

35-
// Enable high pass filter for click detection
36-
data = CTRL_REG2_HPCLICK;
37-
Write(CTRL_REG2, &data, 1);
38-
39-
// Enable click event on interrupt function 1 and pin 1
40-
data = CTRL_REG3_I1_CLICK;
41-
Write(CTRL_REG3, &data, 1);
42-
// Set interrupt to active low
43-
data = CTRL_REG6_H_LACTIVE;
44-
Write(CTRL_REG6, &data, 1);
45-
46-
// Configure click treshold, latch interrupt and timings
47-
SetMotion(MotionEvents::None);
48-
data = SC7A20_click_treshold | CLICK_THS_LIR_CLICK;
49-
Write(CLICK_THS, &data, 1);
50-
data = SC7A20_click_time_limit;
51-
Write(TIME_LIMIT, &data, 1);
52-
data = SC7A20_click_latency;
53-
Write(TIME_LATENCY, &data, 1);
54-
data = SC7A20_click_window;
55-
Write(TIME_WINDOW, &data, 1);
35+
#if defined(DRIVER_WAKE_ACC)
36+
// Enable high pass filter for click detection
37+
data = CTRL_REG2_HPCLICK;
38+
Write(CTRL_REG2, &data, 1);
39+
40+
// Enable click event on interrupt function 1 and pin 1
41+
data = CTRL_REG3_I1_CLICK;
42+
Write(CTRL_REG3, &data, 1);
43+
// Set interrupt to active low
44+
data = CTRL_REG6_H_LACTIVE;
45+
Write(CTRL_REG6, &data, 1);
46+
47+
// Configure click treshold, latch interrupt and timings
48+
SetMotion(MotionEvents::None);
49+
data = SC7A20_click_treshold | CLICK_THS_LIR_CLICK;
50+
Write(CLICK_THS, &data, 1);
51+
data = SC7A20_click_time_limit;
52+
Write(TIME_LIMIT, &data, 1);
53+
data = SC7A20_click_latency;
54+
Write(TIME_LATENCY, &data, 1);
55+
data = SC7A20_click_window;
56+
Write(TIME_WINDOW, &data, 1);
57+
#endif
5658

5759
// Enable block update, configure resolution mode
5860
data = CTRL_REG4_BDU;
@@ -123,25 +125,29 @@ void SC7A20::SoftReset() {
123125

124126
void SC7A20::SetMotion(MotionEvents event) {
125127
// Configure axis to measure for click detection
126-
uint8_t data = 0;
127-
if(event == MotionEvents::SingleTap) {
128-
data = CLICK_CFG_ZS;
129-
} else if(event == MotionEvents::DoubleTap) {
130-
data = CLICK_CFG_ZD;
131-
}
132-
Write(CLICK_CFG, &data, 1);
128+
#if defined(DRIVER_WAKE_ACC)
129+
uint8_t data = 0;
130+
if(event == MotionEvents::SingleTap) {
131+
data = CLICK_CFG_ZS;
132+
} else if(event == MotionEvents::DoubleTap) {
133+
data = CLICK_CFG_ZD;
134+
}
135+
Write(CLICK_CFG, &data, 1);
136+
#endif
133137
}
134138

135139
MotionEvents SC7A20::GetMotionInfo() {
136-
uint8_t click_source = 0;
137-
Read(CLICK_SRC, &click_source, 1);
138-
139-
// Check if an event (into the correct direction) has been generated
140-
if(click_source & CLICK_SRC_IA && !(click_source & CLICK_SRC_SIGN)) {
141-
// Double tap takes precedence over single tap
142-
if(click_source & CLICK_SRC_DCLICK) return MotionEvents::DoubleTap;
143-
if(click_source & CLICK_SRC_SCLICK) return MotionEvents::SingleTap;
144-
}
140+
#if defined(DRIVER_WAKE_ACC)
141+
uint8_t click_source = 0;
142+
Read(CLICK_SRC, &click_source, 1);
143+
144+
// Check if an event (into the correct direction) has been generated
145+
if(click_source & CLICK_SRC_IA && !(click_source & CLICK_SRC_SIGN)) {
146+
// Double tap takes precedence over single tap
147+
if(click_source & CLICK_SRC_DCLICK) return MotionEvents::DoubleTap;
148+
if(click_source & CLICK_SRC_SCLICK) return MotionEvents::SingleTap;
149+
}
150+
#endif
145151

146152
return MotionEvents::None;
147153
}

0 commit comments

Comments
 (0)