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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user