Update touchpad driver
This commit is contained in:
parent
a07b6382ae
commit
5bc40c9287
|
@ -336,7 +336,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
|
||||||
break;
|
break;
|
||||||
case Apps::SysInfo:
|
case Apps::SysInfo:
|
||||||
currentScreen =
|
currentScreen =
|
||||||
std::make_unique<Screens::SystemInfo>(this, dateTimeController, batteryController, brightnessController, bleController, watchdog, motionController);
|
std::make_unique<Screens::SystemInfo>(this, dateTimeController, batteryController, brightnessController, bleController, watchdog, motionController, touchPanel);
|
||||||
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
|
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
|
||||||
break;
|
break;
|
||||||
case Apps::FlashLight:
|
case Apps::FlashLight:
|
||||||
|
@ -395,7 +395,7 @@ void DisplayApp::PushMessage(Messages msg) {
|
||||||
|
|
||||||
TouchEvents DisplayApp::OnTouchEvent() {
|
TouchEvents DisplayApp::OnTouchEvent() {
|
||||||
auto info = touchPanel.GetTouchInfo();
|
auto info = touchPanel.GetTouchInfo();
|
||||||
if (info.isTouch) {
|
if (info.isValid) {
|
||||||
switch (info.gesture) {
|
switch (info.gesture) {
|
||||||
case Pinetime::Drivers::Cst816S::Gestures::SingleTap:
|
case Pinetime::Drivers::Cst816S::Gestures::SingleTap:
|
||||||
if (touchMode == TouchModes::Gestures) {
|
if (touchMode == TouchModes::Gestures) {
|
||||||
|
|
|
@ -31,7 +31,8 @@ SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp* app,
|
||||||
Pinetime::Controllers::BrightnessController& brightnessController,
|
Pinetime::Controllers::BrightnessController& brightnessController,
|
||||||
Pinetime::Controllers::Ble& bleController,
|
Pinetime::Controllers::Ble& bleController,
|
||||||
Pinetime::Drivers::WatchdogView& watchdog,
|
Pinetime::Drivers::WatchdogView& watchdog,
|
||||||
Pinetime::Controllers::MotionController& motionController)
|
Pinetime::Controllers::MotionController& motionController,
|
||||||
|
Pinetime::Drivers::Cst816S& touchPanel)
|
||||||
: Screen(app),
|
: Screen(app),
|
||||||
dateTimeController {dateTimeController},
|
dateTimeController {dateTimeController},
|
||||||
batteryController {batteryController},
|
batteryController {batteryController},
|
||||||
|
@ -39,6 +40,7 @@ SystemInfo::SystemInfo(Pinetime::Applications::DisplayApp* app,
|
||||||
bleController {bleController},
|
bleController {bleController},
|
||||||
watchdog {watchdog},
|
watchdog {watchdog},
|
||||||
motionController{motionController},
|
motionController{motionController},
|
||||||
|
touchPanel{touchPanel},
|
||||||
screens {app,
|
screens {app,
|
||||||
0,
|
0,
|
||||||
{[this]() -> std::unique_ptr<Screen> {
|
{[this]() -> std::unique_ptr<Screen> {
|
||||||
|
@ -151,7 +153,8 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
|
||||||
"#444444 Battery# %d%%/%03imV\n"
|
"#444444 Battery# %d%%/%03imV\n"
|
||||||
"#444444 Backlight# %s\n"
|
"#444444 Backlight# %s\n"
|
||||||
"#444444 Last reset# %s\n"
|
"#444444 Last reset# %s\n"
|
||||||
"#444444 Accel.# %s\n",
|
"#444444 Accel.# %s\n"
|
||||||
|
"#444444 Touch.# %x.%x.%x\n",
|
||||||
dateTimeController.Day(),
|
dateTimeController.Day(),
|
||||||
static_cast<uint8_t>(dateTimeController.Month()),
|
static_cast<uint8_t>(dateTimeController.Month()),
|
||||||
dateTimeController.Year(),
|
dateTimeController.Year(),
|
||||||
|
@ -166,7 +169,10 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
|
||||||
batteryController.Voltage(),
|
batteryController.Voltage(),
|
||||||
brightnessController.ToString(),
|
brightnessController.ToString(),
|
||||||
resetReason,
|
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);
|
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
||||||
return std::make_unique<Screens::Label>(1, 5, app, label);
|
return std::make_unique<Screens::Label>(1, 5, app, label);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,8 @@ namespace Pinetime {
|
||||||
Pinetime::Controllers::BrightnessController& brightnessController,
|
Pinetime::Controllers::BrightnessController& brightnessController,
|
||||||
Pinetime::Controllers::Ble& bleController,
|
Pinetime::Controllers::Ble& bleController,
|
||||||
Pinetime::Drivers::WatchdogView& watchdog,
|
Pinetime::Drivers::WatchdogView& watchdog,
|
||||||
Pinetime::Controllers::MotionController& motionController);
|
Pinetime::Controllers::MotionController& motionController,
|
||||||
|
Pinetime::Drivers::Cst816S& touchPanel);
|
||||||
~SystemInfo() override;
|
~SystemInfo() override;
|
||||||
bool Refresh() override;
|
bool Refresh() override;
|
||||||
bool OnButtonPushed() override;
|
bool OnButtonPushed() override;
|
||||||
|
@ -43,6 +44,7 @@ namespace Pinetime {
|
||||||
Pinetime::Controllers::Ble& bleController;
|
Pinetime::Controllers::Ble& bleController;
|
||||||
Pinetime::Drivers::WatchdogView& watchdog;
|
Pinetime::Drivers::WatchdogView& watchdog;
|
||||||
Pinetime::Controllers::MotionController& motionController;
|
Pinetime::Controllers::MotionController& motionController;
|
||||||
|
Pinetime::Drivers::Cst816S& touchPanel;
|
||||||
|
|
||||||
ScreenList<5> screens;
|
ScreenList<5> screens;
|
||||||
|
|
||||||
|
|
|
@ -40,38 +40,45 @@ void Cst816S::Init() {
|
||||||
*/
|
*/
|
||||||
static constexpr uint8_t motionMask = 0b00000101;
|
static constexpr uint8_t motionMask = 0b00000101;
|
||||||
twiMaster.Write(twiAddress, 0xEC, &motionMask, 1);
|
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 Cst816S::GetTouchInfo() {
|
||||||
Cst816S::TouchInfos info;
|
Cst816S::TouchInfos info;
|
||||||
|
|
||||||
auto ret = twiMaster.Read(twiAddress, 0, touchData, sizeof(touchData));
|
auto ret = twiMaster.Read(twiAddress, 0, touchData, sizeof(touchData));
|
||||||
if (ret != TwiMaster::ErrorCodes::NoError)
|
if (ret != TwiMaster::ErrorCodes::NoError) {
|
||||||
return {};
|
info.isValid = false;
|
||||||
|
|
||||||
auto nbTouchPoints = touchData[2] & 0x0f;
|
|
||||||
|
|
||||||
uint8_t i = 0;
|
|
||||||
|
|
||||||
uint8_t pointId = (touchData[touchIdIndex + (touchStep * i)]) >> 4;
|
|
||||||
if (nbTouchPoints == 0 && pointId == lastTouchId)
|
|
||||||
return info;
|
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 xHigh = touchData[touchXHighIndex] & 0x0f;
|
||||||
auto xLow = touchData[touchXLowIndex + (touchStep * i)];
|
auto xLow = touchData[touchXLowIndex];
|
||||||
uint16_t x = (xHigh << 8) | xLow;
|
uint16_t x = (xHigh << 8) | xLow;
|
||||||
|
|
||||||
auto yHigh = touchData[touchYHighIndex + (touchStep * i)] & 0x0f;
|
auto yHigh = touchData[touchYHighIndex] & 0x0f;
|
||||||
auto yLow = touchData[touchYLowIndex + (touchStep * i)];
|
auto yLow = touchData[touchYLowIndex];
|
||||||
uint16_t y = (yHigh << 8) | yLow;
|
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.x = x;
|
||||||
info.y = y;
|
info.y = y;
|
||||||
info.action = action;
|
info.action = action;
|
||||||
|
info.touching = (nbTouchPoints > 0);
|
||||||
info.gesture = static_cast<Gestures>(touchData[gestureIndex]);
|
info.gesture = static_cast<Gestures>(touchData[gestureIndex]);
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
|
|
|
@ -20,11 +20,9 @@ namespace Pinetime {
|
||||||
uint16_t x = 0;
|
uint16_t x = 0;
|
||||||
uint16_t y = 0;
|
uint16_t y = 0;
|
||||||
uint8_t action = 0;
|
uint8_t action = 0;
|
||||||
uint8_t finger = 0;
|
bool touching = false;
|
||||||
uint8_t pressure = 0;
|
|
||||||
uint8_t area = 0;
|
|
||||||
Gestures gesture = Gestures::None;
|
Gestures gesture = Gestures::None;
|
||||||
bool isTouch = false;
|
bool isValid = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
Cst816S(TwiMaster& twiMaster, uint8_t twiAddress);
|
Cst816S(TwiMaster& twiMaster, uint8_t twiAddress);
|
||||||
|
@ -38,25 +36,39 @@ namespace Pinetime {
|
||||||
void Sleep();
|
void Sleep();
|
||||||
void Wakeup();
|
void Wakeup();
|
||||||
|
|
||||||
|
uint8_t GetChipId() const {
|
||||||
|
return chipId;
|
||||||
|
}
|
||||||
|
uint8_t GetVendorId() const {
|
||||||
|
return vendorId;
|
||||||
|
}
|
||||||
|
uint8_t GetFwVersion() const {
|
||||||
|
return fwVersion;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
static constexpr uint8_t pinIrq = 28;
|
static constexpr uint8_t pinIrq = 28;
|
||||||
static constexpr uint8_t pinReset = 10;
|
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 touchPointNumIndex = 2;
|
||||||
static constexpr uint8_t touchMiscIndex = 8;
|
|
||||||
static constexpr uint8_t touchXYIndex = 7;
|
|
||||||
static constexpr uint8_t touchEventIndex = 3;
|
static constexpr uint8_t touchEventIndex = 3;
|
||||||
static constexpr uint8_t touchXHighIndex = 3;
|
static constexpr uint8_t touchXHighIndex = 3;
|
||||||
static constexpr uint8_t touchXLowIndex = 4;
|
static constexpr uint8_t touchXLowIndex = 4;
|
||||||
|
//static constexpr uint8_t touchIdIndex = 5;
|
||||||
static constexpr uint8_t touchYHighIndex = 5;
|
static constexpr uint8_t touchYHighIndex = 5;
|
||||||
static constexpr uint8_t touchYLowIndex = 6;
|
static constexpr uint8_t touchYLowIndex = 6;
|
||||||
static constexpr uint8_t touchIdIndex = 5;
|
//static constexpr uint8_t touchStep = 6;
|
||||||
static constexpr uint8_t touchStep = 6;
|
//static constexpr uint8_t touchXYIndex = 7;
|
||||||
static constexpr uint8_t gestureIndex = 1;
|
//static constexpr uint8_t touchMiscIndex = 8;
|
||||||
|
|
||||||
uint8_t touchData[10];
|
uint8_t touchData[7];
|
||||||
TwiMaster& twiMaster;
|
TwiMaster& twiMaster;
|
||||||
uint8_t twiAddress;
|
uint8_t twiAddress;
|
||||||
|
|
||||||
|
uint8_t chipId;
|
||||||
|
uint8_t vendorId;
|
||||||
|
uint8_t fwVersion;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,7 +231,7 @@ void SystemTask::Work() {
|
||||||
twiMaster.Wakeup();
|
twiMaster.Wakeup();
|
||||||
auto touchInfo = touchPanel.GetTouchInfo();
|
auto touchInfo = touchPanel.GetTouchInfo();
|
||||||
twiMaster.Sleep();
|
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.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::DoubleTap) or
|
settingsController.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::DoubleTap) or
|
||||||
(touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and
|
(touchInfo.gesture == Pinetime::Drivers::Cst816S::Gestures::SingleTap and
|
||||||
settingsController.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::SingleTap))) {
|
settingsController.getWakeUpMode() == Pinetime::Controllers::Settings::WakeUpMode::SingleTap))) {
|
||||||
|
|
Loading…
Reference in a new issue