1
0
Fork 0

Fix touch wakeup and code cleanup

This commit is contained in:
Riku Isokoski 2021-07-16 01:49:20 +03:00
parent 2a3e126390
commit 93ccbf38e8
7 changed files with 43 additions and 53 deletions

View file

@ -181,27 +181,6 @@ bool LittleVgl::GetTouchPadInfo(lv_indev_data_t* ptr) {
ptr->state = LV_INDEV_STATE_REL; ptr->state = LV_INDEV_STATE_REL;
} }
return false; return false;
/*
auto info = touchPanel.GetTouchInfo();
if((previousClick.x != info.x || previousClick.y != info.y) &&
(info.gesture == Drivers::Cst816S::Gestures::SingleTap)) {
// TODO For an unknown reason, the first touch is taken twice into account.
// 'firstTouch' is a quite'n'dirty workaound until I find a better solution
if(firstTouch) ptr->state = LV_INDEV_STATE_REL;
else ptr->state = LV_INDEV_STATE_PR;
firstTouch = false;
previousClick.x = info.x;
previousClick.y = info.y;
}
else {
ptr->state = LV_INDEV_STATE_REL;
}
ptr->point.x = info.x;
ptr->point.y = info.y;
return false;
*/
} }
void LittleVgl::InitTheme() { void LittleVgl::InitTheme() {

View file

@ -12,9 +12,10 @@ TwiMaster::TwiMaster(const Modules module, const Parameters& params) : module {m
} }
void TwiMaster::Init() { void TwiMaster::Init() {
sleeping = false;
if(mutex == nullptr) if(mutex == nullptr)
mutex = xSemaphoreCreateBinary(); mutex = xSemaphoreCreateBinary();
NRF_GPIO->PIN_CNF[params.pinScl] = NRF_GPIO->PIN_CNF[params.pinScl] =
((uint32_t) GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | ((uint32_t) GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | ((uint32_t) GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | ((uint32_t) GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
((uint32_t) GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) | ((uint32_t) GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | ((uint32_t) GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) | ((uint32_t) GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) |
@ -176,11 +177,14 @@ void TwiMaster::Sleep() {
nrf_gpio_cfg_default(6); nrf_gpio_cfg_default(6);
nrf_gpio_cfg_default(7); nrf_gpio_cfg_default(7);
NRF_LOG_INFO("[TWIMASTER] Sleep"); NRF_LOG_INFO("[TWIMASTER] Sleep");
sleeping = true;
} }
void TwiMaster::Wakeup() { void TwiMaster::Wakeup() {
Init(); if (sleeping) {
NRF_LOG_INFO("[TWIMASTER] Wakeup"); Init();
NRF_LOG_INFO("[TWIMASTER] Wakeup");
}
} }
/* Sometimes, the TWIM device just freeze and never set the event EVENTS_LASTTX. /* Sometimes, the TWIM device just freeze and never set the event EVENTS_LASTTX.
@ -206,4 +210,4 @@ void TwiMaster::FixHwFreezed() {
// Re-enable I²C // Re-enable I²C
twiBaseAddress->ENABLE = twi_state; twiBaseAddress->ENABLE = twi_state;
} }

View file

@ -39,6 +39,7 @@ namespace Pinetime {
uint8_t internalBuffer[maxDataSize + registerSize]; uint8_t internalBuffer[maxDataSize + registerSize];
uint32_t txStartedCycleCount = 0; uint32_t txStartedCycleCount = 0;
static constexpr uint32_t HwFreezedDelay {161000}; static constexpr uint32_t HwFreezedDelay {161000};
bool sleeping;
}; };
} }
} }

View file

@ -161,10 +161,12 @@ Pinetime::System::SystemTask systemTask(spi,
heartRateController, heartRateController,
displayApp, displayApp,
heartRateApp, heartRateApp,
fs); fs,
touchHandler);
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
if (pin == pinTouchIrq) { if (pin == pinTouchIrq) {
twiMaster.Wakeup();
touchHandler.WakeUp(); touchHandler.WakeUp();
return; return;
} }

View file

@ -60,7 +60,8 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
Pinetime::Controllers::HeartRateController& heartRateController, Pinetime::Controllers::HeartRateController& heartRateController,
Pinetime::Applications::DisplayApp& displayApp, Pinetime::Applications::DisplayApp& displayApp,
Pinetime::Applications::HeartRateTask& heartRateApp, Pinetime::Applications::HeartRateTask& heartRateApp,
Pinetime::Controllers::FS& fs) Pinetime::Controllers::FS& fs,
Pinetime::Controllers::TouchHandler& touchHandler)
: spi {spi}, : spi {spi},
lcd {lcd}, lcd {lcd},
spiNorFlash {spiNorFlash}, spiNorFlash {spiNorFlash},
@ -72,18 +73,18 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
dateTimeController {dateTimeController}, dateTimeController {dateTimeController},
timerController {timerController}, timerController {timerController},
watchdog {watchdog}, watchdog {watchdog},
notificationManager{notificationManager}, notificationManager {notificationManager},
motorController {motorController}, motorController {motorController},
heartRateSensor {heartRateSensor}, heartRateSensor {heartRateSensor},
motionSensor {motionSensor}, motionSensor {motionSensor},
settingsController {settingsController}, settingsController {settingsController},
heartRateController{heartRateController}, heartRateController {heartRateController},
motionController{motionController}, motionController {motionController},
displayApp{displayApp}, displayApp {displayApp},
heartRateApp(heartRateApp), heartRateApp(heartRateApp),
fs{fs}, fs {fs},
touchHandler {touchHandler},
nimbleController(*this, bleController, dateTimeController, notificationManager, batteryController, spiNorFlash, heartRateController) { nimbleController(*this, bleController, dateTimeController, notificationManager, batteryController, spiNorFlash, heartRateController) {
} }
void SystemTask::Start() { void SystemTask::Start() {
@ -105,11 +106,11 @@ void SystemTask::Work() {
APP_GPIOTE_INIT(2); APP_GPIOTE_INIT(2);
app_timer_init(); app_timer_init();
spi.Init(); spi.Init();
spiNorFlash.Init(); spiNorFlash.Init();
spiNorFlash.Wakeup(); spiNorFlash.Wakeup();
fs.Init(); fs.Init();
nimbleController.Init(); nimbleController.Init();
@ -228,14 +229,14 @@ void SystemTask::Work() {
isWakingUp = false; isWakingUp = false;
break; break;
case Messages::TouchWakeUp: { case Messages::TouchWakeUp: {
twiMaster.Wakeup(); auto gesture = touchHandler.GestureGet();
auto touchInfo = touchPanel.GetTouchInfo(); if ((gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap &&
twiMaster.Sleep(); settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) ||
if (touchInfo.isValid and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and (gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap &&
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) or settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap))) {
(touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::SingleTap)))) {
GoToRunning(); GoToRunning();
} else {
twiMaster.Sleep();
} }
} break; } break;
case Messages::GoToSleep: case Messages::GoToSleep:
@ -311,7 +312,7 @@ void SystemTask::Work() {
break; break;
case Messages::OnChargingEvent: case Messages::OnChargingEvent:
motorController.SetDuration(15); motorController.SetDuration(15);
// Battery level is updated on every message - there's no need to do anything // Battery level is updated on every message - there's no need to do anything
break; break;
default: default:
@ -410,14 +411,13 @@ void SystemTask::PushMessage(System::Messages msg) {
isGoingToSleep = true; isGoingToSleep = true;
} }
if(in_isr()) { if (in_isr()) {
BaseType_t xHigherPriorityTaskWoken; BaseType_t xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE; xHigherPriorityTaskWoken = pdFALSE;
xQueueSendFromISR(systemTasksMsgQueue, &msg, &xHigherPriorityTaskWoken); xQueueSendFromISR(systemTasksMsgQueue, &msg, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken) { if (xHigherPriorityTaskWoken) {
/* Actual macro used here is port specific. */ /* Actual macro used here is port specific. */
portYIELD_FROM_ISR(xHigherPriorityTaskWoken); portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
} }
} else { } else {
xQueueSend(systemTasksMsgQueue, &msg, portMAX_DELAY); xQueueSend(systemTasksMsgQueue, &msg, portMAX_DELAY);

View file

@ -17,6 +17,7 @@
#include "components/motor/MotorController.h" #include "components/motor/MotorController.h"
#include "components/timer/TimerController.h" #include "components/timer/TimerController.h"
#include "components/fs/FS.h" #include "components/fs/FS.h"
#include "touchhandler/TouchHandler.h"
#ifdef PINETIME_IS_RECOVERY #ifdef PINETIME_IS_RECOVERY
#include "displayapp/DisplayAppRecovery.h" #include "displayapp/DisplayAppRecovery.h"
@ -24,7 +25,7 @@
#else #else
#include "components/settings/Settings.h" #include "components/settings/Settings.h"
#include "displayapp/DisplayApp.h" #include "displayapp/DisplayApp.h"
#include "displayapp/LittleVgl.h" #include "displayapp/LittleVgl.h"
#endif #endif
#include "drivers/Watchdog.h" #include "drivers/Watchdog.h"
@ -39,6 +40,9 @@ namespace Pinetime {
class TwiMaster; class TwiMaster;
class Hrs3300; class Hrs3300;
} }
namespace Controllers {
class TouchHandler;
}
namespace System { namespace System {
class SystemTask { class SystemTask {
public: public:
@ -62,7 +66,8 @@ namespace Pinetime {
Pinetime::Controllers::HeartRateController& heartRateController, Pinetime::Controllers::HeartRateController& heartRateController,
Pinetime::Applications::DisplayApp& displayApp, Pinetime::Applications::DisplayApp& displayApp,
Pinetime::Applications::HeartRateTask& heartRateApp, Pinetime::Applications::HeartRateTask& heartRateApp,
Pinetime::Controllers::FS& fs); Pinetime::Controllers::FS& fs,
Pinetime::Controllers::TouchHandler& touchHandler);
void Start(); void Start();
void PushMessage(Messages msg); void PushMessage(Messages msg);
@ -91,7 +96,6 @@ namespace Pinetime {
Pinetime::Components::LittleVgl& lvgl; Pinetime::Components::LittleVgl& lvgl;
Pinetime::Controllers::Battery& batteryController; Pinetime::Controllers::Battery& batteryController;
Pinetime::Controllers::Ble& bleController; Pinetime::Controllers::Ble& bleController;
Pinetime::Controllers::DateTime& dateTimeController; Pinetime::Controllers::DateTime& dateTimeController;
Pinetime::Controllers::TimerController& timerController; Pinetime::Controllers::TimerController& timerController;
@ -106,13 +110,14 @@ namespace Pinetime {
Pinetime::Drivers::Bma421& motionSensor; Pinetime::Drivers::Bma421& motionSensor;
Pinetime::Controllers::Settings& settingsController; Pinetime::Controllers::Settings& settingsController;
Pinetime::Controllers::HeartRateController& heartRateController; Pinetime::Controllers::HeartRateController& heartRateController;
Controllers::BrightnessController brightnessController; Controllers::BrightnessController brightnessController;
Pinetime::Controllers::MotionController& motionController; Pinetime::Controllers::MotionController& motionController;
Pinetime::Applications::DisplayApp& displayApp; Pinetime::Applications::DisplayApp& displayApp;
Pinetime::Applications::HeartRateTask& heartRateApp; Pinetime::Applications::HeartRateTask& heartRateApp;
Pinetime::Controllers::FS& fs; Pinetime::Controllers::FS& fs;
Pinetime::Controllers::TouchHandler& touchHandler;
Pinetime::Controllers::NimbleController nimbleController; Pinetime::Controllers::NimbleController nimbleController;
static constexpr uint8_t pinSpiSck = 2; static constexpr uint8_t pinSpiSck = 2;

View file

@ -2,9 +2,7 @@
using namespace Pinetime::Controllers; using namespace Pinetime::Controllers;
TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel, Components::LittleVgl& lvgl) TouchHandler::TouchHandler(Drivers::Cst816S& touchPanel, Components::LittleVgl& lvgl) : touchPanel {touchPanel}, lvgl {lvgl} {
: touchPanel {touchPanel},
lvgl {lvgl} {
} }
void TouchHandler::CancelTap() { void TouchHandler::CancelTap() {
@ -35,6 +33,7 @@ void TouchHandler::Work() {
vTaskSuspend(taskHandle); vTaskSuspend(taskHandle);
info = touchPanel.GetTouchInfo(); info = touchPanel.GetTouchInfo();
if (systemTask->IsSleeping()) { if (systemTask->IsSleeping()) {
gesture = info.gesture;
systemTask->PushMessage(System::Messages::TouchWakeUp); systemTask->PushMessage(System::Messages::TouchWakeUp);
} else { } else {
x = info.x; x = info.x;