feat(X12S): Add support for touch screen mod (#1779)

Adds support of RadioMaster TX16S touch screen on FrSky X12S radio.
This commit is contained in:
Wilhelm
2022-04-23 12:22:47 +02:00
committed by GitHub
parent 25254cc4be
commit 7a6d6239b5
4 changed files with 48 additions and 43 deletions
+1
View File
@@ -126,6 +126,7 @@ if (PCB STREQUAL X10)
add_definitions(-DMANUFACTURER_FRSKY)
endif()
elseif (PCB STREQUAL X12S)
set(HARDWARE_TOUCH YES)
set(DEFAULT_INTERNAL_MODULE XJT_PXX1 CACHE STRING "Default internal module")
set(FLAVOUR x12s)
set(BLUETOOTH ON)
+4 -1
View File
@@ -699,8 +699,11 @@
#define TOUCH_RST_RCC_AHB1Periph RCC_AHB1Periph_GPIOF
#define TOUCH_RST_GPIO GPIOF
#if defined(PCBX12S)
#define TOUCH_RST_GPIO_PIN GPIO_Pin_7 // PF.7
#else
#define TOUCH_RST_GPIO_PIN GPIO_Pin_10 // PF.10
#endif
#define TOUCH_INT_EXTI_LINE1 EXTI_Line2
#define TOUCH_INT_EXTI_IRQn1 EXTI2_IRQn
#define TOUCH_INT_EXTI_IRQHandler1 EXTI2_IRQHandler
+29 -22
View File
@@ -25,10 +25,10 @@
#if defined (RADIO_T18)
const uint8_t TOUCH_GT911_Cfg[] = {
GT911_CFG_NUMER, // 0x8047 Config version
GT911_CFG_NUMBER, // 0x8047 Config version
0xE0, // 0x8048 X output map : x 480
0x01,
0x10, // 0x804A Y ouptut max : y 272
0x10, // 0x804A Y ouptut max : y 272
0x01,
GT911_MAX_TP, // 0x804C Touch number
0x0C, // 0x804D Module switch 1 : bit4= xy change Int mode
@@ -216,7 +216,7 @@ const uint8_t TOUCH_GT911_Cfg[] = {
//GT911 param table
const uint8_t TOUCH_GT911_Cfg[] =
{
GT911_CFG_NUMER, // 0x8047 Config version
GT911_CFG_NUMBER, // 0x8047 Config version
0xE0, // 0x8048 X output map : x 480
0x01,
0x10, // 0x804A Y ouptut max : y 272
@@ -409,12 +409,13 @@ volatile static bool touchEventOccured = false;
struct TouchData touchData;
uint16_t touchGT911fwver = 0;
uint32_t touchGT911hiccups = 0;
tmr10ms_t downTime = 0;
tmr10ms_t tapTime = 0;
short tapCount = 0;
static tmr10ms_t downTime = 0;
static tmr10ms_t tapTime = 0;
static short tapCount = 0;
#define TAP_TIME 25
I2C_HandleTypeDef hi2c1;
static I2C_HandleTypeDef hi2c1;
static TouchState internalTouchState = {};
@@ -564,7 +565,7 @@ bool I2C_GT911_ReadRegister(uint16_t reg, uint8_t * buf, uint8_t len)
return true;
}
bool I2C_GT911_SendConfig(void)
bool I2C_GT911_SendConfig()
{
uint8_t buf[2];
uint8_t i = 0;
@@ -572,17 +573,18 @@ bool I2C_GT911_SendConfig(void)
buf[1] = 1;
bool bResult = true;
for (i = 0; i < sizeof(TOUCH_GT911_Cfg); i++)
buf[0] += TOUCH_GT911_Cfg[i];//check sum
for (i = 0; i < sizeof(TOUCH_GT911_Cfg); i++) {
buf[0] += TOUCH_GT911_Cfg[i]; //check sum
}
buf[0] = (~buf[0]) + 1;
if (!I2C_GT911_WriteRegister(GT_CFGS_REG, (uint8_t *) TOUCH_GT911_Cfg, sizeof(TOUCH_GT911_Cfg)))
if (!I2C_GT911_WriteRegister(GT911_CONFIG_REG, (uint8_t *) TOUCH_GT911_Cfg, sizeof(TOUCH_GT911_Cfg)))
{
TRACE("GT911 ERROR: write config failed");
bResult = false;
}
if (!I2C_GT911_WriteRegister(GT_CHECK_REG, buf, 2)) //write checksum
if (!I2C_GT911_WriteRegister(GT911_CONFIG_CHECKSUM_REG, buf, 2)) //write checksum and config_fresh
{
TRACE("GT911 ERROR: write config checksum failed");
bResult = false;
@@ -625,7 +627,7 @@ bool touchPanelInit(void)
delay_ms(50);
TRACE("Reading Touch registry");
if (!I2C_GT911_ReadRegister(GT_PID_REG, tmp, 4))
if (!I2C_GT911_ReadRegister(GT911_PRODUCT_ID_REG, tmp, 4))
{
TRACE("GT911 ERROR: Product ID read failed");
}
@@ -634,19 +636,19 @@ bool touchPanelInit(void)
{
TRACE("GT911 chip detected");
tmp[0] = 0X02;
if (!I2C_GT911_WriteRegister(GT_CTRL_REG, tmp, 1))
if (!I2C_GT911_WriteRegister(GT911_COMMAND_REG, tmp, 1))
{
TRACE("GT911 ERROR: write to control register failed");
TRACE("GT911 ERROR: write to command register failed");
}
if (!I2C_GT911_ReadRegister(GT_CFGS_REG, tmp, 1))
if (!I2C_GT911_ReadRegister(GT911_CONFIG_REG, tmp, 1))
{
TRACE("GT911 ERROR: configuration register read failed");
}
TRACE("Chip config Ver:%x", tmp[0]);
if (tmp[0] < GT911_CFG_NUMER) //Config ver
if (tmp[0] < GT911_CFG_NUMBER) //Config ver
{
TRACE("Sending new config %d", GT911_CFG_NUMER);
TRACE("Sending new config %d", GT911_CFG_NUMBER);
if (!I2C_GT911_SendConfig())
{
TRACE("GT911 ERROR: sending configration failed");
@@ -665,15 +667,14 @@ bool touchPanelInit(void)
delay_ms(10);
tmp[0] = 0X00;
if (!I2C_GT911_WriteRegister(GT_CTRL_REG, tmp, 1)) //end reset
if (!I2C_GT911_WriteRegister(GT911_COMMAND_REG, tmp, 1)) //end reset
{
TRACE("GT911 ERROR: write to control register failed");
TRACE("GT911 ERROR: write to command register failed");
}
touchGT911Flag = true;
TOUCH_AF_ExtiConfig();
return true;
}
TRACE("GT911 chip NOT FOUND");
@@ -763,6 +764,12 @@ struct TouchState touchPanelRead()
TRACE("I2C B1 ReInit failed");
return internalTouchState;
}
#if defined (PCBX12S)
touchData.points[0].x = LCD_W - touchData.points[0].x;
touchData.points[0].y = LCD_H - touchData.points[0].y;
#endif
if (internalTouchState.event == TE_NONE || internalTouchState.event == TE_UP ||
internalTouchState.event == TE_SLIDE_END) {
internalTouchState.event = TE_DOWN;
+14 -20
View File
@@ -37,36 +37,30 @@ struct TouchState getInternalTouchState();
#define GT911_TIMEOUT 3 // 3ms
#define GT911_MAX_TP 5
#define GT911_CFG_NUMER 0x6D
#define GT911_CFG_NUMBER 0x6D
//I2C
#define GT911_I2C_ADDR 0x14
//#define GT_CMD_WR 0x28
//#define GT_CMD_RD 0x29
//#define I2C_TIMEOUT_MAX 1000
//GT911
#define GT_CTRL_REG 0x8040
#define GT_CFGS_REG 0x8047
#define GT_CHECK_REG 0x80FF
#define GT_PID_REG 0x8140
#define GT_GSTID_REG 0x814E
#define GT_TP1_REG 0x8150
#define GT_TP2_REG 0x8158
#define GT_TP3_REG 0x8160
#define GT_TP4_REG 0x8168
#define GT_TP5_REG 0x8170
#define GT911_READ_XY_REG 0x814E
#define GT911_CLEARBUF_REG 0x814E
#define GT911_CONFIG_REG 0x8047
#define GT911_COMMAND_REG 0x8040
#define GT911_PRODUCT_ID_REG 0x8140
#define GT911_VENDOR_ID_REG 0x814A
#define GT911_CONFIG_VERSION_REG 0x8047
#define GT911_CONFIG_REG 0x8047
#define GT911_COORDINATE_REG 0x804D
#define GT911_CONFIG_CHECKSUM_REG 0x80FF
#define GT911_PRODUCT_ID_REG 0x8140
#define GT911_FIRMWARE_VERSION_REG 0x8144
#define GT911_VENDOR_ID_REG 0x814A
#define GT911_READ_XY_REG 0x814E
#define GT911_TP1_REG 0x8150
#define GT911_TP2_REG 0x8158
#define GT911_TP3_REG 0x8160
#define GT911_TP4_REG 0x8168
#define GT911_TP5_REG 0x8170
PACK(typedef struct {
uint8_t track;