summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorRiku Isokoski <riksu9000@gmail.com>2021-07-14 17:11:16 +0300
committerRiku Isokoski <riksu9000@gmail.com>2021-07-14 17:11:16 +0300
commit5bc40c9287f06d2c2bb24a5691175f1d29a17c1b (patch)
tree78f2be3a64c331426d761d83ab2f65324e9ac995 /src/drivers
parenta07b6382aef3c30d8ea8f28fcc3cc880d7afd747 (diff)
Update touchpad driver
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Cst816s.cpp39
-rw-r--r--src/drivers/Cst816s.h36
2 files changed, 47 insertions, 28 deletions
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
+}