Library to control Silicon Labs SI570 10 MHZ TO 1.4 GHZ I2C PROGRAMMABLE XO/VCXO.

Dependencies:   mbed

Fork of SI570 by Gerrit Polder

Committer:
DL3LD
Date:
Sun Mar 27 06:55:59 2016 +0000
Revision:
1:1556bcaaf759
STM32F746NG SI570 VFO Test

Who changed what in which revision?

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