Skip to content

Commit

Permalink
feat(GT911): Add CLI command to reset touch panel cfg (#2351)
Browse files Browse the repository at this point in the history
* GT911: add CLI command to reset config

Related to #2063

* X12S: touch coordinate inversion in GT911 config

Note: config reset with CLI "reset_gt911" required.

* Remove touch sensor software inversion
  • Loading branch information
raphaelcoeffic authored Sep 25, 2022
1 parent 3969b2b commit 78e9931
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 15 deletions.
37 changes: 37 additions & 0 deletions radio/src/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,40 @@ int cliCrypt(const char ** argv)
}
#endif

#if defined(HARDWARE_TOUCH) && !defined(PCBNV14)

// from tp_gt911.cpp
extern uint8_t tp_gt911_cfgVer;

int cliResetGT911(const char** argv)
{
(void)argv;

if (!touchGT911Flag) {
cliSerialPrint("GT911 not detected: exit\n");
return 0;
}

// stop pulses & suspend RTOS scheduler
watchdogSuspend(200/*2s*/);
stopPulses();
vTaskSuspendAll();

// reset touch controller
touchPanelDeInit();
cliSerialPrintf("GT911: old config version is %u\n", tp_gt911_cfgVer);
tp_gt911_cfgVer = 0;
touchPanelInit();
cliSerialPrintf("GT911: new config version is %u\n", tp_gt911_cfgVer);

// restart pulses & RTOS scheduler
startPulses();
xTaskResumeAll();

return 0;
}
#endif

const CliCommand cliCommands[] = {
{ "beep", cliBeep, "[<frequency>] [<duration>]" },
{ "ls", cliLs, "<directory>" },
Expand Down Expand Up @@ -1608,6 +1642,9 @@ const CliCommand cliCommands[] = {
#endif
#if defined(ACCESS_DENIED) && defined(DEBUG_CRYPT)
{ "crypt", cliCrypt, "<string to be encrypted>" },
#endif
#if defined(HARDWARE_TOUCH) && !defined(PCBNV14)
{ "reset_gt911", cliResetGT911, ""},
#endif
{ nullptr, nullptr, nullptr } /* sentinel */
};
Expand Down
5 changes: 0 additions & 5 deletions radio/src/gui/colorlcd/LvglWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,6 @@ extern "C" void touchDriverRead(lv_indev_drv_t *drv, lv_indev_data_t *data)

TouchState st = touchPanelRead();

#if defined(TOUCH_PANEL_INVERTED) && !defined(SIMU)
st.x = LCD_W - st.x;
st.y = LCD_H - st.y;
#endif

// no touch input if backlight is disabled
if (!isBacklightEnabled()) {
reset_inactivity();
Expand Down
34 changes: 24 additions & 10 deletions radio/src/targets/horus/tp_gt911.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,11 @@ const uint8_t TOUCH_GT911_Cfg[] =
0x10, // 0x804A Y ouptut max : y 272
0x01,
GT911_MAX_TP, // 0x804C Touch number
#if defined(TOUCH_PANEL_INVERTED)
0x3C | 0xC0, // 0x804D Module switch 1 : 180° rotation
#else
0x3C, // 0x804D Module switch 1 : bit4= xy change Int mode
#endif
0x20, // 0x804E Module switch 2
0x22, // 0x804F Shake_Count
0x0A, // 0x8050 Filter
Expand Down Expand Up @@ -562,21 +566,24 @@ bool I2C_GT911_ReadRegister(uint16_t reg, uint8_t *buf, uint8_t len)
return true;
}

bool I2C_GT911_SendConfig()
bool I2C_GT911_SendConfig(uint8_t cfgVer)
{
uint8_t buf[2];
uint8_t i = 0;
buf[0] = 0;
buf[1] = 1;
uint8_t buf[2] = { cfgVer, 1 };
bool bResult = true;

for (i = 0; i < sizeof(TOUCH_GT911_Cfg); i++) {
for (uint8_t i = 1; i < sizeof(TOUCH_GT911_Cfg); i++) {
buf[0] += TOUCH_GT911_Cfg[i]; //check sum
}

buf[0] = (~buf[0]) + 1;
if (!I2C_GT911_WriteRegister(GT911_CONFIG_REG, (uint8_t *)TOUCH_GT911_Cfg,
sizeof(TOUCH_GT911_Cfg))) {

if (!I2C_GT911_WriteRegister(GT911_CONFIG_REG, (uint8_t *)&cfgVer, 1)) {
TRACE("GT911 ERROR: write config failed");
bResult = false;
}

if (!I2C_GT911_WriteRegister(GT911_CONFIG_REG+1, (uint8_t *)&TOUCH_GT911_Cfg[1],
sizeof(TOUCH_GT911_Cfg)-1)) {
TRACE("GT911 ERROR: write config failed");
bResult = false;
}
Expand All @@ -586,6 +593,7 @@ bool I2C_GT911_SendConfig()
TRACE("GT911 ERROR: write config checksum failed");
bResult = false;
}

return bResult;
}

Expand All @@ -595,6 +603,8 @@ void touchPanelDeInit(void)
touchGT911Flag = false;
}

uint8_t tp_gt911_cfgVer = GT911_CFG_NUMBER;

bool touchPanelInit(void)
{
uint8_t tmp[4] = {0};
Expand Down Expand Up @@ -638,11 +648,15 @@ bool touchPanelInit(void)
}

TRACE("Chip config Ver:%x", tmp[0]);
if (tmp[0] < GT911_CFG_NUMBER) { // Config ver
if ((tp_gt911_cfgVer == 0) || (tmp[0] < tp_gt911_cfgVer)) { // Config ver
TRACE("Sending new config %d", GT911_CFG_NUMBER);
if (!I2C_GT911_SendConfig()) {
if (!I2C_GT911_SendConfig(tp_gt911_cfgVer)) {
TRACE("GT911 ERROR: sending configration failed");
}
if (!I2C_GT911_ReadRegister(GT911_CONFIG_REG, tmp, 1)) {
TRACE("GT911 ERROR: configuration register read failed");
}
tp_gt911_cfgVer = tmp[0];
}

if (!I2C_GT911_ReadRegister(GT911_FIRMWARE_VERSION_REG, tmp, 2)) {
Expand Down
2 changes: 2 additions & 0 deletions radio/src/targets/horus/tp_gt911.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
extern bool touchGT911Flag;
extern uint16_t touchGT911fwver;
extern uint32_t touchGT911hiccups;

extern void touchPanelDeInit();
extern bool touchPanelInit();

struct TouchState touchPanelRead();
Expand Down

0 comments on commit 78e9931

Please sign in to comment.