patch for F746 demo

Dependents:   F7DISCO_Demo

Fork of BSP_DISCO_F746NG by ST

Committer:
NirT
Date:
Mon Nov 02 23:35:17 2015 +0000
Revision:
1:e8fac4061a5b
Error: Incomplete type is not allowed in "patch/LwIP/src/include/lwip/dhcp.h", Line: 83, Col: 4; ; and more like this.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NirT 1:e8fac4061a5b 1 /**
NirT 1:e8fac4061a5b 2 ******************************************************************************
NirT 1:e8fac4061a5b 3 * @file ft5336.c
NirT 1:e8fac4061a5b 4 * @author MCD Application Team
NirT 1:e8fac4061a5b 5 * @version V1.0.0
NirT 1:e8fac4061a5b 6 * @date 25-June-2015
NirT 1:e8fac4061a5b 7 * @brief This file provides a set of functions needed to manage the FT5336
NirT 1:e8fac4061a5b 8 * touch screen devices.
NirT 1:e8fac4061a5b 9 ******************************************************************************
NirT 1:e8fac4061a5b 10 * @attention
NirT 1:e8fac4061a5b 11 *
NirT 1:e8fac4061a5b 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
NirT 1:e8fac4061a5b 13 *
NirT 1:e8fac4061a5b 14 * Redistribution and use in source and binary forms, with or without modification,
NirT 1:e8fac4061a5b 15 * are permitted provided that the following conditions are met:
NirT 1:e8fac4061a5b 16 * 1. Redistributions of source code must retain the above copyright notice,
NirT 1:e8fac4061a5b 17 * this list of conditions and the following disclaimer.
NirT 1:e8fac4061a5b 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
NirT 1:e8fac4061a5b 19 * this list of conditions and the following disclaimer in the documentation
NirT 1:e8fac4061a5b 20 * and/or other materials provided with the distribution.
NirT 1:e8fac4061a5b 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
NirT 1:e8fac4061a5b 22 * may be used to endorse or promote products derived from this software
NirT 1:e8fac4061a5b 23 * without specific prior written permission.
NirT 1:e8fac4061a5b 24 *
NirT 1:e8fac4061a5b 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
NirT 1:e8fac4061a5b 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
NirT 1:e8fac4061a5b 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
NirT 1:e8fac4061a5b 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
NirT 1:e8fac4061a5b 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
NirT 1:e8fac4061a5b 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
NirT 1:e8fac4061a5b 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
NirT 1:e8fac4061a5b 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
NirT 1:e8fac4061a5b 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
NirT 1:e8fac4061a5b 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NirT 1:e8fac4061a5b 35 *
NirT 1:e8fac4061a5b 36 ******************************************************************************
NirT 1:e8fac4061a5b 37 */
NirT 1:e8fac4061a5b 38
NirT 1:e8fac4061a5b 39 /* Includes ------------------------------------------------------------------*/
NirT 1:e8fac4061a5b 40 #include "ft5336.h"
NirT 1:e8fac4061a5b 41
NirT 1:e8fac4061a5b 42 /** @addtogroup BSP
NirT 1:e8fac4061a5b 43 * @{
NirT 1:e8fac4061a5b 44 */
NirT 1:e8fac4061a5b 45
NirT 1:e8fac4061a5b 46 /** @addtogroup Component
NirT 1:e8fac4061a5b 47 * @{
NirT 1:e8fac4061a5b 48 */
NirT 1:e8fac4061a5b 49
NirT 1:e8fac4061a5b 50 /** @defgroup FT5336
NirT 1:e8fac4061a5b 51 * @{
NirT 1:e8fac4061a5b 52 */
NirT 1:e8fac4061a5b 53
NirT 1:e8fac4061a5b 54 /* Private typedef -----------------------------------------------------------*/
NirT 1:e8fac4061a5b 55
NirT 1:e8fac4061a5b 56 /** @defgroup FT5336_Private_Types_Definitions
NirT 1:e8fac4061a5b 57 * @{
NirT 1:e8fac4061a5b 58 */
NirT 1:e8fac4061a5b 59
NirT 1:e8fac4061a5b 60 /* Private define ------------------------------------------------------------*/
NirT 1:e8fac4061a5b 61
NirT 1:e8fac4061a5b 62 /** @defgroup FT5336_Private_Defines
NirT 1:e8fac4061a5b 63 * @{
NirT 1:e8fac4061a5b 64 */
NirT 1:e8fac4061a5b 65
NirT 1:e8fac4061a5b 66 /* Private macro -------------------------------------------------------------*/
NirT 1:e8fac4061a5b 67
NirT 1:e8fac4061a5b 68 /** @defgroup FT5336_Private_Macros
NirT 1:e8fac4061a5b 69 * @{
NirT 1:e8fac4061a5b 70 */
NirT 1:e8fac4061a5b 71
NirT 1:e8fac4061a5b 72 /* Private variables ---------------------------------------------------------*/
NirT 1:e8fac4061a5b 73
NirT 1:e8fac4061a5b 74 /** @defgroup FT5336_Private_Variables
NirT 1:e8fac4061a5b 75 * @{
NirT 1:e8fac4061a5b 76 */
NirT 1:e8fac4061a5b 77
NirT 1:e8fac4061a5b 78 /* Touch screen driver structure initialization */
NirT 1:e8fac4061a5b 79 TS_DrvTypeDef ft5336_ts_drv =
NirT 1:e8fac4061a5b 80 {
NirT 1:e8fac4061a5b 81 ft5336_Init,
NirT 1:e8fac4061a5b 82 ft5336_ReadID,
NirT 1:e8fac4061a5b 83 ft5336_Reset,
NirT 1:e8fac4061a5b 84
NirT 1:e8fac4061a5b 85 ft5336_TS_Start,
NirT 1:e8fac4061a5b 86 ft5336_TS_DetectTouch,
NirT 1:e8fac4061a5b 87 ft5336_TS_GetXY,
NirT 1:e8fac4061a5b 88
NirT 1:e8fac4061a5b 89 ft5336_TS_EnableIT,
NirT 1:e8fac4061a5b 90 ft5336_TS_ClearIT,
NirT 1:e8fac4061a5b 91 ft5336_TS_ITStatus,
NirT 1:e8fac4061a5b 92 ft5336_TS_DisableIT
NirT 1:e8fac4061a5b 93
NirT 1:e8fac4061a5b 94 };
NirT 1:e8fac4061a5b 95
NirT 1:e8fac4061a5b 96 /* Global ft5336 handle */
NirT 1:e8fac4061a5b 97 static ft5336_handle_TypeDef ft5336_handle = { FT5336_I2C_NOT_INITIALIZED, 0, 0};
NirT 1:e8fac4061a5b 98
NirT 1:e8fac4061a5b 99 /**
NirT 1:e8fac4061a5b 100 * @}
NirT 1:e8fac4061a5b 101 */
NirT 1:e8fac4061a5b 102
NirT 1:e8fac4061a5b 103 /** @defgroup ft5336_Private_Function_Prototypes
NirT 1:e8fac4061a5b 104 * @{
NirT 1:e8fac4061a5b 105 */
NirT 1:e8fac4061a5b 106
NirT 1:e8fac4061a5b 107 /* Private functions prototypes-----------------------------------------------*/
NirT 1:e8fac4061a5b 108
NirT 1:e8fac4061a5b 109 /**
NirT 1:e8fac4061a5b 110 * @brief Return the status of I2C was initialized or not.
NirT 1:e8fac4061a5b 111 * @param None.
NirT 1:e8fac4061a5b 112 * @retval : I2C initialization status.
NirT 1:e8fac4061a5b 113 */
NirT 1:e8fac4061a5b 114 static uint8_t ft5336_Get_I2C_InitializedStatus(void);
NirT 1:e8fac4061a5b 115
NirT 1:e8fac4061a5b 116 /**
NirT 1:e8fac4061a5b 117 * @brief I2C initialize if needed.
NirT 1:e8fac4061a5b 118 * @param None.
NirT 1:e8fac4061a5b 119 * @retval : None.
NirT 1:e8fac4061a5b 120 */
NirT 1:e8fac4061a5b 121 static void ft5336_I2C_InitializeIfRequired(void);
NirT 1:e8fac4061a5b 122
NirT 1:e8fac4061a5b 123 /**
NirT 1:e8fac4061a5b 124 * @brief Basic static configuration of TouchScreen
NirT 1:e8fac4061a5b 125 * @param DeviceAddr: FT5336 Device address for communication on I2C Bus.
NirT 1:e8fac4061a5b 126 * @retval Status FT5336_STATUS_OK or FT5336_STATUS_NOT_OK.
NirT 1:e8fac4061a5b 127 */
NirT 1:e8fac4061a5b 128 static uint32_t ft5336_TS_Configure(uint16_t DeviceAddr);
NirT 1:e8fac4061a5b 129
NirT 1:e8fac4061a5b 130 /** @defgroup ft5336_Private_Functions
NirT 1:e8fac4061a5b 131 * @{
NirT 1:e8fac4061a5b 132 */
NirT 1:e8fac4061a5b 133
NirT 1:e8fac4061a5b 134 /** @defgroup ft5336_Public_Function_Body
NirT 1:e8fac4061a5b 135 * @{
NirT 1:e8fac4061a5b 136 */
NirT 1:e8fac4061a5b 137
NirT 1:e8fac4061a5b 138 /* Public functions bodies-----------------------------------------------*/
NirT 1:e8fac4061a5b 139
NirT 1:e8fac4061a5b 140
NirT 1:e8fac4061a5b 141 /**
NirT 1:e8fac4061a5b 142 * @brief Initialize the ft5336 communication bus
NirT 1:e8fac4061a5b 143 * from MCU to FT5336 : ie I2C channel initialization (if required).
NirT 1:e8fac4061a5b 144 * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
NirT 1:e8fac4061a5b 145 * @retval None
NirT 1:e8fac4061a5b 146 */
NirT 1:e8fac4061a5b 147 void ft5336_Init(uint16_t DeviceAddr)
NirT 1:e8fac4061a5b 148 {
NirT 1:e8fac4061a5b 149 /* Wait at least 200ms after power up before accessing registers
NirT 1:e8fac4061a5b 150 * Trsi timing (Time of starting to report point after resetting) from FT5336GQQ datasheet */
NirT 1:e8fac4061a5b 151 TS_IO_Delay(200);
NirT 1:e8fac4061a5b 152
NirT 1:e8fac4061a5b 153 /* Initialize I2C link if needed */
NirT 1:e8fac4061a5b 154 ft5336_I2C_InitializeIfRequired();
NirT 1:e8fac4061a5b 155 }
NirT 1:e8fac4061a5b 156
NirT 1:e8fac4061a5b 157 /**
NirT 1:e8fac4061a5b 158 * @brief Software Reset the ft5336.
NirT 1:e8fac4061a5b 159 * @note : Not applicable to FT5336.
NirT 1:e8fac4061a5b 160 * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
NirT 1:e8fac4061a5b 161 * @retval None
NirT 1:e8fac4061a5b 162 */
NirT 1:e8fac4061a5b 163 void ft5336_Reset(uint16_t DeviceAddr)
NirT 1:e8fac4061a5b 164 {
NirT 1:e8fac4061a5b 165 /* Do nothing */
NirT 1:e8fac4061a5b 166 /* No software reset sequence available in FT5336 IC */
NirT 1:e8fac4061a5b 167 }
NirT 1:e8fac4061a5b 168
NirT 1:e8fac4061a5b 169 /**
NirT 1:e8fac4061a5b 170 * @brief Read the ft5336 device ID, pre initialize I2C in case of need to be
NirT 1:e8fac4061a5b 171 * able to read the FT5336 device ID, and verify this is a FT5336.
NirT 1:e8fac4061a5b 172 * @param DeviceAddr: I2C FT5336 Slave address.
NirT 1:e8fac4061a5b 173 * @retval The Device ID (two bytes).
NirT 1:e8fac4061a5b 174 */
NirT 1:e8fac4061a5b 175 uint16_t ft5336_ReadID(uint16_t DeviceAddr)
NirT 1:e8fac4061a5b 176 {
NirT 1:e8fac4061a5b 177 volatile uint8_t ucReadId = 0;
NirT 1:e8fac4061a5b 178 uint8_t nbReadAttempts = 0;
NirT 1:e8fac4061a5b 179 uint8_t bFoundDevice = 0; /* Device not found by default */
NirT 1:e8fac4061a5b 180
NirT 1:e8fac4061a5b 181 /* Initialize I2C link if needed */
NirT 1:e8fac4061a5b 182 ft5336_I2C_InitializeIfRequired();
NirT 1:e8fac4061a5b 183
NirT 1:e8fac4061a5b 184 /* At maximum 4 attempts to read ID : exit at first finding of the searched device ID */
NirT 1:e8fac4061a5b 185 for(nbReadAttempts = 0; ((nbReadAttempts < 3) && !(bFoundDevice)); nbReadAttempts++)
NirT 1:e8fac4061a5b 186 {
NirT 1:e8fac4061a5b 187 /* Read register FT5336_CHIP_ID_REG as DeviceID detection */
NirT 1:e8fac4061a5b 188 ucReadId = TS_IO_Read(DeviceAddr, FT5336_CHIP_ID_REG);
NirT 1:e8fac4061a5b 189
NirT 1:e8fac4061a5b 190 /* Found the searched device ID ? */
NirT 1:e8fac4061a5b 191 if(ucReadId == FT5336_ID_VALUE)
NirT 1:e8fac4061a5b 192 {
NirT 1:e8fac4061a5b 193 /* Set device as found */
NirT 1:e8fac4061a5b 194 bFoundDevice = 1;
NirT 1:e8fac4061a5b 195 }
NirT 1:e8fac4061a5b 196 }
NirT 1:e8fac4061a5b 197
NirT 1:e8fac4061a5b 198 /* Return the device ID value */
NirT 1:e8fac4061a5b 199 return (ucReadId);
NirT 1:e8fac4061a5b 200 }
NirT 1:e8fac4061a5b 201
NirT 1:e8fac4061a5b 202 /**
NirT 1:e8fac4061a5b 203 * @brief Configures the touch Screen IC device to start detecting touches
NirT 1:e8fac4061a5b 204 * @param DeviceAddr: Device address on communication Bus (I2C slave address).
NirT 1:e8fac4061a5b 205 * @retval None.
NirT 1:e8fac4061a5b 206 */
NirT 1:e8fac4061a5b 207 void ft5336_TS_Start(uint16_t DeviceAddr)
NirT 1:e8fac4061a5b 208 {
NirT 1:e8fac4061a5b 209 /* Minimum static configuration of FT5336 */
NirT 1:e8fac4061a5b 210 FT5336_ASSERT(ft5336_TS_Configure(DeviceAddr));
NirT 1:e8fac4061a5b 211
NirT 1:e8fac4061a5b 212 /* By default set FT5336 IC in Polling mode : no INT generation on FT5336 for new touch available */
NirT 1:e8fac4061a5b 213 /* Note TS_INT is active low */
NirT 1:e8fac4061a5b 214 ft5336_TS_DisableIT(DeviceAddr);
NirT 1:e8fac4061a5b 215 }
NirT 1:e8fac4061a5b 216
NirT 1:e8fac4061a5b 217 /**
NirT 1:e8fac4061a5b 218 * @brief Return if there is touches detected or not.
NirT 1:e8fac4061a5b 219 * Try to detect new touches and forget the old ones (reset internal global
NirT 1:e8fac4061a5b 220 * variables).
NirT 1:e8fac4061a5b 221 * @param DeviceAddr: Device address on communication Bus.
NirT 1:e8fac4061a5b 222 * @retval : Number of active touches detected (can be 0, 1 or 2).
NirT 1:e8fac4061a5b 223 */
NirT 1:e8fac4061a5b 224 uint8_t ft5336_TS_DetectTouch(uint16_t DeviceAddr)
NirT 1:e8fac4061a5b 225 {
NirT 1:e8fac4061a5b 226 volatile uint8_t nbTouch = 0;
NirT 1:e8fac4061a5b 227
NirT 1:e8fac4061a5b 228 /* Read register FT5336_TD_STAT_REG to check number of touches detection */
NirT 1:e8fac4061a5b 229 nbTouch = TS_IO_Read(DeviceAddr, FT5336_TD_STAT_REG);
NirT 1:e8fac4061a5b 230 nbTouch &= FT5336_TD_STAT_MASK;
NirT 1:e8fac4061a5b 231
NirT 1:e8fac4061a5b 232 if(nbTouch > FT5336_MAX_DETECTABLE_TOUCH)
NirT 1:e8fac4061a5b 233 {
NirT 1:e8fac4061a5b 234 /* If invalid number of touch detected, set it to zero */
NirT 1:e8fac4061a5b 235 nbTouch = 0;
NirT 1:e8fac4061a5b 236 }
NirT 1:e8fac4061a5b 237
NirT 1:e8fac4061a5b 238 /* Update ft5336 driver internal global : current number of active touches */
NirT 1:e8fac4061a5b 239 ft5336_handle.currActiveTouchNb = nbTouch;
NirT 1:e8fac4061a5b 240
NirT 1:e8fac4061a5b 241 /* Reset current active touch index on which to work on */
NirT 1:e8fac4061a5b 242 ft5336_handle.currActiveTouchIdx = 0;
NirT 1:e8fac4061a5b 243
NirT 1:e8fac4061a5b 244 return(nbTouch);
NirT 1:e8fac4061a5b 245 }
NirT 1:e8fac4061a5b 246
NirT 1:e8fac4061a5b 247 /**
NirT 1:e8fac4061a5b 248 * @brief Get the touch screen X and Y positions values
NirT 1:e8fac4061a5b 249 * Manage multi touch thanks to touch Index global
NirT 1:e8fac4061a5b 250 * variable 'ft5336_handle.currActiveTouchIdx'.
NirT 1:e8fac4061a5b 251 * @param DeviceAddr: Device address on communication Bus.
NirT 1:e8fac4061a5b 252 * @param X: Pointer to X position value
NirT 1:e8fac4061a5b 253 * @param Y: Pointer to Y position value
NirT 1:e8fac4061a5b 254 * @retval None.
NirT 1:e8fac4061a5b 255 */
NirT 1:e8fac4061a5b 256 void ft5336_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y)
NirT 1:e8fac4061a5b 257 {
NirT 1:e8fac4061a5b 258 volatile uint8_t ucReadData = 0;
NirT 1:e8fac4061a5b 259 static uint16_t coord;
NirT 1:e8fac4061a5b 260 uint8_t regAddressXLow = 0;
NirT 1:e8fac4061a5b 261 uint8_t regAddressXHigh = 0;
NirT 1:e8fac4061a5b 262 uint8_t regAddressYLow = 0;
NirT 1:e8fac4061a5b 263 uint8_t regAddressYHigh = 0;
NirT 1:e8fac4061a5b 264
NirT 1:e8fac4061a5b 265 if(ft5336_handle.currActiveTouchIdx < ft5336_handle.currActiveTouchNb)
NirT 1:e8fac4061a5b 266 {
NirT 1:e8fac4061a5b 267 switch(ft5336_handle.currActiveTouchIdx)
NirT 1:e8fac4061a5b 268 {
NirT 1:e8fac4061a5b 269 case 0 :
NirT 1:e8fac4061a5b 270 regAddressXLow = FT5336_P1_XL_REG;
NirT 1:e8fac4061a5b 271 regAddressXHigh = FT5336_P1_XH_REG;
NirT 1:e8fac4061a5b 272 regAddressYLow = FT5336_P1_YL_REG;
NirT 1:e8fac4061a5b 273 regAddressYHigh = FT5336_P1_YH_REG;
NirT 1:e8fac4061a5b 274 break;
NirT 1:e8fac4061a5b 275
NirT 1:e8fac4061a5b 276 case 1 :
NirT 1:e8fac4061a5b 277 regAddressXLow = FT5336_P2_XL_REG;
NirT 1:e8fac4061a5b 278 regAddressXHigh = FT5336_P2_XH_REG;
NirT 1:e8fac4061a5b 279 regAddressYLow = FT5336_P2_YL_REG;
NirT 1:e8fac4061a5b 280 regAddressYHigh = FT5336_P2_YH_REG;
NirT 1:e8fac4061a5b 281 break;
NirT 1:e8fac4061a5b 282
NirT 1:e8fac4061a5b 283 case 2 :
NirT 1:e8fac4061a5b 284 regAddressXLow = FT5336_P3_XL_REG;
NirT 1:e8fac4061a5b 285 regAddressXHigh = FT5336_P3_XH_REG;
NirT 1:e8fac4061a5b 286 regAddressYLow = FT5336_P3_YL_REG;
NirT 1:e8fac4061a5b 287 regAddressYHigh = FT5336_P3_YH_REG;
NirT 1:e8fac4061a5b 288 break;
NirT 1:e8fac4061a5b 289
NirT 1:e8fac4061a5b 290 case 3 :
NirT 1:e8fac4061a5b 291 regAddressXLow = FT5336_P4_XL_REG;
NirT 1:e8fac4061a5b 292 regAddressXHigh = FT5336_P4_XH_REG;
NirT 1:e8fac4061a5b 293 regAddressYLow = FT5336_P4_YL_REG;
NirT 1:e8fac4061a5b 294 regAddressYHigh = FT5336_P4_YH_REG;
NirT 1:e8fac4061a5b 295 break;
NirT 1:e8fac4061a5b 296
NirT 1:e8fac4061a5b 297 case 4 :
NirT 1:e8fac4061a5b 298 regAddressXLow = FT5336_P5_XL_REG;
NirT 1:e8fac4061a5b 299 regAddressXHigh = FT5336_P5_XH_REG;
NirT 1:e8fac4061a5b 300 regAddressYLow = FT5336_P5_YL_REG;
NirT 1:e8fac4061a5b 301 regAddressYHigh = FT5336_P5_YH_REG;
NirT 1:e8fac4061a5b 302 break;
NirT 1:e8fac4061a5b 303
NirT 1:e8fac4061a5b 304 case 5 :
NirT 1:e8fac4061a5b 305 regAddressXLow = FT5336_P6_XL_REG;
NirT 1:e8fac4061a5b 306 regAddressXHigh = FT5336_P6_XH_REG;
NirT 1:e8fac4061a5b 307 regAddressYLow = FT5336_P6_YL_REG;
NirT 1:e8fac4061a5b 308 regAddressYHigh = FT5336_P6_YH_REG;
NirT 1:e8fac4061a5b 309 break;
NirT 1:e8fac4061a5b 310
NirT 1:e8fac4061a5b 311 case 6 :
NirT 1:e8fac4061a5b 312 regAddressXLow = FT5336_P7_XL_REG;
NirT 1:e8fac4061a5b 313 regAddressXHigh = FT5336_P7_XH_REG;
NirT 1:e8fac4061a5b 314 regAddressYLow = FT5336_P7_YL_REG;
NirT 1:e8fac4061a5b 315 regAddressYHigh = FT5336_P7_YH_REG;
NirT 1:e8fac4061a5b 316 break;
NirT 1:e8fac4061a5b 317
NirT 1:e8fac4061a5b 318 case 7 :
NirT 1:e8fac4061a5b 319 regAddressXLow = FT5336_P8_XL_REG;
NirT 1:e8fac4061a5b 320 regAddressXHigh = FT5336_P8_XH_REG;
NirT 1:e8fac4061a5b 321 regAddressYLow = FT5336_P8_YL_REG;
NirT 1:e8fac4061a5b 322 regAddressYHigh = FT5336_P8_YH_REG;
NirT 1:e8fac4061a5b 323 break;
NirT 1:e8fac4061a5b 324
NirT 1:e8fac4061a5b 325 case 8 :
NirT 1:e8fac4061a5b 326 regAddressXLow = FT5336_P9_XL_REG;
NirT 1:e8fac4061a5b 327 regAddressXHigh = FT5336_P9_XH_REG;
NirT 1:e8fac4061a5b 328 regAddressYLow = FT5336_P9_YL_REG;
NirT 1:e8fac4061a5b 329 regAddressYHigh = FT5336_P9_YH_REG;
NirT 1:e8fac4061a5b 330 break;
NirT 1:e8fac4061a5b 331
NirT 1:e8fac4061a5b 332 case 9 :
NirT 1:e8fac4061a5b 333 regAddressXLow = FT5336_P10_XL_REG;
NirT 1:e8fac4061a5b 334 regAddressXHigh = FT5336_P10_XH_REG;
NirT 1:e8fac4061a5b 335 regAddressYLow = FT5336_P10_YL_REG;
NirT 1:e8fac4061a5b 336 regAddressYHigh = FT5336_P10_YH_REG;
NirT 1:e8fac4061a5b 337 break;
NirT 1:e8fac4061a5b 338
NirT 1:e8fac4061a5b 339 default :
NirT 1:e8fac4061a5b 340 break;
NirT 1:e8fac4061a5b 341
NirT 1:e8fac4061a5b 342 } /* end switch(ft5336_handle.currActiveTouchIdx) */
NirT 1:e8fac4061a5b 343
NirT 1:e8fac4061a5b 344 /* Read low part of X position */
NirT 1:e8fac4061a5b 345 ucReadData = TS_IO_Read(DeviceAddr, regAddressXLow);
NirT 1:e8fac4061a5b 346 coord = (ucReadData & FT5336_TOUCH_POS_LSB_MASK) >> FT5336_TOUCH_POS_LSB_SHIFT;
NirT 1:e8fac4061a5b 347
NirT 1:e8fac4061a5b 348 /* Read high part of X position */
NirT 1:e8fac4061a5b 349 ucReadData = TS_IO_Read(DeviceAddr, regAddressXHigh);
NirT 1:e8fac4061a5b 350 coord |= ((ucReadData & FT5336_TOUCH_POS_MSB_MASK) >> FT5336_TOUCH_POS_MSB_SHIFT) << 8;
NirT 1:e8fac4061a5b 351
NirT 1:e8fac4061a5b 352 /* Send back ready X position to caller */
NirT 1:e8fac4061a5b 353 *X = coord;
NirT 1:e8fac4061a5b 354
NirT 1:e8fac4061a5b 355 /* Read low part of Y position */
NirT 1:e8fac4061a5b 356 ucReadData = TS_IO_Read(DeviceAddr, regAddressYLow);
NirT 1:e8fac4061a5b 357 coord = (ucReadData & FT5336_TOUCH_POS_LSB_MASK) >> FT5336_TOUCH_POS_LSB_SHIFT;
NirT 1:e8fac4061a5b 358
NirT 1:e8fac4061a5b 359 /* Read high part of Y position */
NirT 1:e8fac4061a5b 360 ucReadData = TS_IO_Read(DeviceAddr, regAddressYHigh);
NirT 1:e8fac4061a5b 361 coord |= ((ucReadData & FT5336_TOUCH_POS_MSB_MASK) >> FT5336_TOUCH_POS_MSB_SHIFT) << 8;
NirT 1:e8fac4061a5b 362
NirT 1:e8fac4061a5b 363 /* Send back ready Y position to caller */
NirT 1:e8fac4061a5b 364 *Y = coord;
NirT 1:e8fac4061a5b 365
NirT 1:e8fac4061a5b 366 ft5336_handle.currActiveTouchIdx++; /* next call will work on next touch */
NirT 1:e8fac4061a5b 367
NirT 1:e8fac4061a5b 368 } /* of if(ft5336_handle.currActiveTouchIdx < ft5336_handle.currActiveTouchNb) */
NirT 1:e8fac4061a5b 369 }
NirT 1:e8fac4061a5b 370
NirT 1:e8fac4061a5b 371 /**
NirT 1:e8fac4061a5b 372 * @brief Configure the FT5336 device to generate IT on given INT pin
NirT 1:e8fac4061a5b 373 * connected to MCU as EXTI.
NirT 1:e8fac4061a5b 374 * @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT5336).
NirT 1:e8fac4061a5b 375 * @retval None
NirT 1:e8fac4061a5b 376 */
NirT 1:e8fac4061a5b 377 void ft5336_TS_EnableIT(uint16_t DeviceAddr)
NirT 1:e8fac4061a5b 378 {
NirT 1:e8fac4061a5b 379 uint8_t regValue = 0;
NirT 1:e8fac4061a5b 380 regValue = (FT5336_G_MODE_INTERRUPT_TRIGGER & (FT5336_G_MODE_INTERRUPT_MASK >> FT5336_G_MODE_INTERRUPT_SHIFT)) << FT5336_G_MODE_INTERRUPT_SHIFT;
NirT 1:e8fac4061a5b 381
NirT 1:e8fac4061a5b 382 /* Set interrupt trigger mode in FT5336_GMODE_REG */
NirT 1:e8fac4061a5b 383 TS_IO_Write(DeviceAddr, FT5336_GMODE_REG, regValue);
NirT 1:e8fac4061a5b 384 }
NirT 1:e8fac4061a5b 385
NirT 1:e8fac4061a5b 386 /**
NirT 1:e8fac4061a5b 387 * @brief Configure the FT5336 device to stop generating IT on the given INT pin
NirT 1:e8fac4061a5b 388 * connected to MCU as EXTI.
NirT 1:e8fac4061a5b 389 * @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT5336).
NirT 1:e8fac4061a5b 390 * @retval None
NirT 1:e8fac4061a5b 391 */
NirT 1:e8fac4061a5b 392 void ft5336_TS_DisableIT(uint16_t DeviceAddr)
NirT 1:e8fac4061a5b 393 {
NirT 1:e8fac4061a5b 394 uint8_t regValue = 0;
NirT 1:e8fac4061a5b 395 regValue = (FT5336_G_MODE_INTERRUPT_POLLING & (FT5336_G_MODE_INTERRUPT_MASK >> FT5336_G_MODE_INTERRUPT_SHIFT)) << FT5336_G_MODE_INTERRUPT_SHIFT;
NirT 1:e8fac4061a5b 396
NirT 1:e8fac4061a5b 397 /* Set interrupt polling mode in FT5336_GMODE_REG */
NirT 1:e8fac4061a5b 398 TS_IO_Write(DeviceAddr, FT5336_GMODE_REG, regValue);
NirT 1:e8fac4061a5b 399 }
NirT 1:e8fac4061a5b 400
NirT 1:e8fac4061a5b 401 /**
NirT 1:e8fac4061a5b 402 * @brief Get IT status from FT5336 interrupt status registers
NirT 1:e8fac4061a5b 403 * Should be called Following an EXTI coming to the MCU to know the detailed
NirT 1:e8fac4061a5b 404 * reason of the interrupt.
NirT 1:e8fac4061a5b 405 * @note : This feature is not applicable to FT5336.
NirT 1:e8fac4061a5b 406 * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
NirT 1:e8fac4061a5b 407 * @retval TS interrupts status : always return 0 here
NirT 1:e8fac4061a5b 408 */
NirT 1:e8fac4061a5b 409 uint8_t ft5336_TS_ITStatus(uint16_t DeviceAddr)
NirT 1:e8fac4061a5b 410 {
NirT 1:e8fac4061a5b 411 /* Always return 0 as feature not applicable to FT5336 */
NirT 1:e8fac4061a5b 412 return 0;
NirT 1:e8fac4061a5b 413 }
NirT 1:e8fac4061a5b 414
NirT 1:e8fac4061a5b 415 /**
NirT 1:e8fac4061a5b 416 * @brief Clear IT status in FT5336 interrupt status clear registers
NirT 1:e8fac4061a5b 417 * Should be called Following an EXTI coming to the MCU.
NirT 1:e8fac4061a5b 418 * @note : This feature is not applicable to FT5336.
NirT 1:e8fac4061a5b 419 * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
NirT 1:e8fac4061a5b 420 * @retval None
NirT 1:e8fac4061a5b 421 */
NirT 1:e8fac4061a5b 422 void ft5336_TS_ClearIT(uint16_t DeviceAddr)
NirT 1:e8fac4061a5b 423 {
NirT 1:e8fac4061a5b 424 /* Nothing to be done here for FT5336 */
NirT 1:e8fac4061a5b 425 }
NirT 1:e8fac4061a5b 426
NirT 1:e8fac4061a5b 427 /**** NEW FEATURES enabled when Multi-touch support is enabled ****/
NirT 1:e8fac4061a5b 428
NirT 1:e8fac4061a5b 429 #if (TS_MULTI_TOUCH_SUPPORTED == 1)
NirT 1:e8fac4061a5b 430
NirT 1:e8fac4061a5b 431 /**
NirT 1:e8fac4061a5b 432 * @brief Get the last touch gesture identification (zoom, move up/down...).
NirT 1:e8fac4061a5b 433 * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
NirT 1:e8fac4061a5b 434 * @param pGestureId : Pointer to get last touch gesture Identification.
NirT 1:e8fac4061a5b 435 * @retval None.
NirT 1:e8fac4061a5b 436 */
NirT 1:e8fac4061a5b 437 void ft5336_TS_GetGestureID(uint16_t DeviceAddr, uint32_t * pGestureId)
NirT 1:e8fac4061a5b 438 {
NirT 1:e8fac4061a5b 439 volatile uint8_t ucReadData = 0;
NirT 1:e8fac4061a5b 440
NirT 1:e8fac4061a5b 441 ucReadData = TS_IO_Read(DeviceAddr, FT5336_GEST_ID_REG);
NirT 1:e8fac4061a5b 442
NirT 1:e8fac4061a5b 443 * pGestureId = ucReadData;
NirT 1:e8fac4061a5b 444 }
NirT 1:e8fac4061a5b 445
NirT 1:e8fac4061a5b 446 /**
NirT 1:e8fac4061a5b 447 * @brief Get the touch detailed informations on touch number 'touchIdx' (0..1)
NirT 1:e8fac4061a5b 448 * This touch detailed information contains :
NirT 1:e8fac4061a5b 449 * - weight that was applied to this touch
NirT 1:e8fac4061a5b 450 * - sub-area of the touch in the touch panel
NirT 1:e8fac4061a5b 451 * - event of linked to the touch (press down, lift up, ...)
NirT 1:e8fac4061a5b 452 * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT5336).
NirT 1:e8fac4061a5b 453 * @param touchIdx : Passed index of the touch (0..1) on which we want to get the
NirT 1:e8fac4061a5b 454 * detailed information.
NirT 1:e8fac4061a5b 455 * @param pWeight : Pointer to to get the weight information of 'touchIdx'.
NirT 1:e8fac4061a5b 456 * @param pArea : Pointer to to get the sub-area information of 'touchIdx'.
NirT 1:e8fac4061a5b 457 * @param pEvent : Pointer to to get the event information of 'touchIdx'.
NirT 1:e8fac4061a5b 458
NirT 1:e8fac4061a5b 459 * @retval None.
NirT 1:e8fac4061a5b 460 */
NirT 1:e8fac4061a5b 461 void ft5336_TS_GetTouchInfo(uint16_t DeviceAddr,
NirT 1:e8fac4061a5b 462 uint32_t touchIdx,
NirT 1:e8fac4061a5b 463 uint32_t * pWeight,
NirT 1:e8fac4061a5b 464 uint32_t * pArea,
NirT 1:e8fac4061a5b 465 uint32_t * pEvent)
NirT 1:e8fac4061a5b 466 {
NirT 1:e8fac4061a5b 467 volatile uint8_t ucReadData = 0;
NirT 1:e8fac4061a5b 468 uint8_t regAddressXHigh = 0;
NirT 1:e8fac4061a5b 469 uint8_t regAddressPWeight = 0;
NirT 1:e8fac4061a5b 470 uint8_t regAddressPMisc = 0;
NirT 1:e8fac4061a5b 471
NirT 1:e8fac4061a5b 472 if(touchIdx < ft5336_handle.currActiveTouchNb)
NirT 1:e8fac4061a5b 473 {
NirT 1:e8fac4061a5b 474 switch(touchIdx)
NirT 1:e8fac4061a5b 475 {
NirT 1:e8fac4061a5b 476 case 0 :
NirT 1:e8fac4061a5b 477 regAddressXHigh = FT5336_P1_XH_REG;
NirT 1:e8fac4061a5b 478 regAddressPWeight = FT5336_P1_WEIGHT_REG;
NirT 1:e8fac4061a5b 479 regAddressPMisc = FT5336_P1_MISC_REG;
NirT 1:e8fac4061a5b 480 break;
NirT 1:e8fac4061a5b 481
NirT 1:e8fac4061a5b 482 case 1 :
NirT 1:e8fac4061a5b 483 regAddressXHigh = FT5336_P2_XH_REG;
NirT 1:e8fac4061a5b 484 regAddressPWeight = FT5336_P2_WEIGHT_REG;
NirT 1:e8fac4061a5b 485 regAddressPMisc = FT5336_P2_MISC_REG;
NirT 1:e8fac4061a5b 486 break;
NirT 1:e8fac4061a5b 487
NirT 1:e8fac4061a5b 488 case 2 :
NirT 1:e8fac4061a5b 489 regAddressXHigh = FT5336_P3_XH_REG;
NirT 1:e8fac4061a5b 490 regAddressPWeight = FT5336_P3_WEIGHT_REG;
NirT 1:e8fac4061a5b 491 regAddressPMisc = FT5336_P3_MISC_REG;
NirT 1:e8fac4061a5b 492 break;
NirT 1:e8fac4061a5b 493
NirT 1:e8fac4061a5b 494 case 3 :
NirT 1:e8fac4061a5b 495 regAddressXHigh = FT5336_P4_XH_REG;
NirT 1:e8fac4061a5b 496 regAddressPWeight = FT5336_P4_WEIGHT_REG;
NirT 1:e8fac4061a5b 497 regAddressPMisc = FT5336_P4_MISC_REG;
NirT 1:e8fac4061a5b 498 break;
NirT 1:e8fac4061a5b 499
NirT 1:e8fac4061a5b 500 case 4 :
NirT 1:e8fac4061a5b 501 regAddressXHigh = FT5336_P5_XH_REG;
NirT 1:e8fac4061a5b 502 regAddressPWeight = FT5336_P5_WEIGHT_REG;
NirT 1:e8fac4061a5b 503 regAddressPMisc = FT5336_P5_MISC_REG;
NirT 1:e8fac4061a5b 504 break;
NirT 1:e8fac4061a5b 505
NirT 1:e8fac4061a5b 506 case 5 :
NirT 1:e8fac4061a5b 507 regAddressXHigh = FT5336_P6_XH_REG;
NirT 1:e8fac4061a5b 508 regAddressPWeight = FT5336_P6_WEIGHT_REG;
NirT 1:e8fac4061a5b 509 regAddressPMisc = FT5336_P6_MISC_REG;
NirT 1:e8fac4061a5b 510 break;
NirT 1:e8fac4061a5b 511
NirT 1:e8fac4061a5b 512 case 6 :
NirT 1:e8fac4061a5b 513 regAddressXHigh = FT5336_P7_XH_REG;
NirT 1:e8fac4061a5b 514 regAddressPWeight = FT5336_P7_WEIGHT_REG;
NirT 1:e8fac4061a5b 515 regAddressPMisc = FT5336_P7_MISC_REG;
NirT 1:e8fac4061a5b 516 break;
NirT 1:e8fac4061a5b 517
NirT 1:e8fac4061a5b 518 case 7 :
NirT 1:e8fac4061a5b 519 regAddressXHigh = FT5336_P8_XH_REG;
NirT 1:e8fac4061a5b 520 regAddressPWeight = FT5336_P8_WEIGHT_REG;
NirT 1:e8fac4061a5b 521 regAddressPMisc = FT5336_P8_MISC_REG;
NirT 1:e8fac4061a5b 522 break;
NirT 1:e8fac4061a5b 523
NirT 1:e8fac4061a5b 524 case 8 :
NirT 1:e8fac4061a5b 525 regAddressXHigh = FT5336_P9_XH_REG;
NirT 1:e8fac4061a5b 526 regAddressPWeight = FT5336_P9_WEIGHT_REG;
NirT 1:e8fac4061a5b 527 regAddressPMisc = FT5336_P9_MISC_REG;
NirT 1:e8fac4061a5b 528 break;
NirT 1:e8fac4061a5b 529
NirT 1:e8fac4061a5b 530 case 9 :
NirT 1:e8fac4061a5b 531 regAddressXHigh = FT5336_P10_XH_REG;
NirT 1:e8fac4061a5b 532 regAddressPWeight = FT5336_P10_WEIGHT_REG;
NirT 1:e8fac4061a5b 533 regAddressPMisc = FT5336_P10_MISC_REG;
NirT 1:e8fac4061a5b 534 break;
NirT 1:e8fac4061a5b 535
NirT 1:e8fac4061a5b 536 default :
NirT 1:e8fac4061a5b 537 break;
NirT 1:e8fac4061a5b 538
NirT 1:e8fac4061a5b 539 } /* end switch(touchIdx) */
NirT 1:e8fac4061a5b 540
NirT 1:e8fac4061a5b 541 /* Read Event Id of touch index */
NirT 1:e8fac4061a5b 542 ucReadData = TS_IO_Read(DeviceAddr, regAddressXHigh);
NirT 1:e8fac4061a5b 543 * pEvent = (ucReadData & FT5336_TOUCH_EVT_FLAG_MASK) >> FT5336_TOUCH_EVT_FLAG_SHIFT;
NirT 1:e8fac4061a5b 544
NirT 1:e8fac4061a5b 545 /* Read weight of touch index */
NirT 1:e8fac4061a5b 546 ucReadData = TS_IO_Read(DeviceAddr, regAddressPWeight);
NirT 1:e8fac4061a5b 547 * pWeight = (ucReadData & FT5336_TOUCH_WEIGHT_MASK) >> FT5336_TOUCH_WEIGHT_SHIFT;
NirT 1:e8fac4061a5b 548
NirT 1:e8fac4061a5b 549 /* Read area of touch index */
NirT 1:e8fac4061a5b 550 ucReadData = TS_IO_Read(DeviceAddr, regAddressPMisc);
NirT 1:e8fac4061a5b 551 * pArea = (ucReadData & FT5336_TOUCH_AREA_MASK) >> FT5336_TOUCH_AREA_SHIFT;
NirT 1:e8fac4061a5b 552
NirT 1:e8fac4061a5b 553 } /* of if(touchIdx < ft5336_handle.currActiveTouchNb) */
NirT 1:e8fac4061a5b 554 }
NirT 1:e8fac4061a5b 555
NirT 1:e8fac4061a5b 556 #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
NirT 1:e8fac4061a5b 557
NirT 1:e8fac4061a5b 558 /** @defgroup ft5336_Static_Function_Body
NirT 1:e8fac4061a5b 559 * @{
NirT 1:e8fac4061a5b 560 */
NirT 1:e8fac4061a5b 561
NirT 1:e8fac4061a5b 562 /* Static functions bodies-----------------------------------------------*/
NirT 1:e8fac4061a5b 563
NirT 1:e8fac4061a5b 564
NirT 1:e8fac4061a5b 565 /**
NirT 1:e8fac4061a5b 566 * @brief Return the status of I2C was initialized or not.
NirT 1:e8fac4061a5b 567 * @param None.
NirT 1:e8fac4061a5b 568 * @retval : I2C initialization status.
NirT 1:e8fac4061a5b 569 */
NirT 1:e8fac4061a5b 570 static uint8_t ft5336_Get_I2C_InitializedStatus(void)
NirT 1:e8fac4061a5b 571 {
NirT 1:e8fac4061a5b 572 return(ft5336_handle.i2cInitialized);
NirT 1:e8fac4061a5b 573 }
NirT 1:e8fac4061a5b 574
NirT 1:e8fac4061a5b 575 /**
NirT 1:e8fac4061a5b 576 * @brief I2C initialize if needed.
NirT 1:e8fac4061a5b 577 * @param None.
NirT 1:e8fac4061a5b 578 * @retval : None.
NirT 1:e8fac4061a5b 579 */
NirT 1:e8fac4061a5b 580 static void ft5336_I2C_InitializeIfRequired(void)
NirT 1:e8fac4061a5b 581 {
NirT 1:e8fac4061a5b 582 if(ft5336_Get_I2C_InitializedStatus() == FT5336_I2C_NOT_INITIALIZED)
NirT 1:e8fac4061a5b 583 {
NirT 1:e8fac4061a5b 584 /* Initialize TS IO BUS layer (I2C) */
NirT 1:e8fac4061a5b 585 TS_IO_Init();
NirT 1:e8fac4061a5b 586
NirT 1:e8fac4061a5b 587 /* Set state to initialized */
NirT 1:e8fac4061a5b 588 ft5336_handle.i2cInitialized = FT5336_I2C_INITIALIZED;
NirT 1:e8fac4061a5b 589 }
NirT 1:e8fac4061a5b 590 }
NirT 1:e8fac4061a5b 591
NirT 1:e8fac4061a5b 592 /**
NirT 1:e8fac4061a5b 593 * @brief Basic static configuration of TouchScreen
NirT 1:e8fac4061a5b 594 * @param DeviceAddr: FT5336 Device address for communication on I2C Bus.
NirT 1:e8fac4061a5b 595 * @retval Status FT5336_STATUS_OK or FT5336_STATUS_NOT_OK.
NirT 1:e8fac4061a5b 596 */
NirT 1:e8fac4061a5b 597 static uint32_t ft5336_TS_Configure(uint16_t DeviceAddr)
NirT 1:e8fac4061a5b 598 {
NirT 1:e8fac4061a5b 599 uint32_t status = FT5336_STATUS_OK;
NirT 1:e8fac4061a5b 600
NirT 1:e8fac4061a5b 601 /* Nothing special to be done for FT5336 */
NirT 1:e8fac4061a5b 602
NirT 1:e8fac4061a5b 603 return(status);
NirT 1:e8fac4061a5b 604 }
NirT 1:e8fac4061a5b 605
NirT 1:e8fac4061a5b 606 /**
NirT 1:e8fac4061a5b 607 * @}
NirT 1:e8fac4061a5b 608 */
NirT 1:e8fac4061a5b 609
NirT 1:e8fac4061a5b 610 /**
NirT 1:e8fac4061a5b 611 * @}
NirT 1:e8fac4061a5b 612 */
NirT 1:e8fac4061a5b 613
NirT 1:e8fac4061a5b 614 /**
NirT 1:e8fac4061a5b 615 * @}
NirT 1:e8fac4061a5b 616 */
NirT 1:e8fac4061a5b 617
NirT 1:e8fac4061a5b 618 /**
NirT 1:e8fac4061a5b 619 * @}
NirT 1:e8fac4061a5b 620 */
NirT 1:e8fac4061a5b 621
NirT 1:e8fac4061a5b 622 /**
NirT 1:e8fac4061a5b 623 * @}
NirT 1:e8fac4061a5b 624 */
NirT 1:e8fac4061a5b 625 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/