summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiku Isokoski <riksu9000@gmail.com>2021-08-10 22:03:34 +0300
committerRiku Isokoski <riksu9000@gmail.com>2021-08-10 22:03:34 +0300
commit8a694adb0979339664da0af6d51c480d26c5527b (patch)
tree89c0deb381b34d3060edfcee249a9e5177244e67
parent7e92577c14895f57f5adda27ad54adbbc4b7ffe9 (diff)
Rework TouchHandler into not a task
-rw-r--r--src/drivers/TwiMaster.cpp12
-rw-r--r--src/drivers/TwiMaster.h3
-rw-r--r--src/main.cpp3
-rw-r--r--src/systemtask/SystemTask.cpp8
-rw-r--r--src/touchhandler/TouchHandler.cpp80
-rw-r--r--src/touchhandler/TouchHandler.h9
6 files changed, 47 insertions, 68 deletions
diff --git a/src/drivers/TwiMaster.cpp b/src/drivers/TwiMaster.cpp
index 456c3e64..fc9edf81 100644
--- a/src/drivers/TwiMaster.cpp
+++ b/src/drivers/TwiMaster.cpp
@@ -12,10 +12,9 @@ TwiMaster::TwiMaster(const Modules module, const Parameters& params) : module {m
}
void TwiMaster::Init() {
- sleeping = false;
if(mutex == nullptr)
mutex = xSemaphoreCreateBinary();
-
+
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_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos) | ((uint32_t) GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) |
@@ -177,14 +176,11 @@ 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");
- }
+ Init();
+ NRF_LOG_INFO("[TWIMASTER] Wakeup");
}
/* Sometimes, the TWIM device just freeze and never set the event EVENTS_LASTTX.
@@ -210,4 +206,4 @@ void TwiMaster::FixHwFreezed() {
// Re-enable I²C
twiBaseAddress->ENABLE = twi_state;
-}
+} \ No newline at end of file
diff --git a/src/drivers/TwiMaster.h b/src/drivers/TwiMaster.h
index 5748ec65..6175b99b 100644
--- a/src/drivers/TwiMaster.h
+++ b/src/drivers/TwiMaster.h
@@ -39,7 +39,6 @@ namespace Pinetime {
uint8_t internalBuffer[maxDataSize + registerSize];
uint32_t txStartedCycleCount = 0;
static constexpr uint32_t HwFreezedDelay {161000};
- bool sleeping;
};
}
-}
+} \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index 62e4446f..dffec28a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -166,8 +166,7 @@ Pinetime::System::SystemTask systemTask(spi,
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
if (pin == pinTouchIrq) {
- twiMaster.Wakeup();
- touchHandler.WakeUp();
+ systemTask.OnTouchEvent();
return;
}
diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp
index 7ba7cf69..5f363130 100644
--- a/src/systemtask/SystemTask.cpp
+++ b/src/systemtask/SystemTask.cpp
@@ -150,9 +150,6 @@ void SystemTask::Work() {
heartRateSensor.Disable();
heartRateApp.Start();
- touchHandler.Register(this);
- touchHandler.Start();
-
nrf_gpio_cfg_sense_input(pinButton, (nrf_gpio_pin_pull_t) GPIO_PIN_CNF_PULL_Pulldown, (nrf_gpio_pin_sense_t) GPIO_PIN_CNF_SENSE_High);
nrf_gpio_cfg_output(15);
nrf_gpio_pin_set(15);
@@ -244,6 +241,8 @@ void SystemTask::Work() {
isDimmed = false;
break;
case Messages::TouchWakeUp: {
+ twiMaster.Wakeup();
+ touchHandler.GetNewTouchInfo();
auto gesture = touchHandler.GestureGet();
if ((gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap &&
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) ||
@@ -299,6 +298,9 @@ void SystemTask::Work() {
xTimerStart(dimTimer, 0);
break;
case Messages::OnTouchEvent:
+ if (touchHandler.GetNewTouchInfo()) {
+ touchHandler.UpdateLvglTouchPoint();
+ }
ReloadIdleTimer();
break;
case Messages::OnButtonEvent:
diff --git a/src/touchhandler/TouchHandler.cpp b/src/touchhandler/TouchHandler.cpp
index 187aa696..c1a3c0d0 100644
--- a/src/touchhandler/TouchHandler.cpp
+++ b/src/touchhandler/TouchHandler.cpp
@@ -18,61 +18,47 @@ Pinetime::Drivers::Cst816S::Gestures TouchHandler::GestureGet() {
return returnGesture;
}
-void TouchHandler::Start() {
- if (pdPASS != xTaskCreate(TouchHandler::Process, "Touch", 100, this, 0, &taskHandle)) {
- APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
- }
-}
-
-void TouchHandler::Process(void* instance) {
- auto* app = static_cast<TouchHandler*>(instance);
- app->Work();
-}
-
-void TouchHandler::Work() {
- bool slideReleased = true;
- while (true) {
- vTaskSuspend(taskHandle);
+bool TouchHandler::GetNewTouchInfo() {
+ info = touchPanel.GetTouchInfo();
- info = touchPanel.GetTouchInfo();
-
- if (info.isValid) {
- if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
- if (slideReleased) {
- if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown ||
- info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft ||
- info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp ||
- info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) {
- slideReleased = false;
- }
- gesture = info.gesture;
- }
- }
+ if (!info.isValid) {
+ return false;
+ }
- if (!systemTask->IsSleeping()) {
+ if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
+ if (slideReleased) {
+ if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown ||
+ info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft ||
+ info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp ||
+ info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) {
if (info.touching) {
- if (!isCancelled) {
- lvgl.SetNewTouchPoint(info.x, info.y, true);
- }
- } else {
- if (isCancelled) {
- lvgl.SetNewTouchPoint(-1, -1, false);
- isCancelled = false;
- } else {
- lvgl.SetNewTouchPoint(info.x, info.y, false);
- }
- slideReleased = true;
+ gesture = info.gesture;
+ slideReleased = false;
}
+ } else {
+ gesture = info.gesture;
}
- systemTask->OnTouchEvent();
}
}
-}
-void TouchHandler::Register(Pinetime::System::SystemTask* systemTask) {
- this->systemTask = systemTask;
+ if (!info.touching) {
+ slideReleased = true;
+ }
+
+ return true;
}
-void TouchHandler::WakeUp() {
- vTaskResume(taskHandle);
+void TouchHandler::UpdateLvglTouchPoint() {
+ if (info.touching) {
+ if (!isCancelled) {
+ lvgl.SetNewTouchPoint(info.x, info.y, true);
+ }
+ } else {
+ if (isCancelled) {
+ lvgl.SetNewTouchPoint(-1, -1, false);
+ isCancelled = false;
+ } else {
+ lvgl.SetNewTouchPoint(info.x, info.y, false);
+ }
+ }
}
diff --git a/src/touchhandler/TouchHandler.h b/src/touchhandler/TouchHandler.h
index 6b8189f5..38cb36cb 100644
--- a/src/touchhandler/TouchHandler.h
+++ b/src/touchhandler/TouchHandler.h
@@ -19,9 +19,9 @@ namespace Pinetime {
public:
explicit TouchHandler(Drivers::Cst816S&, Components::LittleVgl&);
void CancelTap();
+ bool GetNewTouchInfo();
+ void UpdateLvglTouchPoint();
void Register(Pinetime::System::SystemTask* systemTask);
- void Start();
- void WakeUp();
bool IsTouching() const {
return info.touching;
@@ -34,16 +34,13 @@ namespace Pinetime {
}
Drivers::Cst816S::Gestures GestureGet();
private:
- static void Process(void* instance);
- void Work();
Pinetime::Drivers::Cst816S::TouchInfos info;
- Pinetime::System::SystemTask* systemTask = nullptr;
- TaskHandle_t taskHandle;
Pinetime::Drivers::Cst816S& touchPanel;
Pinetime::Components::LittleVgl& lvgl;
Pinetime::Drivers::Cst816S::Gestures gesture;
bool isCancelled = false;
+ bool slideReleased = true;
};
}
}