summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Cst816s.cpp49
-rw-r--r--src/drivers/Cst816s.h19
-rw-r--r--src/drivers/PinMap.h38
3 files changed, 85 insertions, 21 deletions
diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp
index b8f8e45d..49d6ed0e 100644
--- a/src/drivers/Cst816s.cpp
+++ b/src/drivers/Cst816s.cpp
@@ -3,6 +3,7 @@
#include <legacy/nrf_drv_gpiote.h>
#include <nrfx_log.h>
#include <task.h>
+#include "drivers/PinMap.h"
using namespace Pinetime::Drivers;
@@ -17,13 +18,13 @@ using namespace Pinetime::Drivers;
Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaster}, twiAddress {twiAddress} {
}
-void Cst816S::Init() {
- nrf_gpio_cfg_output(pinReset);
- nrf_gpio_pin_set(pinReset);
+bool Cst816S::Init() {
+ nrf_gpio_cfg_output(PinMap::Cst816sReset);
+ nrf_gpio_pin_set(PinMap::Cst816sReset);
vTaskDelay(50);
- nrf_gpio_pin_clear(pinReset);
+ nrf_gpio_pin_clear(PinMap::Cst816sReset);
vTaskDelay(5);
- nrf_gpio_pin_set(pinReset);
+ nrf_gpio_pin_set(PinMap::Cst816sReset);
vTaskDelay(50);
// Wake the touchpanel up
@@ -50,10 +51,27 @@ void Cst816S::Init() {
*/
static constexpr uint8_t irqCtl = 0b01110000;
twiMaster.Write(twiAddress, 0xFA, &irqCtl, 1);
+
+ // There's mixed information about which register contains which information
+ if (twiMaster.Read(twiAddress, 0xA7, &chipId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
+ chipId = 0xFF;
+ return false;
+ }
+ if (twiMaster.Read(twiAddress, 0xA8, &vendorId, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
+ vendorId = 0xFF;
+ return false;
+ }
+ if (twiMaster.Read(twiAddress, 0xA9, &fwVersion, 1) == TwiMaster::ErrorCodes::TransactionFailed) {
+ fwVersion = 0xFF;
+ return false;
+ }
+
+ return chipId == 0xb4 && vendorId == 0 && fwVersion == 1;
}
Cst816S::TouchInfos Cst816S::GetTouchInfo() {
Cst816S::TouchInfos info;
+ uint8_t touchData[7];
auto ret = twiMaster.Read(twiAddress, 0, touchData, sizeof(touchData));
if (ret != TwiMaster::ErrorCodes::NoError) {
@@ -61,18 +79,17 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() {
return info;
}
- auto nbTouchPoints = touchData[2] & 0x0f;
+ // This can only be 0 or 1
+ uint8_t nbTouchPoints = touchData[touchPointNumIndex] & 0x0f;
- auto xHigh = touchData[touchXHighIndex] & 0x0f;
- auto xLow = touchData[touchXLowIndex];
- uint16_t x = (xHigh << 8) | xLow;
+ uint8_t xHigh = touchData[touchXHighIndex] & 0x0f;
+ uint8_t xLow = touchData[touchXLowIndex];
+ info.x = (xHigh << 8) | xLow;
- auto yHigh = touchData[touchYHighIndex] & 0x0f;
- auto yLow = touchData[touchYLowIndex];
- uint16_t y = (yHigh << 8) | yLow;
+ uint8_t yHigh = touchData[touchYHighIndex] & 0x0f;
+ uint8_t yLow = touchData[touchYLowIndex];
+ info.y = (yHigh << 8) | yLow;
- info.x = x;
- info.y = y;
info.touching = (nbTouchPoints > 0);
info.gesture = static_cast<Gestures>(touchData[gestureIndex]);
@@ -80,9 +97,9 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() {
}
void Cst816S::Sleep() {
- nrf_gpio_pin_clear(pinReset);
+ nrf_gpio_pin_clear(PinMap::Cst816sReset);
vTaskDelay(5);
- nrf_gpio_pin_set(pinReset);
+ nrf_gpio_pin_set(PinMap::Cst816sReset);
vTaskDelay(50);
static constexpr uint8_t sleepValue = 0x03;
twiMaster.Write(twiAddress, 0xA5, &sleepValue, 1);
diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h
index d4c17bb8..0fec8419 100644
--- a/src/drivers/Cst816s.h
+++ b/src/drivers/Cst816s.h
@@ -30,15 +30,21 @@ namespace Pinetime {
Cst816S(Cst816S&&) = delete;
Cst816S& operator=(Cst816S&&) = delete;
- void Init();
+ bool Init();
TouchInfos GetTouchInfo();
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;
-
// Unused/Unavailable commented out
static constexpr uint8_t gestureIndex = 1;
static constexpr uint8_t touchPointNumIndex = 2;
@@ -52,9 +58,12 @@ namespace Pinetime {
//static constexpr uint8_t touchXYIndex = 7;
//static constexpr uint8_t touchMiscIndex = 8;
- uint8_t touchData[7];
TwiMaster& twiMaster;
uint8_t twiAddress;
+
+ uint8_t chipId;
+ uint8_t vendorId;
+ uint8_t fwVersion;
};
}
diff --git a/src/drivers/PinMap.h b/src/drivers/PinMap.h
new file mode 100644
index 00000000..57964020
--- /dev/null
+++ b/src/drivers/PinMap.h
@@ -0,0 +1,38 @@
+#pragma once
+
+namespace Pinetime {
+ namespace PinMap {
+
+ #ifdef WATCH_P8
+ // COLMI P8
+ static constexpr uint8_t Charging = 19;
+ static constexpr uint8_t Cst816sReset = 13;
+ static constexpr uint8_t Button = 17;
+ #else
+ // Pinetime
+ static constexpr uint8_t Charging = 12;
+ static constexpr uint8_t Cst816sReset = 10;
+ static constexpr uint8_t Button = 13;
+ #endif
+
+ static constexpr uint8_t Cst816sIrq = 28;
+ static constexpr uint8_t PowerPresent = 19;
+
+ static constexpr uint8_t Motor = 16;
+
+ static constexpr uint8_t LcdBacklightLow = 14;
+ static constexpr uint8_t LcdBacklightMedium = 22;
+ static constexpr uint8_t LcdBacklightHigh = 23;
+
+ static constexpr uint8_t SpiSck = 2;
+ static constexpr uint8_t SpiMosi = 3;
+ static constexpr uint8_t SpiMiso = 4;
+
+ static constexpr uint8_t SpiFlashCsn = 5;
+ static constexpr uint8_t SpiLcdCsn = 25;
+ static constexpr uint8_t LcdDataCommand = 18;
+
+ static constexpr uint8_t TwiScl = 7;
+ static constexpr uint8_t TwiSda = 6;
+ }
+}