STM32746G-Discovery board drivers V1.0.0

Dependents:   F746_SD_GraphicEqualizer_ren0620

Fork of BSP_DISCO_F746NG by ST

Committer:
edamame22
Date:
Wed Jun 22 03:48:49 2016 +0000
Revision:
3:286943c42d38
Parent:
0:c9112f0c67e3
timeout is shortened.; play will not stop.

Who changed what in which revision?

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