BSP files for STM32H747I-Discovery Copy from ST Cube delivery

Dependents:   DISCO_H747I_LCD_demo DISCO_H747I_AUDIO_demo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ft6x06.h Source File

ft6x06.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    ft6x06.h
00004  * @author  MCD Application Team
00005   * @version V1.0.0
00006   * @date    03-August-2015
00007  * @brief   This file contains all the functions prototypes for the
00008  *          ft6x06.c IO expander driver.
00009  ******************************************************************************
00010  * @attention
00011  *
00012  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
00013  *
00014  * Redistribution and use in source and binary forms, with or without modification,
00015  * are permitted provided that the following conditions are met:
00016  *   1. Redistributions of source code must retain the above copyright notice,
00017  *      this list of conditions and the following disclaimer.
00018  *   2. Redistributions in binary form must reproduce the above copyright notice,
00019  *      this list of conditions and the following disclaimer in the documentation
00020  *      and/or other materials provided with the distribution.
00021  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00022  *      may be used to endorse or promote products derived from this software
00023  *      without specific prior written permission.
00024  *
00025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00026  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00029  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00030  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00031  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00033  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  ******************************************************************************
00037  */
00038 
00039 /* Define to prevent recursive inclusion -------------------------------------*/
00040 #ifndef __FT6X06_H
00041 #define __FT6X06_H
00042 
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046 
00047 /* Set Multi-touch as non supported */
00048 #ifndef TS_MULTI_TOUCH_SUPPORTED
00049   #define TS_MULTI_TOUCH_SUPPORTED 0
00050 #endif
00051 
00052 /* Set Auto-calibration as non supported */  
00053 #ifndef TS_AUTO_CALIBRATION_SUPPORTED
00054   #define TS_AUTO_CALIBRATION_SUPPORTED 0
00055 #endif
00056   
00057 /* Includes ------------------------------------------------------------------*/
00058 #include "../Common/ts.h"
00059 
00060 /* Macros --------------------------------------------------------------------*/
00061 
00062 /** @typedef ft6x06_handle_TypeDef
00063  *  ft6x06 Handle definition.
00064  */
00065 typedef struct
00066 {
00067   uint8_t i2cInitialized;
00068 
00069   /* field holding the current number of simultaneous active touches */
00070   uint8_t currActiveTouchNb;
00071 
00072   /* field holding the touch index currently managed */
00073   uint8_t currActiveTouchIdx;
00074 
00075 } ft6x06_handle_TypeDef;
00076 
00077   /** @addtogroup BSP
00078    * @{
00079    */
00080 
00081   /** @addtogroup Component
00082    * @{
00083    */
00084 
00085   /** @defgroup FT6X06
00086    * @{
00087    */
00088 
00089   /* Exported types ------------------------------------------------------------*/
00090 
00091   /** @defgroup FT6X06_Exported_Types
00092    * @{
00093    */
00094 
00095   /* Exported constants --------------------------------------------------------*/
00096 
00097   /** @defgroup FT6X06_Exported_Constants
00098    * @{
00099    */
00100 
00101   /* Maximum border values of the touchscreen pad */
00102 #define  FT_6206_MAX_WIDTH              ((uint16_t)800)     /* Touchscreen pad max width   */
00103 #define  FT_6206_MAX_HEIGHT             ((uint16_t)480)     /* Touchscreen pad max height  */
00104 
00105   /* Possible values of driver functions return status */
00106 #define FT6206_STATUS_OK                0
00107 #define FT6206_STATUS_NOT_OK            1
00108 
00109   /* Possible values of global variable 'TS_I2C_Initialized' */
00110 #define FT6206_I2C_NOT_INITIALIZED      0
00111 #define FT6206_I2C_INITIALIZED          1
00112 
00113   /* Max detectable simultaneous touches */
00114 #define FT6206_MAX_DETECTABLE_TOUCH     2
00115 
00116   /**
00117    * @brief : Definitions for FT6206 I2C register addresses on 8 bit
00118    **/
00119 
00120   /* Current mode register of the FT6206 (R/W) */
00121 #define FT6206_DEV_MODE_REG             0x00
00122 
00123   /* Possible values of FT6206_DEV_MODE_REG */
00124 #define FT6206_DEV_MODE_WORKING         0x00
00125 #define FT6206_DEV_MODE_FACTORY         0x04
00126 
00127 #define FT6206_DEV_MODE_MASK            0x7
00128 #define FT6206_DEV_MODE_SHIFT           4
00129 
00130   /* Gesture ID register */
00131 #define FT6206_GEST_ID_REG              0x01
00132 
00133   /* Possible values of FT6206_GEST_ID_REG */
00134 #define FT6206_GEST_ID_NO_GESTURE       0x00
00135 #define FT6206_GEST_ID_MOVE_UP          0x10
00136 #define FT6206_GEST_ID_MOVE_RIGHT       0x14
00137 #define FT6206_GEST_ID_MOVE_DOWN        0x18
00138 #define FT6206_GEST_ID_MOVE_LEFT        0x1C
00139 #define FT6206_GEST_ID_ZOOM_IN          0x48
00140 #define FT6206_GEST_ID_ZOOM_OUT         0x49
00141 
00142   /* Touch Data Status register : gives number of active touch points (0..2) */
00143 #define FT6206_TD_STAT_REG              0x02
00144 
00145   /* Values related to FT6206_TD_STAT_REG */
00146 #define FT6206_TD_STAT_MASK             0x0F
00147 #define FT6206_TD_STAT_SHIFT            0x00
00148 
00149   /* Values Pn_XH and Pn_YH related */
00150 #define FT6206_TOUCH_EVT_FLAG_PRESS_DOWN 0x00
00151 #define FT6206_TOUCH_EVT_FLAG_LIFT_UP    0x01
00152 #define FT6206_TOUCH_EVT_FLAG_CONTACT    0x02
00153 #define FT6206_TOUCH_EVT_FLAG_NO_EVENT   0x03
00154 
00155 #define FT6206_TOUCH_EVT_FLAG_SHIFT     6
00156 #define FT6206_TOUCH_EVT_FLAG_MASK      (3 << FT6206_TOUCH_EVT_FLAG_SHIFT)
00157 
00158 #define FT6206_MSB_MASK                 0x0F
00159 #define FT6206_MSB_SHIFT                0
00160 
00161   /* Values Pn_XL and Pn_YL related */
00162 #define FT6206_LSB_MASK                 0xFF
00163 #define FT6206_LSB_SHIFT                0
00164 
00165 #define FT6206_P1_XH_REG                0x03
00166 #define FT6206_P1_XL_REG                0x04
00167 #define FT6206_P1_YH_REG                0x05
00168 #define FT6206_P1_YL_REG                0x06
00169 
00170   /* Touch Pressure register value (R) */
00171 #define FT6206_P1_WEIGHT_REG            0x07
00172 
00173   /* Values Pn_WEIGHT related  */
00174 #define FT6206_TOUCH_WEIGHT_MASK        0xFF
00175 #define FT6206_TOUCH_WEIGHT_SHIFT       0
00176 
00177   /* Touch area register */
00178 #define FT6206_P1_MISC_REG              0x08
00179 
00180   /* Values related to FT6206_Pn_MISC_REG */
00181 #define FT6206_TOUCH_AREA_MASK         (0x04 << 4)
00182 #define FT6206_TOUCH_AREA_SHIFT        0x04
00183 
00184 #define FT6206_P2_XH_REG               0x09
00185 #define FT6206_P2_XL_REG               0x0A
00186 #define FT6206_P2_YH_REG               0x0B
00187 #define FT6206_P2_YL_REG               0x0C
00188 #define FT6206_P2_WEIGHT_REG           0x0D
00189 #define FT6206_P2_MISC_REG             0x0E
00190 
00191   /* Threshold for touch detection */
00192 #define FT6206_TH_GROUP_REG            0x80
00193 
00194   /* Values FT6206_TH_GROUP_REG : threshold related  */
00195 #define FT6206_THRESHOLD_MASK          0xFF
00196 #define FT6206_THRESHOLD_SHIFT         0
00197 
00198   /* Filter function coefficients */
00199 #define FT6206_TH_DIFF_REG             0x85
00200 
00201   /* Control register */
00202 #define FT6206_CTRL_REG                0x86
00203 
00204   /* Values related to FT6206_CTRL_REG */
00205 
00206   /* Will keep the Active mode when there is no touching */
00207 #define FT6206_CTRL_KEEP_ACTIVE_MODE    0x00
00208 
00209   /* Switching from Active mode to Monitor mode automatically when there is no touching */
00210 #define FT6206_CTRL_KEEP_AUTO_SWITCH_MONITOR_MODE  0x01
00211 
00212   /* The time period of switching from Active mode to Monitor mode when there is no touching */
00213 #define FT6206_TIMEENTERMONITOR_REG     0x87
00214 
00215   /* Report rate in Active mode */
00216 #define FT6206_PERIODACTIVE_REG         0x88
00217 
00218   /* Report rate in Monitor mode */
00219 #define FT6206_PERIODMONITOR_REG        0x89
00220 
00221   /* The value of the minimum allowed angle while Rotating gesture mode */
00222 #define FT6206_RADIAN_VALUE_REG         0x91
00223 
00224   /* Maximum offset while Moving Left and Moving Right gesture */
00225 #define FT6206_OFFSET_LEFT_RIGHT_REG    0x92
00226 
00227   /* Maximum offset while Moving Up and Moving Down gesture */
00228 #define FT6206_OFFSET_UP_DOWN_REG       0x93
00229 
00230   /* Minimum distance while Moving Left and Moving Right gesture */
00231 #define FT6206_DISTANCE_LEFT_RIGHT_REG  0x94
00232 
00233   /* Minimum distance while Moving Up and Moving Down gesture */
00234 #define FT6206_DISTANCE_UP_DOWN_REG     0x95
00235 
00236   /* Maximum distance while Zoom In and Zoom Out gesture */
00237 #define FT6206_DISTANCE_ZOOM_REG        0x96
00238 
00239   /* High 8-bit of LIB Version info */
00240 #define FT6206_LIB_VER_H_REG            0xA1
00241 
00242   /* Low 8-bit of LIB Version info */
00243 #define FT6206_LIB_VER_L_REG            0xA2
00244 
00245   /* Chip Selecting */
00246 #define FT6206_CIPHER_REG               0xA3
00247 
00248   /* Interrupt mode register (used when in interrupt mode) */
00249 #define FT6206_GMODE_REG                0xA4
00250 
00251 #define FT6206_G_MODE_INTERRUPT_MASK    0x03
00252 #define FT6206_G_MODE_INTERRUPT_SHIFT   0x00
00253 
00254   /* Possible values of FT6206_GMODE_REG */
00255 #define FT6206_G_MODE_INTERRUPT_POLLING 0x00
00256 #define FT6206_G_MODE_INTERRUPT_TRIGGER 0x01
00257 
00258   /* Current power mode the FT6206 system is in (R) */
00259 #define FT6206_PWR_MODE_REG             0xA5
00260 
00261   /* FT6206 firmware version */
00262 #define FT6206_FIRMID_REG               0xA6
00263 
00264   /* FT6206 Chip identification register */
00265 #define FT6206_CHIP_ID_REG              0xA8
00266 
00267   /*  Possible values of FT6206_CHIP_ID_REG */
00268 #define FT6206_ID_VALUE                 0x11
00269 
00270   /* Release code version */
00271 #define FT6206_RELEASE_CODE_ID_REG      0xAF
00272 
00273   /* Current operating mode the FT6206 system is in (R) */
00274 #define FT6206_STATE_REG                0xBC
00275 
00276   /**
00277    * @}
00278    */
00279 
00280   /* Exported macro ------------------------------------------------------------*/
00281 
00282   /** @defgroup ft6x06_Exported_Macros
00283    * @{
00284    */
00285 
00286   /* Exported functions --------------------------------------------------------*/
00287 
00288   /** @defgroup ft6x06_Exported_Functions
00289    * @{
00290    */
00291 
00292   /**
00293    * @brief ft6x06 Control functions
00294    */
00295 
00296 
00297 /**
00298  * @brief  Initialize the ft6x06 communication bus
00299  *         from MCU to FT6206 : ie I2C channel initialization (if required).
00300  * @param  DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
00301  * @retval None
00302  */
00303 void ft6x06_Init(uint16_t DeviceAddr);
00304 
00305 /**
00306  * @brief  Software Reset the ft6x06.
00307  * @param  DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
00308  * @retval None
00309  */
00310 void ft6x06_Reset(uint16_t DeviceAddr);
00311 
00312 /**
00313  * @brief  Read the ft6x06 device ID, pre intitalize I2C in case of need to be
00314  *         able to read the FT6206 device ID, and verify this is a FT6206.
00315  * @param  DeviceAddr: I2C FT6x06 Slave address.
00316  * @retval The Device ID (two bytes).
00317  */
00318 uint16_t ft6x06_ReadID(uint16_t DeviceAddr);
00319 
00320 /**
00321  * @brief  Configures the touch Screen IC device to start detecting touches
00322  * @param  DeviceAddr: Device address on communication Bus (I2C slave address).
00323  * @retval None.
00324  */
00325 void ft6x06_TS_Start(uint16_t DeviceAddr);
00326 
00327 /**
00328  * @brief  Return if there is touches detected or not.
00329  *         Try to detect new touches and forget the old ones (reset internal global
00330  *         variables).
00331  * @param  DeviceAddr: Device address on communication Bus.
00332  * @retval : Number of active touches detected (can be 0, 1 or 2).
00333  */
00334 uint8_t ft6x06_TS_DetectTouch(uint16_t DeviceAddr);
00335 
00336 /**
00337  * @brief  Get the touch screen X and Y positions values
00338  *         Manage multi touch thanks to touch Index global
00339  *         variable 'ft6x06_handle.currActiveTouchIdx'.
00340  * @param  DeviceAddr: Device address on communication Bus.
00341  * @param  X: Pointer to X position value
00342  * @param  Y: Pointer to Y position value
00343  * @retval None.
00344  */
00345 void ft6x06_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y);
00346 
00347 /**
00348  * @brief  Configure the FT6206 device to generate IT on given INT pin
00349  *         connected to MCU as EXTI.
00350  * @param  DeviceAddr: Device address on communication Bus (Slave I2C address of FT6206).
00351  * @retval None
00352  */
00353 void ft6x06_TS_EnableIT(uint16_t DeviceAddr);
00354 
00355 /**
00356  * @brief  Configure the FT6206 device to stop generating IT on the given INT pin
00357  *         connected to MCU as EXTI.
00358  * @param  DeviceAddr: Device address on communication Bus (Slave I2C address of FT6206).
00359  * @retval None
00360  */
00361 void ft6x06_TS_DisableIT(uint16_t DeviceAddr);
00362 
00363 /**
00364  * @brief  Get IT status from FT6206 interrupt status registers
00365  *         Should be called Following an EXTI coming to the MCU to know the detailed
00366  *         reason of the interrupt.
00367  * @param  DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
00368  * @retval TS interrupts status
00369  */
00370 uint8_t ft6x06_TS_ITStatus (uint16_t DeviceAddr);
00371 
00372 /**
00373  * @brief  Clear IT status in FT6206 interrupt status clear registers
00374  *         Should be called Following an EXTI coming to the MCU.
00375  * @param  DeviceAddr: Device address on communication Bus (I2C slave address of FT6206).
00376  * @retval TS interrupts status
00377  */
00378 void ft6x06_TS_ClearIT (uint16_t DeviceAddr);
00379 
00380 /**** NEW FEATURES enabled when Multi-touch support is enabled ****/
00381 
00382 #if (TS_MULTI_TOUCH_SUPPORTED == 1)
00383 
00384 /**
00385  * @brief  Get the last touch gesture identification (zoom, move up/down...).
00386  * @param  DeviceAddr: Device address on communication Bus (I2C slave address of FT6x06).
00387  * @param  pGestureId : Pointer to get last touch gesture Identification.
00388  * @retval None.
00389  */
00390 void ft6x06_TS_GetGestureID(uint16_t DeviceAddr, uint32_t * pGestureId);
00391 
00392 /**
00393  * @brief  Get the touch detailed informations on touch number 'touchIdx' (0..1)
00394  *         This touch detailed information contains :
00395  *         - weight that was applied to this touch
00396  *         - sub-area of the touch in the touch panel
00397  *         - event of linked to the touch (press down, lift up, ...)
00398  * @param  DeviceAddr: Device address on communication Bus (I2C slave address of FT6x06).
00399  * @param  touchIdx : Passed index of the touch (0..1) on which we want to get the
00400  *                    detailed information.
00401  * @param  pWeight : Pointer to to get the weight information of 'touchIdx'.
00402  * @param  pArea   : Pointer to to get the sub-area information of 'touchIdx'.
00403  * @param  pEvent  : Pointer to to get the event information of 'touchIdx'.
00404 
00405  * @retval None.
00406  */
00407 void ft6x06_TS_GetTouchInfo(uint16_t   DeviceAddr,
00408                             uint32_t   touchIdx,
00409                             uint32_t * pWeight,
00410                             uint32_t * pArea,
00411                             uint32_t * pEvent);
00412 
00413 #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
00414 
00415 /* Imported TS IO functions --------------------------------------------------------*/
00416 
00417 /** @defgroup ft6x06_Imported_Functions
00418  * @{
00419  */
00420 
00421 /* TouchScreen (TS) external IO functions */
00422 extern void     TS_IO_Init(void);
00423 extern void     TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
00424 extern uint8_t  TS_IO_Read(uint8_t Addr, uint8_t Reg);
00425 extern uint16_t TS_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
00426 extern void     TS_IO_Delay(uint32_t Delay);
00427 
00428   /**
00429    * @}
00430    */
00431 
00432   /* Imported global variables --------------------------------------------------------*/
00433 
00434   /** @defgroup ft6x06_Imported_Globals
00435    * @{
00436    */
00437 
00438 
00439 /* Touch screen driver structure */
00440 extern TS_DrvTypeDef ft6x06_ts_drv;
00441 
00442   /**
00443    * @}
00444    */
00445 
00446 #ifdef __cplusplus
00447 }
00448 #endif
00449 #endif /* __FT6X06_H */
00450 
00451 
00452 /**
00453  * @}
00454  */
00455 
00456 /**
00457  * @}
00458  */
00459 
00460 /**
00461  * @}
00462  */
00463 
00464 /**
00465  * @}
00466  */
00467 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/