Skip to content

Commit

Permalink
Wake: Add parameter to configure tap wake source
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
StarGate01 committed Apr 6, 2022
1 parent ba4ba98 commit 0b86558
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 44 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ set_property(CACHE DRIVER_ACC PROPERTY STRINGS BMA421 SC7A20)
set(DRIVER_TOUCH "DYNAMIC" CACHE STRING "Touch sensor driver factory configuration")
set_property(CACHE DRIVER_TOUCH PROPERTY STRINGS DYNAMIC GESTURE REPORT)

set(DRIVER_WAKE "TOUCH" CACHE STRING "Sensor to detect taps to wake")
set_property(CACHE DRIVER_WAKE PROPERTY STRINGS TOUCH ACC)

set(PROJECT_GIT_COMMIT_HASH "")

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

set(VERSION_EDIT_WARNING "// Do not edit this file, it is automatically generated by CMAKE!")
Expand Down
5 changes: 3 additions & 2 deletions doc/buildAndProgram.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ CMake configures the project according to variables you specify the command line
**LF_CLK**|Configures the LF clock source. Allowed: `RC, XTAL, SYNT`|`-DLF_CLK=XTAL` (Default)
**DRIVER_ACC**|Acceleration sensor driver selection. Allowed: `BMA421, SC7A20`|`-DDRIVER_ACC=BMA421` (Default)
**DRIVER_TOUCH**|Touch sensor driver factory configuration selection. Allowed: `DYNAMIC, GESTURE, REPORT`|`-DDRIVER_TOUCH=DYNAMIC` (Default)
**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)
####(**) Note about **CMAKE_BUILD_TYPE**:
#### (**) Note about **CMAKE_BUILD_TYPE**:
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.
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.
####(**) Note about **BUILD_DFU**:
#### (**) Note about **BUILD_DFU**:
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.
#### CMake command line for JLink
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ else()
endif()
add_definitions(-DDRIVER_ACC_${DRIVER_ACC})
add_definitions(-DDRIVER_TOUCH_${DRIVER_TOUCH})
add_definitions(-DDRIVER_WAKE_${DRIVER_WAKE})

# Debug configuration
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
Expand Down
12 changes: 7 additions & 5 deletions src/drivers/Cst816s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() {
void Cst816S::Sleep() {
// This only controls the CST716, the CST816S will ignore this register.
// The CST816S power state is managed using auto-sleep.

static constexpr uint8_t sleepValue = PWR_MODE_DEEP_SLEEP;
twiMaster.Write(twiAddress, PWR_MODE_CST716, &sleepValue, 1);

#if !defined(DRIVER_WAKE_TOUCH)
static constexpr uint8_t sleepValue = PWR_MODE_DEEP_SLEEP;
twiMaster.Write(twiAddress, PWR_MODE_CST716, &sleepValue, 1);
#endif
NRF_LOG_INFO("[TOUCHPANEL] Sleep");
}

void Cst816S::Wakeup() {
Init();
#if !defined(DRIVER_WAKE_TOUCH)
Init();
#endif
NRF_LOG_INFO("[TOUCHPANEL] Wakeup");
}
80 changes: 43 additions & 37 deletions src/drivers/SC7A20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,29 @@ void SC7A20::Init() {
data = CTRL_REG4_FS_2G;
Write(CTRL_REG4, &data, 1);

// Enable high pass filter for click detection
data = CTRL_REG2_HPCLICK;
Write(CTRL_REG2, &data, 1);

// Enable click event on interrupt function 1 and pin 1
data = CTRL_REG3_I1_CLICK;
Write(CTRL_REG3, &data, 1);
// Set interrupt to active low
data = CTRL_REG6_H_LACTIVE;
Write(CTRL_REG6, &data, 1);

// Configure click treshold, latch interrupt and timings
SetMotion(MotionEvents::None);
data = SC7A20_click_treshold | CLICK_THS_LIR_CLICK;
Write(CLICK_THS, &data, 1);
data = SC7A20_click_time_limit;
Write(TIME_LIMIT, &data, 1);
data = SC7A20_click_latency;
Write(TIME_LATENCY, &data, 1);
data = SC7A20_click_window;
Write(TIME_WINDOW, &data, 1);
#if defined(DRIVER_WAKE_ACC)
// Enable high pass filter for click detection
data = CTRL_REG2_HPCLICK;
Write(CTRL_REG2, &data, 1);

// Enable click event on interrupt function 1 and pin 1
data = CTRL_REG3_I1_CLICK;
Write(CTRL_REG3, &data, 1);
// Set interrupt to active low
data = CTRL_REG6_H_LACTIVE;
Write(CTRL_REG6, &data, 1);

// Configure click treshold, latch interrupt and timings
SetMotion(MotionEvents::None);
data = SC7A20_click_treshold | CLICK_THS_LIR_CLICK;
Write(CLICK_THS, &data, 1);
data = SC7A20_click_time_limit;
Write(TIME_LIMIT, &data, 1);
data = SC7A20_click_latency;
Write(TIME_LATENCY, &data, 1);
data = SC7A20_click_window;
Write(TIME_WINDOW, &data, 1);
#endif

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

void SC7A20::SetMotion(MotionEvents event) {
// Configure axis to measure for click detection
uint8_t data = 0;
if(event == MotionEvents::SingleTap) {
data = CLICK_CFG_ZS;
} else if(event == MotionEvents::DoubleTap) {
data = CLICK_CFG_ZD;
}
Write(CLICK_CFG, &data, 1);
#if defined(DRIVER_WAKE_ACC)
uint8_t data = 0;
if(event == MotionEvents::SingleTap) {
data = CLICK_CFG_ZS;
} else if(event == MotionEvents::DoubleTap) {
data = CLICK_CFG_ZD;
}
Write(CLICK_CFG, &data, 1);
#endif
}

MotionEvents SC7A20::GetMotionInfo() {
uint8_t click_source = 0;
Read(CLICK_SRC, &click_source, 1);

// Check if an event (into the correct direction) has been generated
if(click_source & CLICK_SRC_IA && !(click_source & CLICK_SRC_SIGN)) {
// Double tap takes precedence over single tap
if(click_source & CLICK_SRC_DCLICK) return MotionEvents::DoubleTap;
if(click_source & CLICK_SRC_SCLICK) return MotionEvents::SingleTap;
}
#if defined(DRIVER_WAKE_ACC)
uint8_t click_source = 0;
Read(CLICK_SRC, &click_source, 1);

// Check if an event (into the correct direction) has been generated
if(click_source & CLICK_SRC_IA && !(click_source & CLICK_SRC_SIGN)) {
// Double tap takes precedence over single tap
if(click_source & CLICK_SRC_DCLICK) return MotionEvents::DoubleTap;
if(click_source & CLICK_SRC_SCLICK) return MotionEvents::SingleTap;
}
#endif

return MotionEvents::None;
}

0 comments on commit 0b86558

Please sign in to comment.