diff --git a/radio/src/cli.cpp b/radio/src/cli.cpp index f9e49e29347..c2bc5ce0a18 100644 --- a/radio/src/cli.cpp +++ b/radio/src/cli.cpp @@ -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, "[] []" }, { "ls", cliLs, "" }, @@ -1608,6 +1642,9 @@ const CliCommand cliCommands[] = { #endif #if defined(ACCESS_DENIED) && defined(DEBUG_CRYPT) { "crypt", cliCrypt, "" }, +#endif +#if defined(HARDWARE_TOUCH) && !defined(PCBNV14) + { "reset_gt911", cliResetGT911, ""}, #endif { nullptr, nullptr, nullptr } /* sentinel */ }; diff --git a/radio/src/gui/colorlcd/LvglWrapper.cpp b/radio/src/gui/colorlcd/LvglWrapper.cpp index b07e8e3af0b..053c894d7c5 100644 --- a/radio/src/gui/colorlcd/LvglWrapper.cpp +++ b/radio/src/gui/colorlcd/LvglWrapper.cpp @@ -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(); diff --git a/radio/src/targets/horus/tp_gt911.cpp b/radio/src/targets/horus/tp_gt911.cpp index 51de5244c83..abe0d84d4df 100644 --- a/radio/src/targets/horus/tp_gt911.cpp +++ b/radio/src/targets/horus/tp_gt911.cpp @@ -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 @@ -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; } @@ -586,6 +593,7 @@ bool I2C_GT911_SendConfig() TRACE("GT911 ERROR: write config checksum failed"); bResult = false; } + return bResult; } @@ -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}; @@ -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)) { diff --git a/radio/src/targets/horus/tp_gt911.h b/radio/src/targets/horus/tp_gt911.h index 0b8f31e5d73..2e7f2c81836 100644 --- a/radio/src/targets/horus/tp_gt911.h +++ b/radio/src/targets/horus/tp_gt911.h @@ -29,6 +29,8 @@ extern bool touchGT911Flag; extern uint16_t touchGT911fwver; extern uint32_t touchGT911hiccups; + +extern void touchPanelDeInit(); extern bool touchPanelInit(); struct TouchState touchPanelRead();