updated wait_ms(ms) to thread_sleep_for(ms) for Mbed OS 6

Committer:
aa6164
Date:
Wed Jun 09 12:45:23 2021 +0000
Revision:
4:27609b3a44ed
Parent:
2:123b894b49dd
Updated wait_ms() to thread_sleep_for() for Mbed OS 6+

Who changed what in which revision?

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