diff options
| author | mark9064 <30447455+mark9064@users.noreply.github.com> | 2024-12-08 23:39:30 +0000 |
|---|---|---|
| committer | mark9064 <30447455+mark9064@users.noreply.github.com> | 2025-10-08 17:54:18 +0100 |
| commit | 0881edd2e6404a21224af2667e8becddf188cf24 (patch) | |
| tree | 47bcf2d7aacb159b41bba35808956c66600a8f0c /src | |
| parent | 957ba59ef328602a2326ecd812f77c736186b529 (diff) | |
Remove redundant touchpanel read
Diffstat (limited to 'src')
| -rw-r--r-- | src/drivers/Cst816s.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/drivers/Cst816s.cpp b/src/drivers/Cst816s.cpp index cf10c895..6abca66e 100644 --- a/src/drivers/Cst816s.cpp +++ b/src/drivers/Cst816s.cpp @@ -1,5 +1,6 @@ #include "drivers/Cst816s.h" #include <FreeRTOS.h> +#include <array> #include <legacy/nrf_drv_gpiote.h> #include <nrfx_log.h> #include <task.h> @@ -61,23 +62,25 @@ bool Cst816S::Init() { Cst816S::TouchInfos Cst816S::GetTouchInfo() { Cst816S::TouchInfos info; - uint8_t touchData[7]; + std::array<uint8_t, 6> touchData {}; - auto ret = twiMaster.Read(twiAddress, 0, touchData, sizeof(touchData)); + // Skip reading register 0 as we don't need it + constexpr uint8_t addressOffset = 1; + auto ret = twiMaster.Read(twiAddress, addressOffset, touchData.data(), sizeof(touchData)); if (ret != TwiMaster::ErrorCodes::NoError) { info.isValid = false; return info; } // This can only be 0 or 1 - uint8_t nbTouchPoints = touchData[touchPointNumIndex] & 0x0f; - uint8_t xHigh = touchData[touchXHighIndex] & 0x0f; - uint8_t xLow = touchData[touchXLowIndex]; + uint8_t nbTouchPoints = touchData[touchPointNumIndex - addressOffset] & 0x0f; + uint8_t xHigh = touchData[touchXHighIndex - addressOffset] & 0x0f; + uint8_t xLow = touchData[touchXLowIndex - addressOffset]; uint16_t x = (xHigh << 8) | xLow; - uint8_t yHigh = touchData[touchYHighIndex] & 0x0f; - uint8_t yLow = touchData[touchYLowIndex]; + uint8_t yHigh = touchData[touchYHighIndex - addressOffset] & 0x0f; + uint8_t yLow = touchData[touchYLowIndex - addressOffset]; uint16_t y = (yHigh << 8) | yLow; - Gestures gesture = static_cast<Gestures>(touchData[gestureIndex]); + Gestures gesture = static_cast<Gestures>(touchData[gestureIndex - addressOffset]); // Validity check if (x >= maxX || y >= maxY || |
