fsdfsdf

Fork of BSP_DISCO_F469NI by ST

Committer:
bcostm
Date:
Mon May 30 11:09:05 2016 +0000
Revision:
1:9e4eb47092ed
Parent:
0:0002c86c2220
Fix issue with LCD in Portrait mode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:0002c86c2220 1 /**
bcostm 0:0002c86c2220 2 ******************************************************************************
bcostm 0:0002c86c2220 3 * @file ft6x06.c
bcostm 0:0002c86c2220 4 * @author MCD Application Team
bcostm 0:0002c86c2220 5 * @version V1.0.0
bcostm 0:0002c86c2220 6 * @date 03-August-2015
bcostm 0:0002c86c2220 7 * @brief This file provides a set of functions needed to manage the FT6X06
bcostm 0:0002c86c2220 8 * IO Expander devices.
bcostm 0:0002c86c2220 9 ******************************************************************************
bcostm 0:0002c86c2220 10 * @attention
bcostm 0:0002c86c2220 11 *
bcostm 0:0002c86c2220 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
bcostm 0:0002c86c2220 13 *
bcostm 0:0002c86c2220 14 * Redistribution and use in source and binary forms, with or without modification,
bcostm 0:0002c86c2220 15 * are permitted provided that the following conditions are met:
bcostm 0:0002c86c2220 16 * 1. Redistributions of source code must retain the above copyright notice,
bcostm 0:0002c86c2220 17 * this list of conditions and the following disclaimer.
bcostm 0:0002c86c2220 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
bcostm 0:0002c86c2220 19 * this list of conditions and the following disclaimer in the documentation
bcostm 0:0002c86c2220 20 * and/or other materials provided with the distribution.
bcostm 0:0002c86c2220 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
bcostm 0:0002c86c2220 22 * may be used to endorse or promote products derived from this software
bcostm 0:0002c86c2220 23 * without specific prior written permission.
bcostm 0:0002c86c2220 24 *
bcostm 0:0002c86c2220 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
bcostm 0:0002c86c2220 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
bcostm 0:0002c86c2220 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
bcostm 0:0002c86c2220 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
bcostm 0:0002c86c2220 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
bcostm 0:0002c86c2220 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
bcostm 0:0002c86c2220 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
bcostm 0:0002c86c2220 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
bcostm 0:0002c86c2220 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
bcostm 0:0002c86c2220 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bcostm 0:0002c86c2220 35 *
bcostm 0:0002c86c2220 36 ******************************************************************************
bcostm 0:0002c86c2220 37 */
bcostm 0:0002c86c2220 38
bcostm 0:0002c86c2220 39 /* Includes ------------------------------------------------------------------*/
bcostm 0:0002c86c2220 40 #include "ft6x06.h"
bcostm 0:0002c86c2220 41
bcostm 0:0002c86c2220 42 /** @addtogroup BSP
bcostm 0:0002c86c2220 43 * @{
bcostm 0:0002c86c2220 44 */
bcostm 0:0002c86c2220 45
bcostm 0:0002c86c2220 46 /** @addtogroup Component
bcostm 0:0002c86c2220 47 * @{
bcostm 0:0002c86c2220 48 */
bcostm 0:0002c86c2220 49
bcostm 0:0002c86c2220 50 /** @defgroup FT6X06
bcostm 0:0002c86c2220 51 * @{
bcostm 0:0002c86c2220 52 */
bcostm 0:0002c86c2220 53
bcostm 0:0002c86c2220 54 /* Private typedef -----------------------------------------------------------*/
bcostm 0:0002c86c2220 55
bcostm 0:0002c86c2220 56 /** @defgroup FT6X06_Private_Defines FT6X06 Private Defines
bcostm 0:0002c86c2220 57 * @{
bcostm 0:0002c86c2220 58 */
bcostm 0:0002c86c2220 59 #define FT6x06_MAX_INSTANCE 2
bcostm 0:0002c86c2220 60 /**
bcostm 0:0002c86c2220 61 * @}
bcostm 0:0002c86c2220 62 */
bcostm 0:0002c86c2220 63
bcostm 0:0002c86c2220 64 /* Private macro -------------------------------------------------------------*/
bcostm 0:0002c86c2220 65
bcostm 0:0002c86c2220 66 /** @defgroup FT6X06_Private_Variables FT6X06 Private Variables
bcostm 0:0002c86c2220 67 * @{
bcostm 0:0002c86c2220 68 */
bcostm 0:0002c86c2220 69
bcostm 0:0002c86c2220 70 /* Touch screen driver structure initialization */
bcostm 0:0002c86c2220 71 TS_DrvTypeDef ft6x06_ts_drv =
bcostm 0:0002c86c2220 72 {
bcostm 0:0002c86c2220 73 ft6x06_Init,
bcostm 0:0002c86c2220 74 ft6x06_ReadID,
bcostm 0:0002c86c2220 75 ft6x06_Reset,
bcostm 0:0002c86c2220 76
bcostm 0:0002c86c2220 77 ft6x06_TS_Start,
bcostm 0:0002c86c2220 78 ft6x06_TS_DetectTouch,
bcostm 0:0002c86c2220 79 ft6x06_TS_GetXY,
bcostm 0:0002c86c2220 80
bcostm 0:0002c86c2220 81 ft6x06_TS_EnableIT,
bcostm 0:0002c86c2220 82 ft6x06_TS_ClearIT,
bcostm 0:0002c86c2220 83 ft6x06_TS_ITStatus,
bcostm 0:0002c86c2220 84 ft6x06_TS_DisableIT
bcostm 0:0002c86c2220 85
bcostm 0:0002c86c2220 86 };
bcostm 0:0002c86c2220 87
bcostm 0:0002c86c2220 88 /* ft6x06 instances by address */
bcostm 0:0002c86c2220 89 uint8_t ft6x06[FT6x06_MAX_INSTANCE] = {0};
bcostm 0:0002c86c2220 90
bcostm 0:0002c86c2220 91 /* Global ft6x06 handle */
bcostm 0:0002c86c2220 92 static ft6x06_handle_TypeDef ft6x06_handle = { FT6206_I2C_NOT_INITIALIZED, 0, 0};
bcostm 0:0002c86c2220 93
bcostm 0:0002c86c2220 94 /**
bcostm 0:0002c86c2220 95 * @}
bcostm 0:0002c86c2220 96 */
bcostm 0:0002c86c2220 97
bcostm 0:0002c86c2220 98 /** @defgroup ft6x06_Private_Function_Prototypes ft6x06 Private Function Prototypes
bcostm 0:0002c86c2220 99 * @{
bcostm 0:0002c86c2220 100 */
bcostm 0:0002c86c2220 101 static uint8_t ft6x06_GetInstance(uint16_t DeviceAddr);
bcostm 0:0002c86c2220 102 /* Private functions prototypes-----------------------------------------------*/
bcostm 0:0002c86c2220 103 #if (TS_AUTO_CALIBRATION_SUPPORTED == 1)
bcostm 0:0002c86c2220 104 /**
bcostm 0:0002c86c2220 105 * @brief Start TouchScreen calibration phase
bcostm 0:0002c86c2220 106 * @param DeviceAddr: FT6206 Device address for communication on I2C Bus.
bcostm 0:0002c86c2220 107 * @retval Status FT6206_STATUS_OK or FT6206_STATUS_NOT_OK.
bcostm 0:0002c86c2220 108 */
bcostm 0:0002c86c2220 109 static uint32_t ft6x06_TS_Calibration(uint16_t DeviceAddr);
bcostm 0:0002c86c2220 110 #endif /* TS_AUTO_CALIBRATION_SUPPORTED == 1 */
bcostm 0:0002c86c2220 111
bcostm 0:0002c86c2220 112 /**
bcostm 0:0002c86c2220 113 * @brief Basic static configuration of TouchScreen
bcostm 0:0002c86c2220 114 * @param DeviceAddr: FT6206 Device address for communication on I2C Bus.
bcostm 0:0002c86c2220 115 * @retval Status FT6206_STATUS_OK or FT6206_STATUS_NOT_OK.
bcostm 0:0002c86c2220 116 */
bcostm 0:0002c86c2220 117 static uint32_t ft6x06_TS_Configure(uint16_t DeviceAddr);
bcostm 0:0002c86c2220 118
bcostm 0:0002c86c2220 119 /**
bcostm 0:0002c86c2220 120 * @}
bcostm 0:0002c86c2220 121 */
bcostm 0:0002c86c2220 122
bcostm 0:0002c86c2220 123 /** @defgroup ft6x06_Private_Functions ft6x06 Private Functions
bcostm 0:0002c86c2220 124 * @{
bcostm 0:0002c86c2220 125 */
bcostm 0:0002c86c2220 126
bcostm 0:0002c86c2220 127 /**
bcostm 0:0002c86c2220 128 * @brief Initialize the ft6x06 communication bus
bcostm 0:0002c86c2220 129 * from MCU to FT6206 : ie I2C channel initialization (if required).
bcostm 0:0002c86c2220 130 * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
bcostm 0:0002c86c2220 131 * @retval None
bcostm 0:0002c86c2220 132 */
bcostm 0:0002c86c2220 133 void ft6x06_Init(uint16_t DeviceAddr)
bcostm 0:0002c86c2220 134 {
bcostm 0:0002c86c2220 135 uint8_t instance;
bcostm 0:0002c86c2220 136 uint8_t empty;
bcostm 0:0002c86c2220 137
bcostm 0:0002c86c2220 138 /* Check if device instance already exists */
bcostm 0:0002c86c2220 139 instance = ft6x06_GetInstance(DeviceAddr);
bcostm 0:0002c86c2220 140
bcostm 0:0002c86c2220 141 /* To prevent double initialization */
bcostm 0:0002c86c2220 142 if(instance == 0xFF)
bcostm 0:0002c86c2220 143 {
bcostm 0:0002c86c2220 144 /* Look for empty instance */
bcostm 0:0002c86c2220 145 empty = ft6x06_GetInstance(0);
bcostm 0:0002c86c2220 146
bcostm 0:0002c86c2220 147 if(empty < FT6x06_MAX_INSTANCE)
bcostm 0:0002c86c2220 148 {
bcostm 0:0002c86c2220 149 /* Register the current device instance */
bcostm 0:0002c86c2220 150 ft6x06[empty] = DeviceAddr;
bcostm 0:0002c86c2220 151
bcostm 0:0002c86c2220 152 /* Initialize IO BUS layer */
bcostm 0:0002c86c2220 153 TS_IO_Init();
bcostm 0:0002c86c2220 154 }
bcostm 0:0002c86c2220 155 }
bcostm 0:0002c86c2220 156 }
bcostm 0:0002c86c2220 157
bcostm 0:0002c86c2220 158 /**
bcostm 0:0002c86c2220 159 * @brief Software Reset the ft6x06.
bcostm 0:0002c86c2220 160 * @note : Not applicable to FT6206.
bcostm 0:0002c86c2220 161 * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
bcostm 0:0002c86c2220 162 * @retval None
bcostm 0:0002c86c2220 163 */
bcostm 0:0002c86c2220 164 void ft6x06_Reset(uint16_t DeviceAddr)
bcostm 0:0002c86c2220 165 {
bcostm 0:0002c86c2220 166 /* Do nothing */
bcostm 0:0002c86c2220 167 /* No software reset sequence available in FT6206 IC */
bcostm 0:0002c86c2220 168 }
bcostm 0:0002c86c2220 169
bcostm 0:0002c86c2220 170 /**
bcostm 0:0002c86c2220 171 * @brief Read the ft6x06 device ID, pre initialize I2C in case of need to be
bcostm 0:0002c86c2220 172 * able to read the FT6206 device ID, and verify this is a FT6206.
bcostm 0:0002c86c2220 173 * @param DeviceAddr: I2C FT6x06 Slave address.
bcostm 0:0002c86c2220 174 * @retval The Device ID (two bytes).
bcostm 0:0002c86c2220 175 */
bcostm 0:0002c86c2220 176 uint16_t ft6x06_ReadID(uint16_t DeviceAddr)
bcostm 0:0002c86c2220 177 {
bcostm 0:0002c86c2220 178 /* Initialize I2C link if needed */
bcostm 0:0002c86c2220 179 TS_IO_Init();
bcostm 0:0002c86c2220 180
bcostm 0:0002c86c2220 181 /* Return the device ID value */
bcostm 0:0002c86c2220 182 return (TS_IO_Read(DeviceAddr, FT6206_CHIP_ID_REG));
bcostm 0:0002c86c2220 183 }
bcostm 0:0002c86c2220 184
bcostm 0:0002c86c2220 185 /**
bcostm 0:0002c86c2220 186 * @brief Configures the touch Screen IC device to start detecting touches
bcostm 0:0002c86c2220 187 * It goes through an internal calibration process (Hw calibration sequence of
bcostm 0:0002c86c2220 188 * the touch screen).
bcostm 0:0002c86c2220 189 * @param DeviceAddr: Device address on communication Bus (I2C slave address).
bcostm 0:0002c86c2220 190 * @retval None.
bcostm 0:0002c86c2220 191 */
bcostm 0:0002c86c2220 192 void ft6x06_TS_Start(uint16_t DeviceAddr)
bcostm 0:0002c86c2220 193 {
bcostm 0:0002c86c2220 194 #if (TS_AUTO_CALIBRATION_SUPPORTED == 1)
bcostm 0:0002c86c2220 195 /* Hw Calibration sequence start : should be done once after each power up */
bcostm 0:0002c86c2220 196 /* This is called internal calibration of the touch screen */
bcostm 0:0002c86c2220 197 ft6x06_TS_Calibration(DeviceAddr);
bcostm 0:0002c86c2220 198 #endif
bcostm 0:0002c86c2220 199 /* Minimum static configuration of FT6206 */
bcostm 0:0002c86c2220 200 ft6x06_TS_Configure(DeviceAddr);
bcostm 0:0002c86c2220 201
bcostm 0:0002c86c2220 202 /* By default set FT6206 IC in Polling mode : no INT generation on FT6206 for new touch available */
bcostm 0:0002c86c2220 203 /* Note TS_INT is active low */
bcostm 0:0002c86c2220 204 ft6x06_TS_DisableIT(DeviceAddr);
bcostm 0:0002c86c2220 205 }
bcostm 0:0002c86c2220 206
bcostm 0:0002c86c2220 207 /**
bcostm 0:0002c86c2220 208 * @brief Return if there is touches detected or not.
bcostm 0:0002c86c2220 209 * Try to detect new touches and forget the old ones (reset internal global
bcostm 0:0002c86c2220 210 * variables).
bcostm 0:0002c86c2220 211 * @param DeviceAddr: Device address on communication Bus.
bcostm 0:0002c86c2220 212 * @retval : Number of active touches detected (can be 0, 1 or 2).
bcostm 0:0002c86c2220 213 */
bcostm 0:0002c86c2220 214 uint8_t ft6x06_TS_DetectTouch(uint16_t DeviceAddr)
bcostm 0:0002c86c2220 215 {
bcostm 0:0002c86c2220 216 volatile uint8_t nbTouch = 0;
bcostm 0:0002c86c2220 217
bcostm 0:0002c86c2220 218 /* Read register FT6206_TD_STAT_REG to check number of touches detection */
bcostm 0:0002c86c2220 219 nbTouch = TS_IO_Read(DeviceAddr, FT6206_TD_STAT_REG);
bcostm 0:0002c86c2220 220 nbTouch &= FT6206_TD_STAT_MASK;
bcostm 0:0002c86c2220 221
bcostm 0:0002c86c2220 222 if(nbTouch > FT6206_MAX_DETECTABLE_TOUCH)
bcostm 0:0002c86c2220 223 {
bcostm 0:0002c86c2220 224 /* If invalid number of touch detected, set it to zero */
bcostm 0:0002c86c2220 225 nbTouch = 0;
bcostm 0:0002c86c2220 226 }
bcostm 0:0002c86c2220 227
bcostm 0:0002c86c2220 228 /* Update ft6x06 driver internal global : current number of active touches */
bcostm 0:0002c86c2220 229 ft6x06_handle.currActiveTouchNb = nbTouch;
bcostm 0:0002c86c2220 230
bcostm 0:0002c86c2220 231 /* Reset current active touch index on which to work on */
bcostm 0:0002c86c2220 232 ft6x06_handle.currActiveTouchIdx = 0;
bcostm 0:0002c86c2220 233
bcostm 0:0002c86c2220 234 return(nbTouch);
bcostm 0:0002c86c2220 235 }
bcostm 0:0002c86c2220 236
bcostm 0:0002c86c2220 237 /**
bcostm 0:0002c86c2220 238 * @brief Get the touch screen X and Y positions values
bcostm 0:0002c86c2220 239 * Manage multi touch thanks to touch Index global
bcostm 0:0002c86c2220 240 * variable 'ft6x06_handle.currActiveTouchIdx'.
bcostm 0:0002c86c2220 241 * @param DeviceAddr: Device address on communication Bus.
bcostm 0:0002c86c2220 242 * @param X: Pointer to X position value
bcostm 0:0002c86c2220 243 * @param Y: Pointer to Y position value
bcostm 0:0002c86c2220 244 * @retval None.
bcostm 0:0002c86c2220 245 */
bcostm 0:0002c86c2220 246 void ft6x06_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y)
bcostm 0:0002c86c2220 247 {
bcostm 0:0002c86c2220 248 uint8_t regAddress = 0;
bcostm 0:0002c86c2220 249 uint8_t dataxy[4];
bcostm 0:0002c86c2220 250
bcostm 0:0002c86c2220 251 if(ft6x06_handle.currActiveTouchIdx < ft6x06_handle.currActiveTouchNb)
bcostm 0:0002c86c2220 252 {
bcostm 0:0002c86c2220 253 switch(ft6x06_handle.currActiveTouchIdx)
bcostm 0:0002c86c2220 254 {
bcostm 0:0002c86c2220 255 case 0 :
bcostm 0:0002c86c2220 256 regAddress = FT6206_P1_XH_REG;
bcostm 0:0002c86c2220 257 break;
bcostm 0:0002c86c2220 258 case 1 :
bcostm 0:0002c86c2220 259 regAddress = FT6206_P2_XH_REG;
bcostm 0:0002c86c2220 260 break;
bcostm 0:0002c86c2220 261
bcostm 0:0002c86c2220 262 default :
bcostm 0:0002c86c2220 263 break;
bcostm 0:0002c86c2220 264 }
bcostm 0:0002c86c2220 265
bcostm 0:0002c86c2220 266 /* Read X and Y positions */
bcostm 0:0002c86c2220 267 TS_IO_ReadMultiple(DeviceAddr, regAddress, dataxy, sizeof(dataxy));
bcostm 0:0002c86c2220 268
bcostm 0:0002c86c2220 269 /* Send back ready X position to caller */
bcostm 0:0002c86c2220 270 *X = ((dataxy[0] & FT6206_MSB_MASK) << 8) | (dataxy[1] & FT6206_LSB_MASK);
bcostm 0:0002c86c2220 271
bcostm 0:0002c86c2220 272 /* Send back ready Y position to caller */
bcostm 0:0002c86c2220 273 *Y = ((dataxy[2] & FT6206_MSB_MASK) << 8) | (dataxy[3] & FT6206_LSB_MASK);
bcostm 0:0002c86c2220 274
bcostm 0:0002c86c2220 275 ft6x06_handle.currActiveTouchIdx++;
bcostm 0:0002c86c2220 276 }
bcostm 0:0002c86c2220 277 }
bcostm 0:0002c86c2220 278
bcostm 0:0002c86c2220 279 /**
bcostm 0:0002c86c2220 280 * @brief Configure the FT6206 device to generate IT on given INT pin
bcostm 0:0002c86c2220 281 * connected to MCU as EXTI.
bcostm 0:0002c86c2220 282 * @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT6206).
bcostm 0:0002c86c2220 283 * @retval None
bcostm 0:0002c86c2220 284 */
bcostm 0:0002c86c2220 285 void ft6x06_TS_EnableIT(uint16_t DeviceAddr)
bcostm 0:0002c86c2220 286 {
bcostm 0:0002c86c2220 287 uint8_t regValue = 0;
bcostm 0:0002c86c2220 288 regValue = (FT6206_G_MODE_INTERRUPT_TRIGGER & (FT6206_G_MODE_INTERRUPT_MASK >> FT6206_G_MODE_INTERRUPT_SHIFT)) << FT6206_G_MODE_INTERRUPT_SHIFT;
bcostm 0:0002c86c2220 289
bcostm 0:0002c86c2220 290 /* Set interrupt trigger mode in FT6206_GMODE_REG */
bcostm 0:0002c86c2220 291 TS_IO_Write(DeviceAddr, FT6206_GMODE_REG, regValue);
bcostm 0:0002c86c2220 292 }
bcostm 0:0002c86c2220 293
bcostm 0:0002c86c2220 294 /**
bcostm 0:0002c86c2220 295 * @brief Configure the FT6206 device to stop generating IT on the given INT pin
bcostm 0:0002c86c2220 296 * connected to MCU as EXTI.
bcostm 0:0002c86c2220 297 * @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT6206).
bcostm 0:0002c86c2220 298 * @retval None
bcostm 0:0002c86c2220 299 */
bcostm 0:0002c86c2220 300 void ft6x06_TS_DisableIT(uint16_t DeviceAddr)
bcostm 0:0002c86c2220 301 {
bcostm 0:0002c86c2220 302 uint8_t regValue = 0;
bcostm 0:0002c86c2220 303 regValue = (FT6206_G_MODE_INTERRUPT_POLLING & (FT6206_G_MODE_INTERRUPT_MASK >> FT6206_G_MODE_INTERRUPT_SHIFT)) << FT6206_G_MODE_INTERRUPT_SHIFT;
bcostm 0:0002c86c2220 304
bcostm 0:0002c86c2220 305 /* Set interrupt polling mode in FT6206_GMODE_REG */
bcostm 0:0002c86c2220 306 TS_IO_Write(DeviceAddr, FT6206_GMODE_REG, regValue);
bcostm 0:0002c86c2220 307 }
bcostm 0:0002c86c2220 308
bcostm 0:0002c86c2220 309 /**
bcostm 0:0002c86c2220 310 * @brief Get IT status from FT6206 interrupt status registers
bcostm 0:0002c86c2220 311 * Should be called Following an EXTI coming to the MCU to know the detailed
bcostm 0:0002c86c2220 312 * reason of the interrupt.
bcostm 0:0002c86c2220 313 * @note : This feature is not applicable to FT6206.
bcostm 0:0002c86c2220 314 * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
bcostm 0:0002c86c2220 315 * @retval TS interrupts status : always return 0 here
bcostm 0:0002c86c2220 316 */
bcostm 0:0002c86c2220 317 uint8_t ft6x06_TS_ITStatus(uint16_t DeviceAddr)
bcostm 0:0002c86c2220 318 {
bcostm 0:0002c86c2220 319 /* Always return 0 as feature not applicable to FT6206 */
bcostm 0:0002c86c2220 320 return 0;
bcostm 0:0002c86c2220 321 }
bcostm 0:0002c86c2220 322
bcostm 0:0002c86c2220 323 /**
bcostm 0:0002c86c2220 324 * @brief Clear IT status in FT6206 interrupt status clear registers
bcostm 0:0002c86c2220 325 * Should be called Following an EXTI coming to the MCU.
bcostm 0:0002c86c2220 326 * @note : This feature is not applicable to FT6206.
bcostm 0:0002c86c2220 327 * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
bcostm 0:0002c86c2220 328 * @retval None
bcostm 0:0002c86c2220 329 */
bcostm 0:0002c86c2220 330 void ft6x06_TS_ClearIT(uint16_t DeviceAddr)
bcostm 0:0002c86c2220 331 {
bcostm 0:0002c86c2220 332 /* Nothing to be done here for FT6206 */
bcostm 0:0002c86c2220 333 }
bcostm 0:0002c86c2220 334
bcostm 0:0002c86c2220 335 /**** NEW FEATURES enabled when Multi-touch support is enabled ****/
bcostm 0:0002c86c2220 336
bcostm 0:0002c86c2220 337 #if (TS_MULTI_TOUCH_SUPPORTED == 1)
bcostm 0:0002c86c2220 338
bcostm 0:0002c86c2220 339 /**
bcostm 0:0002c86c2220 340 * @brief Get the last touch gesture identification (zoom, move up/down...).
bcostm 0:0002c86c2220 341 * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6x06).
bcostm 0:0002c86c2220 342 * @param pGestureId : Pointer to get last touch gesture Identification.
bcostm 0:0002c86c2220 343 * @retval None.
bcostm 0:0002c86c2220 344 */
bcostm 0:0002c86c2220 345 void ft6x06_TS_GetGestureID(uint16_t DeviceAddr, uint32_t * pGestureId)
bcostm 0:0002c86c2220 346 {
bcostm 0:0002c86c2220 347 volatile uint8_t ucReadData = 0;
bcostm 0:0002c86c2220 348
bcostm 0:0002c86c2220 349 ucReadData = TS_IO_Read(DeviceAddr, FT6206_GEST_ID_REG);
bcostm 0:0002c86c2220 350
bcostm 0:0002c86c2220 351 * pGestureId = ucReadData;
bcostm 0:0002c86c2220 352 }
bcostm 0:0002c86c2220 353
bcostm 0:0002c86c2220 354 /**
bcostm 0:0002c86c2220 355 * @brief Get the touch detailed informations on touch number 'touchIdx' (0..1)
bcostm 0:0002c86c2220 356 * This touch detailed information contains :
bcostm 0:0002c86c2220 357 * - weight that was applied to this touch
bcostm 0:0002c86c2220 358 * - sub-area of the touch in the touch panel
bcostm 0:0002c86c2220 359 * - event of linked to the touch (press down, lift up, ...)
bcostm 0:0002c86c2220 360 * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6x06).
bcostm 0:0002c86c2220 361 * @param touchIdx : Passed index of the touch (0..1) on which we want to get the
bcostm 0:0002c86c2220 362 * detailed information.
bcostm 0:0002c86c2220 363 * @param pWeight : Pointer to to get the weight information of 'touchIdx'.
bcostm 0:0002c86c2220 364 * @param pArea : Pointer to to get the sub-area information of 'touchIdx'.
bcostm 0:0002c86c2220 365 * @param pEvent : Pointer to to get the event information of 'touchIdx'.
bcostm 0:0002c86c2220 366
bcostm 0:0002c86c2220 367 * @retval None.
bcostm 0:0002c86c2220 368 */
bcostm 0:0002c86c2220 369 void ft6x06_TS_GetTouchInfo(uint16_t DeviceAddr,
bcostm 0:0002c86c2220 370 uint32_t touchIdx,
bcostm 0:0002c86c2220 371 uint32_t * pWeight,
bcostm 0:0002c86c2220 372 uint32_t * pArea,
bcostm 0:0002c86c2220 373 uint32_t * pEvent)
bcostm 0:0002c86c2220 374 {
bcostm 0:0002c86c2220 375 uint8_t regAddress = 0;
bcostm 0:0002c86c2220 376 uint8_t dataxy[3];
bcostm 0:0002c86c2220 377
bcostm 0:0002c86c2220 378 if(touchIdx < ft6x06_handle.currActiveTouchNb)
bcostm 0:0002c86c2220 379 {
bcostm 0:0002c86c2220 380 switch(touchIdx)
bcostm 0:0002c86c2220 381 {
bcostm 0:0002c86c2220 382 case 0 :
bcostm 0:0002c86c2220 383 regAddress = FT6206_P1_WEIGHT_REG;
bcostm 0:0002c86c2220 384 break;
bcostm 0:0002c86c2220 385
bcostm 0:0002c86c2220 386 case 1 :
bcostm 0:0002c86c2220 387 regAddress = FT6206_P2_WEIGHT_REG;
bcostm 0:0002c86c2220 388 break;
bcostm 0:0002c86c2220 389
bcostm 0:0002c86c2220 390 default :
bcostm 0:0002c86c2220 391 break;
bcostm 0:0002c86c2220 392
bcostm 0:0002c86c2220 393 } /* end switch(touchIdx) */
bcostm 0:0002c86c2220 394
bcostm 0:0002c86c2220 395 /* Read weight, area and Event Id of touch index */
bcostm 0:0002c86c2220 396 TS_IO_ReadMultiple(DeviceAddr, regAddress, dataxy, sizeof(dataxy));
bcostm 0:0002c86c2220 397
bcostm 0:0002c86c2220 398 /* Return weight of touch index */
bcostm 0:0002c86c2220 399 * pWeight = (dataxy[0] & FT6206_TOUCH_WEIGHT_MASK) >> FT6206_TOUCH_WEIGHT_SHIFT;
bcostm 0:0002c86c2220 400 /* Return area of touch index */
bcostm 0:0002c86c2220 401 * pArea = (dataxy[1] & FT6206_TOUCH_AREA_MASK) >> FT6206_TOUCH_AREA_SHIFT;
bcostm 0:0002c86c2220 402 /* Return Event Id of touch index */
bcostm 0:0002c86c2220 403 * pEvent = (dataxy[2] & FT6206_TOUCH_EVT_FLAG_MASK) >> FT6206_TOUCH_EVT_FLAG_SHIFT;
bcostm 0:0002c86c2220 404
bcostm 0:0002c86c2220 405 } /* of if(touchIdx < ft6x06_handle.currActiveTouchNb) */
bcostm 0:0002c86c2220 406 }
bcostm 0:0002c86c2220 407
bcostm 0:0002c86c2220 408 #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
bcostm 0:0002c86c2220 409
bcostm 0:0002c86c2220 410 #if (TS_AUTO_CALIBRATION_SUPPORTED == 1)
bcostm 0:0002c86c2220 411 /**
bcostm 0:0002c86c2220 412 * @brief Start TouchScreen calibration phase
bcostm 0:0002c86c2220 413 * @param DeviceAddr: FT6206 Device address for communication on I2C Bus.
bcostm 0:0002c86c2220 414 * @retval Status FT6206_STATUS_OK or FT6206_STATUS_NOT_OK.
bcostm 0:0002c86c2220 415 */
bcostm 0:0002c86c2220 416 static uint32_t ft6x06_TS_Calibration(uint16_t DeviceAddr)
bcostm 0:0002c86c2220 417 {
bcostm 0:0002c86c2220 418 uint32_t nbAttempt = 0;
bcostm 0:0002c86c2220 419 volatile uint8_t ucReadData;
bcostm 0:0002c86c2220 420 volatile uint8_t regValue;
bcostm 0:0002c86c2220 421 uint32_t status = FT6206_STATUS_OK;
bcostm 0:0002c86c2220 422 uint8_t bEndCalibration = 0;
bcostm 0:0002c86c2220 423
bcostm 0:0002c86c2220 424 /* >> Calibration sequence start */
bcostm 0:0002c86c2220 425
bcostm 0:0002c86c2220 426 /* Switch FT6206 back to factory mode to calibrate */
bcostm 0:0002c86c2220 427 regValue = (FT6206_DEV_MODE_FACTORY & FT6206_DEV_MODE_MASK) << FT6206_DEV_MODE_SHIFT;
bcostm 0:0002c86c2220 428 TS_IO_Write(DeviceAddr, FT6206_DEV_MODE_REG, regValue); /* 0x40 */
bcostm 0:0002c86c2220 429
bcostm 0:0002c86c2220 430 /* Read back the same register FT6206_DEV_MODE_REG */
bcostm 0:0002c86c2220 431 ucReadData = TS_IO_Read(DeviceAddr, FT6206_DEV_MODE_REG);
bcostm 0:0002c86c2220 432 TS_IO_Delay(300); /* Wait 300 ms */
bcostm 0:0002c86c2220 433
bcostm 0:0002c86c2220 434 if(((ucReadData & (FT6206_DEV_MODE_MASK << FT6206_DEV_MODE_SHIFT)) >> FT6206_DEV_MODE_SHIFT) != FT6206_DEV_MODE_FACTORY )
bcostm 0:0002c86c2220 435 {
bcostm 0:0002c86c2220 436 /* Return error to caller */
bcostm 0:0002c86c2220 437 return(FT6206_STATUS_NOT_OK);
bcostm 0:0002c86c2220 438 }
bcostm 0:0002c86c2220 439
bcostm 0:0002c86c2220 440 /* Start calibration command */
bcostm 0:0002c86c2220 441 TS_IO_Write(DeviceAddr, FT6206_TD_STAT_REG, 0x04);
bcostm 0:0002c86c2220 442 TS_IO_Delay(300); /* Wait 300 ms */
bcostm 0:0002c86c2220 443
bcostm 0:0002c86c2220 444 /* 100 attempts to wait switch from factory mode (calibration) to working mode */
bcostm 0:0002c86c2220 445 for (nbAttempt=0; ((nbAttempt < 100) && (!bEndCalibration)) ; nbAttempt++)
bcostm 0:0002c86c2220 446 {
bcostm 0:0002c86c2220 447 ucReadData = TS_IO_Read(DeviceAddr, FT6206_DEV_MODE_REG);
bcostm 0:0002c86c2220 448 ucReadData = (ucReadData & (FT6206_DEV_MODE_MASK << FT6206_DEV_MODE_SHIFT)) >> FT6206_DEV_MODE_SHIFT;
bcostm 0:0002c86c2220 449 if(ucReadData == FT6206_DEV_MODE_WORKING)
bcostm 0:0002c86c2220 450 {
bcostm 0:0002c86c2220 451 /* Auto Switch to FT6206_DEV_MODE_WORKING : means calibration have ended */
bcostm 0:0002c86c2220 452 bEndCalibration = 1; /* exit for loop */
bcostm 0:0002c86c2220 453 }
bcostm 0:0002c86c2220 454
bcostm 0:0002c86c2220 455 TS_IO_Delay(200); /* Wait 200 ms */
bcostm 0:0002c86c2220 456 }
bcostm 0:0002c86c2220 457
bcostm 0:0002c86c2220 458 /* Calibration sequence end << */
bcostm 0:0002c86c2220 459
bcostm 0:0002c86c2220 460 return(status);
bcostm 0:0002c86c2220 461 }
bcostm 0:0002c86c2220 462 #endif /* TS_AUTO_CALIBRATION_SUPPORTED == 1 */
bcostm 0:0002c86c2220 463
bcostm 0:0002c86c2220 464 /**
bcostm 0:0002c86c2220 465 * @brief Basic static configuration of TouchScreen
bcostm 0:0002c86c2220 466 * @param DeviceAddr: FT6206 Device address for communication on I2C Bus.
bcostm 0:0002c86c2220 467 * @retval Status FT6206_STATUS_OK or FT6206_STATUS_NOT_OK.
bcostm 0:0002c86c2220 468 */
bcostm 0:0002c86c2220 469 static uint32_t ft6x06_TS_Configure(uint16_t DeviceAddr)
bcostm 0:0002c86c2220 470 {
bcostm 0:0002c86c2220 471 uint32_t status = FT6206_STATUS_OK;
bcostm 0:0002c86c2220 472
bcostm 0:0002c86c2220 473 /* Nothing special to be done for FT6206 */
bcostm 0:0002c86c2220 474
bcostm 0:0002c86c2220 475 return(status);
bcostm 0:0002c86c2220 476 }
bcostm 0:0002c86c2220 477
bcostm 0:0002c86c2220 478 /**
bcostm 0:0002c86c2220 479 * @brief Check if the device instance of the selected address is already registered
bcostm 0:0002c86c2220 480 * and return its index
bcostm 0:0002c86c2220 481 * @param DeviceAddr: Device address on communication Bus.
bcostm 0:0002c86c2220 482 * @retval Index of the device instance if registered, 0xFF if not.
bcostm 0:0002c86c2220 483 */
bcostm 0:0002c86c2220 484 static uint8_t ft6x06_GetInstance(uint16_t DeviceAddr)
bcostm 0:0002c86c2220 485 {
bcostm 0:0002c86c2220 486 uint8_t idx = 0;
bcostm 0:0002c86c2220 487
bcostm 0:0002c86c2220 488 /* Check all the registered instances */
bcostm 0:0002c86c2220 489 for(idx = 0; idx < FT6x06_MAX_INSTANCE ; idx ++)
bcostm 0:0002c86c2220 490 {
bcostm 0:0002c86c2220 491 if(ft6x06[idx] == DeviceAddr)
bcostm 0:0002c86c2220 492 {
bcostm 0:0002c86c2220 493 return idx;
bcostm 0:0002c86c2220 494 }
bcostm 0:0002c86c2220 495 }
bcostm 0:0002c86c2220 496
bcostm 0:0002c86c2220 497 return 0xFF;
bcostm 0:0002c86c2220 498 }
bcostm 0:0002c86c2220 499
bcostm 0:0002c86c2220 500 /**
bcostm 0:0002c86c2220 501 * @}
bcostm 0:0002c86c2220 502 */
bcostm 0:0002c86c2220 503
bcostm 0:0002c86c2220 504 /**
bcostm 0:0002c86c2220 505 * @}
bcostm 0:0002c86c2220 506 */
bcostm 0:0002c86c2220 507
bcostm 0:0002c86c2220 508 /**
bcostm 0:0002c86c2220 509 * @}
bcostm 0:0002c86c2220 510 */
bcostm 0:0002c86c2220 511
bcostm 0:0002c86c2220 512 /**
bcostm 0:0002c86c2220 513 * @}
bcostm 0:0002c86c2220 514 */
bcostm 0:0002c86c2220 515
bcostm 0:0002c86c2220 516 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/