Skip to content

Commit

Permalink
GT911: add CLI command to reset config
Browse files Browse the repository at this point in the history
Related to #2063
  • Loading branch information
raphaelcoeffic committed Sep 24, 2022
1 parent e8f9f64 commit 1721fd4
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 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(NV14)

// 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(NV14)
{ "reset_gt911", cliResetGT911, ""},
#endif
{ nullptr, nullptr, nullptr } /* sentinel */
};
Expand Down
30 changes: 20 additions & 10 deletions radio/src/targets/horus/tp_gt911.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,21 +562,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 +589,7 @@ bool I2C_GT911_SendConfig()
TRACE("GT911 ERROR: write config checksum failed");
bResult = false;
}

return bResult;
}

Expand All @@ -595,6 +599,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 +644,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 1721fd4

Please sign in to comment.