STM32Cube BSP FW for STM32F769I-Discovery

Dependents:   mbed-os-example-blinky-5 DISCO-F769NI_TOUCHSCREEN_demo_custom_1 Datarecorder2 DISCO-F769NI_TOUCHSCREEN_demo ... more

Committer:
Jerome Coutant
Date:
Fri Feb 10 13:08:21 2017 +0100
Revision:
0:c0f3bbab73d2
Child:
4:72a949940ad6
STM32Cube_FW_F7_V1.5.1 BSP STM32F769I-Discovery

Who changed what in which revision?

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