summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/displayapp/DisplayApp.cpp2
-rw-r--r--src/displayapp/screens/SystemInfo.cpp12
-rw-r--r--src/displayapp/screens/SystemInfo.h4
-rw-r--r--src/drivers/Cst816s.cpp39
-rw-r--r--src/drivers/Cst816s.h36
-rw-r--r--src/systemtask/SystemTask.cpp2
6 files changed, 61 insertions, 34 deletions
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp
index 5150162a..4b73a201 100644
--- a/src/displayapp/DisplayApp.cpp
+++ b/src/displayapp/DisplayApp.cpp
@@ -384,7 +384,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
break;
case Apps::SysInfo:
currentScreen = std::make_unique<Screens::SystemInfo>(
- this, dateTimeController, batteryController, brightnessController, bleController, watchdog, motionController);
+ this, dateTimeController, batteryController, brightnessController, bleController, watchdog, motionController, touchPanel);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::FlashLight:
diff --git a/src/displayapp/screens/SystemInfo.cpp b/src/displayapp/screens/SystemInfo.cpp
index e7c5b65a..ca9a4e7c 100644
--- a/src/displayapp/screens/SystemInfo.cpp
+++ b/src/displayapp/screens/SystemInfo.cpp
@@ -33,7 +33,8 @@ SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp* app,
Pinetime::Controllers::BrightnessController& brightnessController,
Pinetime::Controllers::Ble& bleController,
Pinetime::Drivers::WatchdogView& watchdog,
- Pinetime::Controllers::MotionController& motionController)
+ Pinetime::Controllers::MotionController& motionController,
+ Pinetime::Drivers::Cst816S& touchPanel)
: Screen(app),
dateTimeController {dateTimeController},
batteryController {batteryController},
@@ -41,6 +42,7 @@ SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp* app,
bleController {bleController},
watchdog {watchdog},
motionController{motionController},
+ touchPanel{touchPanel},
screens {app,
0,
{[this]() -> std::unique_ptr<Screen> {
@@ -148,7 +150,8 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
"#444444 Battery# %d%%/%03imV\n"
"#444444 Backlight# %s\n"
"#444444 Last reset# %s\n"
- "#444444 Accel.# %s\n",
+ "#444444 Accel.# %s\n"
+ "#444444 Touch.# %x.%x.%x\n",
dateTimeController.Day(),
static_cast<uint8_t>(dateTimeController.Month()),
dateTimeController.Year(),
@@ -163,7 +166,10 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
batteryController.Voltage(),
brightnessController.ToString(),
resetReason,
- ToString(motionController.DeviceType()));
+ ToString(motionController.DeviceType()),
+ touchPanel.GetChipId(),
+ touchPanel.GetVendorId(),
+ touchPanel.GetFwVersion());
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
return std::make_unique<Screens::Label>(1, 5, app, label);
}
diff --git a/src/displayapp/screens/SystemInfo.h b/src/displayapp/screens/SystemInfo.h
index a9ad652d..d28d97e3 100644
--- a/src/displayapp/screens/SystemInfo.h
+++ b/src/displayapp/screens/SystemInfo.h
@@ -28,7 +28,8 @@ namespace Pinetime {
Pinetime::Controllers::BrightnessController& brightnessController,
Pinetime::Controllers::Ble& bleController,
Pinetime::Drivers::WatchdogView& watchdog,
- Pinetime::Controllers::MotionController& motionController);
+ Pinetime::Controllers::MotionController& motionController,
+ Pinetime::Drivers::Cst816S& touchPanel);
~SystemInfo() override;
bool Refresh() override;
bool OnTouchEvent(TouchEvents event) override;
@@ -40,6 +41,7 @@ namespace Pinetime {
Pinetime::Controllers::Ble& bleController;
Pinetime::Drivers::WatchdogView& watchdog;
Pinetime::Controllers::MotionController& motionController;
+ Pinetime::Drivers::Cst816S& touchPanel;
ScreenList<5> screens;
diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp
index fd9792b3..2a6809b1 100644
--- a/src/drivers/Cst816s.cpp
+++ b/src/drivers/Cst816s.cpp
@@ -40,38 +40,45 @@ void Cst816S::Init() {
*/
static constexpr uint8_t motionMask = 0b00000101;
twiMaster.Write(twiAddress, 0xEC, &motionMask, 1);
+
+ // There's mixed information about which register contains which information
+ if (twiMaster.Read(twiAddress, 0xA7, &chipId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
+ chipId = 0xFF;
+ }
+ if (twiMaster.Read(twiAddress, 0xA8, &vendorId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
+ vendorId = 0xFF;
+ }
+ if (twiMaster.Read(twiAddress, 0xA9, &fwVersion, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
+ fwVersion = 0xFF;
+ }
}
Cst816S::TouchInfos Cst816S::GetTouchInfo() {
Cst816S::TouchInfos info;
auto ret = twiMaster.Read(twiAddress, 0, touchData, sizeof(touchData));
- if (ret != TwiMaster::ErrorCodes::NoError)
- return {};
-
- auto nbTouchPoints = touchData[2] & 0x0f;
-
- uint8_t i = 0;
-
- uint8_t pointId = (touchData[touchIdIndex + (touchStep * i)]) >> 4;
- if (nbTouchPoints == 0 && pointId == lastTouchId)
+ if (ret != TwiMaster::ErrorCodes::NoError) {
+ info.isValid = false;
return info;
+ }
- info.isTouch = true;
+ // This can only be 0 or 1
+ auto nbTouchPoints = touchData[touchPointNumIndex] & 0x0f;
- auto xHigh = touchData[touchXHighIndex + (touchStep * i)] & 0x0f;
- auto xLow = touchData[touchXLowIndex + (touchStep * i)];
+ auto xHigh = touchData[touchXHighIndex] & 0x0f;
+ auto xLow = touchData[touchXLowIndex];
uint16_t x = (xHigh << 8) | xLow;
- auto yHigh = touchData[touchYHighIndex + (touchStep * i)] & 0x0f;
- auto yLow = touchData[touchYLowIndex + (touchStep * i)];
+ auto yHigh = touchData[touchYHighIndex] & 0x0f;
+ auto yLow = touchData[touchYLowIndex];
uint16_t y = (yHigh << 8) | yLow;
- auto action = touchData[touchEventIndex + (touchStep * i)] >> 6; /* 0 = Down, 1 = Up, 2 = contact*/
+ auto action = touchData[touchEventIndex] >> 6; /* 0 = Down, 1 = Up, 2 = contact*/
info.x = x;
info.y = y;
info.action = action;
+ info.touching = (nbTouchPoints > 0);
info.gesture = static_cast<Gestures>(touchData[gestureIndex]);
return info;
@@ -90,4 +97,4 @@ void Cst816S::Sleep() {
void Cst816S::Wakeup() {
Init();
NRF_LOG_INFO("[TOUCHPANEL] Wakeup");
-} \ No newline at end of file
+}
diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h
index 14c296ea..394cc40f 100644
--- a/src/drivers/Cst816s.h
+++ b/src/drivers/Cst816s.h
@@ -20,11 +20,9 @@ namespace Pinetime {
uint16_t x = 0;
uint16_t y = 0;
uint8_t action = 0;
- uint8_t finger = 0;
- uint8_t pressure = 0;
- uint8_t area = 0;
+ bool touching = false;
Gestures gesture = Gestures::None;
- bool isTouch = false;
+ bool isValid = true;
};
Cst816S(TwiMaster& twiMaster, uint8_t twiAddress);
@@ -38,26 +36,40 @@ namespace Pinetime {
void Sleep();
void Wakeup();
+ uint8_t GetChipId() const {
+ return chipId;
+ }
+ uint8_t GetVendorId() const {
+ return vendorId;
+ }
+ uint8_t GetFwVersion() const {
+ return fwVersion;
+ }
private:
static constexpr uint8_t pinIrq = 28;
static constexpr uint8_t pinReset = 10;
- static constexpr uint8_t lastTouchId = 0x0f;
+
+ // Unused/Unavailable commented out
+ static constexpr uint8_t gestureIndex = 1;
static constexpr uint8_t touchPointNumIndex = 2;
- static constexpr uint8_t touchMiscIndex = 8;
- static constexpr uint8_t touchXYIndex = 7;
static constexpr uint8_t touchEventIndex = 3;
static constexpr uint8_t touchXHighIndex = 3;
static constexpr uint8_t touchXLowIndex = 4;
+ //static constexpr uint8_t touchIdIndex = 5;
static constexpr uint8_t touchYHighIndex = 5;
static constexpr uint8_t touchYLowIndex = 6;
- static constexpr uint8_t touchIdIndex = 5;
- static constexpr uint8_t touchStep = 6;
- static constexpr uint8_t gestureIndex = 1;
+ //static constexpr uint8_t touchStep = 6;
+ //static constexpr uint8_t touchXYIndex = 7;
+ //static constexpr uint8_t touchMiscIndex = 8;
- uint8_t touchData[10];
+ uint8_t touchData[7];
TwiMaster& twiMaster;
uint8_t twiAddress;
+
+ uint8_t chipId;
+ uint8_t vendorId;
+ uint8_t fwVersion;
};
}
-} \ No newline at end of file
+}
diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp
index 3553f449..500bc8b8 100644
--- a/src/systemtask/SystemTask.cpp
+++ b/src/systemtask/SystemTask.cpp
@@ -243,7 +243,7 @@ void SystemTask::Work() {
twiMaster.Wakeup();
auto touchInfo = touchPanel.GetTouchInfo();
twiMaster.Sleep();
- if (touchInfo.isTouch and ((touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::DoubleTap and
+ 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)))) {