Skip to content

Commit eae6aa1

Browse files
authored
feat(st16): support touch panel mod (#7334)
1 parent 0a65908 commit eae6aa1

2 files changed

Lines changed: 74 additions & 12 deletions

File tree

radio/src/targets/st16/hal.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,22 @@
317317
#define TOUCH_I2C_BUS I2C_Bus_1
318318
#define TOUCH_I2C_CLK_RATE 100000
319319

320+
// Touch pins: INT -> PI11, RST -> PI3
321+
#define TOUCH_INT_GPIO GPIOI
322+
#define TOUCH_INT_GPIO_PIN LL_GPIO_PIN_11
323+
#define TOUCH_RST_GPIO GPIOI
324+
#define TOUCH_RST_GPIO_PIN LL_GPIO_PIN_3
325+
326+
#define TOUCH_INT_EXTI_Line LL_EXTI_LINE_11
327+
#define TOUCH_INT_EXTI_Port LL_SYSCFG_EXTI_PORTI
328+
#define TOUCH_INT_EXTI_SysCfgLine LL_SYSCFG_EXTI_LINE11
329+
330+
// TOUCH_INT_EXTI IRQ for lines 15..10
331+
#if !defined(USE_EXTI15_10_IRQ)
332+
#define USE_EXTI15_10_IRQ
333+
#define EXTI15_10_IRQ_Priority 5
334+
#endif
335+
320336
#define IMU_I2C_BUS I2C_Bus_1
321337
#define IMU_I2C_ADDRESS 0x6A
322338

radio/src/targets/st16/touch_driver.cpp

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "stm32_gpio_driver.h"
2626
#include "stm32_exti_driver.h"
2727

28+
#include "hal/i2c_driver.h"
29+
2830
#include "hal.h"
2931
#include "timers_driver.h"
3032
#include "delays_driver.h"
@@ -109,15 +111,62 @@ static tmr10ms_t downTime = 0;
109111
static tmr10ms_t tapTime = 0;
110112
static short tapCount = 0;
111113

112-
// static void _touch_exti_isr(void)
113-
// {
114-
// touchEventOccured = true;
115-
// }
114+
static void _touch_exti_isr(void)
115+
{
116+
touchEventOccured = true;
117+
}
118+
119+
static void _touch_exti_stop(void) {
120+
stm32_exti_disable(TOUCH_INT_EXTI_Line);
121+
}
122+
123+
static void _touch_exti_config(void) {
124+
__HAL_RCC_SYSCFG_CLK_ENABLE();
125+
LL_SYSCFG_SetEXTISource(TOUCH_INT_EXTI_Port, TOUCH_INT_EXTI_SysCfgLine);
126+
127+
stm32_exti_enable(TOUCH_INT_EXTI_Line,
128+
LL_EXTI_TRIGGER_FALLING,
129+
_touch_exti_isr);
130+
}
131+
132+
static void _touch_gpio_config(void) {
133+
LL_GPIO_InitTypeDef gpioInit;
134+
LL_GPIO_StructInit(&gpioInit);
135+
136+
// Enable clocks for the GPIO ports used by touch
137+
stm32_gpio_enable_clock(TOUCH_RST_GPIO);
138+
stm32_gpio_enable_clock(TOUCH_INT_GPIO);
139+
140+
// Configure RST as output, push-pull
141+
gpioInit.Mode = LL_GPIO_MODE_OUTPUT;
142+
gpioInit.Speed = LL_GPIO_SPEED_FREQ_LOW;
143+
gpioInit.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
144+
gpioInit.Pull = LL_GPIO_PULL_NO;
145+
gpioInit.Pin = TOUCH_RST_GPIO_PIN;
146+
LL_GPIO_Init(TOUCH_RST_GPIO, &gpioInit);
147+
LL_GPIO_SetOutputPin(TOUCH_RST_GPIO, TOUCH_RST_GPIO_PIN);
148+
149+
// Configure INT as input with pull-up (10k external pull-up also present)
150+
gpioInit.Pin = TOUCH_INT_GPIO_PIN;
151+
gpioInit.Mode = LL_GPIO_MODE_INPUT;
152+
gpioInit.Pull = LL_GPIO_PULL_UP;
153+
gpioInit.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
154+
LL_GPIO_Init(TOUCH_INT_GPIO, &gpioInit);
155+
LL_GPIO_SetOutputPin(TOUCH_INT_GPIO, TOUCH_INT_GPIO_PIN);
156+
157+
// Init I2C bus used by touch (use platform i2c wrapper)
158+
if (i2c_init(TOUCH_I2C_BUS) < 0) {
159+
TRACE("Touch I2C Init ERROR: i2c_init failed");
160+
}
161+
}
162+
163+
static void _touch_reset() {
164+
LL_GPIO_ResetOutputPin(TOUCH_RST_GPIO, TOUCH_RST_GPIO_PIN);
165+
delay_ms(10);
166+
LL_GPIO_SetOutputPin(TOUCH_RST_GPIO, TOUCH_RST_GPIO_PIN);
167+
delay_ms(300);
168+
}
116169

117-
static void _touch_exti_stop(void) {}
118-
static void _touch_exti_config(void) {}
119-
static void _touch_gpio_config(void) {}
120-
static void _touch_reset() {}
121170

122171
static int _i2c_read(uint8_t addr, uint32_t reg, uint8_t regSize, uint8_t* data, uint16_t len, uint32_t timeout, bool forceLong = false)
123172
{
@@ -177,8 +226,6 @@ static bool ft6236TouchRead(uint16_t * X, uint16_t * Y)
177226

178227
static bool ft6236HasTouchEvent()
179228
{
180-
touchEventOccured = true;
181-
return true;
182229
return touchEventOccured;
183230
}
184231

@@ -280,9 +327,8 @@ static bool cst836uTouchRead(uint16_t * X, uint16_t * Y)
280327
static bool cst836uHasTouchEvent()
281328
{
282329
static bool lastHasTouch = false;
283-
touchEventOccured = true;
284330
bool ret = touchEventOccured;
285-
if (ret||1) {
331+
if (ret) {
286332
uint8_t data;
287333
_i2c_readMultipleRetry(TOUCH_CST836U_I2C_ADDRESS, TOUCH_CST836U_TOUCH_NUM_REG, 1, &data, sizeof(data), true);
288334
uint8_t hasTouch = data;

0 commit comments

Comments
 (0)