Automatic error detection

This commit is contained in:
Riku Isokoski
2021-08-18 15:23:30 +03:00
parent 9c175e2f0c
commit 780a811f05
10 changed files with 121 additions and 9 deletions

View File

@@ -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);
@@ -44,13 +44,18 @@ void Cst816S::Init() {
// 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() {

View File

@@ -31,7 +31,7 @@ namespace Pinetime {
Cst816S(Cst816S&&) = delete;
Cst816S& operator=(Cst816S&&) = delete;
void Init();
bool Init();
TouchInfos GetTouchInfo();
void Sleep();
void Wakeup();