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;
}
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() {

View File

@ -12,6 +12,7 @@ TwiMaster::TwiMaster(const Modules module, const Parameters& params) : module {m
}
void TwiMaster::Init() {
sleeping = false;
if(mutex == nullptr)
mutex = xSemaphoreCreateBinary();
@ -176,11 +177,14 @@ void TwiMaster::Sleep() {
nrf_gpio_cfg_default(6);
nrf_gpio_cfg_default(7);
NRF_LOG_INFO("[TWIMASTER] Sleep");
sleeping = true;
}
void TwiMaster::Wakeup() {
if (sleeping) {
Init();
NRF_LOG_INFO("[TWIMASTER] Wakeup");
}
}
/* Sometimes, the TWIM device just freeze and never set the event EVENTS_LASTTX.

View File

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

View File

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

View File

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

View File

@ -17,6 +17,7 @@
#include "components/motor/MotorController.h"
#include "components/timer/TimerController.h"
#include "components/fs/FS.h"
#include "touchhandler/TouchHandler.h"
#ifdef PINETIME_IS_RECOVERY
#include "displayapp/DisplayAppRecovery.h"
@ -39,6 +40,9 @@ namespace Pinetime {
class TwiMaster;
class Hrs3300;
}
namespace Controllers {
class TouchHandler;
}
namespace System {
class SystemTask {
public:
@ -62,7 +66,8 @@ namespace Pinetime {
Pinetime::Controllers::HeartRateController& heartRateController,
Pinetime::Applications::DisplayApp& displayApp,
Pinetime::Applications::HeartRateTask& heartRateApp,
Pinetime::Controllers::FS& fs);
Pinetime::Controllers::FS& fs,
Pinetime::Controllers::TouchHandler& touchHandler);
void Start();
void PushMessage(Messages msg);
@ -91,7 +96,6 @@ namespace Pinetime {
Pinetime::Components::LittleVgl& lvgl;
Pinetime::Controllers::Battery& batteryController;
Pinetime::Controllers::Ble& bleController;
Pinetime::Controllers::DateTime& dateTimeController;
Pinetime::Controllers::TimerController& timerController;
@ -113,6 +117,7 @@ namespace Pinetime {
Pinetime::Applications::DisplayApp& displayApp;
Pinetime::Applications::HeartRateTask& heartRateApp;
Pinetime::Controllers::FS& fs;
Pinetime::Controllers::TouchHandler& touchHandler;
Pinetime::Controllers::NimbleController nimbleController;
static constexpr uint8_t pinSpiSck = 2;

View File

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