BSP driver for DISCO_L496AG
Dependents: DISCO_L496AG-LCD-prova_1 DISCO_L496AG-LCD-prova_2 DISCO_L496AG-LCD-demo DISCO_L496AG-SRAM-demo
Drivers/BSP/STM32L496G-Discovery/stm32l496g_discovery_ts.c@2:106c7b82e064, 2019-11-20 (annotated)
- Committer:
- Jerome Coutant
- Date:
- Wed Nov 20 16:48:24 2019 +0100
- Revision:
- 2:106c7b82e064
- Parent:
- 0:d83f1c8ca282
Update BSP files with CubeL4 V1.14.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:d83f1c8ca282 | 1 | /** |
bcostm | 0:d83f1c8ca282 | 2 | ****************************************************************************** |
bcostm | 0:d83f1c8ca282 | 3 | * @file stm32l496g_discovery_ts.c |
bcostm | 0:d83f1c8ca282 | 4 | * @author MCD Application Team |
bcostm | 0:d83f1c8ca282 | 5 | * @brief This file provides a set of functions needed to manage the Touch |
bcostm | 0:d83f1c8ca282 | 6 | * Screen on STM32L496G-DISCOVERY evaluation board. |
bcostm | 0:d83f1c8ca282 | 7 | ****************************************************************************** |
bcostm | 0:d83f1c8ca282 | 8 | * @attention |
bcostm | 0:d83f1c8ca282 | 9 | * |
Jerome Coutant
2:106c7b82e064
|
10
|
* <h2><center>© Copyright (c) 2017 STMicroelectronics.
|
|
Jerome Coutant
2:106c7b82e064
|
11
|
* All rights reserved.</center></h2>
|
|
bcostm | 0:d83f1c8ca282 | 12 | * |
Jerome Coutant
2:106c7b82e064
|
13
|
* This software component is licensed by ST under BSD 3-Clause license,
|
|
Jerome Coutant
2:106c7b82e064
|
14
|
* the "License"; You may not use this file except in compliance with the
|
|
Jerome Coutant
2:106c7b82e064
|
15
|
* License. You may obtain a copy of the License at:
|
|
Jerome Coutant
2:106c7b82e064
|
16
|
* opensource.org/licenses/BSD-3-Clause
|
|
bcostm | 0:d83f1c8ca282 | 17 | * |
bcostm | 0:d83f1c8ca282 | 18 | ****************************************************************************** |
bcostm | 0:d83f1c8ca282 | 19 | */ |
bcostm | 0:d83f1c8ca282 | 20 | |
bcostm | 0:d83f1c8ca282 | 21 | /* File Info : ----------------------------------------------------------------- |
bcostm | 0:d83f1c8ca282 | 22 | User NOTES |
bcostm | 0:d83f1c8ca282 | 23 | 1. How To use this driver: |
bcostm | 0:d83f1c8ca282 | 24 | -------------------------- |
bcostm | 0:d83f1c8ca282 | 25 | - This driver is used to drive the touch screen module of the STM32L496G-DISCOVERY |
bcostm | 0:d83f1c8ca282 | 26 | evaluation board on the FRIDA LCD mounted on MB1261 daughter board. |
bcostm | 0:d83f1c8ca282 | 27 | The touch screen driver IC is a FT6x36 type which share the same register naming |
bcostm | 0:d83f1c8ca282 | 28 | with FT6206 type. |
bcostm | 0:d83f1c8ca282 | 29 | |
bcostm | 0:d83f1c8ca282 | 30 | 2. Driver description: |
bcostm | 0:d83f1c8ca282 | 31 | --------------------- |
bcostm | 0:d83f1c8ca282 | 32 | + Initialization steps: |
bcostm | 0:d83f1c8ca282 | 33 | o Initialize the TS module using the BSP_TS_Init() function. This |
bcostm | 0:d83f1c8ca282 | 34 | function includes the MSP layer hardware resources initialization and the |
bcostm | 0:d83f1c8ca282 | 35 | communication layer configuration to start the TS use. The LCD size properties |
bcostm | 0:d83f1c8ca282 | 36 | (x and y) are passed as parameters. |
bcostm | 0:d83f1c8ca282 | 37 | o If TS interrupt mode is desired, you must configure the TS interrupt mode |
bcostm | 0:d83f1c8ca282 | 38 | by calling the function BSP_TS_ITConfig(). The TS interrupt mode is generated |
bcostm | 0:d83f1c8ca282 | 39 | as an external interrupt whenever a touch is detected. |
bcostm | 0:d83f1c8ca282 | 40 | |
bcostm | 0:d83f1c8ca282 | 41 | + Touch screen use |
bcostm | 0:d83f1c8ca282 | 42 | o The touch screen state is captured whenever the function BSP_TS_GetState() is |
bcostm | 0:d83f1c8ca282 | 43 | used. This function returns information about the last LCD touch occurred |
bcostm | 0:d83f1c8ca282 | 44 | in the TS_StateTypeDef structure. |
bcostm | 0:d83f1c8ca282 | 45 | ------------------------------------------------------------------------------*/ |
bcostm | 0:d83f1c8ca282 | 46 | |
bcostm | 0:d83f1c8ca282 | 47 | /* Includes ------------------------------------------------------------------*/ |
bcostm | 0:d83f1c8ca282 | 48 | #include "stm32l496g_discovery.h" |
bcostm | 0:d83f1c8ca282 | 49 | #include "stm32l496g_discovery_ts.h" |
bcostm | 0:d83f1c8ca282 | 50 | |
bcostm | 0:d83f1c8ca282 | 51 | /** @addtogroup BSP |
bcostm | 0:d83f1c8ca282 | 52 | * @{ |
bcostm | 0:d83f1c8ca282 | 53 | */ |
bcostm | 0:d83f1c8ca282 | 54 | |
bcostm | 0:d83f1c8ca282 | 55 | /** @addtogroup STM32L496G-DISCOVERY |
bcostm | 0:d83f1c8ca282 | 56 | * @{ |
bcostm | 0:d83f1c8ca282 | 57 | */ |
bcostm | 0:d83f1c8ca282 | 58 | |
bcostm | 0:d83f1c8ca282 | 59 | /** @defgroup STM32L496G-DISCOVERY_TS STM32L496G-DISCOVERY TS |
bcostm | 0:d83f1c8ca282 | 60 | * @{ |
bcostm | 0:d83f1c8ca282 | 61 | */ |
bcostm | 0:d83f1c8ca282 | 62 | |
bcostm | 0:d83f1c8ca282 | 63 | /** @defgroup STM32L496G-DISCOVERY_TS_Private_Types_Definitions TS Private Types Definitions |
bcostm | 0:d83f1c8ca282 | 64 | * @{ |
bcostm | 0:d83f1c8ca282 | 65 | */ |
bcostm | 0:d83f1c8ca282 | 66 | /** |
bcostm | 0:d83f1c8ca282 | 67 | * @} |
bcostm | 0:d83f1c8ca282 | 68 | */ |
bcostm | 0:d83f1c8ca282 | 69 | |
bcostm | 0:d83f1c8ca282 | 70 | /** @defgroup STM32L496G-DISCOVERY_TS_Private_Defines TS Private Types Defines |
bcostm | 0:d83f1c8ca282 | 71 | * @{ |
bcostm | 0:d83f1c8ca282 | 72 | */ |
bcostm | 0:d83f1c8ca282 | 73 | /** |
bcostm | 0:d83f1c8ca282 | 74 | * @} |
bcostm | 0:d83f1c8ca282 | 75 | */ |
bcostm | 0:d83f1c8ca282 | 76 | |
bcostm | 0:d83f1c8ca282 | 77 | /** @defgroup STM32L496G-DISCOVERY_TS_Private_Macros TS Private Macros |
bcostm | 0:d83f1c8ca282 | 78 | * @{ |
bcostm | 0:d83f1c8ca282 | 79 | */ |
bcostm | 0:d83f1c8ca282 | 80 | /** |
bcostm | 0:d83f1c8ca282 | 81 | * @} |
bcostm | 0:d83f1c8ca282 | 82 | */ |
bcostm | 0:d83f1c8ca282 | 83 | |
bcostm | 0:d83f1c8ca282 | 84 | /** @defgroup STM32L496G-DISCOVERY_TS_Imported_Variables TS Imported Variables |
bcostm | 0:d83f1c8ca282 | 85 | * @{ |
bcostm | 0:d83f1c8ca282 | 86 | */ |
bcostm | 0:d83f1c8ca282 | 87 | /** |
bcostm | 0:d83f1c8ca282 | 88 | * @} |
bcostm | 0:d83f1c8ca282 | 89 | */ |
bcostm | 0:d83f1c8ca282 | 90 | |
bcostm | 0:d83f1c8ca282 | 91 | /** @defgroup STM32L496G-DISCOVERY_TS_Private_Variables TS Private Variables |
bcostm | 0:d83f1c8ca282 | 92 | * @{ |
bcostm | 0:d83f1c8ca282 | 93 | */ |
bcostm | 0:d83f1c8ca282 | 94 | static TS_DrvTypeDef *tsDriver; |
bcostm | 0:d83f1c8ca282 | 95 | static uint8_t I2C_Address = 0; |
bcostm | 0:d83f1c8ca282 | 96 | static uint8_t tsOrientation = TS_SWAP_NONE; |
bcostm | 0:d83f1c8ca282 | 97 | static uint8_t TS_orientation = TS_ORIENTATION_UNDEFINED; |
bcostm | 0:d83f1c8ca282 | 98 | |
bcostm | 0:d83f1c8ca282 | 99 | /* Table for touchscreen event information display on LCD : table indexed on enum @ref TS_TouchEventTypeDef information */ |
bcostm | 0:d83f1c8ca282 | 100 | char *ts_event_string_tab[TOUCH_EVENT_NB_MAX] = { "None", |
bcostm | 0:d83f1c8ca282 | 101 | "Press down", |
bcostm | 0:d83f1c8ca282 | 102 | "Lift up", |
bcostm | 0:d83f1c8ca282 | 103 | "Contact" |
bcostm | 0:d83f1c8ca282 | 104 | }; |
bcostm | 0:d83f1c8ca282 | 105 | |
bcostm | 0:d83f1c8ca282 | 106 | /* Table for touchscreen gesture Id information display on LCD : table indexed on enum @ref TS_GestureIdTypeDef information */ |
bcostm | 0:d83f1c8ca282 | 107 | char *ts_gesture_id_string_tab[GEST_ID_NB_MAX] = { "None", |
bcostm | 0:d83f1c8ca282 | 108 | "Move Up", |
bcostm | 0:d83f1c8ca282 | 109 | "Move Right", |
bcostm | 0:d83f1c8ca282 | 110 | "Move Down", |
bcostm | 0:d83f1c8ca282 | 111 | "Move Left", |
bcostm | 0:d83f1c8ca282 | 112 | "Zoom In", |
bcostm | 0:d83f1c8ca282 | 113 | "Zoom Out" |
bcostm | 0:d83f1c8ca282 | 114 | }; |
bcostm | 0:d83f1c8ca282 | 115 | /** |
bcostm | 0:d83f1c8ca282 | 116 | * @} |
bcostm | 0:d83f1c8ca282 | 117 | */ |
bcostm | 0:d83f1c8ca282 | 118 | |
bcostm | 0:d83f1c8ca282 | 119 | /** @defgroup STM32L496G-DISCOVERY_TS_Private_Function_Prototypes TS Private Function Prototypes |
bcostm | 0:d83f1c8ca282 | 120 | * @{ |
bcostm | 0:d83f1c8ca282 | 121 | */ |
bcostm | 0:d83f1c8ca282 | 122 | /** |
bcostm | 0:d83f1c8ca282 | 123 | * @} |
bcostm | 0:d83f1c8ca282 | 124 | */ |
bcostm | 0:d83f1c8ca282 | 125 | |
bcostm | 0:d83f1c8ca282 | 126 | /** @defgroup STM32L496G-DISCOVERY_TS_Public_Functions TS Public Functions |
bcostm | 0:d83f1c8ca282 | 127 | * @{ |
bcostm | 0:d83f1c8ca282 | 128 | */ |
bcostm | 0:d83f1c8ca282 | 129 | /** |
bcostm | 0:d83f1c8ca282 | 130 | * @brief Initializes and configures the touch screen functionalities and |
bcostm | 0:d83f1c8ca282 | 131 | * configures all necessary hardware resources (GPIOs, I2C, clocks..). |
bcostm | 0:d83f1c8ca282 | 132 | * @param ts_SizeX : Maximum X size of the TS area on LCD |
bcostm | 0:d83f1c8ca282 | 133 | * @param ts_SizeY : Maximum Y size of the TS area on LCD |
bcostm | 0:d83f1c8ca282 | 134 | * @retval TS_OK if all initializations are OK. Other value if error. |
bcostm | 0:d83f1c8ca282 | 135 | */ |
bcostm | 0:d83f1c8ca282 | 136 | uint8_t BSP_TS_Init(uint16_t ts_SizeX, uint16_t ts_SizeY) |
bcostm | 0:d83f1c8ca282 | 137 | { |
bcostm | 0:d83f1c8ca282 | 138 | return (BSP_TS_InitEx(ts_SizeX, ts_SizeY, TS_ORIENTATION_LANDSCAPE)); |
bcostm | 0:d83f1c8ca282 | 139 | } |
bcostm | 0:d83f1c8ca282 | 140 | |
bcostm | 0:d83f1c8ca282 | 141 | /** |
bcostm | 0:d83f1c8ca282 | 142 | * @brief Initializes and configures the touch screen functionalities and |
bcostm | 0:d83f1c8ca282 | 143 | * configures all necessary hardware resources (GPIOs, I2C, clocks..) |
bcostm | 0:d83f1c8ca282 | 144 | * with a given orientation |
bcostm | 0:d83f1c8ca282 | 145 | * @param ts_SizeX : Maximum X size of the TS area on LCD |
bcostm | 0:d83f1c8ca282 | 146 | * @param ts_SizeY : Maximum Y size of the TS area on LCD |
bcostm | 0:d83f1c8ca282 | 147 | * @param orientation : TS_ORIENTATION_LANDSCAPE or TS_ORIENTATION_PORTRAIT |
bcostm | 0:d83f1c8ca282 | 148 | * @retval TS_OK if all initializations are OK. Other value if error. |
bcostm | 0:d83f1c8ca282 | 149 | */ |
bcostm | 0:d83f1c8ca282 | 150 | uint8_t BSP_TS_InitEx(uint16_t ts_SizeX, uint16_t ts_SizeY, uint8_t orientation) |
bcostm | 0:d83f1c8ca282 | 151 | { |
bcostm | 0:d83f1c8ca282 | 152 | uint8_t ts_status = TS_OK; |
bcostm | 0:d83f1c8ca282 | 153 | uint16_t read_id = 0; |
bcostm | 0:d83f1c8ca282 | 154 | |
bcostm | 0:d83f1c8ca282 | 155 | /* Note : I2C_Address is un-initialized here, but is not used at all in init function */ |
bcostm | 0:d83f1c8ca282 | 156 | /* but the prototype of Init() is like that in template and should be respected */ |
bcostm | 0:d83f1c8ca282 | 157 | |
bcostm | 0:d83f1c8ca282 | 158 | /* Initialize the communication channel to sensor (I2C) if necessary */ |
bcostm | 0:d83f1c8ca282 | 159 | /* that is initialization is done only once after a power up */ |
bcostm | 0:d83f1c8ca282 | 160 | ft6x06_ts_drv.Init(I2C_Address); |
bcostm | 0:d83f1c8ca282 | 161 | |
bcostm | 0:d83f1c8ca282 | 162 | /* Scan FT6x36 TouchScreen IC controller ID register by I2C Read */ |
bcostm | 0:d83f1c8ca282 | 163 | /* Verify this is a FT6x36, otherwise this is an error case */ |
bcostm | 0:d83f1c8ca282 | 164 | |
bcostm | 0:d83f1c8ca282 | 165 | read_id = ft6x06_ts_drv.ReadID(TS_I2C_ADDRESS); |
bcostm | 0:d83f1c8ca282 | 166 | |
bcostm | 0:d83f1c8ca282 | 167 | if (read_id == FT6x36_ID_VALUE) |
bcostm | 0:d83f1c8ca282 | 168 | { |
bcostm | 0:d83f1c8ca282 | 169 | /* Found FT6x36 : Initialize the TS driver structure */ |
bcostm | 0:d83f1c8ca282 | 170 | tsDriver = &ft6x06_ts_drv; |
bcostm | 0:d83f1c8ca282 | 171 | |
bcostm | 0:d83f1c8ca282 | 172 | I2C_Address = TS_I2C_ADDRESS; |
bcostm | 0:d83f1c8ca282 | 173 | |
bcostm | 0:d83f1c8ca282 | 174 | /* Get LCD chosen orientation */ |
bcostm | 0:d83f1c8ca282 | 175 | if (orientation == TS_ORIENTATION_PORTRAIT) |
bcostm | 0:d83f1c8ca282 | 176 | { |
bcostm | 0:d83f1c8ca282 | 177 | tsOrientation = TS_SWAP_X | TS_SWAP_Y; |
bcostm | 0:d83f1c8ca282 | 178 | TS_orientation = TS_ORIENTATION_PORTRAIT; |
bcostm | 0:d83f1c8ca282 | 179 | } |
bcostm | 0:d83f1c8ca282 | 180 | else |
bcostm | 0:d83f1c8ca282 | 181 | { |
bcostm | 0:d83f1c8ca282 | 182 | tsOrientation = TS_SWAP_XY | TS_SWAP_Y; |
bcostm | 0:d83f1c8ca282 | 183 | TS_orientation = TS_ORIENTATION_LANDSCAPE; |
bcostm | 0:d83f1c8ca282 | 184 | } |
bcostm | 0:d83f1c8ca282 | 185 | |
bcostm | 0:d83f1c8ca282 | 186 | if (ts_status == TS_OK) |
bcostm | 0:d83f1c8ca282 | 187 | { |
bcostm | 0:d83f1c8ca282 | 188 | /* Software reset the TouchScreen */ |
bcostm | 0:d83f1c8ca282 | 189 | tsDriver->Reset(I2C_Address); |
bcostm | 0:d83f1c8ca282 | 190 | |
bcostm | 0:d83f1c8ca282 | 191 | /* Calibrate, Configure and Start the TouchScreen driver */ |
bcostm | 0:d83f1c8ca282 | 192 | tsDriver->Start(I2C_Address); |
bcostm | 0:d83f1c8ca282 | 193 | |
bcostm | 0:d83f1c8ca282 | 194 | return TS_OK; |
bcostm | 0:d83f1c8ca282 | 195 | |
bcostm | 0:d83f1c8ca282 | 196 | } /* of if(ts_status == TS_OK) */ |
bcostm | 0:d83f1c8ca282 | 197 | } |
bcostm | 0:d83f1c8ca282 | 198 | |
bcostm | 0:d83f1c8ca282 | 199 | return TS_DEVICE_NOT_FOUND; |
bcostm | 0:d83f1c8ca282 | 200 | |
bcostm | 0:d83f1c8ca282 | 201 | |
bcostm | 0:d83f1c8ca282 | 202 | } |
bcostm | 0:d83f1c8ca282 | 203 | |
bcostm | 0:d83f1c8ca282 | 204 | /** |
bcostm | 0:d83f1c8ca282 | 205 | * @brief Configures and enables the touch screen interrupts. |
bcostm | 0:d83f1c8ca282 | 206 | * @retval TS_OK if all initializations are OK. Other value if error. |
bcostm | 0:d83f1c8ca282 | 207 | */ |
bcostm | 0:d83f1c8ca282 | 208 | uint8_t BSP_TS_ITConfig(void) |
bcostm | 0:d83f1c8ca282 | 209 | { |
bcostm | 0:d83f1c8ca282 | 210 | uint8_t ts_status = TS_OK; |
bcostm | 0:d83f1c8ca282 | 211 | |
bcostm | 0:d83f1c8ca282 | 212 | /* Msp Init of GPIO used for TS_INT pin coming from TouchScreen driver IC FT6x36 */ |
bcostm | 0:d83f1c8ca282 | 213 | /* When touchscreen is operated in interrupt mode */ |
bcostm | 0:d83f1c8ca282 | 214 | BSP_TS_INT_MspInit(); |
bcostm | 0:d83f1c8ca282 | 215 | |
bcostm | 0:d83f1c8ca282 | 216 | /* Enable the TS in interrupt mode */ |
bcostm | 0:d83f1c8ca282 | 217 | /* In that case the INT output of FT6206 when new touch is available */ |
bcostm | 0:d83f1c8ca282 | 218 | /* is active on low level and directed on EXTI */ |
bcostm | 0:d83f1c8ca282 | 219 | tsDriver->EnableIT(I2C_Address); |
bcostm | 0:d83f1c8ca282 | 220 | |
bcostm | 0:d83f1c8ca282 | 221 | return (ts_status); |
bcostm | 0:d83f1c8ca282 | 222 | } |
bcostm | 0:d83f1c8ca282 | 223 | |
bcostm | 0:d83f1c8ca282 | 224 | /** |
bcostm | 0:d83f1c8ca282 | 225 | * @brief deConfigures and enables the touch screen interrupts. |
bcostm | 0:d83f1c8ca282 | 226 | * @retval TS_OK if all initializations are OK. Other value if error. |
bcostm | 0:d83f1c8ca282 | 227 | */ |
bcostm | 0:d83f1c8ca282 | 228 | uint8_t BSP_TS_ITDeConfig(void) |
bcostm | 0:d83f1c8ca282 | 229 | { |
bcostm | 0:d83f1c8ca282 | 230 | uint8_t ts_status = TS_OK; |
bcostm | 0:d83f1c8ca282 | 231 | |
bcostm | 0:d83f1c8ca282 | 232 | /* Msp Init of GPIO used for TS_INT pin coming from TouchScreen driver IC FT6x36 */ |
bcostm | 0:d83f1c8ca282 | 233 | /* When touchscreen is operated in interrupt mode */ |
bcostm | 0:d83f1c8ca282 | 234 | BSP_TS_INT_MspDeInit(); |
bcostm | 0:d83f1c8ca282 | 235 | |
bcostm | 0:d83f1c8ca282 | 236 | /* Enable the TS in interrupt mode */ |
bcostm | 0:d83f1c8ca282 | 237 | /* In that case the INT output of FT6206 when new touch is available */ |
bcostm | 0:d83f1c8ca282 | 238 | /* is active on low level and directed on EXTI */ |
bcostm | 0:d83f1c8ca282 | 239 | tsDriver->DisableIT(I2C_Address); |
bcostm | 0:d83f1c8ca282 | 240 | |
bcostm | 0:d83f1c8ca282 | 241 | return (ts_status); |
bcostm | 0:d83f1c8ca282 | 242 | } |
bcostm | 0:d83f1c8ca282 | 243 | |
bcostm | 0:d83f1c8ca282 | 244 | |
bcostm | 0:d83f1c8ca282 | 245 | /** |
bcostm | 0:d83f1c8ca282 | 246 | * @brief Returns status and positions of the touch screen. |
bcostm | 0:d83f1c8ca282 | 247 | * @param TS_State: Pointer to touch screen current state structure |
bcostm | 0:d83f1c8ca282 | 248 | * @retval TS_OK if all initializations are OK. Other value if error. |
bcostm | 0:d83f1c8ca282 | 249 | */ |
bcostm | 0:d83f1c8ca282 | 250 | uint8_t BSP_TS_GetState(TS_StateTypeDef *TS_State) |
bcostm | 0:d83f1c8ca282 | 251 | { |
bcostm | 0:d83f1c8ca282 | 252 | static uint32_t _x[TS_MAX_NB_TOUCH] = {0, 0}; |
bcostm | 0:d83f1c8ca282 | 253 | static uint32_t _y[TS_MAX_NB_TOUCH] = {0, 0}; |
bcostm | 0:d83f1c8ca282 | 254 | uint8_t ts_status = TS_OK; |
bcostm | 0:d83f1c8ca282 | 255 | uint16_t tmp; |
bcostm | 0:d83f1c8ca282 | 256 | uint16_t Raw_x[TS_MAX_NB_TOUCH]; |
bcostm | 0:d83f1c8ca282 | 257 | uint16_t Raw_y[TS_MAX_NB_TOUCH]; |
bcostm | 0:d83f1c8ca282 | 258 | uint16_t xDiff; |
bcostm | 0:d83f1c8ca282 | 259 | uint16_t yDiff; |
bcostm | 0:d83f1c8ca282 | 260 | uint32_t index; |
bcostm | 0:d83f1c8ca282 | 261 | #if (TS_MULTI_TOUCH_SUPPORTED == 1) |
bcostm | 0:d83f1c8ca282 | 262 | uint32_t weight = 0; |
bcostm | 0:d83f1c8ca282 | 263 | uint32_t area = 0; |
bcostm | 0:d83f1c8ca282 | 264 | uint32_t event = 0; |
bcostm | 0:d83f1c8ca282 | 265 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
bcostm | 0:d83f1c8ca282 | 266 | |
bcostm | 0:d83f1c8ca282 | 267 | /* Check and update the number of touches active detected */ |
bcostm | 0:d83f1c8ca282 | 268 | TS_State->touchDetected = tsDriver->DetectTouch(I2C_Address); |
bcostm | 0:d83f1c8ca282 | 269 | if (TS_State->touchDetected) |
bcostm | 0:d83f1c8ca282 | 270 | { |
bcostm | 0:d83f1c8ca282 | 271 | for (index = 0; index < TS_State->touchDetected; index++) |
bcostm | 0:d83f1c8ca282 | 272 | { |
bcostm | 0:d83f1c8ca282 | 273 | /* Get each touch coordinates */ |
bcostm | 0:d83f1c8ca282 | 274 | tsDriver->GetXY(I2C_Address, &(Raw_x[index]), &(Raw_y[index])); |
bcostm | 0:d83f1c8ca282 | 275 | |
bcostm | 0:d83f1c8ca282 | 276 | if (tsOrientation & TS_SWAP_XY) |
bcostm | 0:d83f1c8ca282 | 277 | { |
bcostm | 0:d83f1c8ca282 | 278 | tmp = Raw_x[index]; |
bcostm | 0:d83f1c8ca282 | 279 | Raw_x[index] = Raw_y[index]; |
bcostm | 0:d83f1c8ca282 | 280 | Raw_y[index] = tmp; |
bcostm | 0:d83f1c8ca282 | 281 | } |
bcostm | 0:d83f1c8ca282 | 282 | |
bcostm | 0:d83f1c8ca282 | 283 | if (tsOrientation & TS_SWAP_X) |
bcostm | 0:d83f1c8ca282 | 284 | { |
bcostm | 0:d83f1c8ca282 | 285 | Raw_x[index] = FT_6206_MAX_WIDTH_HEIGHT - 1 - Raw_x[index]; |
bcostm | 0:d83f1c8ca282 | 286 | } |
bcostm | 0:d83f1c8ca282 | 287 | |
bcostm | 0:d83f1c8ca282 | 288 | if (tsOrientation & TS_SWAP_Y) |
bcostm | 0:d83f1c8ca282 | 289 | { |
bcostm | 0:d83f1c8ca282 | 290 | Raw_y[index] = FT_6206_MAX_WIDTH_HEIGHT - 1 - Raw_y[index]; |
bcostm | 0:d83f1c8ca282 | 291 | } |
bcostm | 0:d83f1c8ca282 | 292 | |
bcostm | 0:d83f1c8ca282 | 293 | xDiff = Raw_x[index] > _x[index] ? (Raw_x[index] - _x[index]) : (_x[index] - Raw_x[index]); |
bcostm | 0:d83f1c8ca282 | 294 | yDiff = Raw_y[index] > _y[index] ? (Raw_y[index] - _y[index]) : (_y[index] - Raw_y[index]); |
bcostm | 0:d83f1c8ca282 | 295 | |
bcostm | 0:d83f1c8ca282 | 296 | if ((xDiff + yDiff) > 5) |
bcostm | 0:d83f1c8ca282 | 297 | { |
bcostm | 0:d83f1c8ca282 | 298 | _x[index] = Raw_x[index]; |
bcostm | 0:d83f1c8ca282 | 299 | _y[index] = Raw_y[index]; |
bcostm | 0:d83f1c8ca282 | 300 | } |
bcostm | 0:d83f1c8ca282 | 301 | |
bcostm | 0:d83f1c8ca282 | 302 | |
bcostm | 0:d83f1c8ca282 | 303 | TS_State->touchX[index] = _x[index]; |
bcostm | 0:d83f1c8ca282 | 304 | TS_State->touchY[index] = _y[index]; |
bcostm | 0:d83f1c8ca282 | 305 | |
bcostm | 0:d83f1c8ca282 | 306 | #if (TS_MULTI_TOUCH_SUPPORTED == 1) |
bcostm | 0:d83f1c8ca282 | 307 | |
bcostm | 0:d83f1c8ca282 | 308 | /* Get touch info related to the current touch */ |
bcostm | 0:d83f1c8ca282 | 309 | ft6x06_TS_GetTouchInfo(I2C_Address, index, &weight, &area, &event); |
bcostm | 0:d83f1c8ca282 | 310 | |
bcostm | 0:d83f1c8ca282 | 311 | /* Update TS_State structure */ |
bcostm | 0:d83f1c8ca282 | 312 | TS_State->touchWeight[index] = weight; |
bcostm | 0:d83f1c8ca282 | 313 | TS_State->touchArea[index] = area; |
bcostm | 0:d83f1c8ca282 | 314 | |
bcostm | 0:d83f1c8ca282 | 315 | /* Remap touch event */ |
bcostm | 0:d83f1c8ca282 | 316 | switch (event) |
bcostm | 0:d83f1c8ca282 | 317 | { |
bcostm | 0:d83f1c8ca282 | 318 | case FT6206_TOUCH_EVT_FLAG_PRESS_DOWN : |
bcostm | 0:d83f1c8ca282 | 319 | TS_State->touchEventId[index] = TOUCH_EVENT_PRESS_DOWN; |
bcostm | 0:d83f1c8ca282 | 320 | break; |
bcostm | 0:d83f1c8ca282 | 321 | case FT6206_TOUCH_EVT_FLAG_LIFT_UP : |
bcostm | 0:d83f1c8ca282 | 322 | TS_State->touchEventId[index] = TOUCH_EVENT_LIFT_UP; |
bcostm | 0:d83f1c8ca282 | 323 | break; |
bcostm | 0:d83f1c8ca282 | 324 | case FT6206_TOUCH_EVT_FLAG_CONTACT : |
bcostm | 0:d83f1c8ca282 | 325 | TS_State->touchEventId[index] = TOUCH_EVENT_CONTACT; |
bcostm | 0:d83f1c8ca282 | 326 | break; |
bcostm | 0:d83f1c8ca282 | 327 | case FT6206_TOUCH_EVT_FLAG_NO_EVENT : |
bcostm | 0:d83f1c8ca282 | 328 | TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT; |
bcostm | 0:d83f1c8ca282 | 329 | break; |
bcostm | 0:d83f1c8ca282 | 330 | default : |
bcostm | 0:d83f1c8ca282 | 331 | ts_status = TS_ERROR; |
bcostm | 0:d83f1c8ca282 | 332 | break; |
bcostm | 0:d83f1c8ca282 | 333 | } /* of switch(event) */ |
bcostm | 0:d83f1c8ca282 | 334 | |
bcostm | 0:d83f1c8ca282 | 335 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
bcostm | 0:d83f1c8ca282 | 336 | |
bcostm | 0:d83f1c8ca282 | 337 | } /* of for(index=0; index < TS_State->touchDetected; index++) */ |
bcostm | 0:d83f1c8ca282 | 338 | |
bcostm | 0:d83f1c8ca282 | 339 | #if (TS_MULTI_TOUCH_SUPPORTED == 1) |
bcostm | 0:d83f1c8ca282 | 340 | /* Get gesture Id */ |
bcostm | 0:d83f1c8ca282 | 341 | ts_status = BSP_TS_Get_GestureId(TS_State); |
bcostm | 0:d83f1c8ca282 | 342 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
bcostm | 0:d83f1c8ca282 | 343 | |
bcostm | 0:d83f1c8ca282 | 344 | } /* end of if(TS_State->touchDetected != 0) */ |
bcostm | 0:d83f1c8ca282 | 345 | |
bcostm | 0:d83f1c8ca282 | 346 | return (ts_status); |
bcostm | 0:d83f1c8ca282 | 347 | } |
bcostm | 0:d83f1c8ca282 | 348 | |
bcostm | 0:d83f1c8ca282 | 349 | #if (TS_MULTI_TOUCH_SUPPORTED == 1) |
bcostm | 0:d83f1c8ca282 | 350 | /** |
bcostm | 0:d83f1c8ca282 | 351 | * @brief Update gesture Id following a touch detected. |
bcostm | 0:d83f1c8ca282 | 352 | * @param TS_State: Pointer to touch screen current state structure |
bcostm | 0:d83f1c8ca282 | 353 | * @retval TS_OK if all initializations are OK. Other value if error. |
bcostm | 0:d83f1c8ca282 | 354 | */ |
bcostm | 0:d83f1c8ca282 | 355 | uint8_t BSP_TS_Get_GestureId(TS_StateTypeDef *TS_State) |
bcostm | 0:d83f1c8ca282 | 356 | { |
bcostm | 0:d83f1c8ca282 | 357 | uint32_t gestureId = 0; |
bcostm | 0:d83f1c8ca282 | 358 | uint8_t ts_status = TS_OK; |
bcostm | 0:d83f1c8ca282 | 359 | |
bcostm | 0:d83f1c8ca282 | 360 | /* Get gesture Id */ |
bcostm | 0:d83f1c8ca282 | 361 | ft6x06_TS_GetGestureID(I2C_Address, &gestureId); |
bcostm | 0:d83f1c8ca282 | 362 | |
bcostm | 0:d83f1c8ca282 | 363 | /* Remap gesture Id to a TS_GestureIdTypeDef value */ |
bcostm | 0:d83f1c8ca282 | 364 | switch (gestureId) |
bcostm | 0:d83f1c8ca282 | 365 | { |
bcostm | 0:d83f1c8ca282 | 366 | case FT6206_GEST_ID_NO_GESTURE : |
bcostm | 0:d83f1c8ca282 | 367 | TS_State->gestureId = GEST_ID_NO_GESTURE; |
bcostm | 0:d83f1c8ca282 | 368 | break; |
bcostm | 0:d83f1c8ca282 | 369 | case FT6206_GEST_ID_MOVE_UP : |
bcostm | 0:d83f1c8ca282 | 370 | TS_State->gestureId = GEST_ID_MOVE_UP; |
bcostm | 0:d83f1c8ca282 | 371 | break; |
bcostm | 0:d83f1c8ca282 | 372 | case FT6206_GEST_ID_MOVE_RIGHT : |
bcostm | 0:d83f1c8ca282 | 373 | TS_State->gestureId = GEST_ID_MOVE_RIGHT; |
bcostm | 0:d83f1c8ca282 | 374 | break; |
bcostm | 0:d83f1c8ca282 | 375 | case FT6206_GEST_ID_MOVE_DOWN : |
bcostm | 0:d83f1c8ca282 | 376 | TS_State->gestureId = GEST_ID_MOVE_DOWN; |
bcostm | 0:d83f1c8ca282 | 377 | break; |
bcostm | 0:d83f1c8ca282 | 378 | case FT6206_GEST_ID_MOVE_LEFT : |
bcostm | 0:d83f1c8ca282 | 379 | TS_State->gestureId = GEST_ID_MOVE_LEFT; |
bcostm | 0:d83f1c8ca282 | 380 | break; |
bcostm | 0:d83f1c8ca282 | 381 | case FT6206_GEST_ID_ZOOM_IN : |
bcostm | 0:d83f1c8ca282 | 382 | TS_State->gestureId = GEST_ID_ZOOM_IN; |
bcostm | 0:d83f1c8ca282 | 383 | break; |
bcostm | 0:d83f1c8ca282 | 384 | case FT6206_GEST_ID_ZOOM_OUT : |
bcostm | 0:d83f1c8ca282 | 385 | TS_State->gestureId = GEST_ID_ZOOM_OUT; |
bcostm | 0:d83f1c8ca282 | 386 | break; |
bcostm | 0:d83f1c8ca282 | 387 | default : |
bcostm | 0:d83f1c8ca282 | 388 | ts_status = TS_ERROR; |
bcostm | 0:d83f1c8ca282 | 389 | break; |
bcostm | 0:d83f1c8ca282 | 390 | } /* of switch(gestureId) */ |
bcostm | 0:d83f1c8ca282 | 391 | |
bcostm | 0:d83f1c8ca282 | 392 | return (ts_status); |
bcostm | 0:d83f1c8ca282 | 393 | } |
bcostm | 0:d83f1c8ca282 | 394 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
bcostm | 0:d83f1c8ca282 | 395 | |
bcostm | 0:d83f1c8ca282 | 396 | |
bcostm | 0:d83f1c8ca282 | 397 | /** @defgroup STM32L496G-DISCOVERY_TS_Private_Functions TS Private Functions |
bcostm | 0:d83f1c8ca282 | 398 | * @{ |
bcostm | 0:d83f1c8ca282 | 399 | */ |
bcostm | 0:d83f1c8ca282 | 400 | |
bcostm | 0:d83f1c8ca282 | 401 | #if (TS_MULTI_TOUCH_SUPPORTED == 1) |
bcostm | 0:d83f1c8ca282 | 402 | /** |
bcostm | 0:d83f1c8ca282 | 403 | * @brief Function used to reset all touch data before a new acquisition |
bcostm | 0:d83f1c8ca282 | 404 | * of touch information. |
bcostm | 0:d83f1c8ca282 | 405 | * @param TS_State: Pointer to touch screen current state structure |
bcostm | 0:d83f1c8ca282 | 406 | * @retval TS_OK if OK, TE_ERROR if problem found. |
bcostm | 0:d83f1c8ca282 | 407 | */ |
bcostm | 0:d83f1c8ca282 | 408 | uint8_t BSP_TS_ResetTouchData(TS_StateTypeDef *TS_State) |
bcostm | 0:d83f1c8ca282 | 409 | { |
bcostm | 0:d83f1c8ca282 | 410 | uint8_t ts_status = TS_ERROR; |
bcostm | 0:d83f1c8ca282 | 411 | uint32_t index; |
bcostm | 0:d83f1c8ca282 | 412 | |
bcostm | 0:d83f1c8ca282 | 413 | if (TS_State != (TS_StateTypeDef *)NULL) |
bcostm | 0:d83f1c8ca282 | 414 | { |
bcostm | 0:d83f1c8ca282 | 415 | TS_State->gestureId = GEST_ID_NO_GESTURE; |
bcostm | 0:d83f1c8ca282 | 416 | TS_State->touchDetected = 0; |
bcostm | 0:d83f1c8ca282 | 417 | |
bcostm | 0:d83f1c8ca282 | 418 | for (index = 0; index < TS_MAX_NB_TOUCH; index++) |
bcostm | 0:d83f1c8ca282 | 419 | { |
bcostm | 0:d83f1c8ca282 | 420 | TS_State->touchX[index] = 0; |
bcostm | 0:d83f1c8ca282 | 421 | TS_State->touchY[index] = 0; |
bcostm | 0:d83f1c8ca282 | 422 | TS_State->touchArea[index] = 0; |
bcostm | 0:d83f1c8ca282 | 423 | TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT; |
bcostm | 0:d83f1c8ca282 | 424 | TS_State->touchWeight[index] = 0; |
bcostm | 0:d83f1c8ca282 | 425 | } |
bcostm | 0:d83f1c8ca282 | 426 | |
bcostm | 0:d83f1c8ca282 | 427 | ts_status = TS_OK; |
bcostm | 0:d83f1c8ca282 | 428 | |
bcostm | 0:d83f1c8ca282 | 429 | } /* of if (TS_State != (TS_StateTypeDef *)NULL) */ |
bcostm | 0:d83f1c8ca282 | 430 | |
bcostm | 0:d83f1c8ca282 | 431 | return (ts_status); |
bcostm | 0:d83f1c8ca282 | 432 | } |
bcostm | 0:d83f1c8ca282 | 433 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
bcostm | 0:d83f1c8ca282 | 434 | |
bcostm | 0:d83f1c8ca282 | 435 | |
bcostm | 0:d83f1c8ca282 | 436 | uint8_t BSP_TS_GetOrientation(void) |
bcostm | 0:d83f1c8ca282 | 437 | { |
bcostm | 0:d83f1c8ca282 | 438 | return TS_orientation; |
bcostm | 0:d83f1c8ca282 | 439 | } |
bcostm | 0:d83f1c8ca282 | 440 | |
bcostm | 0:d83f1c8ca282 | 441 | /** |
bcostm | 0:d83f1c8ca282 | 442 | * @brief Initializes the TS_INT pin MSP. |
bcostm | 0:d83f1c8ca282 | 443 | * @param None |
bcostm | 0:d83f1c8ca282 | 444 | * @retval None |
bcostm | 0:d83f1c8ca282 | 445 | */ |
bcostm | 0:d83f1c8ca282 | 446 | __weak void BSP_TS_INT_MspInit(void) |
bcostm | 0:d83f1c8ca282 | 447 | { |
bcostm | 0:d83f1c8ca282 | 448 | GPIO_InitTypeDef gpio_init_structure; |
bcostm | 0:d83f1c8ca282 | 449 | |
bcostm | 0:d83f1c8ca282 | 450 | __HAL_RCC_PWR_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 451 | SET_BIT(PWR->CR2, PWR_CR2_IOSV); |
bcostm | 0:d83f1c8ca282 | 452 | |
bcostm | 0:d83f1c8ca282 | 453 | TS_INT_GPIO_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 454 | |
bcostm | 0:d83f1c8ca282 | 455 | /* GPIO configuration in input for TouchScreen interrupt signal on TS_INT pin */ |
bcostm | 0:d83f1c8ca282 | 456 | gpio_init_structure.Pin = TS_INT_PIN; |
bcostm | 0:d83f1c8ca282 | 457 | |
bcostm | 0:d83f1c8ca282 | 458 | /* Configure Interrupt mode for TS_INT pin falling edge : when a new touch is available */ |
bcostm | 0:d83f1c8ca282 | 459 | /* TS_INT pin is active on low level on new touch available */ |
bcostm | 0:d83f1c8ca282 | 460 | gpio_init_structure.Pin = TS_INT_PIN; |
bcostm | 0:d83f1c8ca282 | 461 | gpio_init_structure.Pull = GPIO_PULLUP; |
bcostm | 0:d83f1c8ca282 | 462 | gpio_init_structure.Speed = GPIO_SPEED_FAST; |
bcostm | 0:d83f1c8ca282 | 463 | gpio_init_structure.Mode = GPIO_MODE_IT_FALLING; |
bcostm | 0:d83f1c8ca282 | 464 | HAL_GPIO_Init(TS_INT_GPIO_PORT, &gpio_init_structure); |
bcostm | 0:d83f1c8ca282 | 465 | |
bcostm | 0:d83f1c8ca282 | 466 | /* Enable and set the TS_INT EXTI Interrupt to an intermediate priority */ |
bcostm | 0:d83f1c8ca282 | 467 | HAL_NVIC_SetPriority((IRQn_Type)(TS_INT_EXTI_IRQn), 0x08, 0x00); |
bcostm | 0:d83f1c8ca282 | 468 | HAL_NVIC_EnableIRQ((IRQn_Type)(TS_INT_EXTI_IRQn)); |
bcostm | 0:d83f1c8ca282 | 469 | } |
bcostm | 0:d83f1c8ca282 | 470 | |
bcostm | 0:d83f1c8ca282 | 471 | /** |
bcostm | 0:d83f1c8ca282 | 472 | * @brief Initializes the TS_INT pin MSP. |
bcostm | 0:d83f1c8ca282 | 473 | * @param None |
bcostm | 0:d83f1c8ca282 | 474 | * @retval None |
bcostm | 0:d83f1c8ca282 | 475 | */ |
bcostm | 0:d83f1c8ca282 | 476 | __weak void BSP_TS_INT_MspDeInit(void) |
bcostm | 0:d83f1c8ca282 | 477 | { |
bcostm | 0:d83f1c8ca282 | 478 | GPIO_InitTypeDef gpio_init_structure; |
bcostm | 0:d83f1c8ca282 | 479 | |
bcostm | 0:d83f1c8ca282 | 480 | __HAL_RCC_PWR_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 481 | SET_BIT(PWR->CR2, PWR_CR2_IOSV); |
bcostm | 0:d83f1c8ca282 | 482 | |
bcostm | 0:d83f1c8ca282 | 483 | TS_INT_GPIO_CLK_ENABLE(); |
bcostm | 0:d83f1c8ca282 | 484 | |
bcostm | 0:d83f1c8ca282 | 485 | /* GPIO configuration in input for TouchScreen interrupt signal on TS_INT pin */ |
bcostm | 0:d83f1c8ca282 | 486 | gpio_init_structure.Pin = TS_INT_PIN; |
bcostm | 0:d83f1c8ca282 | 487 | |
bcostm | 0:d83f1c8ca282 | 488 | gpio_init_structure.Pin = GPIO_PIN_All; |
bcostm | 0:d83f1c8ca282 | 489 | gpio_init_structure.Mode = GPIO_MODE_ANALOG; |
bcostm | 0:d83f1c8ca282 | 490 | gpio_init_structure.Pull = GPIO_NOPULL; |
bcostm | 0:d83f1c8ca282 | 491 | HAL_GPIO_Init(TS_INT_GPIO_PORT, &gpio_init_structure); |
bcostm | 0:d83f1c8ca282 | 492 | |
bcostm | 0:d83f1c8ca282 | 493 | HAL_NVIC_DisableIRQ((IRQn_Type)(TS_INT_EXTI_IRQn)); |
bcostm | 0:d83f1c8ca282 | 494 | } |
bcostm | 0:d83f1c8ca282 | 495 | |
bcostm | 0:d83f1c8ca282 | 496 | |
bcostm | 0:d83f1c8ca282 | 497 | /** |
bcostm | 0:d83f1c8ca282 | 498 | * @} |
bcostm | 0:d83f1c8ca282 | 499 | */ |
bcostm | 0:d83f1c8ca282 | 500 | |
bcostm | 0:d83f1c8ca282 | 501 | /** |
bcostm | 0:d83f1c8ca282 | 502 | * @} |
bcostm | 0:d83f1c8ca282 | 503 | */ |
bcostm | 0:d83f1c8ca282 | 504 | |
bcostm | 0:d83f1c8ca282 | 505 | /** |
bcostm | 0:d83f1c8ca282 | 506 | * @} |
bcostm | 0:d83f1c8ca282 | 507 | */ |
bcostm | 0:d83f1c8ca282 | 508 | |
bcostm | 0:d83f1c8ca282 | 509 | /** |
bcostm | 0:d83f1c8ca282 | 510 | * @} |
bcostm | 0:d83f1c8ca282 | 511 | */ |
bcostm | 0:d83f1c8ca282 | 512 | |
bcostm | 0:d83f1c8ca282 | 513 | /** |
bcostm | 0:d83f1c8ca282 | 514 | * @} |
bcostm | 0:d83f1c8ca282 | 515 | */ |
bcostm | 0:d83f1c8ca282 | 516 | |
bcostm | 0:d83f1c8ca282 | 517 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |