Skip to content

Commit 8a694ad

Browse files
committed
Rework TouchHandler into not a task
1 parent 7e92577 commit 8a694ad

6 files changed

Lines changed: 47 additions & 68 deletions

File tree

src/drivers/TwiMaster.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ TwiMaster::TwiMaster(const Modules module, const Parameters& params) : module {m
1212
}
1313

1414
void TwiMaster::Init() {
15-
sleeping = false;
1615
if(mutex == nullptr)
1716
mutex = xSemaphoreCreateBinary();
18-
17+
1918
NRF_GPIO->PIN_CNF[params.pinScl] =
2019
((uint32_t) GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | ((uint32_t) GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) |
2120
((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() {
177176
nrf_gpio_cfg_default(6);
178177
nrf_gpio_cfg_default(7);
179178
NRF_LOG_INFO("[TWIMASTER] Sleep");
180-
sleeping = true;
181179
}
182180

183181
void TwiMaster::Wakeup() {
184-
if (sleeping) {
185-
Init();
186-
NRF_LOG_INFO("[TWIMASTER] Wakeup");
187-
}
182+
Init();
183+
NRF_LOG_INFO("[TWIMASTER] Wakeup");
188184
}
189185

190186
/* Sometimes, the TWIM device just freeze and never set the event EVENTS_LASTTX.
@@ -210,4 +206,4 @@ void TwiMaster::FixHwFreezed() {
210206

211207
// Re-enable I²C
212208
twiBaseAddress->ENABLE = twi_state;
213-
}
209+
}

src/drivers/TwiMaster.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ namespace Pinetime {
3939
uint8_t internalBuffer[maxDataSize + registerSize];
4040
uint32_t txStartedCycleCount = 0;
4141
static constexpr uint32_t HwFreezedDelay {161000};
42-
bool sleeping;
4342
};
4443
}
45-
}
44+
}

src/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ Pinetime::System::SystemTask systemTask(spi,
166166

167167
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) {
168168
if (pin == pinTouchIrq) {
169-
twiMaster.Wakeup();
170-
touchHandler.WakeUp();
169+
systemTask.OnTouchEvent();
171170
return;
172171
}
173172

src/systemtask/SystemTask.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@ void SystemTask::Work() {
150150
heartRateSensor.Disable();
151151
heartRateApp.Start();
152152

153-
touchHandler.Register(this);
154-
touchHandler.Start();
155-
156153
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);
157154
nrf_gpio_cfg_output(15);
158155
nrf_gpio_pin_set(15);
@@ -244,6 +241,8 @@ void SystemTask::Work() {
244241
isDimmed = false;
245242
break;
246243
case Messages::TouchWakeUp: {
244+
twiMaster.Wakeup();
245+
touchHandler.GetNewTouchInfo();
247246
auto gesture = touchHandler.GestureGet();
248247
if ((gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap &&
249248
settingsController.isWakeUpModeOn(Pinetime::Controllers::Settings::WakeUpMode::DoubleTap)) ||
@@ -299,6 +298,9 @@ void SystemTask::Work() {
299298
xTimerStart(dimTimer, 0);
300299
break;
301300
case Messages::OnTouchEvent:
301+
if (touchHandler.GetNewTouchInfo()) {
302+
touchHandler.UpdateLvglTouchPoint();
303+
}
302304
ReloadIdleTimer();
303305
break;
304306
case Messages::OnButtonEvent:

src/touchhandler/TouchHandler.cpp

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,61 +18,47 @@ Pinetime::Drivers::Cst816S::Gestures TouchHandler::GestureGet() {
1818
return returnGesture;
1919
}
2020

21-
void TouchHandler::Start() {
22-
if (pdPASS != xTaskCreate(TouchHandler::Process, "Touch", 100, this, 0, &taskHandle)) {
23-
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
24-
}
25-
}
26-
27-
void TouchHandler::Process(void* instance) {
28-
auto* app = static_cast<TouchHandler*>(instance);
29-
app->Work();
30-
}
31-
32-
void TouchHandler::Work() {
33-
bool slideReleased = true;
34-
while (true) {
35-
vTaskSuspend(taskHandle);
21+
bool TouchHandler::GetNewTouchInfo() {
22+
info = touchPanel.GetTouchInfo();
3623

37-
info = touchPanel.GetTouchInfo();
38-
39-
if (info.isValid) {
40-
if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
41-
if (slideReleased) {
42-
if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown ||
43-
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft ||
44-
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp ||
45-
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) {
46-
slideReleased = false;
47-
}
48-
gesture = info.gesture;
49-
}
50-
}
24+
if (!info.isValid) {
25+
return false;
26+
}
5127

52-
if (!systemTask->IsSleeping()) {
28+
if (info.gesture != Pinetime::Drivers::Cst816S::Gestures::None) {
29+
if (slideReleased) {
30+
if (info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideDown ||
31+
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideLeft ||
32+
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideUp ||
33+
info.gesture == Pinetime::Drivers::Cst816S::Gestures::SlideRight) {
5334
if (info.touching) {
54-
if (!isCancelled) {
55-
lvgl.SetNewTouchPoint(info.x, info.y, true);
56-
}
57-
} else {
58-
if (isCancelled) {
59-
lvgl.SetNewTouchPoint(-1, -1, false);
60-
isCancelled = false;
61-
} else {
62-
lvgl.SetNewTouchPoint(info.x, info.y, false);
63-
}
64-
slideReleased = true;
35+
gesture = info.gesture;
36+
slideReleased = false;
6537
}
38+
} else {
39+
gesture = info.gesture;
6640
}
67-
systemTask->OnTouchEvent();
6841
}
6942
}
70-
}
7143

72-
void TouchHandler::Register(Pinetime::System::SystemTask* systemTask) {
73-
this->systemTask = systemTask;
44+
if (!info.touching) {
45+
slideReleased = true;
46+
}
47+
48+
return true;
7449
}
7550

76-
void TouchHandler::WakeUp() {
77-
vTaskResume(taskHandle);
51+
void TouchHandler::UpdateLvglTouchPoint() {
52+
if (info.touching) {
53+
if (!isCancelled) {
54+
lvgl.SetNewTouchPoint(info.x, info.y, true);
55+
}
56+
} else {
57+
if (isCancelled) {
58+
lvgl.SetNewTouchPoint(-1, -1, false);
59+
isCancelled = false;
60+
} else {
61+
lvgl.SetNewTouchPoint(info.x, info.y, false);
62+
}
63+
}
7864
}

src/touchhandler/TouchHandler.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ namespace Pinetime {
1919
public:
2020
explicit TouchHandler(Drivers::Cst816S&, Components::LittleVgl&);
2121
void CancelTap();
22+
bool GetNewTouchInfo();
23+
void UpdateLvglTouchPoint();
2224
void Register(Pinetime::System::SystemTask* systemTask);
23-
void Start();
24-
void WakeUp();
2525

2626
bool IsTouching() const {
2727
return info.touching;
@@ -34,16 +34,13 @@ namespace Pinetime {
3434
}
3535
Drivers::Cst816S::Gestures GestureGet();
3636
private:
37-
static void Process(void* instance);
38-
void Work();
3937

4038
Pinetime::Drivers::Cst816S::TouchInfos info;
41-
Pinetime::System::SystemTask* systemTask = nullptr;
42-
TaskHandle_t taskHandle;
4339
Pinetime::Drivers::Cst816S& touchPanel;
4440
Pinetime::Components::LittleVgl& lvgl;
4541
Pinetime::Drivers::Cst816S::Gestures gesture;
4642
bool isCancelled = false;
43+
bool slideReleased = true;
4744
};
4845
}
4946
}

0 commit comments

Comments
 (0)