Skip to content

Commit

Permalink
Added GT911 Home Button function
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Jun 4, 2024
1 parent 6635f0f commit b474b4b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/REG/GT911Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,11 @@
#define GT911_POINT_2 (0X8157)
#define GT911_POINT_3 (0X815F)
#define GT911_POINT_4 (0X8167)
#define GT911_POINT_5 (0X816F)
#define GT911_POINT_5 (0X816F)


#define GT911_GET_POINT(x) (x & 0x0F)
#define GT911_GET_BUFFER_STATUS(x) (x & 0x80)
#define GT911_GET_HAVE_KEY(x) (x & 0x10)


28 changes: 23 additions & 5 deletions src/TouchDrvGT911.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ class TouchDrvGT911 :
writeCommand(0x05);

/*
* Depending on the chip and platform, setting it to input after removing sleep will affect power consumption.
* Depending on the chip and platform, setting it to input after removing sleep will affect power consumption.
* The chip platform determines whether
*
*
* * */
// if (__irq != SENSOR_PIN_NONE) {
// this->setGpioLevel(__irq, INPUT);
Expand Down Expand Up @@ -184,7 +184,19 @@ class TouchDrvGT911 :
if (!x_array || !y_array || size == 0)
return 0;

touchPoint = getPoint();
uint8_t val = readGT911(GT911_POINT_INFO);

bool haveKey = GT911_GET_HAVE_KEY(val);
// bool bufferStatus = GT911_GET_BUFFER_STATUS(val);
// log_i("REG:0x%X S:0X%d K:%d\n", val,bufferStatus,haveKey);

if (__homeButtonCb && haveKey) {
__homeButtonCb(__userData);
}

clearBuffer();

touchPoint = GT911_GET_POINT(val);
if (touchPoint == 0) {
return 0;
}
Expand Down Expand Up @@ -261,9 +273,9 @@ class TouchDrvGT911 :
uint8_t getPoint()
{
// GT911_POINT_INFO 0X814E
uint8_t val = readGT911(GT911_POINT_INFO) & 0x0F;
uint8_t val = readGT911(GT911_POINT_INFO);
clearBuffer();
return val & 0x0F;
return GT911_GET_POINT(val);
}


Expand Down Expand Up @@ -323,6 +335,12 @@ class TouchDrvGT911 :
SensorCommon::setGpioReadCallback(read_cb);
}

void setHomeButtonCallback(home_button_callback_t cb, void *user_data)
{
__homeButtonCb = cb;
__userData = user_data;
}

private:

uint8_t readGT911(uint16_t cmd)
Expand Down

0 comments on commit b474b4b

Please sign in to comment.