nguyen nam
/
BSP-DISCO_F746NG
Nam
Drivers/BSP/STM32746G-Discovery/stm32746g_discovery_ts.c@8:56384bddaba5, 2017-02-23 (annotated)
- Committer:
- Jerome Coutant
- Date:
- Thu Feb 23 14:14:09 2017 +0100
- Revision:
- 8:56384bddaba5
- Parent:
- 6:e1d9da7fe856
STM32Cube_FW_F7_V1.6.0 BSP_DISCO_F746NG
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 6:e1d9da7fe856 | 1 | /** |
bcostm | 6:e1d9da7fe856 | 2 | ****************************************************************************** |
bcostm | 6:e1d9da7fe856 | 3 | * @file stm32746g_discovery_ts.c |
bcostm | 6:e1d9da7fe856 | 4 | * @author MCD Application Team |
Jerome Coutant
8:56384bddaba5
|
5
|
* @version V2.0.0
|
|
Jerome Coutant
8:56384bddaba5
|
6
|
* @date 30-December-2016
|
|
bcostm | 6:e1d9da7fe856 | 7 | * @brief This file provides a set of functions needed to manage the Touch |
bcostm | 6:e1d9da7fe856 | 8 | * Screen on STM32746G-Discovery board. |
bcostm | 6:e1d9da7fe856 | 9 | @verbatim |
bcostm | 6:e1d9da7fe856 | 10 | 1. How To use this driver: |
bcostm | 6:e1d9da7fe856 | 11 | -------------------------- |
bcostm | 6:e1d9da7fe856 | 12 | - This driver is used to drive the touch screen module of the STM32746G-Discovery |
bcostm | 6:e1d9da7fe856 | 13 | board on the RK043FN48H-CT672B 480x272 LCD screen with capacitive touch screen. |
bcostm | 6:e1d9da7fe856 | 14 | - The FT5336 component driver must be included in project files according to |
bcostm | 6:e1d9da7fe856 | 15 | the touch screen driver present on this board. |
bcostm | 6:e1d9da7fe856 | 16 | |
bcostm | 6:e1d9da7fe856 | 17 | 2. Driver description: |
bcostm | 6:e1d9da7fe856 | 18 | --------------------- |
bcostm | 6:e1d9da7fe856 | 19 | + Initialization steps: |
bcostm | 6:e1d9da7fe856 | 20 | o Initialize the TS module using the BSP_TS_Init() function. This |
bcostm | 6:e1d9da7fe856 | 21 | function includes the MSP layer hardware resources initialization and the |
bcostm | 6:e1d9da7fe856 | 22 | communication layer configuration to start the TS use. The LCD size properties |
bcostm | 6:e1d9da7fe856 | 23 | (x and y) are passed as parameters. |
bcostm | 6:e1d9da7fe856 | 24 | o If TS interrupt mode is desired, you must configure the TS interrupt mode |
bcostm | 6:e1d9da7fe856 | 25 | by calling the function BSP_TS_ITConfig(). The TS interrupt mode is generated |
bcostm | 6:e1d9da7fe856 | 26 | as an external interrupt whenever a touch is detected. |
bcostm | 6:e1d9da7fe856 | 27 | The interrupt mode internally uses the IO functionalities driver driven by |
bcostm | 6:e1d9da7fe856 | 28 | the IO expander, to configure the IT line. |
bcostm | 6:e1d9da7fe856 | 29 | |
bcostm | 6:e1d9da7fe856 | 30 | + Touch screen use |
bcostm | 6:e1d9da7fe856 | 31 | o The touch screen state is captured whenever the function BSP_TS_GetState() is |
bcostm | 6:e1d9da7fe856 | 32 | used. This function returns information about the last LCD touch occurred |
bcostm | 6:e1d9da7fe856 | 33 | in the TS_StateTypeDef structure. |
bcostm | 6:e1d9da7fe856 | 34 | o If TS interrupt mode is used, the function BSP_TS_ITGetStatus() is needed to get |
bcostm | 6:e1d9da7fe856 | 35 | the interrupt status. To clear the IT pending bits, you should call the |
bcostm | 6:e1d9da7fe856 | 36 | function BSP_TS_ITClear(). |
bcostm | 6:e1d9da7fe856 | 37 | o The IT is handled using the corresponding external interrupt IRQ handler, |
bcostm | 6:e1d9da7fe856 | 38 | the user IT callback treatment is implemented on the same external interrupt |
bcostm | 6:e1d9da7fe856 | 39 | callback. |
bcostm | 6:e1d9da7fe856 | 40 | @endverbatim |
bcostm | 6:e1d9da7fe856 | 41 | ****************************************************************************** |
bcostm | 6:e1d9da7fe856 | 42 | * @attention |
bcostm | 6:e1d9da7fe856 | 43 | * |
bcostm | 6:e1d9da7fe856 | 44 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
bcostm | 6:e1d9da7fe856 | 45 | * |
bcostm | 6:e1d9da7fe856 | 46 | * Redistribution and use in source and binary forms, with or without modification, |
bcostm | 6:e1d9da7fe856 | 47 | * are permitted provided that the following conditions are met: |
bcostm | 6:e1d9da7fe856 | 48 | * 1. Redistributions of source code must retain the above copyright notice, |
bcostm | 6:e1d9da7fe856 | 49 | * this list of conditions and the following disclaimer. |
bcostm | 6:e1d9da7fe856 | 50 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
bcostm | 6:e1d9da7fe856 | 51 | * this list of conditions and the following disclaimer in the documentation |
bcostm | 6:e1d9da7fe856 | 52 | * and/or other materials provided with the distribution. |
bcostm | 6:e1d9da7fe856 | 53 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
bcostm | 6:e1d9da7fe856 | 54 | * may be used to endorse or promote products derived from this software |
bcostm | 6:e1d9da7fe856 | 55 | * without specific prior written permission. |
bcostm | 6:e1d9da7fe856 | 56 | * |
bcostm | 6:e1d9da7fe856 | 57 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
bcostm | 6:e1d9da7fe856 | 58 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
bcostm | 6:e1d9da7fe856 | 59 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
bcostm | 6:e1d9da7fe856 | 60 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
bcostm | 6:e1d9da7fe856 | 61 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
bcostm | 6:e1d9da7fe856 | 62 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
bcostm | 6:e1d9da7fe856 | 63 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
bcostm | 6:e1d9da7fe856 | 64 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
bcostm | 6:e1d9da7fe856 | 65 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
bcostm | 6:e1d9da7fe856 | 66 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
bcostm | 6:e1d9da7fe856 | 67 | * |
bcostm | 6:e1d9da7fe856 | 68 | ****************************************************************************** |
bcostm | 6:e1d9da7fe856 | 69 | */ |
bcostm | 6:e1d9da7fe856 | 70 | |
bcostm | 6:e1d9da7fe856 | 71 | /* Includes ------------------------------------------------------------------*/ |
bcostm | 6:e1d9da7fe856 | 72 | #include "stm32746g_discovery_ts.h" |
bcostm | 6:e1d9da7fe856 | 73 | |
bcostm | 6:e1d9da7fe856 | 74 | /** @addtogroup BSP |
bcostm | 6:e1d9da7fe856 | 75 | * @{ |
bcostm | 6:e1d9da7fe856 | 76 | */ |
bcostm | 6:e1d9da7fe856 | 77 | |
bcostm | 6:e1d9da7fe856 | 78 | /** @addtogroup STM32746G_DISCOVERY |
bcostm | 6:e1d9da7fe856 | 79 | * @{ |
bcostm | 6:e1d9da7fe856 | 80 | */ |
bcostm | 6:e1d9da7fe856 | 81 | |
bcostm | 6:e1d9da7fe856 | 82 | /** @defgroup STM32746G_DISCOVERY_TS STM32746G_DISCOVERY_TS |
bcostm | 6:e1d9da7fe856 | 83 | * @{ |
bcostm | 6:e1d9da7fe856 | 84 | */ |
bcostm | 6:e1d9da7fe856 | 85 | |
bcostm | 6:e1d9da7fe856 | 86 | /** @defgroup STM32746G_DISCOVERY_TS_Private_Types_Definitions STM32746G_DISCOVERY_TS Types Definitions |
bcostm | 6:e1d9da7fe856 | 87 | * @{ |
bcostm | 6:e1d9da7fe856 | 88 | */ |
bcostm | 6:e1d9da7fe856 | 89 | /** |
bcostm | 6:e1d9da7fe856 | 90 | * @} |
bcostm | 6:e1d9da7fe856 | 91 | */ |
bcostm | 6:e1d9da7fe856 | 92 | |
bcostm | 6:e1d9da7fe856 | 93 | /** @defgroup STM32746G_DISCOVERY_TS_Private_Defines STM32746G_DISCOVERY_TS Types Defines |
bcostm | 6:e1d9da7fe856 | 94 | * @{ |
bcostm | 6:e1d9da7fe856 | 95 | */ |
bcostm | 6:e1d9da7fe856 | 96 | /** |
bcostm | 6:e1d9da7fe856 | 97 | * @} |
bcostm | 6:e1d9da7fe856 | 98 | */ |
bcostm | 6:e1d9da7fe856 | 99 | |
bcostm | 6:e1d9da7fe856 | 100 | /** @defgroup STM32746G_DISCOVERY_TS_Private_Macros STM32746G_DISCOVERY_TS Private Macros |
bcostm | 6:e1d9da7fe856 | 101 | * @{ |
bcostm | 6:e1d9da7fe856 | 102 | */ |
bcostm | 6:e1d9da7fe856 | 103 | /** |
bcostm | 6:e1d9da7fe856 | 104 | * @} |
bcostm | 6:e1d9da7fe856 | 105 | */ |
bcostm | 6:e1d9da7fe856 | 106 | |
bcostm | 6:e1d9da7fe856 | 107 | /** @defgroup STM32746G_DISCOVERY_TS_Imported_Variables STM32746G_DISCOVERY_TS Imported Variables |
bcostm | 6:e1d9da7fe856 | 108 | * @{ |
bcostm | 6:e1d9da7fe856 | 109 | */ |
bcostm | 6:e1d9da7fe856 | 110 | /** |
bcostm | 6:e1d9da7fe856 | 111 | * @} |
bcostm | 6:e1d9da7fe856 | 112 | */ |
bcostm | 6:e1d9da7fe856 | 113 | |
bcostm | 6:e1d9da7fe856 | 114 | /** @defgroup STM32746G_DISCOVERY_TS_Private_Variables STM32746G_DISCOVERY_TS Private Variables |
bcostm | 6:e1d9da7fe856 | 115 | * @{ |
bcostm | 6:e1d9da7fe856 | 116 | */ |
bcostm | 6:e1d9da7fe856 | 117 | static TS_DrvTypeDef *tsDriver; |
bcostm | 6:e1d9da7fe856 | 118 | static uint16_t tsXBoundary, tsYBoundary; |
bcostm | 6:e1d9da7fe856 | 119 | static uint8_t tsOrientation; |
bcostm | 6:e1d9da7fe856 | 120 | static uint8_t I2cAddress; |
bcostm | 6:e1d9da7fe856 | 121 | /** |
bcostm | 6:e1d9da7fe856 | 122 | * @} |
bcostm | 6:e1d9da7fe856 | 123 | */ |
bcostm | 6:e1d9da7fe856 | 124 | |
bcostm | 6:e1d9da7fe856 | 125 | /** @defgroup STM32746G_DISCOVERY_TS_Private_Function_Prototypes STM32746G_DISCOVERY_TS Private Function Prototypes |
bcostm | 6:e1d9da7fe856 | 126 | * @{ |
bcostm | 6:e1d9da7fe856 | 127 | */ |
bcostm | 6:e1d9da7fe856 | 128 | /** |
bcostm | 6:e1d9da7fe856 | 129 | * @} |
bcostm | 6:e1d9da7fe856 | 130 | */ |
bcostm | 6:e1d9da7fe856 | 131 | |
bcostm | 6:e1d9da7fe856 | 132 | /** @defgroup STM32746G_DISCOVERY_TS_Exported_Functions STM32746G_DISCOVERY_TS Exported Functions |
bcostm | 6:e1d9da7fe856 | 133 | * @{ |
bcostm | 6:e1d9da7fe856 | 134 | */ |
bcostm | 6:e1d9da7fe856 | 135 | |
bcostm | 6:e1d9da7fe856 | 136 | /** |
bcostm | 6:e1d9da7fe856 | 137 | * @brief Initializes and configures the touch screen functionalities and |
bcostm | 6:e1d9da7fe856 | 138 | * configures all necessary hardware resources (GPIOs, I2C, clocks..). |
bcostm | 6:e1d9da7fe856 | 139 | * @param ts_SizeX: Maximum X size of the TS area on LCD |
bcostm | 6:e1d9da7fe856 | 140 | * @param ts_SizeY: Maximum Y size of the TS area on LCD |
bcostm | 6:e1d9da7fe856 | 141 | * @retval TS_OK if all initializations are OK. Other value if error. |
bcostm | 6:e1d9da7fe856 | 142 | */ |
bcostm | 6:e1d9da7fe856 | 143 | uint8_t BSP_TS_Init(uint16_t ts_SizeX, uint16_t ts_SizeY) |
bcostm | 6:e1d9da7fe856 | 144 | { |
bcostm | 6:e1d9da7fe856 | 145 | uint8_t status = TS_OK; |
bcostm | 6:e1d9da7fe856 | 146 | tsXBoundary = ts_SizeX; |
bcostm | 6:e1d9da7fe856 | 147 | tsYBoundary = ts_SizeY; |
bcostm | 6:e1d9da7fe856 | 148 | |
bcostm | 6:e1d9da7fe856 | 149 | /* Read ID and verify if the touch screen driver is ready */ |
bcostm | 6:e1d9da7fe856 | 150 | ft5336_ts_drv.Init(TS_I2C_ADDRESS); |
bcostm | 6:e1d9da7fe856 | 151 | if(ft5336_ts_drv.ReadID(TS_I2C_ADDRESS) == FT5336_ID_VALUE) |
bcostm | 6:e1d9da7fe856 | 152 | { |
bcostm | 6:e1d9da7fe856 | 153 | /* Initialize the TS driver structure */ |
bcostm | 6:e1d9da7fe856 | 154 | tsDriver = &ft5336_ts_drv; |
bcostm | 6:e1d9da7fe856 | 155 | I2cAddress = TS_I2C_ADDRESS; |
bcostm | 6:e1d9da7fe856 | 156 | tsOrientation = TS_SWAP_XY; |
bcostm | 6:e1d9da7fe856 | 157 | |
bcostm | 6:e1d9da7fe856 | 158 | /* Initialize the TS driver */ |
bcostm | 6:e1d9da7fe856 | 159 | tsDriver->Start(I2cAddress); |
bcostm | 6:e1d9da7fe856 | 160 | } |
bcostm | 6:e1d9da7fe856 | 161 | else |
bcostm | 6:e1d9da7fe856 | 162 | { |
bcostm | 6:e1d9da7fe856 | 163 | status = TS_DEVICE_NOT_FOUND; |
bcostm | 6:e1d9da7fe856 | 164 | } |
bcostm | 6:e1d9da7fe856 | 165 | |
bcostm | 6:e1d9da7fe856 | 166 | return status; |
bcostm | 6:e1d9da7fe856 | 167 | } |
bcostm | 6:e1d9da7fe856 | 168 | |
bcostm | 6:e1d9da7fe856 | 169 | /** |
bcostm | 6:e1d9da7fe856 | 170 | * @brief DeInitializes the TouchScreen. |
bcostm | 6:e1d9da7fe856 | 171 | * @retval TS state |
bcostm | 6:e1d9da7fe856 | 172 | */ |
bcostm | 6:e1d9da7fe856 | 173 | uint8_t BSP_TS_DeInit(void) |
bcostm | 6:e1d9da7fe856 | 174 | { |
bcostm | 6:e1d9da7fe856 | 175 | /* Actually ts_driver does not provide a DeInit function */ |
bcostm | 6:e1d9da7fe856 | 176 | return TS_OK; |
bcostm | 6:e1d9da7fe856 | 177 | } |
bcostm | 6:e1d9da7fe856 | 178 | |
bcostm | 6:e1d9da7fe856 | 179 | /** |
bcostm | 6:e1d9da7fe856 | 180 | * @brief Configures and enables the touch screen interrupts. |
bcostm | 6:e1d9da7fe856 | 181 | * @retval TS_OK if all initializations are OK. Other value if error. |
bcostm | 6:e1d9da7fe856 | 182 | */ |
bcostm | 6:e1d9da7fe856 | 183 | uint8_t BSP_TS_ITConfig(void) |
bcostm | 6:e1d9da7fe856 | 184 | { |
bcostm | 6:e1d9da7fe856 | 185 | GPIO_InitTypeDef gpio_init_structure; |
bcostm | 6:e1d9da7fe856 | 186 | |
bcostm | 6:e1d9da7fe856 | 187 | /* Configure Interrupt mode for SD detection pin */ |
bcostm | 6:e1d9da7fe856 | 188 | gpio_init_structure.Pin = TS_INT_PIN; |
bcostm | 6:e1d9da7fe856 | 189 | gpio_init_structure.Pull = GPIO_NOPULL; |
bcostm | 6:e1d9da7fe856 | 190 | gpio_init_structure.Speed = GPIO_SPEED_FAST; |
bcostm | 6:e1d9da7fe856 | 191 | gpio_init_structure.Mode = GPIO_MODE_IT_RISING; |
bcostm | 6:e1d9da7fe856 | 192 | HAL_GPIO_Init(TS_INT_GPIO_PORT, &gpio_init_structure); |
bcostm | 6:e1d9da7fe856 | 193 | |
bcostm | 6:e1d9da7fe856 | 194 | /* Enable and set Touch screen EXTI Interrupt to the lowest priority */ |
bcostm | 6:e1d9da7fe856 | 195 | HAL_NVIC_SetPriority((IRQn_Type)(TS_INT_EXTI_IRQn), 0x0F, 0x00); |
bcostm | 6:e1d9da7fe856 | 196 | HAL_NVIC_EnableIRQ((IRQn_Type)(TS_INT_EXTI_IRQn)); |
bcostm | 6:e1d9da7fe856 | 197 | |
bcostm | 6:e1d9da7fe856 | 198 | /* Enable the TS ITs */ |
bcostm | 6:e1d9da7fe856 | 199 | tsDriver->EnableIT(I2cAddress); |
bcostm | 6:e1d9da7fe856 | 200 | |
bcostm | 6:e1d9da7fe856 | 201 | return TS_OK; |
bcostm | 6:e1d9da7fe856 | 202 | } |
bcostm | 6:e1d9da7fe856 | 203 | |
bcostm | 6:e1d9da7fe856 | 204 | /** |
bcostm | 6:e1d9da7fe856 | 205 | * @brief Gets the touch screen interrupt status. |
bcostm | 6:e1d9da7fe856 | 206 | * @retval TS_OK if all initializations are OK. Other value if error. |
bcostm | 6:e1d9da7fe856 | 207 | */ |
bcostm | 6:e1d9da7fe856 | 208 | uint8_t BSP_TS_ITGetStatus(void) |
bcostm | 6:e1d9da7fe856 | 209 | { |
bcostm | 6:e1d9da7fe856 | 210 | /* Return the TS IT status */ |
bcostm | 6:e1d9da7fe856 | 211 | return (tsDriver->GetITStatus(I2cAddress)); |
bcostm | 6:e1d9da7fe856 | 212 | } |
bcostm | 6:e1d9da7fe856 | 213 | |
bcostm | 6:e1d9da7fe856 | 214 | /** |
bcostm | 6:e1d9da7fe856 | 215 | * @brief Returns status and positions of the touch screen. |
bcostm | 6:e1d9da7fe856 | 216 | * @param TS_State: Pointer to touch screen current state structure |
bcostm | 6:e1d9da7fe856 | 217 | * @retval TS_OK if all initializations are OK. Other value if error. |
bcostm | 6:e1d9da7fe856 | 218 | */ |
bcostm | 6:e1d9da7fe856 | 219 | uint8_t BSP_TS_GetState(TS_StateTypeDef *TS_State) |
bcostm | 6:e1d9da7fe856 | 220 | { |
bcostm | 6:e1d9da7fe856 | 221 | static uint32_t _x[TS_MAX_NB_TOUCH] = {0, 0}; |
bcostm | 6:e1d9da7fe856 | 222 | static uint32_t _y[TS_MAX_NB_TOUCH] = {0, 0}; |
bcostm | 6:e1d9da7fe856 | 223 | uint8_t ts_status = TS_OK; |
bcostm | 6:e1d9da7fe856 | 224 | uint16_t x[TS_MAX_NB_TOUCH]; |
bcostm | 6:e1d9da7fe856 | 225 | uint16_t y[TS_MAX_NB_TOUCH]; |
bcostm | 6:e1d9da7fe856 | 226 | uint16_t brute_x[TS_MAX_NB_TOUCH]; |
bcostm | 6:e1d9da7fe856 | 227 | uint16_t brute_y[TS_MAX_NB_TOUCH]; |
bcostm | 6:e1d9da7fe856 | 228 | uint16_t x_diff; |
bcostm | 6:e1d9da7fe856 | 229 | uint16_t y_diff; |
bcostm | 6:e1d9da7fe856 | 230 | uint32_t index; |
bcostm | 6:e1d9da7fe856 | 231 | #if (TS_MULTI_TOUCH_SUPPORTED == 1) |
bcostm | 6:e1d9da7fe856 | 232 | uint32_t weight = 0; |
bcostm | 6:e1d9da7fe856 | 233 | uint32_t area = 0; |
bcostm | 6:e1d9da7fe856 | 234 | uint32_t event = 0; |
bcostm | 6:e1d9da7fe856 | 235 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
bcostm | 6:e1d9da7fe856 | 236 | |
bcostm | 6:e1d9da7fe856 | 237 | /* Check and update the number of touches active detected */ |
bcostm | 6:e1d9da7fe856 | 238 | TS_State->touchDetected = tsDriver->DetectTouch(I2cAddress); |
bcostm | 6:e1d9da7fe856 | 239 | |
bcostm | 6:e1d9da7fe856 | 240 | if(TS_State->touchDetected) |
bcostm | 6:e1d9da7fe856 | 241 | { |
bcostm | 6:e1d9da7fe856 | 242 | for(index=0; index < TS_State->touchDetected; index++) |
bcostm | 6:e1d9da7fe856 | 243 | { |
bcostm | 6:e1d9da7fe856 | 244 | /* Get each touch coordinates */ |
bcostm | 6:e1d9da7fe856 | 245 | tsDriver->GetXY(I2cAddress, &(brute_x[index]), &(brute_y[index])); |
bcostm | 6:e1d9da7fe856 | 246 | |
bcostm | 6:e1d9da7fe856 | 247 | if(tsOrientation == TS_SWAP_NONE) |
bcostm | 6:e1d9da7fe856 | 248 | { |
bcostm | 6:e1d9da7fe856 | 249 | x[index] = brute_x[index]; |
bcostm | 6:e1d9da7fe856 | 250 | y[index] = brute_y[index]; |
bcostm | 6:e1d9da7fe856 | 251 | } |
bcostm | 6:e1d9da7fe856 | 252 | |
bcostm | 6:e1d9da7fe856 | 253 | if(tsOrientation & TS_SWAP_X) |
bcostm | 6:e1d9da7fe856 | 254 | { |
bcostm | 6:e1d9da7fe856 | 255 | x[index] = 4096 - brute_x[index]; |
bcostm | 6:e1d9da7fe856 | 256 | } |
bcostm | 6:e1d9da7fe856 | 257 | |
bcostm | 6:e1d9da7fe856 | 258 | if(tsOrientation & TS_SWAP_Y) |
bcostm | 6:e1d9da7fe856 | 259 | { |
bcostm | 6:e1d9da7fe856 | 260 | y[index] = 4096 - brute_y[index]; |
bcostm | 6:e1d9da7fe856 | 261 | } |
bcostm | 6:e1d9da7fe856 | 262 | |
bcostm | 6:e1d9da7fe856 | 263 | if(tsOrientation & TS_SWAP_XY) |
bcostm | 6:e1d9da7fe856 | 264 | { |
bcostm | 6:e1d9da7fe856 | 265 | y[index] = brute_x[index]; |
bcostm | 6:e1d9da7fe856 | 266 | x[index] = brute_y[index]; |
bcostm | 6:e1d9da7fe856 | 267 | } |
bcostm | 6:e1d9da7fe856 | 268 | |
bcostm | 6:e1d9da7fe856 | 269 | x_diff = x[index] > _x[index]? (x[index] - _x[index]): (_x[index] - x[index]); |
bcostm | 6:e1d9da7fe856 | 270 | y_diff = y[index] > _y[index]? (y[index] - _y[index]): (_y[index] - y[index]); |
bcostm | 6:e1d9da7fe856 | 271 | |
bcostm | 6:e1d9da7fe856 | 272 | if ((x_diff + y_diff) > 5) |
bcostm | 6:e1d9da7fe856 | 273 | { |
bcostm | 6:e1d9da7fe856 | 274 | _x[index] = x[index]; |
bcostm | 6:e1d9da7fe856 | 275 | _y[index] = y[index]; |
bcostm | 6:e1d9da7fe856 | 276 | } |
bcostm | 6:e1d9da7fe856 | 277 | |
bcostm | 6:e1d9da7fe856 | 278 | if(I2cAddress == FT5336_I2C_SLAVE_ADDRESS) |
bcostm | 6:e1d9da7fe856 | 279 | { |
bcostm | 6:e1d9da7fe856 | 280 | TS_State->touchX[index] = x[index]; |
bcostm | 6:e1d9da7fe856 | 281 | TS_State->touchY[index] = y[index]; |
bcostm | 6:e1d9da7fe856 | 282 | } |
bcostm | 6:e1d9da7fe856 | 283 | else |
bcostm | 6:e1d9da7fe856 | 284 | { |
bcostm | 6:e1d9da7fe856 | 285 | /* 2^12 = 4096 : indexes are expressed on a dynamic of 4096 */ |
bcostm | 6:e1d9da7fe856 | 286 | TS_State->touchX[index] = (tsXBoundary * _x[index]) >> 12; |
bcostm | 6:e1d9da7fe856 | 287 | TS_State->touchY[index] = (tsYBoundary * _y[index]) >> 12; |
bcostm | 6:e1d9da7fe856 | 288 | } |
bcostm | 6:e1d9da7fe856 | 289 | |
bcostm | 6:e1d9da7fe856 | 290 | #if (TS_MULTI_TOUCH_SUPPORTED == 1) |
bcostm | 6:e1d9da7fe856 | 291 | |
bcostm | 6:e1d9da7fe856 | 292 | /* Get touch info related to the current touch */ |
bcostm | 6:e1d9da7fe856 | 293 | ft5336_TS_GetTouchInfo(I2cAddress, index, &weight, &area, &event); |
bcostm | 6:e1d9da7fe856 | 294 | |
bcostm | 6:e1d9da7fe856 | 295 | /* Update TS_State structure */ |
bcostm | 6:e1d9da7fe856 | 296 | TS_State->touchWeight[index] = weight; |
bcostm | 6:e1d9da7fe856 | 297 | TS_State->touchArea[index] = area; |
bcostm | 6:e1d9da7fe856 | 298 | |
bcostm | 6:e1d9da7fe856 | 299 | /* Remap touch event */ |
bcostm | 6:e1d9da7fe856 | 300 | switch(event) |
bcostm | 6:e1d9da7fe856 | 301 | { |
bcostm | 6:e1d9da7fe856 | 302 | case FT5336_TOUCH_EVT_FLAG_PRESS_DOWN : |
bcostm | 6:e1d9da7fe856 | 303 | TS_State->touchEventId[index] = TOUCH_EVENT_PRESS_DOWN; |
bcostm | 6:e1d9da7fe856 | 304 | break; |
bcostm | 6:e1d9da7fe856 | 305 | case FT5336_TOUCH_EVT_FLAG_LIFT_UP : |
bcostm | 6:e1d9da7fe856 | 306 | TS_State->touchEventId[index] = TOUCH_EVENT_LIFT_UP; |
bcostm | 6:e1d9da7fe856 | 307 | break; |
bcostm | 6:e1d9da7fe856 | 308 | case FT5336_TOUCH_EVT_FLAG_CONTACT : |
bcostm | 6:e1d9da7fe856 | 309 | TS_State->touchEventId[index] = TOUCH_EVENT_CONTACT; |
bcostm | 6:e1d9da7fe856 | 310 | break; |
bcostm | 6:e1d9da7fe856 | 311 | case FT5336_TOUCH_EVT_FLAG_NO_EVENT : |
bcostm | 6:e1d9da7fe856 | 312 | TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT; |
bcostm | 6:e1d9da7fe856 | 313 | break; |
bcostm | 6:e1d9da7fe856 | 314 | default : |
bcostm | 6:e1d9da7fe856 | 315 | ts_status = TS_ERROR; |
bcostm | 6:e1d9da7fe856 | 316 | break; |
bcostm | 6:e1d9da7fe856 | 317 | } /* of switch(event) */ |
bcostm | 6:e1d9da7fe856 | 318 | |
bcostm | 6:e1d9da7fe856 | 319 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
bcostm | 6:e1d9da7fe856 | 320 | |
bcostm | 6:e1d9da7fe856 | 321 | } /* of for(index=0; index < TS_State->touchDetected; index++) */ |
bcostm | 6:e1d9da7fe856 | 322 | |
bcostm | 6:e1d9da7fe856 | 323 | #if (TS_MULTI_TOUCH_SUPPORTED == 1) |
bcostm | 6:e1d9da7fe856 | 324 | /* Get gesture Id */ |
bcostm | 6:e1d9da7fe856 | 325 | ts_status = BSP_TS_Get_GestureId(TS_State); |
bcostm | 6:e1d9da7fe856 | 326 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
bcostm | 6:e1d9da7fe856 | 327 | |
bcostm | 6:e1d9da7fe856 | 328 | } /* end of if(TS_State->touchDetected != 0) */ |
bcostm | 6:e1d9da7fe856 | 329 | |
bcostm | 6:e1d9da7fe856 | 330 | return (ts_status); |
bcostm | 6:e1d9da7fe856 | 331 | } |
bcostm | 6:e1d9da7fe856 | 332 | |
bcostm | 6:e1d9da7fe856 | 333 | #if (TS_MULTI_TOUCH_SUPPORTED == 1) |
bcostm | 6:e1d9da7fe856 | 334 | /** |
bcostm | 6:e1d9da7fe856 | 335 | * @brief Update gesture Id following a touch detected. |
bcostm | 6:e1d9da7fe856 | 336 | * @param TS_State: Pointer to touch screen current state structure |
bcostm | 6:e1d9da7fe856 | 337 | * @retval TS_OK if all initializations are OK. Other value if error. |
bcostm | 6:e1d9da7fe856 | 338 | */ |
bcostm | 6:e1d9da7fe856 | 339 | uint8_t BSP_TS_Get_GestureId(TS_StateTypeDef *TS_State) |
bcostm | 6:e1d9da7fe856 | 340 | { |
bcostm | 6:e1d9da7fe856 | 341 | uint32_t gestureId = 0; |
bcostm | 6:e1d9da7fe856 | 342 | uint8_t ts_status = TS_OK; |
bcostm | 6:e1d9da7fe856 | 343 | |
bcostm | 6:e1d9da7fe856 | 344 | /* Get gesture Id */ |
bcostm | 6:e1d9da7fe856 | 345 | ft5336_TS_GetGestureID(I2cAddress, &gestureId); |
bcostm | 6:e1d9da7fe856 | 346 | |
bcostm | 6:e1d9da7fe856 | 347 | /* Remap gesture Id to a TS_GestureIdTypeDef value */ |
bcostm | 6:e1d9da7fe856 | 348 | switch(gestureId) |
bcostm | 6:e1d9da7fe856 | 349 | { |
bcostm | 6:e1d9da7fe856 | 350 | case FT5336_GEST_ID_NO_GESTURE : |
bcostm | 6:e1d9da7fe856 | 351 | TS_State->gestureId = GEST_ID_NO_GESTURE; |
bcostm | 6:e1d9da7fe856 | 352 | break; |
bcostm | 6:e1d9da7fe856 | 353 | case FT5336_GEST_ID_MOVE_UP : |
bcostm | 6:e1d9da7fe856 | 354 | TS_State->gestureId = GEST_ID_MOVE_UP; |
bcostm | 6:e1d9da7fe856 | 355 | break; |
bcostm | 6:e1d9da7fe856 | 356 | case FT5336_GEST_ID_MOVE_RIGHT : |
bcostm | 6:e1d9da7fe856 | 357 | TS_State->gestureId = GEST_ID_MOVE_RIGHT; |
bcostm | 6:e1d9da7fe856 | 358 | break; |
bcostm | 6:e1d9da7fe856 | 359 | case FT5336_GEST_ID_MOVE_DOWN : |
bcostm | 6:e1d9da7fe856 | 360 | TS_State->gestureId = GEST_ID_MOVE_DOWN; |
bcostm | 6:e1d9da7fe856 | 361 | break; |
bcostm | 6:e1d9da7fe856 | 362 | case FT5336_GEST_ID_MOVE_LEFT : |
bcostm | 6:e1d9da7fe856 | 363 | TS_State->gestureId = GEST_ID_MOVE_LEFT; |
bcostm | 6:e1d9da7fe856 | 364 | break; |
bcostm | 6:e1d9da7fe856 | 365 | case FT5336_GEST_ID_ZOOM_IN : |
bcostm | 6:e1d9da7fe856 | 366 | TS_State->gestureId = GEST_ID_ZOOM_IN; |
bcostm | 6:e1d9da7fe856 | 367 | break; |
bcostm | 6:e1d9da7fe856 | 368 | case FT5336_GEST_ID_ZOOM_OUT : |
bcostm | 6:e1d9da7fe856 | 369 | TS_State->gestureId = GEST_ID_ZOOM_OUT; |
bcostm | 6:e1d9da7fe856 | 370 | break; |
bcostm | 6:e1d9da7fe856 | 371 | default : |
bcostm | 6:e1d9da7fe856 | 372 | ts_status = TS_ERROR; |
bcostm | 6:e1d9da7fe856 | 373 | break; |
bcostm | 6:e1d9da7fe856 | 374 | } /* of switch(gestureId) */ |
bcostm | 6:e1d9da7fe856 | 375 | |
bcostm | 6:e1d9da7fe856 | 376 | return(ts_status); |
bcostm | 6:e1d9da7fe856 | 377 | } |
bcostm | 6:e1d9da7fe856 | 378 | #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ |
bcostm | 6:e1d9da7fe856 | 379 | |
bcostm | 6:e1d9da7fe856 | 380 | /** |
bcostm | 6:e1d9da7fe856 | 381 | * @brief Clears all touch screen interrupts. |
bcostm | 6:e1d9da7fe856 | 382 | */ |
bcostm | 6:e1d9da7fe856 | 383 | void BSP_TS_ITClear(void) |
bcostm | 6:e1d9da7fe856 | 384 | { |
bcostm | 6:e1d9da7fe856 | 385 | /* Clear TS IT pending bits */ |
bcostm | 6:e1d9da7fe856 | 386 | tsDriver->ClearIT(I2cAddress); |
bcostm | 6:e1d9da7fe856 | 387 | } |
bcostm | 6:e1d9da7fe856 | 388 | |
bcostm | 6:e1d9da7fe856 | 389 | |
bcostm | 6:e1d9da7fe856 | 390 | /** @defgroup STM32756G_DISCOVERY_TS_Private_Functions TS Private Functions |
bcostm | 6:e1d9da7fe856 | 391 | * @{ |
bcostm | 6:e1d9da7fe856 | 392 | */ |
bcostm | 6:e1d9da7fe856 | 393 | |
bcostm | 6:e1d9da7fe856 | 394 | |
bcostm | 6:e1d9da7fe856 | 395 | /** |
bcostm | 6:e1d9da7fe856 | 396 | * @brief Function used to reset all touch data before a new acquisition |
bcostm | 6:e1d9da7fe856 | 397 | * of touch information. |
bcostm | 6:e1d9da7fe856 | 398 | * @param TS_State: Pointer to touch screen current state structure |
bcostm | 6:e1d9da7fe856 | 399 | * @retval TS_OK if OK, TE_ERROR if problem found. |
bcostm | 6:e1d9da7fe856 | 400 | */ |
bcostm | 6:e1d9da7fe856 | 401 | uint8_t BSP_TS_ResetTouchData(TS_StateTypeDef *TS_State) |
bcostm | 6:e1d9da7fe856 | 402 | { |
bcostm | 6:e1d9da7fe856 | 403 | uint8_t ts_status = TS_ERROR; |
bcostm | 6:e1d9da7fe856 | 404 | uint32_t index; |
bcostm | 6:e1d9da7fe856 | 405 | |
bcostm | 6:e1d9da7fe856 | 406 | if (TS_State != (TS_StateTypeDef *)NULL) |
bcostm | 6:e1d9da7fe856 | 407 | { |
bcostm | 6:e1d9da7fe856 | 408 | TS_State->gestureId = GEST_ID_NO_GESTURE; |
bcostm | 6:e1d9da7fe856 | 409 | TS_State->touchDetected = 0; |
bcostm | 6:e1d9da7fe856 | 410 | |
bcostm | 6:e1d9da7fe856 | 411 | for(index = 0; index < TS_MAX_NB_TOUCH; index++) |
bcostm | 6:e1d9da7fe856 | 412 | { |
bcostm | 6:e1d9da7fe856 | 413 | TS_State->touchX[index] = 0; |
bcostm | 6:e1d9da7fe856 | 414 | TS_State->touchY[index] = 0; |
bcostm | 6:e1d9da7fe856 | 415 | TS_State->touchArea[index] = 0; |
bcostm | 6:e1d9da7fe856 | 416 | TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT; |
bcostm | 6:e1d9da7fe856 | 417 | TS_State->touchWeight[index] = 0; |
bcostm | 6:e1d9da7fe856 | 418 | } |
bcostm | 6:e1d9da7fe856 | 419 | |
bcostm | 6:e1d9da7fe856 | 420 | ts_status = TS_OK; |
bcostm | 6:e1d9da7fe856 | 421 | |
bcostm | 6:e1d9da7fe856 | 422 | } /* of if (TS_State != (TS_StateTypeDef *)NULL) */ |
bcostm | 6:e1d9da7fe856 | 423 | |
bcostm | 6:e1d9da7fe856 | 424 | return (ts_status); |
bcostm | 6:e1d9da7fe856 | 425 | } |
bcostm | 6:e1d9da7fe856 | 426 | |
bcostm | 6:e1d9da7fe856 | 427 | /** |
bcostm | 6:e1d9da7fe856 | 428 | * @} |
bcostm | 6:e1d9da7fe856 | 429 | */ |
bcostm | 6:e1d9da7fe856 | 430 | |
bcostm | 6:e1d9da7fe856 | 431 | /** |
bcostm | 6:e1d9da7fe856 | 432 | * @} |
bcostm | 6:e1d9da7fe856 | 433 | */ |
bcostm | 6:e1d9da7fe856 | 434 | |
bcostm | 6:e1d9da7fe856 | 435 | /** |
bcostm | 6:e1d9da7fe856 | 436 | * @} |
bcostm | 6:e1d9da7fe856 | 437 | */ |
bcostm | 6:e1d9da7fe856 | 438 | |
bcostm | 6:e1d9da7fe856 | 439 | /** |
bcostm | 6:e1d9da7fe856 | 440 | * @} |
bcostm | 6:e1d9da7fe856 | 441 | */ |
bcostm | 6:e1d9da7fe856 | 442 | |
bcostm | 6:e1d9da7fe856 | 443 | /** |
bcostm | 6:e1d9da7fe856 | 444 | * @} |
bcostm | 6:e1d9da7fe856 | 445 | */ |
bcostm | 6:e1d9da7fe856 | 446 | |
bcostm | 6:e1d9da7fe856 | 447 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |