[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)
|
if (!touchEventOccured)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
touchEventOccured = false;
|
touchEventOccured = 0;
|
||||||
I2C_GT911_ReadRegister(GT911_READ_XY_REG, &state, 1);
|
|
||||||
|
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);
|
TRACE("touch state = 0x%x", state);
|
||||||
if ((state & 0x80u) == 0x00) {
|
if (state & 0x80u) {
|
||||||
// not ready
|
uint8_t pointsCount = (state & 0x0Fu);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t pointsCount = (state & 0x0Fu);
|
if (pointsCount > 0 && pointsCount <= GT911_MAX_TP) {
|
||||||
|
if (!I2C_GT911_ReadRegister(GT911_READ_XY_REG + 1, touchData.data,
|
||||||
if (pointsCount > 0 && pointsCount < GT911_MAX_TP) {
|
pointsCount * sizeof(TouchPoint))) {
|
||||||
I2C_GT911_ReadRegister(GT911_READ_XY_REG + 1, touchData.data, pointsCount * sizeof(TouchPoint));
|
TRACE("GT911 I2C read error");
|
||||||
if (touchState.event == TE_NONE || touchState.event == TE_UP || touchState.event == TE_SLIDE_END) {
|
return;
|
||||||
touchState.event = TE_DOWN;
|
}
|
||||||
touchState.startX = touchState.x = touchData.points[0].x;
|
if (touchState.event == TE_NONE || touchState.event == TE_UP ||
|
||||||
touchState.startY = touchState.y = touchData.points[0].y;
|
touchState.event == TE_SLIDE_END) {
|
||||||
}
|
touchState.event = TE_DOWN;
|
||||||
else {
|
touchState.startX = touchState.x = touchData.points[0].x;
|
||||||
touchState.deltaX = touchData.points[0].x - touchState.x;
|
touchState.startY = touchState.y = touchData.points[0].y;
|
||||||
touchState.deltaY = touchData.points[0].y - touchState.y;
|
} else {
|
||||||
if (touchState.event == TE_SLIDE || abs(touchState.deltaX) >= SLIDE_RANGE || abs(touchState.deltaY) >= SLIDE_RANGE) {
|
touchState.deltaX = touchData.points[0].x - touchState.x;
|
||||||
touchState.event = TE_SLIDE;
|
touchState.deltaY = touchData.points[0].y - touchState.y;
|
||||||
touchState.x = touchData.points[0].x;
|
if (touchState.event == TE_SLIDE ||
|
||||||
touchState.y = touchData.points[0].y;
|
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.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _FT5X06_H_
|
#pragma once
|
||||||
#define _FT5X06_H_
|
|
||||||
|
|
||||||
#define HAS_TOUCH_PANEL() touchGT911Flag == true
|
#define HAS_TOUCH_PANEL() touchGT911Flag == true
|
||||||
|
|
||||||
@@ -29,6 +28,8 @@ extern bool touchPanelInit();
|
|||||||
void touchPanelRead();
|
void touchPanelRead();
|
||||||
bool touchPanelEventOccured();
|
bool touchPanelEventOccured();
|
||||||
|
|
||||||
|
#define GT911_TIMEOUT 20 // 20ms
|
||||||
|
|
||||||
#define GT911_MAX_TP 5
|
#define GT911_MAX_TP 5
|
||||||
#define GT911_CFG_NUMER 0x6C
|
#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_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)
|
#define TPINT_HIGH() do { TOUCH_INT_GPIO->BSRRL = TOUCH_INT_GPIO_PIN; } while(0)
|
||||||
|
|
||||||
#endif // _FT5X06_H_
|
|
||||||
Reference in New Issue
Block a user