Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BSP_DISCO_F469NI by
stm32469i_discovery/stm32469i_discovery_ts.c@1:9e4eb47092ed, 2016-05-30 (annotated)
- Committer:
 - bcostm
 - Date:
 - Mon May 30 11:09:05 2016 +0000
 - Revision:
 - 1:9e4eb47092ed
 - Parent:
 - 0:0002c86c2220
 
Fix issue with LCD in Portrait mode
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| bcostm | 0:0002c86c2220 | 1 | /** | 
| bcostm | 0:0002c86c2220 | 2 | ****************************************************************************** | 
| bcostm | 0:0002c86c2220 | 3 | * @file stm32469i_discovery_ts.c | 
| bcostm | 0:0002c86c2220 | 4 | * @author MCD Application Team | 
| bcostm | 0:0002c86c2220 | 5 | * @version V1.0.1 | 
| bcostm | 0:0002c86c2220 | 6 | * @date 29-September-2015 | 
| bcostm | 0:0002c86c2220 | 7 | * @brief This file provides a set of functions needed to manage the Touch | 
| bcostm | 0:0002c86c2220 | 8 | * Screen on STM32469I-Discovery board. | 
| bcostm | 0:0002c86c2220 | 9 | ****************************************************************************** | 
| bcostm | 0:0002c86c2220 | 10 | * @attention | 
| bcostm | 0:0002c86c2220 | 11 | * | 
| bcostm | 0:0002c86c2220 | 12 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> | 
| bcostm | 0:0002c86c2220 | 13 | * | 
| bcostm | 0:0002c86c2220 | 14 | * Redistribution and use in source and binary forms, with or without modification, | 
| bcostm | 0:0002c86c2220 | 15 | * are permitted provided that the following conditions are met: | 
| bcostm | 0:0002c86c2220 | 16 | * 1. Redistributions of source code must retain the above copyright notice, | 
| bcostm | 0:0002c86c2220 | 17 | * this list of conditions and the following disclaimer. | 
| bcostm | 0:0002c86c2220 | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, | 
| bcostm | 0:0002c86c2220 | 19 | * this list of conditions and the following disclaimer in the documentation | 
| bcostm | 0:0002c86c2220 | 20 | * and/or other materials provided with the distribution. | 
| bcostm | 0:0002c86c2220 | 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors | 
| bcostm | 0:0002c86c2220 | 22 | * may be used to endorse or promote products derived from this software | 
| bcostm | 0:0002c86c2220 | 23 | * without specific prior written permission. | 
| bcostm | 0:0002c86c2220 | 24 | * | 
| bcostm | 0:0002c86c2220 | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
| bcostm | 0:0002c86c2220 | 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
| bcostm | 0:0002c86c2220 | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
| bcostm | 0:0002c86c2220 | 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | 
| bcostm | 0:0002c86c2220 | 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
| bcostm | 0:0002c86c2220 | 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 
| bcostm | 0:0002c86c2220 | 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
| bcostm | 0:0002c86c2220 | 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
| bcostm | 0:0002c86c2220 | 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
| bcostm | 0:0002c86c2220 | 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
| bcostm | 0:0002c86c2220 | 35 | * | 
| bcostm | 0:0002c86c2220 | 36 | ****************************************************************************** | 
| bcostm | 0:0002c86c2220 | 37 | */ | 
| bcostm | 0:0002c86c2220 | 38 | |
| bcostm | 0:0002c86c2220 | 39 | /* File Info : ----------------------------------------------------------------- | 
| bcostm | 0:0002c86c2220 | 40 | User NOTES | 
| bcostm | 0:0002c86c2220 | 41 | 1. How To use this driver: | 
| bcostm | 0:0002c86c2220 | 42 | -------------------------- | 
| bcostm | 0:0002c86c2220 | 43 | - This driver is used to drive the touch screen module of the STM32469I-Discovery | 
| bcostm | 0:0002c86c2220 | 44 | board on the K.O.D Optica Technology 480x800 TFT-LCD mounted on | 
| bcostm | 0:0002c86c2220 | 45 | MB1189 board. The touch screen driver IC inside the K.O.D module KM-040TMP-02 | 
| bcostm | 0:0002c86c2220 | 46 | is a FT6206 by Focal Tech. | 
| bcostm | 0:0002c86c2220 | 47 | |
| bcostm | 0:0002c86c2220 | 48 | 2. Driver description: | 
| bcostm | 0:0002c86c2220 | 49 | --------------------- | 
| bcostm | 0:0002c86c2220 | 50 | + Initialization steps: | 
| bcostm | 0:0002c86c2220 | 51 | o Initialize the TS module using the BSP_TS_Init() function. This | 
| bcostm | 0:0002c86c2220 | 52 | function includes the MSP layer hardware resources initialization and the | 
| bcostm | 0:0002c86c2220 | 53 | communication layer configuration to start the TS use. The LCD size properties | 
| bcostm | 0:0002c86c2220 | 54 | (x and y) are passed as parameters. | 
| bcostm | 0:0002c86c2220 | 55 | o If TS interrupt mode is desired, you must configure the TS interrupt mode | 
| bcostm | 0:0002c86c2220 | 56 | by calling the function BSP_TS_ITConfig(). The TS interrupt mode is generated | 
| bcostm | 0:0002c86c2220 | 57 | as an external interrupt whenever a touch is detected. | 
| bcostm | 0:0002c86c2220 | 58 | The interrupt mode internally uses the IO functionalities driver driven by | 
| bcostm | 0:0002c86c2220 | 59 | the IO expander, to configure the IT line. | 
| bcostm | 0:0002c86c2220 | 60 | |
| bcostm | 0:0002c86c2220 | 61 | + Touch screen use | 
| bcostm | 0:0002c86c2220 | 62 | o The touch screen state is captured whenever the function BSP_TS_GetState() is | 
| bcostm | 0:0002c86c2220 | 63 | used. This function returns information about the last LCD touch occurred | 
| bcostm | 0:0002c86c2220 | 64 | in the TS_StateTypeDef structure. | 
| bcostm | 0:0002c86c2220 | 65 | o If TS interrupt mode is used, the function BSP_TS_ITGetStatus() is needed to get | 
| bcostm | 0:0002c86c2220 | 66 | the interrupt status. To clear the IT pending bits, you should call the | 
| bcostm | 0:0002c86c2220 | 67 | function BSP_TS_ITClear(). | 
| bcostm | 0:0002c86c2220 | 68 | o The IT is handled using the corresponding external interrupt IRQ handler, | 
| bcostm | 0:0002c86c2220 | 69 | the user IT callback treatment is implemented on the same external interrupt | 
| bcostm | 0:0002c86c2220 | 70 | callback. | 
| bcostm | 0:0002c86c2220 | 71 | |
| bcostm | 0:0002c86c2220 | 72 | ------------------------------------------------------------------------------*/ | 
| bcostm | 0:0002c86c2220 | 73 | |
| bcostm | 0:0002c86c2220 | 74 | /* Includes ------------------------------------------------------------------*/ | 
| bcostm | 0:0002c86c2220 | 75 | #include "stm32469i_discovery_ts.h" | 
| bcostm | 0:0002c86c2220 | 76 | |
| bcostm | 0:0002c86c2220 | 77 | /** @addtogroup BSP | 
| bcostm | 0:0002c86c2220 | 78 | * @{ | 
| bcostm | 0:0002c86c2220 | 79 | */ | 
| bcostm | 0:0002c86c2220 | 80 | |
| bcostm | 0:0002c86c2220 | 81 | /** @addtogroup STM32469I-Discovery | 
| bcostm | 0:0002c86c2220 | 82 | * @{ | 
| bcostm | 0:0002c86c2220 | 83 | */ | 
| bcostm | 0:0002c86c2220 | 84 | |
| bcostm | 0:0002c86c2220 | 85 | /** @defgroup STM32469I-Discovery_TS STM32469I-Discovery TS | 
| bcostm | 0:0002c86c2220 | 86 | * @{ | 
| bcostm | 0:0002c86c2220 | 87 | */ | 
| bcostm | 0:0002c86c2220 | 88 | |
| bcostm | 0:0002c86c2220 | 89 | /** @defgroup STM32469I-Discovery_TS_Private_Types_Definitions TS Private Types Definitions | 
| bcostm | 0:0002c86c2220 | 90 | * @{ | 
| bcostm | 0:0002c86c2220 | 91 | */ | 
| bcostm | 0:0002c86c2220 | 92 | /** | 
| bcostm | 0:0002c86c2220 | 93 | * @} | 
| bcostm | 0:0002c86c2220 | 94 | */ | 
| bcostm | 0:0002c86c2220 | 95 | |
| bcostm | 0:0002c86c2220 | 96 | /** @defgroup STM32469I-Discovery_TS_Private_Defines TS Private Types Defines | 
| bcostm | 0:0002c86c2220 | 97 | * @{ | 
| bcostm | 0:0002c86c2220 | 98 | */ | 
| bcostm | 0:0002c86c2220 | 99 | /** | 
| bcostm | 0:0002c86c2220 | 100 | * @} | 
| bcostm | 0:0002c86c2220 | 101 | */ | 
| bcostm | 0:0002c86c2220 | 102 | |
| bcostm | 0:0002c86c2220 | 103 | /** @defgroup STM32469I-Discovery_TS_Private_Macros TS Private Macros | 
| bcostm | 0:0002c86c2220 | 104 | * @{ | 
| bcostm | 0:0002c86c2220 | 105 | */ | 
| bcostm | 0:0002c86c2220 | 106 | /** | 
| bcostm | 0:0002c86c2220 | 107 | * @} | 
| bcostm | 0:0002c86c2220 | 108 | */ | 
| bcostm | 0:0002c86c2220 | 109 | |
| bcostm | 0:0002c86c2220 | 110 | /** @defgroup STM32469I-Discovery_TS_Imported_Variables TS Imported Variables | 
| bcostm | 0:0002c86c2220 | 111 | * @{ | 
| bcostm | 0:0002c86c2220 | 112 | */ | 
| bcostm | 0:0002c86c2220 | 113 | /** | 
| bcostm | 0:0002c86c2220 | 114 | * @} | 
| bcostm | 0:0002c86c2220 | 115 | */ | 
| bcostm | 0:0002c86c2220 | 116 | |
| bcostm | 0:0002c86c2220 | 117 | /** @defgroup STM32469I-Discovery_TS_Private_Variables TS Private Variables | 
| bcostm | 0:0002c86c2220 | 118 | * @{ | 
| bcostm | 0:0002c86c2220 | 119 | */ | 
| bcostm | 0:0002c86c2220 | 120 | static TS_DrvTypeDef *ts_driver; | 
| bcostm | 0:0002c86c2220 | 121 | static uint8_t ts_orientation; | 
| bcostm | 0:0002c86c2220 | 122 | static uint8_t I2C_Address = 0; | 
| bcostm | 0:0002c86c2220 | 123 | |
| bcostm | 0:0002c86c2220 | 124 | /* Table for touchscreen event information display on LCD : table indexed on enum @ref TS_TouchEventTypeDef information */ | 
| bcostm | 0:0002c86c2220 | 125 | char * ts_event_string_tab[TOUCH_EVENT_NB_MAX] = { "None", | 
| bcostm | 0:0002c86c2220 | 126 | "Press down", | 
| bcostm | 0:0002c86c2220 | 127 | "Lift up", | 
| bcostm | 0:0002c86c2220 | 128 | "Contact" | 
| bcostm | 0:0002c86c2220 | 129 | }; | 
| bcostm | 0:0002c86c2220 | 130 | |
| bcostm | 0:0002c86c2220 | 131 | /* Table for touchscreen gesture Id information display on LCD : table indexed on enum @ref TS_GestureIdTypeDef information */ | 
| bcostm | 0:0002c86c2220 | 132 | char * ts_gesture_id_string_tab[GEST_ID_NB_MAX] = { "None", | 
| bcostm | 0:0002c86c2220 | 133 | "Move Up", | 
| bcostm | 0:0002c86c2220 | 134 | "Move Right", | 
| bcostm | 0:0002c86c2220 | 135 | "Move Down", | 
| bcostm | 0:0002c86c2220 | 136 | "Move Left", | 
| bcostm | 0:0002c86c2220 | 137 | "Zoom In", | 
| bcostm | 0:0002c86c2220 | 138 | "Zoom Out" | 
| bcostm | 0:0002c86c2220 | 139 | }; | 
| bcostm | 0:0002c86c2220 | 140 | |
| bcostm | 0:0002c86c2220 | 141 | /** | 
| bcostm | 0:0002c86c2220 | 142 | * @} | 
| bcostm | 0:0002c86c2220 | 143 | */ | 
| bcostm | 0:0002c86c2220 | 144 | |
| bcostm | 0:0002c86c2220 | 145 | /** @defgroup STM32469I-Discovery_TS_Private_Function_Prototypes TS Private Function Prototypes | 
| bcostm | 0:0002c86c2220 | 146 | * @{ | 
| bcostm | 0:0002c86c2220 | 147 | */ | 
| bcostm | 0:0002c86c2220 | 148 | |
| bcostm | 0:0002c86c2220 | 149 | /** | 
| bcostm | 0:0002c86c2220 | 150 | * @} | 
| bcostm | 0:0002c86c2220 | 151 | */ | 
| bcostm | 0:0002c86c2220 | 152 | |
| bcostm | 0:0002c86c2220 | 153 | /** @defgroup STM32469I-Discovery_TS_Public_Functions TS Public Functions | 
| bcostm | 0:0002c86c2220 | 154 | * @{ | 
| bcostm | 0:0002c86c2220 | 155 | */ | 
| bcostm | 0:0002c86c2220 | 156 | |
| bcostm | 0:0002c86c2220 | 157 | /** | 
| bcostm | 0:0002c86c2220 | 158 | * @brief Initializes and configures the touch screen functionalities and | 
| bcostm | 0:0002c86c2220 | 159 | * configures all necessary hardware resources (GPIOs, I2C, clocks..). | 
| bcostm | 0:0002c86c2220 | 160 | * @param ts_SizeX : Maximum X size of the TS area on LCD | 
| bcostm | 0:0002c86c2220 | 161 | * @param ts_SizeY : Maximum Y size of the TS area on LCD | 
| bcostm | 0:0002c86c2220 | 162 | * @retval TS_OK if all initializations are OK. Other value if error. | 
| bcostm | 0:0002c86c2220 | 163 | */ | 
| bcostm | 0:0002c86c2220 | 164 | uint8_t BSP_TS_Init(uint16_t ts_SizeX, uint16_t ts_SizeY) | 
| bcostm | 0:0002c86c2220 | 165 | { | 
| bcostm | 0:0002c86c2220 | 166 | uint8_t ts_status = TS_OK; | 
| bcostm | 0:0002c86c2220 | 167 | |
| bcostm | 0:0002c86c2220 | 168 | /* Note : I2C_Address is un-initialized here, but is not used at all in init function */ | 
| bcostm | 0:0002c86c2220 | 169 | /* but the prototype of Init() is like that in template and should be respected */ | 
| bcostm | 0:0002c86c2220 | 170 | |
| bcostm | 0:0002c86c2220 | 171 | /* Initialize the communication channel to sensor (I2C) if necessary */ | 
| bcostm | 0:0002c86c2220 | 172 | /* that is initialization is done only once after a power up */ | 
| bcostm | 0:0002c86c2220 | 173 | ft6x06_ts_drv.Init(I2C_Address); | 
| bcostm | 0:0002c86c2220 | 174 | |
| bcostm | 0:0002c86c2220 | 175 | /* Scan FT6x06 TouchScreen IC controller ID register by I2C Read */ | 
| bcostm | 0:0002c86c2220 | 176 | /* Verify this is a FT6x06, otherwise this is an error case */ | 
| bcostm | 0:0002c86c2220 | 177 | if(ft6x06_ts_drv.ReadID(TS_I2C_ADDRESS) == FT6206_ID_VALUE) | 
| bcostm | 0:0002c86c2220 | 178 | { | 
| bcostm | 0:0002c86c2220 | 179 | /* Found FT6206 : Initialize the TS driver structure */ | 
| bcostm | 0:0002c86c2220 | 180 | ts_driver = &ft6x06_ts_drv; | 
| bcostm | 0:0002c86c2220 | 181 | |
| bcostm | 0:0002c86c2220 | 182 | I2C_Address = TS_I2C_ADDRESS; | 
| bcostm | 0:0002c86c2220 | 183 | |
| bcostm | 0:0002c86c2220 | 184 | /* Get LCD chosen orientation */ | 
| bcostm | 0:0002c86c2220 | 185 | if(ts_SizeX < ts_SizeY) | 
| bcostm | 0:0002c86c2220 | 186 | { | 
| bcostm | 0:0002c86c2220 | 187 | ts_orientation = TS_SWAP_NONE; | 
| bcostm | 0:0002c86c2220 | 188 | } | 
| bcostm | 0:0002c86c2220 | 189 | else | 
| bcostm | 0:0002c86c2220 | 190 | { | 
| bcostm | 0:0002c86c2220 | 191 | ts_orientation = TS_SWAP_XY | TS_SWAP_Y; | 
| bcostm | 0:0002c86c2220 | 192 | } | 
| bcostm | 0:0002c86c2220 | 193 | |
| bcostm | 0:0002c86c2220 | 194 | if(ts_status == TS_OK) | 
| bcostm | 0:0002c86c2220 | 195 | { | 
| bcostm | 0:0002c86c2220 | 196 | /* Software reset the TouchScreen */ | 
| bcostm | 0:0002c86c2220 | 197 | ts_driver->Reset(I2C_Address); | 
| bcostm | 0:0002c86c2220 | 198 | |
| bcostm | 0:0002c86c2220 | 199 | /* Calibrate, Configure and Start the TouchScreen driver */ | 
| bcostm | 0:0002c86c2220 | 200 | ts_driver->Start(I2C_Address); | 
| bcostm | 0:0002c86c2220 | 201 | |
| bcostm | 0:0002c86c2220 | 202 | } /* of if(ts_status == TS_OK) */ | 
| bcostm | 0:0002c86c2220 | 203 | } | 
| bcostm | 0:0002c86c2220 | 204 | else | 
| bcostm | 0:0002c86c2220 | 205 | { | 
| bcostm | 0:0002c86c2220 | 206 | ts_status = TS_DEVICE_NOT_FOUND; | 
| bcostm | 0:0002c86c2220 | 207 | } | 
| bcostm | 0:0002c86c2220 | 208 | |
| bcostm | 0:0002c86c2220 | 209 | return (ts_status); | 
| bcostm | 0:0002c86c2220 | 210 | } | 
| bcostm | 0:0002c86c2220 | 211 | |
| bcostm | 0:0002c86c2220 | 212 | /** | 
| bcostm | 0:0002c86c2220 | 213 | * @brief Configures and enables the touch screen interrupts both at GPIO level and | 
| bcostm | 0:0002c86c2220 | 214 | * in TouchScreen IC driver configuration. | 
| bcostm | 0:0002c86c2220 | 215 | * @retval TS_OK if all initializations are OK. | 
| bcostm | 0:0002c86c2220 | 216 | */ | 
| bcostm | 0:0002c86c2220 | 217 | uint8_t BSP_TS_ITConfig(void) | 
| bcostm | 0:0002c86c2220 | 218 | { | 
| bcostm | 0:0002c86c2220 | 219 | uint8_t ts_status = TS_OK; | 
| bcostm | 0:0002c86c2220 | 220 | GPIO_InitTypeDef gpio_init_structure; | 
| bcostm | 0:0002c86c2220 | 221 | |
| bcostm | 0:0002c86c2220 | 222 | /* Msp Init of GPIO used for TS_INT pin coming from TouchScreen driver IC FT6x06 */ | 
| bcostm | 0:0002c86c2220 | 223 | /* When touchscreen is operated in interrupt mode */ | 
| bcostm | 0:0002c86c2220 | 224 | BSP_TS_INT_MspInit(); | 
| bcostm | 0:0002c86c2220 | 225 | |
| bcostm | 0:0002c86c2220 | 226 | /* Configure Interrupt mode for TS_INT pin falling edge : when a new touch is available */ | 
| bcostm | 0:0002c86c2220 | 227 | /* TS_INT pin is active on low level on new touch available */ | 
| bcostm | 0:0002c86c2220 | 228 | gpio_init_structure.Pin = TS_INT_PIN; | 
| bcostm | 0:0002c86c2220 | 229 | gpio_init_structure.Pull = GPIO_PULLUP; | 
| bcostm | 0:0002c86c2220 | 230 | gpio_init_structure.Speed = GPIO_SPEED_FAST; | 
| bcostm | 0:0002c86c2220 | 231 | gpio_init_structure.Mode = GPIO_MODE_IT_FALLING; | 
| bcostm | 0:0002c86c2220 | 232 | HAL_GPIO_Init(TS_INT_GPIO_PORT, &gpio_init_structure); | 
| bcostm | 0:0002c86c2220 | 233 | |
| bcostm | 0:0002c86c2220 | 234 | /* Enable and set the TS_INT EXTI Interrupt to an intermediate priority */ | 
| bcostm | 0:0002c86c2220 | 235 | HAL_NVIC_SetPriority((IRQn_Type)(TS_INT_EXTI_IRQn), 0x05, 0x00); | 
| bcostm | 0:0002c86c2220 | 236 | HAL_NVIC_EnableIRQ((IRQn_Type)(TS_INT_EXTI_IRQn)); | 
| bcostm | 0:0002c86c2220 | 237 | |
| bcostm | 0:0002c86c2220 | 238 | /* Enable the TS in interrupt mode */ | 
| bcostm | 0:0002c86c2220 | 239 | /* In that case the INT output of FT6206 when new touch is available */ | 
| bcostm | 0:0002c86c2220 | 240 | /* is active on low level and directed on EXTI */ | 
| bcostm | 0:0002c86c2220 | 241 | ts_driver->EnableIT(I2C_Address); | 
| bcostm | 0:0002c86c2220 | 242 | |
| bcostm | 0:0002c86c2220 | 243 | return (ts_status); | 
| bcostm | 0:0002c86c2220 | 244 | } | 
| bcostm | 0:0002c86c2220 | 245 | |
| bcostm | 0:0002c86c2220 | 246 | /** | 
| bcostm | 0:0002c86c2220 | 247 | * @brief Returns status and positions of the touch screen. | 
| bcostm | 0:0002c86c2220 | 248 | * @param TS_State: Pointer to touch screen current state structure | 
| bcostm | 0:0002c86c2220 | 249 | * @retval TS_OK if all initializations are OK. Other value if error. | 
| bcostm | 0:0002c86c2220 | 250 | */ | 
| bcostm | 0:0002c86c2220 | 251 | uint8_t BSP_TS_GetState(TS_StateTypeDef *TS_State) | 
| bcostm | 0:0002c86c2220 | 252 | { | 
| bcostm | 0:0002c86c2220 | 253 | static uint32_t _x[TS_MAX_NB_TOUCH] = {0, 0}; | 
| bcostm | 0:0002c86c2220 | 254 | static uint32_t _y[TS_MAX_NB_TOUCH] = {0, 0}; | 
| bcostm | 0:0002c86c2220 | 255 | uint8_t ts_status = TS_OK; | 
| bcostm | 0:0002c86c2220 | 256 | uint16_t tmp; | 
| bcostm | 0:0002c86c2220 | 257 | uint16_t Raw_x[TS_MAX_NB_TOUCH]; | 
| bcostm | 0:0002c86c2220 | 258 | uint16_t Raw_y[TS_MAX_NB_TOUCH]; | 
| bcostm | 0:0002c86c2220 | 259 | uint16_t xDiff; | 
| bcostm | 0:0002c86c2220 | 260 | uint16_t yDiff; | 
| bcostm | 0:0002c86c2220 | 261 | uint32_t index; | 
| bcostm | 0:0002c86c2220 | 262 | #if (TS_MULTI_TOUCH_SUPPORTED == 1) | 
| bcostm | 0:0002c86c2220 | 263 | uint32_t weight = 0; | 
| bcostm | 0:0002c86c2220 | 264 | uint32_t area = 0; | 
| bcostm | 0:0002c86c2220 | 265 | uint32_t event = 0; | 
| bcostm | 0:0002c86c2220 | 266 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ | 
| bcostm | 0:0002c86c2220 | 267 | |
| bcostm | 0:0002c86c2220 | 268 | /* Check and update the number of touches active detected */ | 
| bcostm | 0:0002c86c2220 | 269 | TS_State->touchDetected = ts_driver->DetectTouch(I2C_Address); | 
| bcostm | 0:0002c86c2220 | 270 | if(TS_State->touchDetected) | 
| bcostm | 0:0002c86c2220 | 271 | { | 
| bcostm | 0:0002c86c2220 | 272 | for(index=0; index < TS_State->touchDetected; index++) | 
| bcostm | 0:0002c86c2220 | 273 | { | 
| bcostm | 0:0002c86c2220 | 274 | /* Get each touch coordinates */ | 
| bcostm | 0:0002c86c2220 | 275 | ts_driver->GetXY(I2C_Address, &(Raw_x[index]), &(Raw_y[index])); | 
| bcostm | 0:0002c86c2220 | 276 | |
| bcostm | 0:0002c86c2220 | 277 | if(ts_orientation & TS_SWAP_XY) | 
| bcostm | 0:0002c86c2220 | 278 | { | 
| bcostm | 0:0002c86c2220 | 279 | tmp = Raw_x[index]; | 
| bcostm | 0:0002c86c2220 | 280 | Raw_x[index] = Raw_y[index]; | 
| bcostm | 0:0002c86c2220 | 281 | Raw_y[index] = tmp; | 
| bcostm | 0:0002c86c2220 | 282 | } | 
| bcostm | 0:0002c86c2220 | 283 | |
| bcostm | 0:0002c86c2220 | 284 | if(ts_orientation & TS_SWAP_X) | 
| bcostm | 0:0002c86c2220 | 285 | { | 
| bcostm | 0:0002c86c2220 | 286 | Raw_x[index] = FT_6206_MAX_WIDTH - 1 - Raw_x[index]; | 
| bcostm | 0:0002c86c2220 | 287 | } | 
| bcostm | 0:0002c86c2220 | 288 | |
| bcostm | 0:0002c86c2220 | 289 | if(ts_orientation & TS_SWAP_Y) | 
| bcostm | 0:0002c86c2220 | 290 | { | 
| bcostm | 0:0002c86c2220 | 291 | Raw_y[index] = FT_6206_MAX_HEIGHT - 1 - Raw_y[index]; | 
| bcostm | 0:0002c86c2220 | 292 | } | 
| bcostm | 0:0002c86c2220 | 293 | |
| bcostm | 0:0002c86c2220 | 294 | xDiff = Raw_x[index] > _x[index]? (Raw_x[index] - _x[index]): (_x[index] - Raw_x[index]); | 
| bcostm | 0:0002c86c2220 | 295 | yDiff = Raw_y[index] > _y[index]? (Raw_y[index] - _y[index]): (_y[index] - Raw_y[index]); | 
| bcostm | 0:0002c86c2220 | 296 | |
| bcostm | 0:0002c86c2220 | 297 | if ((xDiff + yDiff) > 5) | 
| bcostm | 0:0002c86c2220 | 298 | { | 
| bcostm | 0:0002c86c2220 | 299 | _x[index] = Raw_x[index]; | 
| bcostm | 0:0002c86c2220 | 300 | _y[index] = Raw_y[index]; | 
| bcostm | 0:0002c86c2220 | 301 | } | 
| bcostm | 0:0002c86c2220 | 302 | |
| bcostm | 0:0002c86c2220 | 303 | |
| bcostm | 0:0002c86c2220 | 304 | TS_State->touchX[index] = _x[index]; | 
| bcostm | 0:0002c86c2220 | 305 | TS_State->touchY[index] = _y[index]; | 
| bcostm | 0:0002c86c2220 | 306 | |
| bcostm | 0:0002c86c2220 | 307 | #if (TS_MULTI_TOUCH_SUPPORTED == 1) | 
| bcostm | 0:0002c86c2220 | 308 | |
| bcostm | 0:0002c86c2220 | 309 | /* Get touch info related to the current touch */ | 
| bcostm | 0:0002c86c2220 | 310 | ft6x06_TS_GetTouchInfo(I2C_Address, index, &weight, &area, &event); | 
| bcostm | 0:0002c86c2220 | 311 | |
| bcostm | 0:0002c86c2220 | 312 | /* Update TS_State structure */ | 
| bcostm | 0:0002c86c2220 | 313 | TS_State->touchWeight[index] = weight; | 
| bcostm | 0:0002c86c2220 | 314 | TS_State->touchArea[index] = area; | 
| bcostm | 0:0002c86c2220 | 315 | |
| bcostm | 0:0002c86c2220 | 316 | /* Remap touch event */ | 
| bcostm | 0:0002c86c2220 | 317 | switch(event) | 
| bcostm | 0:0002c86c2220 | 318 | { | 
| bcostm | 0:0002c86c2220 | 319 | case FT6206_TOUCH_EVT_FLAG_PRESS_DOWN : | 
| bcostm | 0:0002c86c2220 | 320 | TS_State->touchEventId[index] = TOUCH_EVENT_PRESS_DOWN; | 
| bcostm | 0:0002c86c2220 | 321 | break; | 
| bcostm | 0:0002c86c2220 | 322 | case FT6206_TOUCH_EVT_FLAG_LIFT_UP : | 
| bcostm | 0:0002c86c2220 | 323 | TS_State->touchEventId[index] = TOUCH_EVENT_LIFT_UP; | 
| bcostm | 0:0002c86c2220 | 324 | break; | 
| bcostm | 0:0002c86c2220 | 325 | case FT6206_TOUCH_EVT_FLAG_CONTACT : | 
| bcostm | 0:0002c86c2220 | 326 | TS_State->touchEventId[index] = TOUCH_EVENT_CONTACT; | 
| bcostm | 0:0002c86c2220 | 327 | break; | 
| bcostm | 0:0002c86c2220 | 328 | case FT6206_TOUCH_EVT_FLAG_NO_EVENT : | 
| bcostm | 0:0002c86c2220 | 329 | TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT; | 
| bcostm | 0:0002c86c2220 | 330 | break; | 
| bcostm | 0:0002c86c2220 | 331 | default : | 
| bcostm | 0:0002c86c2220 | 332 | ts_status = TS_ERROR; | 
| bcostm | 0:0002c86c2220 | 333 | break; | 
| bcostm | 0:0002c86c2220 | 334 | } /* of switch(event) */ | 
| bcostm | 0:0002c86c2220 | 335 | |
| bcostm | 0:0002c86c2220 | 336 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ | 
| bcostm | 0:0002c86c2220 | 337 | |
| bcostm | 0:0002c86c2220 | 338 | } /* of for(index=0; index < TS_State->touchDetected; index++) */ | 
| bcostm | 0:0002c86c2220 | 339 | |
| bcostm | 0:0002c86c2220 | 340 | #if (TS_MULTI_TOUCH_SUPPORTED == 1) | 
| bcostm | 0:0002c86c2220 | 341 | /* Get gesture Id */ | 
| bcostm | 0:0002c86c2220 | 342 | ts_status = BSP_TS_Get_GestureId(TS_State); | 
| bcostm | 0:0002c86c2220 | 343 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ | 
| bcostm | 0:0002c86c2220 | 344 | |
| bcostm | 0:0002c86c2220 | 345 | } /* end of if(TS_State->touchDetected != 0) */ | 
| bcostm | 0:0002c86c2220 | 346 | |
| bcostm | 0:0002c86c2220 | 347 | return (ts_status); | 
| bcostm | 0:0002c86c2220 | 348 | } | 
| bcostm | 0:0002c86c2220 | 349 | |
| bcostm | 0:0002c86c2220 | 350 | #if (TS_MULTI_TOUCH_SUPPORTED == 1) | 
| bcostm | 0:0002c86c2220 | 351 | /** | 
| bcostm | 0:0002c86c2220 | 352 | * @brief Update gesture Id following a touch detected. | 
| bcostm | 0:0002c86c2220 | 353 | * @param TS_State: Pointer to touch screen current state structure | 
| bcostm | 0:0002c86c2220 | 354 | * @retval TS_OK if all initializations are OK. Other value if error. | 
| bcostm | 0:0002c86c2220 | 355 | */ | 
| bcostm | 0:0002c86c2220 | 356 | uint8_t BSP_TS_Get_GestureId(TS_StateTypeDef *TS_State) | 
| bcostm | 0:0002c86c2220 | 357 | { | 
| bcostm | 0:0002c86c2220 | 358 | uint32_t gestureId = 0; | 
| bcostm | 0:0002c86c2220 | 359 | uint8_t ts_status = TS_OK; | 
| bcostm | 0:0002c86c2220 | 360 | |
| bcostm | 0:0002c86c2220 | 361 | /* Get gesture Id */ | 
| bcostm | 0:0002c86c2220 | 362 | ft6x06_TS_GetGestureID(I2C_Address, &gestureId); | 
| bcostm | 0:0002c86c2220 | 363 | |
| bcostm | 0:0002c86c2220 | 364 | /* Remap gesture Id to a TS_GestureIdTypeDef value */ | 
| bcostm | 0:0002c86c2220 | 365 | switch(gestureId) | 
| bcostm | 0:0002c86c2220 | 366 | { | 
| bcostm | 0:0002c86c2220 | 367 | case FT6206_GEST_ID_NO_GESTURE : | 
| bcostm | 0:0002c86c2220 | 368 | TS_State->gestureId = GEST_ID_NO_GESTURE; | 
| bcostm | 0:0002c86c2220 | 369 | break; | 
| bcostm | 0:0002c86c2220 | 370 | case FT6206_GEST_ID_MOVE_UP : | 
| bcostm | 0:0002c86c2220 | 371 | TS_State->gestureId = GEST_ID_MOVE_UP; | 
| bcostm | 0:0002c86c2220 | 372 | break; | 
| bcostm | 0:0002c86c2220 | 373 | case FT6206_GEST_ID_MOVE_RIGHT : | 
| bcostm | 0:0002c86c2220 | 374 | TS_State->gestureId = GEST_ID_MOVE_RIGHT; | 
| bcostm | 0:0002c86c2220 | 375 | break; | 
| bcostm | 0:0002c86c2220 | 376 | case FT6206_GEST_ID_MOVE_DOWN : | 
| bcostm | 0:0002c86c2220 | 377 | TS_State->gestureId = GEST_ID_MOVE_DOWN; | 
| bcostm | 0:0002c86c2220 | 378 | break; | 
| bcostm | 0:0002c86c2220 | 379 | case FT6206_GEST_ID_MOVE_LEFT : | 
| bcostm | 0:0002c86c2220 | 380 | TS_State->gestureId = GEST_ID_MOVE_LEFT; | 
| bcostm | 0:0002c86c2220 | 381 | break; | 
| bcostm | 0:0002c86c2220 | 382 | case FT6206_GEST_ID_ZOOM_IN : | 
| bcostm | 0:0002c86c2220 | 383 | TS_State->gestureId = GEST_ID_ZOOM_IN; | 
| bcostm | 0:0002c86c2220 | 384 | break; | 
| bcostm | 0:0002c86c2220 | 385 | case FT6206_GEST_ID_ZOOM_OUT : | 
| bcostm | 0:0002c86c2220 | 386 | TS_State->gestureId = GEST_ID_ZOOM_OUT; | 
| bcostm | 0:0002c86c2220 | 387 | break; | 
| bcostm | 0:0002c86c2220 | 388 | default : | 
| bcostm | 0:0002c86c2220 | 389 | ts_status = TS_ERROR; | 
| bcostm | 0:0002c86c2220 | 390 | break; | 
| bcostm | 0:0002c86c2220 | 391 | } /* of switch(gestureId) */ | 
| bcostm | 0:0002c86c2220 | 392 | |
| bcostm | 0:0002c86c2220 | 393 | return(ts_status); | 
| bcostm | 0:0002c86c2220 | 394 | } | 
| bcostm | 0:0002c86c2220 | 395 | |
| bcostm | 0:0002c86c2220 | 396 | |
| bcostm | 0:0002c86c2220 | 397 | /** @defgroup STM32469I-Discovery_TS_Private_Functions TS Private Functions | 
| bcostm | 0:0002c86c2220 | 398 | * @{ | 
| bcostm | 0:0002c86c2220 | 399 | */ | 
| bcostm | 0:0002c86c2220 | 400 | |
| bcostm | 0:0002c86c2220 | 401 | |
| bcostm | 0:0002c86c2220 | 402 | /** | 
| bcostm | 0:0002c86c2220 | 403 | * @brief Function used to reset all touch data before a new acquisition | 
| bcostm | 0:0002c86c2220 | 404 | * of touch information. | 
| bcostm | 0:0002c86c2220 | 405 | * @param TS_State: Pointer to touch screen current state structure | 
| bcostm | 0:0002c86c2220 | 406 | * @retval TS_OK if OK, TE_ERROR if problem found. | 
| bcostm | 0:0002c86c2220 | 407 | */ | 
| bcostm | 0:0002c86c2220 | 408 | uint8_t BSP_TS_ResetTouchData(TS_StateTypeDef *TS_State) | 
| bcostm | 0:0002c86c2220 | 409 | { | 
| bcostm | 0:0002c86c2220 | 410 | uint8_t ts_status = TS_ERROR; | 
| bcostm | 0:0002c86c2220 | 411 | uint32_t index; | 
| bcostm | 0:0002c86c2220 | 412 | |
| bcostm | 0:0002c86c2220 | 413 | if (TS_State != (TS_StateTypeDef *)NULL) | 
| bcostm | 0:0002c86c2220 | 414 | { | 
| bcostm | 0:0002c86c2220 | 415 | TS_State->gestureId = GEST_ID_NO_GESTURE; | 
| bcostm | 0:0002c86c2220 | 416 | TS_State->touchDetected = 0; | 
| bcostm | 0:0002c86c2220 | 417 | |
| bcostm | 0:0002c86c2220 | 418 | for(index = 0; index < TS_MAX_NB_TOUCH; index++) | 
| bcostm | 0:0002c86c2220 | 419 | { | 
| bcostm | 0:0002c86c2220 | 420 | TS_State->touchX[index] = 0; | 
| bcostm | 0:0002c86c2220 | 421 | TS_State->touchY[index] = 0; | 
| bcostm | 0:0002c86c2220 | 422 | TS_State->touchArea[index] = 0; | 
| bcostm | 0:0002c86c2220 | 423 | TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT; | 
| bcostm | 0:0002c86c2220 | 424 | TS_State->touchWeight[index] = 0; | 
| bcostm | 0:0002c86c2220 | 425 | } | 
| bcostm | 0:0002c86c2220 | 426 | |
| bcostm | 0:0002c86c2220 | 427 | ts_status = TS_OK; | 
| bcostm | 0:0002c86c2220 | 428 | |
| bcostm | 0:0002c86c2220 | 429 | } /* of if (TS_State != (TS_StateTypeDef *)NULL) */ | 
| bcostm | 0:0002c86c2220 | 430 | |
| bcostm | 0:0002c86c2220 | 431 | return (ts_status); | 
| bcostm | 0:0002c86c2220 | 432 | } | 
| bcostm | 0:0002c86c2220 | 433 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ | 
| bcostm | 0:0002c86c2220 | 434 | /** | 
| bcostm | 0:0002c86c2220 | 435 | * @brief Initializes the TS_INT pin MSP. | 
| bcostm | 0:0002c86c2220 | 436 | * @param None | 
| bcostm | 0:0002c86c2220 | 437 | * @retval None | 
| bcostm | 0:0002c86c2220 | 438 | */ | 
| bcostm | 0:0002c86c2220 | 439 | __weak void BSP_TS_INT_MspInit(void) | 
| bcostm | 0:0002c86c2220 | 440 | { | 
| bcostm | 0:0002c86c2220 | 441 | GPIO_InitTypeDef gpio_init_structure; | 
| bcostm | 0:0002c86c2220 | 442 | |
| bcostm | 0:0002c86c2220 | 443 | TS_INT_GPIO_CLK_ENABLE(); | 
| bcostm | 0:0002c86c2220 | 444 | |
| bcostm | 0:0002c86c2220 | 445 | /* GPIO configuration in input for TouchScreen interrupt signal on TS_INT pin */ | 
| bcostm | 0:0002c86c2220 | 446 | gpio_init_structure.Pin = TS_INT_PIN; | 
| bcostm | 0:0002c86c2220 | 447 | |
| bcostm | 0:0002c86c2220 | 448 | gpio_init_structure.Mode = GPIO_MODE_INPUT; | 
| bcostm | 0:0002c86c2220 | 449 | gpio_init_structure.Pull = GPIO_PULLUP; | 
| bcostm | 0:0002c86c2220 | 450 | gpio_init_structure.Speed = GPIO_SPEED_HIGH; | 
| bcostm | 0:0002c86c2220 | 451 | HAL_GPIO_Init(TS_INT_GPIO_PORT, &gpio_init_structure); | 
| bcostm | 0:0002c86c2220 | 452 | } | 
| bcostm | 0:0002c86c2220 | 453 | |
| bcostm | 0:0002c86c2220 | 454 | |
| bcostm | 0:0002c86c2220 | 455 | /** | 
| bcostm | 0:0002c86c2220 | 456 | * @} | 
| bcostm | 0:0002c86c2220 | 457 | */ | 
| bcostm | 0:0002c86c2220 | 458 | |
| bcostm | 0:0002c86c2220 | 459 | /** | 
| bcostm | 0:0002c86c2220 | 460 | * @} | 
| bcostm | 0:0002c86c2220 | 461 | */ | 
| bcostm | 0:0002c86c2220 | 462 | |
| bcostm | 0:0002c86c2220 | 463 | /** | 
| bcostm | 0:0002c86c2220 | 464 | * @} | 
| bcostm | 0:0002c86c2220 | 465 | */ | 
| bcostm | 0:0002c86c2220 | 466 | |
| bcostm | 0:0002c86c2220 | 467 | /** | 
| bcostm | 0:0002c86c2220 | 468 | * @} | 
| bcostm | 0:0002c86c2220 | 469 | */ | 
| bcostm | 0:0002c86c2220 | 470 | |
| bcostm | 0:0002c86c2220 | 471 | /** | 
| bcostm | 0:0002c86c2220 | 472 | * @} | 
| bcostm | 0:0002c86c2220 | 473 | */ | 
| bcostm | 0:0002c86c2220 | 474 | |
| bcostm | 0:0002c86c2220 | 475 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | 
