summaryrefslogtreecommitdiff
path: root/src/drivers/Cst816s.cpp
diff options
context:
space:
mode:
authorJF <jf@codingfield.com>2021-09-02 18:35:56 (GMT)
committerGitea <gitea@fake.local>2021-09-02 18:35:56 (GMT)
commit6c3d6fb2575888e582e7ef3004a0bc3bf6c588b6 (patch)
treeac396c060b423dd98fd915e742c14fc457a6f6d9 /src/drivers/Cst816s.cpp
parentdb6a701644116932f11c54ee0f619464de9faeb7 (diff)
parent6f9f0e8b0e42a5526d47ca664534fb6b0ccb6ace (diff)
Merge branch 'develop' of JF/PineTime into master
Diffstat (limited to 'src/drivers/Cst816s.cpp')
-rw-r--r--src/drivers/Cst816s.cpp38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp
index fd9792b..b8f8e45 100644
--- a/src/drivers/Cst816s.cpp
+++ b/src/drivers/Cst816s.cpp
@@ -40,38 +40,40 @@ void Cst816S::Init() {
*/
static constexpr uint8_t motionMask = 0b00000101;
twiMaster.Write(twiAddress, 0xEC, &motionMask, 1);
+
+ /*
+ [7] EnTest - Interrupt pin to test, enable automatic periodic issued after a low pulse.
+ [6] EnTouch - When a touch is detected, a periodic pulsed Low.
+ [5] EnChange - Upon detecting a touch state changes, pulsed Low.
+ [4] EnMotion - When the detected gesture is pulsed Low.
+ [0] OnceWLP - Press gesture only issue a pulse signal is low.
+ */
+ static constexpr uint8_t irqCtl = 0b01110000;
+ twiMaster.Write(twiAddress, 0xFA, &irqCtl, 1);
}
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;
+ auto nbTouchPoints = touchData[2] & 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*/
-
info.x = x;
info.y = y;
- info.action = action;
+ info.touching = (nbTouchPoints > 0);
info.gesture = static_cast<Gestures>(touchData[gestureIndex]);
return info;
@@ -90,4 +92,4 @@ void Cst816S::Sleep() {
void Cst816S::Wakeup() {
Init();
NRF_LOG_INFO("[TOUCHPANEL] Wakeup");
-} \ No newline at end of file
+}