From 0b865586269d50f2f7d5060142b1eaee9f1c39d6 Mon Sep 17 00:00:00 2001 From: Christoph Honal Date: Wed, 6 Apr 2022 19:17:04 +0200 Subject: [PATCH] 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. --- CMakeLists.txt | 4 +++ doc/buildAndProgram.md | 5 +-- src/CMakeLists.txt | 1 + src/drivers/Cst816s.cpp | 12 ++++--- src/drivers/SC7A20.cpp | 80 ++++++++++++++++++++++------------------- 5 files changed, 58 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f8a124a5e..1b4bade801 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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!") diff --git a/doc/buildAndProgram.md b/doc/buildAndProgram.md index a3845e8fda..3f7852f4a2 100644 --- a/doc/buildAndProgram.md +++ b/doc/buildAndProgram.md @@ -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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b9cf905639..ba7d238017 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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") diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index 9236ede62f..ecd56460a7 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -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"); } diff --git a/src/drivers/SC7A20.cpp b/src/drivers/SC7A20.cpp index 19107c27d8..761722c30e 100644 --- a/src/drivers/SC7A20.cpp +++ b/src/drivers/SC7A20.cpp @@ -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; @@ -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; }