Skip to content

Commit 6d0e68d

Browse files
committed
Merge branch 'update_touch_driver' of git://github.com/Riksu9000/InfiniTime into Riksu9000-update_touch_driver
# Conflicts: # src/displayapp/Apps.h
2 parents 92aeae7 + f61e88b commit 6d0e68d

12 files changed

Lines changed: 161 additions & 24 deletions

File tree

src/BootErrors.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
namespace Pinetime {
4+
namespace System {
5+
enum class BootErrors {
6+
None,
7+
TouchController,
8+
};
9+
}
10+
}

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ list(APPEND SOURCE_FILES
421421
displayapp/screens/BatteryInfo.cpp
422422
displayapp/screens/Steps.cpp
423423
displayapp/screens/Timer.cpp
424+
displayapp/screens/Error.cpp
424425
displayapp/screens/Alarm.cpp
425426
displayapp/Colors.cpp
426427

src/displayapp/Apps.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ namespace Pinetime {
3434
SettingSteps,
3535
SettingPineTimeStyle,
3636
SettingSetDate,
37-
SettingSetTime
37+
SettingSetTime,
38+
Error,
3839
};
3940
}
4041
}

src/displayapp/DisplayApp.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "displayapp/screens/FlashLight.h"
3030
#include "displayapp/screens/BatteryInfo.h"
3131
#include "displayapp/screens/Steps.h"
32+
#include "displayapp/screens/Error.h"
3233

3334
#include "drivers/Cst816s.h"
3435
#include "drivers/St7789.h"
@@ -112,11 +113,16 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
112113
touchHandler {touchHandler} {
113114
}
114115

115-
void DisplayApp::Start() {
116+
void DisplayApp::Start(System::BootErrors error) {
116117
msgQueue = xQueueCreate(queueSize, itemSize);
117118

118-
// Start clock when smartwatch boots
119-
LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
119+
bootError = error;
120+
121+
if (error == System::BootErrors::TouchController) {
122+
LoadApp(Apps::Error, DisplayApp::FullRefreshDirections::None);
123+
} else {
124+
LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
125+
}
120126

121127
if (pdPASS != xTaskCreate(DisplayApp::Process, "displayapp", 800, this, 0, &taskHandle)) {
122128
APP_ERROR_HANDLER(NRF_ERROR_NO_MEM);
@@ -311,6 +317,11 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
311317
motionController);
312318
break;
313319

320+
case Apps::Error:
321+
currentScreen = std::make_unique<Screens::Error>(this, bootError);
322+
ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None);
323+
break;
324+
314325
case Apps::FirmwareValidation:
315326
currentScreen = std::make_unique<Screens::FirmwareValidation>(this, validator);
316327
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
@@ -385,7 +396,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
385396
break;
386397
case Apps::SysInfo:
387398
currentScreen = std::make_unique<Screens::SystemInfo>(
388-
this, dateTimeController, batteryController, brightnessController, bleController, watchdog, motionController);
399+
this, dateTimeController, batteryController, brightnessController, bleController, watchdog, motionController, touchPanel);
389400
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
390401
break;
391402
case Apps::FlashLight:

src/displayapp/DisplayApp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "touchhandler/TouchHandler.h"
1919

2020
#include "Messages.h"
21+
#include "BootErrors.h"
2122

2223
namespace Pinetime {
2324

@@ -61,7 +62,7 @@ namespace Pinetime {
6162
Pinetime::Controllers::TimerController& timerController,
6263
Pinetime::Controllers::AlarmController& alarmController,
6364
Pinetime::Controllers::TouchHandler& touchHandler);
64-
void Start();
65+
void Start(System::BootErrors error);
6566
void PushMessage(Display::Messages msg);
6667

6768
void StartApp(Apps app, DisplayApp::FullRefreshDirections direction);
@@ -116,6 +117,7 @@ namespace Pinetime {
116117

117118
Apps nextApp = Apps::None;
118119
DisplayApp::FullRefreshDirections nextDirection;
120+
System::BootErrors bootError;
119121
};
120122
}
121123
}

