|
25 | 25 | #include "stm32_gpio_driver.h" |
26 | 26 | #include "stm32_exti_driver.h" |
27 | 27 |
|
| 28 | +#include "hal/i2c_driver.h" |
| 29 | + |
28 | 30 | #include "hal.h" |
29 | 31 | #include "timers_driver.h" |
30 | 32 | #include "delays_driver.h" |
@@ -109,15 +111,62 @@ static tmr10ms_t downTime = 0; |
109 | 111 | static tmr10ms_t tapTime = 0; |
110 | 112 | static short tapCount = 0; |
111 | 113 |
|
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 | +} |
116 | 169 |
|
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() {} |
121 | 170 |
|
122 | 171 | 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) |
123 | 172 | { |
@@ -177,8 +226,6 @@ static bool ft6236TouchRead(uint16_t * X, uint16_t * Y) |
177 | 226 |
|
178 | 227 | static bool ft6236HasTouchEvent() |
179 | 228 | { |
180 | | - touchEventOccured = true; |
181 | | - return true; |
182 | 229 | return touchEventOccured; |
183 | 230 | } |
184 | 231 |
|
@@ -280,9 +327,8 @@ static bool cst836uTouchRead(uint16_t * X, uint16_t * Y) |
280 | 327 | static bool cst836uHasTouchEvent() |
281 | 328 | { |
282 | 329 | static bool lastHasTouch = false; |
283 | | - touchEventOccured = true; |
284 | 330 | bool ret = touchEventOccured; |
285 | | - if (ret||1) { |
| 331 | + if (ret) { |
286 | 332 | uint8_t data; |
287 | 333 | _i2c_readMultipleRetry(TOUCH_CST836U_I2C_ADDRESS, TOUCH_CST836U_TOUCH_NUM_REG, 1, &data, sizeof(data), true); |
288 | 334 | uint8_t hasTouch = data; |
|
0 commit comments