diff options
Diffstat (limited to 'src/drivers')
-rw-r--r-- | src/drivers/Cst816s.cpp | 21 | ||||
-rw-r--r-- | src/drivers/Cst816s.h | 15 |
2 files changed, 33 insertions, 3 deletions
diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index b8f8e45d..474ec73e 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -17,7 +17,7 @@ using namespace Pinetime::Drivers; Cst816S::Cst816S(TwiMaster& twiMaster, uint8_t twiAddress) : twiMaster {twiMaster}, twiAddress {twiAddress} { } -void Cst816S::Init() { +bool Cst816S::Init() { nrf_gpio_cfg_output(pinReset); nrf_gpio_pin_set(pinReset); vTaskDelay(50); @@ -50,6 +50,22 @@ 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() { @@ -61,7 +77,8 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() { return info; } - auto nbTouchPoints = touchData[2] & 0x0f; + // This can only be 0 or 1 + auto nbTouchPoints = touchData[touchPointNumIndex] & 0x0f; auto xHigh = touchData[touchXHighIndex] & 0x0f; auto xLow = touchData[touchXLowIndex]; diff --git a/src/drivers/Cst816s.h b/src/drivers/Cst816s.h index d4c17bb8..a1c1214e 100644 --- a/src/drivers/Cst816s.h +++ b/src/drivers/Cst816s.h @@ -30,11 +30,20 @@ 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; @@ -55,6 +64,10 @@ namespace Pinetime { uint8_t touchData[7]; TwiMaster& twiMaster; uint8_t twiAddress; + + uint8_t chipId; + uint8_t vendorId; + uint8_t fwVersion; }; } |