src/displayapp/screens/Error.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "Error.h"
2+
3+
using namespace Pinetime::Applications::Screens;
4+
5+
namespace {
6+
void ButtonEventCallback(lv_obj_t* obj, lv_event_t /*event*/) {
7+
auto* errorScreen = static_cast<Error*>(obj->user_data);
8+
errorScreen->ButtonEventHandler();
9+
}
10+
}
11+
12+
Error::Error(Pinetime::Applications::DisplayApp* app, System::BootErrors error)
13+
: Screen(app) {
14+
15+
lv_obj_t* warningLabel = lv_label_create(lv_scr_act(), nullptr);
16+
lv_obj_set_style_local_text_color(warningLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
17+
lv_label_set_text_static(warningLabel, "Warning");
18+
lv_obj_align(warningLabel, nullptr, LV_ALIGN_IN_TOP_MID, 0, 0);
19+
20+
lv_obj_t* causeLabel = lv_label_create(lv_scr_act(), nullptr);
21+
lv_label_set_long_mode(causeLabel, LV_LABEL_LONG_BREAK);
22+
lv_obj_set_width(causeLabel, LV_HOR_RES);
23+
lv_obj_align(causeLabel, warningLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
24+
25+
if (error == System::BootErrors::TouchController) {
26+
lv_label_set_text_static(causeLabel, "Touch controller error detected.");
27+
}
28+
29+
lv_obj_t* tipLabel = lv_label_create(lv_scr_act(), nullptr);
30+
lv_label_set_long_mode(tipLabel, LV_LABEL_LONG_BREAK);
31+
lv_obj_set_width(tipLabel, LV_HOR_RES);
32+
lv_label_set_text_static(tipLabel, "If you encounter problems and your device is under warranty, contact the devices seller.");
33+
lv_obj_align(tipLabel, causeLabel, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
34+
35+
btnOk = lv_btn_create(lv_scr_act(), nullptr);
36+
btnOk->user_data = this;
37+
lv_obj_set_event_cb(btnOk, ButtonEventCallback);
38+
lv_obj_set_size(btnOk, LV_HOR_RES, 50);
39+
lv_obj_align(btnOk, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
40+
lv_obj_set_style_local_value_str(btnOk, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Proceed");
41+
lv_obj_set_style_local_bg_color(btnOk, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
42+
}
43+
44+
void Error::ButtonEventHandler() {
45+
running = false;
46+
}
47+
48+
Error::~Error() {
49+
lv_obj_clean(lv_scr_act());
50+
}

src/displayapp/screens/Error.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#include "Screen.h"
4+
#include "BootErrors.h"
5+
#include <lvgl/lvgl.h>
6+
7+
namespace Pinetime {
8+
namespace Applications {
9+
namespace Screens {
10+
class Error : public Screen {
11+
public:
12+
Error(DisplayApp* app, System::BootErrors error);
13+
~Error() override;
14+
15+
void ButtonEventHandler();
16+
private:
17+
lv_obj_t* btnOk;
18+
};
19+
}
20+
}
21+
}

src/displayapp/screens/SystemInfo.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp* app,
3333
Pinetime::Controllers::BrightnessController& brightnessController,
3434
Pinetime::Controllers::Ble& bleController,
3535
Pinetime::Drivers::WatchdogView& watchdog,
36-
Pinetime::Controllers::MotionController& motionController)
36+
Pinetime::Controllers::MotionController& motionController,
37+
Pinetime::Drivers::Cst816S& touchPanel)
3738
: Screen(app),
3839
dateTimeController {dateTimeController},
3940
batteryController {batteryController},
4041
brightnessController {brightnessController},
4142
bleController {bleController},
4243
watchdog {watchdog},
4344
motionController{motionController},
45+
touchPanel{touchPanel},
4446
screens {app,
4547
0,
4648
{[this]() -> std::unique_ptr<Screen> {
@@ -141,7 +143,8 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
141143
"#444444 Battery# %d%%/%03imV\n"
142144
"#444444 Backlight# %s\n"
143145
"#444444 Last reset# %s\n"
144-
"#444444 Accel.# %s\n",
146+
"#444444 Accel.# %s\n"
147+
"#444444 Touch.# %x.%x.%x\n",
145148
dateTimeController.Day(),
146149
static_cast<uint8_t>(dateTimeController.Month()),
147150
dateTimeController.Year(),
@@ -156,7 +159,10 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
156159
batteryController.Voltage(),
157160
brightnessController.ToString(),
158161
resetReason,
159-
ToString(motionController.DeviceType()));
162+
ToString(motionController.DeviceType()),
163+
touchPanel.GetChipId(),
164+
touchPanel.GetVendorId(),
165+
touchPanel.GetFwVersion());
160166
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
161167
return std::make_unique<Screens::Label>(1, 5, app, label);
162168
}

src/displayapp/screens/SystemInfo.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ namespace Pinetime {
2828
Pinetime::Controllers::BrightnessController& brightnessController,
2929
Pinetime::Controllers::Ble& bleController,
3030
Pinetime::Drivers::WatchdogView& watchdog,
31-
Pinetime::Controllers::MotionController& motionController);
31+
Pinetime::Controllers::MotionController& motionController,
32+
Pinetime::Drivers::Cst816S& touchPanel);
3233
~SystemInfo() override;
3334
bool OnTouchEvent(TouchEvents event) override;
3435

@@ -39,6 +40,7 @@ namespace Pinetime {
3940
Pinetime::Controllers::Ble& bleController;
4041
Pinetime::Drivers::WatchdogView& watchdog;
4142
Pinetime::Controllers::MotionController& motionController;
43+
Pinetime::Drivers::Cst816S& touchPanel;
4244

4345
ScreenList<5> screens;
4446

src/drivers/Cst816s.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ using namespace Pinetime::Drivers;
1818
Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaster}, twiAddress {twiAddress} {
1919
}
2020

21-
void Cst816S::Init() {
21+
bool Cst816S::Init() {
2222
nrf_gpio_cfg_output(PinMap::Cst816sReset);
2323
nrf_gpio_pin_set(PinMap::Cst816sReset);
2424
vTaskDelay(50);
@@ -51,29 +51,45 @@ void Cst816S::Init() {
5151
*/
5252
static constexpr uint8_t irqCtl = 0b01110000;
5353
twiMaster.Write(twiAddress, 0xFA, &irqCtl, 1);
54+
55+
// There's mixed information about which register contains which information
56+
if (twiMaster.Read(twiAddress, 0xA7, &chipId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
57+
chipId = 0xFF;
58+
return false;
59+
}
60+
if (twiMaster.Read(twiAddress, 0xA8, &vendorId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
61+
vendorId = 0xFF;
62+
return false;
63+
}
64+
if (twiMaster.Read(twiAddress, 0xA9, &fwVersion, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
65+
fwVersion = 0xFF;
66+
return false;
67+
}
68+
69+
return chipId == 0xb4 && vendorId == 0 && fwVersion == 1;
5470
}
5571

5672
Cst816S::TouchInfos Cst816S::GetTouchInfo() {
5773
Cst816S::TouchInfos info;
74+
uint8_t touchData[7];
5875

5976
auto ret = twiMaster.Read(twiAddress, 0, touchData, sizeof(touchData));
6077
if (ret != TwiMaster::ErrorCodes::NoError) {
6178
info.isValid = false;
6279
return info;
6380
}
6481

65-
auto nbTouchPoints = touchData[2] & 0x0f;
82+
// This can only be 0 or 1
83+
uint8_t nbTouchPoints = touchData[touchPointNumIndex] & 0x0f;
6684

67-
auto xHigh = touchData[touchXHighIndex] & 0x0f;
68-
auto xLow = touchData[touchXLowIndex];
69-
uint16_t x = (xHigh << 8) | xLow;
85+
uint8_t xHigh = touchData[touchXHighIndex] & 0x0f;
86+
uint8_t xLow = touchData[touchXLowIndex];
87+
info.x = (xHigh << 8) | xLow;
7088

71-
auto yHigh = touchData[touchYHighIndex] & 0x0f;
72-
auto yLow = touchData[touchYLowIndex];
73-
uint16_t y = (yHigh << 8) | yLow;
89+
uint8_t yHigh = touchData[touchYHighIndex] & 0x0f;
90+
uint8_t yLow = touchData[touchYLowIndex];
91+
info.y = (yHigh << 8) | yLow;
7492

75-
info.x = x;
76-
info.y = y;
7793
info.touching = (nbTouchPoints > 0);
7894
info.gesture = static_cast<Gestures>(touchData[gestureIndex]);
7995

0 commit comments

Comments
 (0)