|
|
@ -32,6 +32,18 @@ bool Cst816S::Init() {
|
|
|
|
twiMaster.Read(twiAddress, 0xa7, &dummy, 1);
|
|
|
|
twiMaster.Read(twiAddress, 0xa7, &dummy, 1);
|
|
|
|
vTaskDelay(5);
|
|
|
|
vTaskDelay(5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static constexpr uint8_t maxRetries = 3;
|
|
|
|
|
|
|
|
bool isDeviceOk;
|
|
|
|
|
|
|
|
uint8_t retries = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
isDeviceOk = CheckDeviceIds();
|
|
|
|
|
|
|
|
retries++;
|
|
|
|
|
|
|
|
} while (!isDeviceOk && retries < maxRetries);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isDeviceOk) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
[2] EnConLR - Continuous operation can slide around
|
|
|
|
[2] EnConLR - Continuous operation can slide around
|
|
|
|
[1] EnConUD - Slide up and down to enable continuous operation
|
|
|
|
[1] EnConUD - Slide up and down to enable continuous operation
|
|
|
@ -50,21 +62,7 @@ bool Cst816S::Init() {
|
|
|
|
static constexpr uint8_t irqCtl = 0b01110000;
|
|
|
|
static constexpr uint8_t irqCtl = 0b01110000;
|
|
|
|
twiMaster.Write(twiAddress, 0xFA, &irqCtl, 1);
|
|
|
|
twiMaster.Write(twiAddress, 0xFA, &irqCtl, 1);
|
|
|
|
|
|
|
|
|
|
|
|
// There's mixed information about which register contains which information
|
|
|
|
return true;
|
|
|
|
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 Cst816S::GetTouchInfo() {
|
|
|
@ -79,18 +77,33 @@ Cst816S::TouchInfos Cst816S::GetTouchInfo() {
|
|
|
|
|
|
|
|
|
|
|
|
// This can only be 0 or 1
|
|
|
|
// This can only be 0 or 1
|
|
|
|
uint8_t nbTouchPoints = touchData[touchPointNumIndex] & 0x0f;
|
|
|
|
uint8_t nbTouchPoints = touchData[touchPointNumIndex] & 0x0f;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t xHigh = touchData[touchXHighIndex] & 0x0f;
|
|
|
|
uint8_t xHigh = touchData[touchXHighIndex] & 0x0f;
|
|
|
|
uint8_t xLow = touchData[touchXLowIndex];
|
|
|
|
uint8_t xLow = touchData[touchXLowIndex];
|
|
|
|
info.x = (xHigh << 8) | xLow;
|
|
|
|
uint16_t x = (xHigh << 8) | xLow;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t yHigh = touchData[touchYHighIndex] & 0x0f;
|
|
|
|
uint8_t yHigh = touchData[touchYHighIndex] & 0x0f;
|
|
|
|
uint8_t yLow = touchData[touchYLowIndex];
|
|
|
|
uint8_t yLow = touchData[touchYLowIndex];
|
|
|
|
info.y = (yHigh << 8) | yLow;
|
|
|
|
uint16_t y = (yHigh << 8) | yLow;
|
|
|
|
|
|
|
|
Gestures gesture = static_cast<Gestures>(touchData[gestureIndex]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Validity check
|
|
|
|
|
|
|
|
if(x >= maxX || y >= maxY ||
|
|
|
|
|
|
|
|
(gesture != Gestures::None &&
|
|
|
|
|
|
|
|
gesture != Gestures::SlideDown &&
|
|
|
|
|
|
|
|
gesture != Gestures::SlideUp &&
|
|
|
|
|
|
|
|
gesture != Gestures::SlideLeft &&
|
|
|
|
|
|
|
|
gesture != Gestures::SlideRight &&
|
|
|
|
|
|
|
|
gesture != Gestures::SingleTap &&
|
|
|
|
|
|
|
|
gesture != Gestures::DoubleTap &&
|
|
|
|
|
|
|
|
gesture != Gestures::LongPress)) {
|
|
|
|
|
|
|
|
info.isValid = false;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
info.x = x;
|
|
|
|
|
|
|
|
info.y = y;
|
|
|
|
info.touching = (nbTouchPoints > 0);
|
|
|
|
info.touching = (nbTouchPoints > 0);
|
|
|
|
info.gesture = static_cast<Gestures>(touchData[gestureIndex]);
|
|
|
|
info.gesture = gesture;
|
|
|
|
|
|
|
|
info.isValid = true;
|
|
|
|
return info;
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -108,3 +121,21 @@ void Cst816S::Wakeup() {
|
|
|
|
Init();
|
|
|
|
Init();
|
|
|
|
NRF_LOG_INFO("[TOUCHPANEL] Wakeup");
|
|
|
|
NRF_LOG_INFO("[TOUCHPANEL] Wakeup");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Cst816S::CheckDeviceIds() {
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
}
|
|
|
|