Skip to content

Commit 5bc40c9

Browse files
committed
Update touchpad driver
1 parent a07b638 commit 5bc40c9

6 files changed

Lines changed: 63 additions & 36 deletions

File tree

src/displayapp/DisplayApp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
336336
break;
337337
case Apps::SysInfo:
338338
currentScreen =
339-
std::make_unique<Screens::SystemInfo>(this, dateTimeController, batteryController, brightnessController, bleController, watchdog, motionController);
339+
std::make_unique<Screens::SystemInfo>(this, dateTimeController, batteryController, brightnessController, bleController, watchdog, motionController, touchPanel);
340340
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
341341
break;
342342
case Apps::FlashLight:
@@ -395,7 +395,7 @@ void DisplayApp::PushMessage(Messages msg) {
395395

396396
TouchEvents DisplayApp::OnTouchEvent() {
397397
auto info = touchPanel.GetTouchInfo();
398-
if (info.isTouch) {
398+
if (info.isValid) {
399399
switch (info.gesture) {
400400
case Pinetime::Drivers::Cst816S::Gestures::SingleTap:
401401
if (touchMode == TouchModes::Gestures) {

src/displayapp/screens/SystemInfo.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp* app,
3131
Pinetime::Controllers::BrightnessController& brightnessController,
3232
Pinetime::Controllers::Ble& bleController,
3333
Pinetime::Drivers::WatchdogView& watchdog,
34-
Pinetime::Controllers::MotionController& motionController)
34+
Pinetime::Controllers::MotionController& motionController,
35+
Pinetime::Drivers::Cst816S& touchPanel)
3536
: Screen(app),
3637
dateTimeController {dateTimeController},
3738
batteryController {batteryController},
3839
brightnessController {brightnessController},
3940
bleController {bleController},
4041
watchdog {watchdog},
4142
motionController{motionController},
43+
touchPanel{touchPanel},
4244
screens {app,
4345
0,
4446
{[this]() -> std::unique_ptr<Screen> {
@@ -151,7 +153,8 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
151153
"#444444 Battery# %d%%/%03imV\n"
152154
"#444444 Backlight# %s\n"
153155
"#444444 Last reset# %s\n"
154-
"#444444 Accel.# %s\n",
156+
"#444444 Accel.# %s\n"
157+
"#444444 Touch.# %x.%x.%x\n",
155158
dateTimeController.Day(),
156159
static_cast<uint8_t>(dateTimeController.Month()),
157160
dateTimeController.Year(),
@@ -166,7 +169,10 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
166169
batteryController.Voltage(),
167170
brightnessController.ToString(),
168171
resetReason,
169-
ToString(motionController.DeviceType()));
172+
ToString(motionController.DeviceType()),
173+
touchPanel.GetChipId(),
174+
touchPanel.GetVendorId(),
175+
touchPanel.GetFwVersion());
170176
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
171177
return std::make_unique<Screens::Label>(1, 5, app, label);
172178
}

src/displayapp/screens/SystemInfo.h

Lines changed: 4 additions & 2 deletions
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 Refresh() override;
3435
bool OnButtonPushed() override;
@@ -43,6 +44,7 @@ namespace Pinetime {
4344
Pinetime::Controllers::Ble& bleController;
4445
Pinetime::Drivers::WatchdogView& watchdog;
4546
Pinetime::Controllers::MotionController& motionController;
47+
Pinetime::Drivers::Cst816S& touchPanel;
4648

4749
ScreenList<5> screens;
4850

@@ -56,4 +58,4 @@ namespace Pinetime {
5658
};
5759
}
5860
}
59-
}
61+
}

src/drivers/Cst816s.cpp

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,45 @@ void Cst816S::Init() {
4040
*/
4141
static constexpr uint8_t motionMask = 0b00000101;
4242
twiMaster.Write(twiAddress, 0xEC, &motionMask, 1);
43+
44+
// There's mixed information about which register contains which information
45+
if (twiMaster.Read(twiAddress, 0xA7, &chipId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
46+
chipId = 0xFF;
47+
}
48+
if (twiMaster.Read(twiAddress, 0xA8, &vendorId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
49+
vendorId = 0xFF;
50+
}
51+
if (twiMaster.Read(twiAddress, 0xA9, &fwVersion, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
52+
fwVersion = 0xFF;
53+
}
4354
}
4455

4556
Cst816S::TouchInfos Cst816S::GetTouchInfo() {
4657
Cst816S::TouchInfos info;
4758

4859
auto ret = twiMaster.Read(twiAddress, 0, touchData, sizeof(touchData));
49-
if (ret != TwiMaster::ErrorCodes::NoError)
50-
return {};
51-
52-
auto nbTouchPoints = touchData[2] & 0x0f;
53-
54-
uint8_t i = 0;
55-
56-
uint8_t pointId = (touchData[touchIdIndex + (touchStep * i)]) >> 4;
57-
if (nbTouchPoints == 0 && pointId == lastTouchId)
60+
if (ret != TwiMaster::ErrorCodes::NoError) {
61+
info.isValid = false;
5862
return info;
63+
}
5964

60-
info.isTouch = true;
65+
// This can only be 0 or 1
66+
auto nbTouchPoints = touchData[touchPointNumIndex] & 0x0f;
6167

62-
auto xHigh = touchData[touchXHighIndex + (touchStep * i)] & 0x0f;
63-
auto xLow = touchData[touchXLowIndex + (touchStep * i)];
68+
auto xHigh = touchData[touchXHighIndex] & 0x0f;
69+
auto xLow = touchData[touchXLowIndex];
6470
uint16_t x = (xHigh << 8) | xLow;
6571

66-
auto yHigh = touchData[touchYHighIndex + (touchStep * i)] & 0x0f;
67-
auto yLow = touchData[touchYLowIndex + (touchStep * i)];
72+
auto yHigh = touchData[touchYHighIndex] & 0x0f;
73+
auto yLow = touchData[touchYLowIndex];
6874
uint16_t y = (yHigh << 8) | yLow;
6975

70-
auto action = touchData[touchEventIndex + (touchStep * i)] >> 6; /* 0 = Down, 1 = Up, 2 = contact*/
76+
auto action = touchData[touchEventIndex] >> 6; /* 0 = Down, 1 = Up, 2 = contact*/
7177

7278
info.x = x;
7379
info.y = y;
7480
info.action = action;
81+
info.touching = (nbTouchPoints > 0);
7582
info.gesture = static_cast<Gestures>(touchData[gestureIndex]);
7683

7784
return info;
@@ -90,4 +97,4 @@ void Cst816S::Sleep() {
9097
void Cst816S::Wakeup() {
9198
Init();
9299
NRF_LOG_INFO("[TOUCHPANEL] Wakeup");
93-
}
100+
}

src/drivers/Cst816s.h

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ namespace Pinetime {
2020
uint16_t x = 0;
2121
uint16_t y = 0;
2222
uint8_t action = 0;
23-
uint8_t finger = 0;
24-
uint8_t pressure = 0;
25-
uint8_t area = 0;
23+
bool touching = false;
2624
Gestures gesture = Gestures::None;
27-
bool isTouch = false;
25+
bool isValid = true;
2826
};
2927

3028
Cst816S(TwiMaster& twiMaster, uint8_t twiAddress);
@@ -38,26 +36,40 @@ namespace Pinetime {
3836
void Sleep();
3937
void Wakeup();
4038

39+
uint8_t GetChipId() const {
40+
return chipId;
41+
}
42+
uint8_t GetVendorId() const {
43+
return vendorId;
44+
}
45+
uint8_t GetFwVersion() const {
46+
return fwVersion;
47+
}
4148
private:
4249
static constexpr uint8_t pinIrq = 28;
4350
static constexpr uint8_t pinReset = 10;
44-
static constexpr uint8_t lastTouchId = 0x0f;
51+
52+
// Unused/Unavailable commented out
53+
static constexpr uint8_t gestureIndex = 1;
4554
static constexpr uint8_t touchPointNumIndex = 2;
46-
static constexpr uint8_t touchMiscIndex = 8;
47-
static constexpr uint8_t touchXYIndex = 7;
4855
static constexpr uint8_t touchEventIndex = 3;
4956
static constexpr uint8_t touchXHighIndex = 3;
5057
static constexpr uint8_t touchXLowIndex = 4;
58+
//static constexpr uint8_t touchIdIndex = 5;
5159
static constexpr uint8_t touchYHighIndex = 5;
5260
static constexpr uint8_t touchYLowIndex = 6;
53-
static constexpr uint8_t touchIdIndex = 5;
54-
static constexpr uint8_t touchStep = 6;
55-
static constexpr uint8_t gestureIndex = 1;
61+
//static constexpr uint8_t touchStep = 6;
62+
//static constexpr uint8_t touchXYIndex = 7;
63+
//static constexpr uint8_t touchMiscIndex = 8;
5664

57-
uint8_t touchData[10];
65+
uint8_t touchData[7];
5866
TwiMaster& twiMaster;
5967
uint8_t twiAddress;
68+
69+
uint8_t chipId;
70+
uint8_t vendorId;
71+
uint8_t fwVersion;
6072
};
6173

6274
}
63-
}
75+
}

src/systemtask/SystemTask.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ void SystemTask::Work() {
231231
twiMaster.Wakeup();
232232
auto touchInfo = touchPanel.GetTouchInfo();
233233
twiMaster.Sleep();
234-
if (touchInfo.isTouch and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and
234+
if (touchInfo.isValid and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and
235235
settingsController.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::DoubleTap) or
236236
(touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and
237237
settingsController.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::SingleTap))) {

0 commit comments

Comments
 (0)