[color] fix attempt for GT911 touch sensor driver
This fix contains 2 modifications: - poll GT911_READ_XY_REG for 20ms in case not yet ready - write 0 to GT911_READ_XY_REG in all cases These fixes are largely inspired from the Linux GT9xx driver (see https://gitlab.com/AdyaAdya/goodix-touchscreen-linux-driver/-/blob/master/goodix.c)
This commit is contained in:
committed by
Raphael Coeffic
parent
d878efb376
commit
4667b29698
@@ -711,40 +711,56 @@ void touchPanelRead()
|
||||
if (!touchEventOccured)
|
||||
return;
|
||||
|
||||
touchEventOccured = false;
|
||||
I2C_GT911_ReadRegister(GT911_READ_XY_REG, &state, 1);
|
||||
touchEventOccured = 0;
|
||||
|
||||
uint32_t startReadStatus = RTOS_GET_MS();
|
||||
do {
|
||||
if (!I2C_GT911_ReadRegister(GT911_READ_XY_REG, &state, 1)) {
|
||||
TRACE("GT911 I2C read error");
|
||||
return;
|
||||
}
|
||||
|
||||
if (state & 0x80u) {
|
||||
// ready
|
||||
break;
|
||||
}
|
||||
RTOS_WAIT_MS(1);
|
||||
} while(RTOS_GET_MS() - startReadStatus < GT911_TIMEOUT);
|
||||
|
||||
TRACE("touch state = 0x%x", state);
|
||||
if ((state & 0x80u) == 0x00) {
|
||||
// not ready
|
||||
return;
|
||||
}
|
||||
if (state & 0x80u) {
|
||||
uint8_t pointsCount = (state & 0x0Fu);
|
||||
|
||||
uint8_t pointsCount = (state & 0x0Fu);
|
||||
|
||||
if (pointsCount > 0 && pointsCount < GT911_MAX_TP) {
|
||||
I2C_GT911_ReadRegister(GT911_READ_XY_REG + 1, touchData.data, pointsCount * sizeof(TouchPoint));
|
||||
if (touchState.event == TE_NONE || touchState.event == TE_UP || touchState.event == TE_SLIDE_END) {
|
||||
touchState.event = TE_DOWN;
|
||||
touchState.startX = touchState.x = touchData.points[0].x;
|
||||
touchState.startY = touchState.y = touchData.points[0].y;
|
||||
}
|
||||
else {
|
||||
touchState.deltaX = touchData.points[0].x - touchState.x;
|
||||
touchState.deltaY = touchData.points[0].y - touchState.y;
|
||||
if (touchState.event == TE_SLIDE || abs(touchState.deltaX) >= SLIDE_RANGE || abs(touchState.deltaY) >= SLIDE_RANGE) {
|
||||
touchState.event = TE_SLIDE;
|
||||
touchState.x = touchData.points[0].x;
|
||||
touchState.y = touchData.points[0].y;
|
||||
if (pointsCount > 0 && pointsCount <= GT911_MAX_TP) {
|
||||
if (!I2C_GT911_ReadRegister(GT911_READ_XY_REG + 1, touchData.data,
|
||||
pointsCount * sizeof(TouchPoint))) {
|
||||
TRACE("GT911 I2C read error");
|
||||
return;
|
||||
}
|
||||
if (touchState.event == TE_NONE || touchState.event == TE_UP ||
|
||||
touchState.event == TE_SLIDE_END) {
|
||||
touchState.event = TE_DOWN;
|
||||
touchState.startX = touchState.x = touchData.points[0].x;
|
||||
touchState.startY = touchState.y = touchData.points[0].y;
|
||||
} else {
|
||||
touchState.deltaX = touchData.points[0].x - touchState.x;
|
||||
touchState.deltaY = touchData.points[0].y - touchState.y;
|
||||
if (touchState.event == TE_SLIDE ||
|
||||
abs(touchState.deltaX) >= SLIDE_RANGE ||
|
||||
abs(touchState.deltaY) >= SLIDE_RANGE) {
|
||||
touchState.event = TE_SLIDE;
|
||||
touchState.x = touchData.points[0].x;
|
||||
touchState.y = touchData.points[0].y;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (touchState.event == TE_SLIDE) {
|
||||
touchState.event = TE_SLIDE_END;
|
||||
} else if (touchState.event == TE_DOWN) {
|
||||
touchState.event = TE_UP;
|
||||
} else if (touchState.event != TE_SLIDE_END) {
|
||||
touchState.event = TE_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (touchState.event == TE_SLIDE) {
|
||||
touchState.event = TE_SLIDE_END;
|
||||
} else if (touchState.event == TE_DOWN) {
|
||||
touchState.event = TE_UP;
|
||||
} else if (touchState.event != TE_SLIDE_END){
|
||||
touchState.event = TE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,7 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _FT5X06_H_
|
||||
#define _FT5X06_H_
|
||||
#pragma once
|
||||
|
||||
#define HAS_TOUCH_PANEL() touchGT911Flag == true
|
||||
|
||||
@@ -29,6 +28,8 @@ extern bool touchPanelInit();
|
||||
void touchPanelRead();
|
||||
bool touchPanelEventOccured();
|
||||
|
||||
#define GT911_TIMEOUT 20 // 20ms
|
||||
|
||||
#define GT911_MAX_TP 5
|
||||
#define GT911_CFG_NUMER 0x6C
|
||||
|
||||
@@ -81,5 +82,3 @@ PACK(struct TouchData {
|
||||
|
||||
#define TPINT_LOW() do { TOUCH_INT_GPIO->BSRRH = TOUCH_INT_GPIO_PIN; } while(0)
|
||||
#define TPINT_HIGH() do { TOUCH_INT_GPIO->BSRRL = TOUCH_INT_GPIO_PIN; } while(0)
|
||||
|
||||
#endif // _FT5X06_H_
|
||||
Reference in New Issue
Block a user