1 /* 2 * Copyright 2019-2020,2024 NXP 3 * All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 #ifndef _FSL_GT911_H_ 9 #define _FSL_GT911_H_ 10 11 #include "fsl_common.h" 12 13 /* 14 * Change Log: 15 * 16 * 1.0.4: 17 * - Added new return status for coordinate not ready to indicate invalid data. 18 * 19 * 1.0.3: 20 * - Fixed MISRA 2012 issues. 21 * 22 * 1.0.2: 23 * - Fixed the issue that INT pin is output low when using kGT911_I2cAddrAny. 24 * 25 * 1.0.1: 26 * - Update GT911_GetMultiTouch and GT911_GetSingleTouch to return 27 * kStatus_TOUCHPANEL_NotTouched when no touch happens. 28 * 29 * 1.0.0: 30 * - Initial version. 31 */ 32 33 /*! 34 * @addtogroup gt911 35 * @{ 36 */ 37 38 /******************************************************************************* 39 * Definitions 40 ******************************************************************************/ 41 /*! @brief GT911 maximum number of simultaneously detected touches. */ 42 #define GT911_MAX_TOUCHES (10U) 43 44 /*! @brief Error code definition. */ 45 enum _touch_status 46 { 47 kStatus_TOUCHPANEL_NotTouched = MAKE_STATUS(kStatusGroup_TOUCH_PANEL, 0), /*!< No touch happen. */ 48 kStatus_TOUCHPANEL_NotReady = MAKE_STATUS(kStatusGroup_TOUCH_PANEL, 1), /*!< Coordinate not ready, data invalid. */ 49 }; 50 51 /*! @brief Touch point definition. */ 52 typedef struct 53 { 54 bool valid; /*!< Whether the touch point coordinate value is valid. */ 55 uint8_t touchID; /*!< Id of the touch point. This numeric value stays constant between down and up event. */ 56 uint16_t x; /*!< X coordinate of the touch point */ 57 uint16_t y; /*!< Y coordinate of the touch point */ 58 } touch_point_t; 59 60 /*! @brief gt911 I2C address mode.*/ 61 typedef enum _gt911_i2c_addr_mode 62 { 63 kGT911_I2cAddrMode0, /*!< 7-bit address 0x5D, or 8-bit 0xBA/0xBB */ 64 kGT911_I2cAddrMode1, /*!< 7-bit address 0x14, or 8-bit 0x28/0x29 */ 65 kGT911_I2cAddrAny, /*!< Use 0x5D or 0x14, driver selects the right one to use, 66 this is used for the case that MCU could not pull 67 the INT pin level. 68 */ 69 } gt911_i2c_addr_mode_t; 70 71 /*! @brief gt911 interrupt pin mode.*/ 72 typedef enum _gt911_int_pin_mode 73 { 74 kGT911_IntPinPullDown, /*!< Interrupt pin output pull down. */ 75 kGT911_IntPinPullUp, /*!< Interrupt pin output pull up. */ 76 kGT911_IntPinInput, /*!< Interrupt pin set to input mode. */ 77 } gt911_int_pin_mode_t; 78 79 /*! @brief gt911 interrupt trigger mode.*/ 80 typedef enum _gt911_int_trig_mode 81 { 82 kGT911_IntRisingEdge, /*!< Rising edge. */ 83 kGT911_IntFallingEdge, /*!< Falling edge. */ 84 kGT911_IntLowLevel, /*!< Low level. */ 85 kGT911_IntHighLevel, /*!< High edge. */ 86 } gt911_int_trig_mode_t; 87 88 typedef status_t (*gt911_i2c_send_func_t)( 89 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, const uint8_t *txBuff, uint8_t txBuffSize); 90 typedef status_t (*gt911_i2c_receive_func_t)( 91 uint8_t deviceAddress, uint32_t subAddress, uint8_t subaddressSize, uint8_t *rxBuff, uint8_t rxBuffSize); 92 typedef void (*gt911_int_pin_func_t)(gt911_int_pin_mode_t mode); 93 typedef void (*gt911_reset_pin_func_t)(bool pullUp); 94 95 /*! @brief gt911 configure structure.*/ 96 typedef struct _gt911_point_reg 97 { 98 uint8_t id; /*!< Track ID. */ 99 uint8_t lowX; /*!< Low byte of x coordinate. */ 100 uint8_t highX; /*!< High byte of x coordinate. */ 101 uint8_t lowY; /*!< Low byte of y coordinate. */ 102 uint8_t highY; /*!< High byte of x coordinate. */ 103 uint8_t lowSize; /*!< Low byte of point size. */ 104 uint8_t highSize; /*!< High byte of point size. */ 105 uint8_t reserved; /*!< Reserved. */ 106 } gt911_point_reg_t; 107 108 /*! @brief gt911 configure structure.*/ 109 typedef struct _gt911_config 110 { 111 gt911_i2c_send_func_t I2C_SendFunc; /*!< Function to send I2C data. */ 112 gt911_i2c_receive_func_t I2C_ReceiveFunc; /*!< Function to receive I2C data. */ 113 void (*timeDelayMsFunc)(uint32_t delayMs); /*!< Function to delay some MS. */ 114 gt911_int_pin_func_t intPinFunc; /*!< Function to set interrupt pin to different mode. */ 115 gt911_reset_pin_func_t pullResetPinFunc; /*!< Function to pull reset pin high or low. */ 116 uint8_t touchPointNum; /*!< How many touch points to enable. */ 117 gt911_i2c_addr_mode_t i2cAddrMode; /*!< I2C address mode. */ 118 gt911_int_trig_mode_t intTrigMode; /*!< Interrupt trigger mode. */ 119 } gt911_config_t; 120 121 /*! @brief gt911 driver structure.*/ 122 typedef struct _gt911_handle 123 { 124 gt911_i2c_send_func_t I2C_SendFunc; /*!< Function to send I2C data. */ 125 gt911_i2c_receive_func_t I2C_ReceiveFunc; /*!< Function to receive I2C data. */ 126 void (*timeDelayMsFunc)(uint32_t delayMs); /*!< Function to delay some MS. */ 127 gt911_reset_pin_func_t pullResetPinFunc; /*!< Function to pull reset pin high or low. */ 128 gt911_point_reg_t pointReg[GT911_MAX_TOUCHES]; /*!< Buffer to receive touch point raw data. */ 129 uint8_t touchPointNum; /*!< How many touch points to enable. */ 130 uint8_t i2cAddr; /*!< I2C address. */ 131 uint16_t resolutionX; /*!< Resolution. */ 132 uint16_t resolutionY; /*!< Resolution. */ 133 } gt911_handle_t; 134 135 /******************************************************************************* 136 * API 137 ******************************************************************************/ 138 139 #if defined(__cplusplus) 140 extern "C" { 141 #endif 142 143 /*! 144 * @brief Initialize the driver. 145 * 146 * @param[in] handle Pointer to the GT911 driver. 147 * @param[in] config Pointer to the configuration. 148 * @return Returns @ref kStatus_Success if succeeded, otherwise return error code. 149 */ 150 status_t GT911_Init(gt911_handle_t *handle, const gt911_config_t *config); 151 152 /*! 153 * @brief De-initialize the driver. 154 * 155 * @param[in] handle Pointer to the GT911 driver. 156 * @return Returns @ref kStatus_Success if succeeded, otherwise return error code. 157 */ 158 status_t GT911_Deinit(gt911_handle_t *handle); 159 160 /*! 161 * @brief Get single touch point coordinate. 162 * 163 * @param[in] handle Pointer to the GT911 driver. 164 * @param[out] touch_x X coordinate of the touch point. 165 * @param[out] touch_y Y coordinate of the touch point. 166 * @return Returns @ref kStatus_Success if succeeded, otherwise return error code. 167 */ 168 status_t GT911_GetSingleTouch(gt911_handle_t *handle, int *touch_x, int *touch_y); 169 170 /*! 171 * @brief Get multiple touch points coordinate. 172 * 173 * When calling this function, parameter @ref touch_count means the array size 174 * of @p touch_array. After the function returns, the @p touch_count means how 175 * many valid touch points there are in the @p touch_array. 176 * 177 * @param[in] handle Pointer to the GT911 driver. 178 * @param[in, out] touch_count The touch point number. 179 * @param[out] touch_array Array of touch points coordinate. 180 * @return Returns @ref kStatus_Success if succeeded, otherwise return error code. 181 */ 182 status_t GT911_GetMultiTouch(gt911_handle_t *handle, uint8_t *touch_count, touch_point_t touch_array[]); 183 184 /*! 185 * @brief Get touch IC resolution. 186 * 187 * Note the touch resolution might be different with display resolution. 188 * 189 * @param handle Pointer to the driver. 190 * @param touch_x X resolution. 191 * @param touch_y Y resolution. 192 * @return Returns @ref kStatus_Success if succeeded, otherwise return error code. 193 */ 194 status_t GT911_GetResolution(gt911_handle_t *handle, int *resolutionX, int *resolutionY); 195 196 #if defined(__cplusplus) 197 } 198 #endif 199 200 /*! @} */ 201 202 #endif /* _FSL_GT911_H_ */ 203