diff --git a/radio/src/gui/480x272/menus.h b/radio/src/gui/480x272/menus.h index edae43fec..f82baeb14 100644 --- a/radio/src/gui/480x272/menus.h +++ b/radio/src/gui/480x272/menus.h @@ -185,7 +185,6 @@ bool menuModelModuleOptions(event_t event); bool menuModelReceiverOptions(event_t event); bool menuRadioDiagKeys(event_t event); bool menuRadioDiagAnalogs(event_t event); -bool menuRadioDiagTouch(event_t event); extern const MenuHandlerFunc menuTabModel[MENU_MODEL_PAGES_COUNT]; diff --git a/radio/src/gui/480x272/radio_diaganas.cpp b/radio/src/gui/480x272/radio_diaganas.cpp index 88f82d748..905987fef 100644 --- a/radio/src/gui/480x272/radio_diaganas.cpp +++ b/radio/src/gui/480x272/radio_diaganas.cpp @@ -19,6 +19,9 @@ */ #include "opentx.h" +#if defined(RADIO_TX16S) +#include "tp_gt911.h" +#endif constexpr coord_t LEFT_NAME_COLUMN = MENUS_MARGIN_LEFT; constexpr coord_t RIGHT_NAME_COLUMN = LCD_W / 2; @@ -28,6 +31,12 @@ bool menuRadioDiagAnalogs(event_t event) { SIMPLE_SUBMENU(STR_MENU_RADIO_ANALOGS, ICON_MODEL_SETUP, 0); +#if defined(HARDWARE_TOUCH) + if (event == EVT_ENTRY || event == EVT_ENTRY_UP) { + touchPanelInit(); + } +#endif + for (uint8_t i = 0; i < NUM_ANALOGS; i++) { coord_t y = MENU_HEADER_HEIGHT + 1 + (i / 2) * FH; uint8_t x = i & 1 ? LCD_W / 2 + 10 : LEFT_NAME_COLUMN; @@ -48,9 +57,24 @@ bool menuRadioDiagAnalogs(event_t event) #endif } -#if (NUM_PWMSTICKS > 0) && !defined(SIMU) +#if (NUM_PWMSTICKS > 0) || defined(SIMU) lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 8 * FH, STICKS_PWM_ENABLED() ? "Sticks: PWM" : "Sticks: ANA"); #endif +#if defined(HARDWARE_TOUCH) + if (touchGT911Flag) { + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 7 * FH, "Touch panel:"); + } + + if (touchPanelEvent) { + uint8_t tmp,mode = 0; + gt911ReadRegister(GT911_READ_XY_REG,&mode,1); //read status + lcdDrawNumber(lcdNextPos + 1, MENU_CONTENT_TOP + 7 * FH, touchState.x); + lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 7 * FH, ", "); + lcdDrawNumber(lcdNextPos + 1, MENU_CONTENT_TOP + 7 * FH, touchState.y); + gt911WriteRegister(GT911_CLEARBUF_REG, &tmp, 1); + } +#endif + return true; } diff --git a/radio/src/gui/480x272/radio_diagtouch.cpp b/radio/src/gui/480x272/radio_diagtouch.cpp deleted file mode 100644 index 3c9834265..000000000 --- a/radio/src/gui/480x272/radio_diagtouch.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) OpenTX - * - * Based on code named - * th9x - http://code.google.com/p/th9x - * er9x - http://code.google.com/p/er9x - * gruvin9x - http://code.google.com/p/gruvin9x - * - * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#include "opentx.h" -#include "tp_gt911.h" - -bool menuRadioDiagTouch(event_t event) -{ - static bool touchAvailable = false; - - SIMPLE_SUBMENU(STR_MENU_RADIO_TOUCH, ICON_MODEL_SETUP, 1); - - if (event == EVT_ENTRY || event == EVT_ENTRY_UP) { - touchAvailable = touchPanelInit(); - touchEventFlag = 0; - } - else if (menuEvent) { - //touchDeInit(); - return false; - } - - if (touchAvailable) { - lcdDrawText(LCD_W / 2, LCD_H / 2, STR_TOUCH_EXIT, CENTERED); - } - else { - lcdDrawText(LCD_W / 2, LCD_H / 2, STR_TOUCH_NOTFOUND, CENTERED); - } - - if (touchEventFlag) { - uint8_t tmp,mode = 0; - GT911_RD_Reg(GT911_READ_XY_REG,&mode,1); //read status - tmp=mode&0x0f; - if((mode&0x80) && (tmp>0)) { - touchPanelDeInit(); - popMenu(); - } - GT911_WR_Reg(GT911_CLEARBUF_REG, &tmp, 1); - } - return true; -} diff --git a/radio/src/gui/480x272/radio_hardware.cpp b/radio/src/gui/480x272/radio_hardware.cpp index f9cefdc9a..e50dcae33 100644 --- a/radio/src/gui/480x272/radio_hardware.cpp +++ b/radio/src/gui/480x272/radio_hardware.cpp @@ -131,12 +131,6 @@ void onHardwareAntennaSwitchConfirm(const char * result) #define SPORT_POWER_ROWS #endif -#if defined(HARDWARE_TOUCH) - #define DEBUG_ROW 2 -#else - #define DEBUG_ROW 1 -#endif - bool menuRadioHardware(event_t event) { MENU(STR_HARDWARE, RADIO_ICONS, menuTabGeneral, MENU_RADIO_HARDWARE, ITEM_RADIO_HARDWARE_MAX, { @@ -168,7 +162,7 @@ bool menuRadioHardware(event_t event) 0, /* ADC filter */ READONLY_ROW /* RAS */, SPORT_POWER_ROWS - DEBUG_ROW, /* Debug */ + 1, /* Debug */ }); if (menuEvent) { @@ -417,9 +411,6 @@ bool menuRadioHardware(event_t event) lcdDrawText(MENUS_MARGIN_LEFT, y, STR_DEBUG); lcdDrawText(HW_SETTINGS_COLUMN2, y, STR_ANALOGS_BTN, menuHorizontalPosition == 0 ? attr : 0); lcdDrawText(lcdNextPos + 10, y, STR_KEYS_BTN, menuHorizontalPosition == 1 ? attr : 0); -#if defined(HARDWARE_TOUCH) - lcdDrawText(lcdNextPos + 10, y, STR_TOUCH_BTN, menuHorizontalPosition == 2 ? attr : 0); -#endif if (attr && event == EVT_KEY_BREAK(KEY_ENTER)) { switch (menuHorizontalPosition) { case 0: @@ -428,11 +419,6 @@ bool menuRadioHardware(event_t event) case 1: pushMenu(menuRadioDiagKeys); break; -#if defined(HARDWARE_TOUCH) - case 2: - pushMenu(menuRadioDiagTouch); - break; -#endif } } break; diff --git a/radio/src/targets/horus/CMakeLists.txt b/radio/src/targets/horus/CMakeLists.txt index 910b43f5f..ba4052d48 100644 --- a/radio/src/targets/horus/CMakeLists.txt +++ b/radio/src/targets/horus/CMakeLists.txt @@ -212,7 +212,6 @@ if(HARDWARE_TOUCH) set(TARGET_SRC ${TARGET_SRC} tp_gt911.cpp ) - set(GUI_SRC ${GUI_SRC} radio_diagtouch.cpp) add_definitions(-DHARDWARE_TOUCH) endif() diff --git a/radio/src/targets/horus/tp_gt911.cpp b/radio/src/targets/horus/tp_gt911.cpp index 87e6e0ce2..d0982788a 100644 --- a/radio/src/targets/horus/tp_gt911.cpp +++ b/radio/src/targets/horus/tp_gt911.cpp @@ -21,8 +21,9 @@ #include "tp_gt911.h" uint8_t touchGT911Flag = 0; -uint8_t TOUCH_SCAN_MODE = 0; -uint8_t touchEventFlag = 0; +uint8_t touchPanelEvent = 0; +struct TouchData touchData; +struct TouchState touchState; void GT911_INT_Change(void) { @@ -46,8 +47,8 @@ uint8_t GT911_Send_Cfg(uint8_t mode) buf[0] += GT911_Cfg[i];//check sum buf[0] = (~buf[0]) + 1; - GT911_WR_Reg(GT_CFGS_REG, (uint8_t *) GT911_Cfg, sizeof(GT911_Cfg));// - GT911_WR_Reg(GT_CHECK_REG, buf, 2);//write checksum + gt911WriteRegister(GT_CFGS_REG, (uint8_t *) GT911_Cfg, sizeof(GT911_Cfg));// + gt911WriteRegister(GT_CHECK_REG, buf, 2);//write checksum return 0; } @@ -266,7 +267,7 @@ uint8_t I2C_Read_Byte(unsigned char ack) return receive; } -uint8_t GT911_WR_Reg(uint16_t reg, uint8_t * buf, uint8_t len) +uint8_t gt911WriteRegister(uint16_t reg, uint8_t * buf, uint8_t len) { { uint8_t i; @@ -290,7 +291,7 @@ uint8_t GT911_WR_Reg(uint16_t reg, uint8_t * buf, uint8_t len) } } -void GT911_RD_Reg(u16 reg, uint8_t * buf, uint8_t len) +void gt911ReadRegister(u16 reg, uint8_t * buf, uint8_t len) { uint8_t i; @@ -341,14 +342,14 @@ bool touchPanelInit(void) delay_ms(50); TRACE("Reading Touch registry"); - GT911_RD_Reg(GT_PID_REG, tmp, 4); + gt911ReadRegister(GT_PID_REG, tmp, 4); if (strcmp((char *) tmp, "911") == 0) //ID==9147 { TRACE("GT911 chip detected"); tmp[0] = 0X02; - GT911_WR_Reg(GT_CTRL_REG, tmp, 1); - GT911_RD_Reg(GT_CFGS_REG, tmp, 1); + gt911WriteRegister(GT_CTRL_REG, tmp, 1); + gt911ReadRegister(GT_CFGS_REG, tmp, 1); if (tmp[0] < 0X69)//ver { @@ -358,7 +359,7 @@ bool touchPanelInit(void) delay_ms(10); tmp[0] = 0X00; - GT911_WR_Reg(GT_CTRL_REG, tmp, 1);//end reset + gt911WriteRegister(GT_CTRL_REG, tmp, 1);//end reset touchGT911Flag = true; TOUCH_AF_ExtiConfig(); @@ -369,11 +370,57 @@ bool touchPanelInit(void) return false; } +void touchPanelRead() +{ + uint8_t state = 0; + gt911ReadRegister(GT911_READ_XY_REG, &state, 1); + + touchPanelEvent = false; + + if ((state & 0x80u) == 0x00) { + // not ready + return; + } + + uint8_t pointsCount = (state & 0x0Fu); + + if (pointsCount > 0 && pointsCount < GT911_MAX_TOUCH_POINTS) { + gt911ReadRegister(GT911_READ_XY_REG + 1, touchData.data, pointsCount * sizeof(TouchPoint)); + if (touchData.pointsCount == 0) { + touchState.event = TE_DOWN; + touchState.startX = touchState.x = touchData.points[0].x; + touchState.startY = touchState.y = touchData.points[0].y; + } + else { + touchState.deltaX = touchData.points[0].x - touchState.x; + touchState.deltaY = touchData.points[0].y - touchState.y; + if (touchState.event == TE_SLIDE || 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; + } + } + touchData.pointsCount = pointsCount; + } + else { + if (touchData.pointsCount > 0) { + touchData.pointsCount = 0; + if (touchState.event == TE_SLIDE) + touchState.event = TE_SLIDE_END; + else + touchState.event = TE_UP; + } + } + + uint8_t zero = 0; + gt911WriteRegister(GT911_READ_XY_REG, &zero, 1); +} + extern "C" void TOUCH_INT_EXTI_IRQHandler1(void) { if (EXTI_GetITStatus(TOUCH_INT_EXTI_LINE1) != RESET) { TRACE("TI"); - touchEventFlag = 1; + touchPanelEvent = 1; EXTI_ClearITPendingBit(TOUCH_INT_EXTI_LINE1); } } diff --git a/radio/src/targets/horus/tp_gt911.h b/radio/src/targets/horus/tp_gt911.h index 64dfac5d6..294de897e 100644 --- a/radio/src/targets/horus/tp_gt911.h +++ b/radio/src/targets/horus/tp_gt911.h @@ -22,6 +22,7 @@ #define _FT5X06_H_ #include "opentx.h" +#include "touch.h" #define HAS_TOUCH_PANEL() touchGT911Flag == true #define TOUCH_INT_STATUS() (GPIO_ReadInputDataBit(TOUCH_INT_GPIO, TOUCH_INT_GPIO_PIN)) @@ -31,10 +32,10 @@ void touchPanelDeInit(); extern uint8_t touchGT911Flag; extern uint8_t TOUCH_SCAN_MODE; -extern uint8_t touchEventFlag; +extern uint8_t touchPanelEvent; -uint8_t GT911_WR_Reg(uint16_t reg, uint8_t * buf, uint8_t len); -void GT911_RD_Reg(uint16_t reg, uint8_t * buf, uint8_t len); +uint8_t gt911WriteRegister(uint16_t reg, uint8_t * buf, uint8_t len); +void gt911ReadRegister(uint16_t reg, uint8_t * buf, uint8_t len); //GT911 param table @@ -97,16 +98,28 @@ const uint8_t GT911_Cfg[]= // #define GT911_CONFIG_CHECKSUM_REG 0x80FF #define GT911_FIRMWARE_VERSION_REG 0x8144 +#define GT911_MAX_TOUCH_POINTS 5 -typedef struct{ +PACK(typedef struct +{ + uint8_t track; uint16_t x; uint16_t y; -}POINT; + uint16_t size; + uint8_t reserved; +}) TouchPoint; -typedef struct{ - uint16_t cnt; - POINT points[5]; -}GT911_POINT_DATA; +PACK(struct TouchData +{ + uint8_t pointsCount; + union + { + TouchPoint points[GT911_MAX_TOUCH_POINTS]; + uint8_t data[GT911_MAX_TOUCH_POINTS * sizeof(TouchPoint)]; + }; +}); + +extern struct TouchData touchData; #define TPRST_LOW() do { TOUCH_RST_GPIO->BSRRH = TOUCH_RST_GPIO_PIN; } while(0) #define TPRST_HIGH() do { TOUCH_RST_GPIO->BSRRL = TOUCH_RST_GPIO_PIN; } while(0) diff --git a/radio/src/touch.h b/radio/src/touch.h new file mode 100644 index 000000000..fbb70e3fe --- /dev/null +++ b/radio/src/touch.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) OpenTX + * + * Based on code named + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef _TOUCH_H_ +#define _TOUCH_H_ + +enum TouchEvent +{ + TE_NONE, + TE_DOWN, + TE_UP, + TE_SLIDE, + TE_SLIDE_END +}; + +struct TouchState +{ + unsigned char event; + short x; + short y; + short startX; + short startY; + short deltaX; + short deltaY; + short lastDeltaX; + short lastDeltaY; +}; + +constexpr uint8_t SLIDE_RANGE = 6; + +extern TouchState touchState; + +#endif // _TOUCH_H_ \ No newline at end of file