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 Nov 15 11:20:11 2019 +0100
Revision:
4:72a949940ad6
Parent:
0:c0f3bbab73d2
STM32Cube_FW_F7_V1.15.0 Update

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