BSP files for STM32H747I-Discovery Copy from ST Cube delivery

Dependents:   DISCO_H747I_LCD_demo DISCO_H747I_AUDIO_demo

Committer:
Jerome Coutant
Date:
Wed Nov 06 11:32:01 2019 +0100
Revision:
3:bc403474b366
Parent:
0:146cf26a9bbb
Add PDM lib

Who changed what in which revision?

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