1 /* 2 * Copyright (c) 2021 HPMicro 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef HPM_FT5406_H 9 #define HPM_FT5406_H 10 #include "hpm_common.h" 11 #include "hpm_i2c_drv.h" 12 13 #define FT5406_I2C_ADDR (0x38U) 14 15 /* 16 * FT5406 registers at operation mode 17 */ 18 #define FT5406_DEVICE_MODE (0U) 19 #define FT5406_GEST_ID (0x1U) 20 #define FT5406_TD_STATUS (0x2U) 21 #define FT5406_TOUCH1_XH (0x3U) 22 #define FT5406_TOUCH1_XL (0x4U) 23 #define FT5406_TOUCH1_YH (0x5U) 24 #define FT5406_TOUCH1_YL (0x6U) 25 26 #define FT5406_TOUCH2_XH (0x9U) 27 #define FT5406_TOUCH2_XL (0xAU) 28 #define FT5406_TOUCH2_YH (0xBU) 29 #define FT5406_TOUCH2_YL (0xCU) 30 31 #define FT5406_TOUCH3_XH (0xFU) 32 #define FT5406_TOUCH3_XL (0x10U) 33 #define FT5406_TOUCH3_YH (0x11U) 34 #define FT5406_TOUCH3_YL (0x12U) 35 36 #define FT5406_TOUCH4_XH (0x15U) 37 #define FT5406_TOUCH4_XL (0x16U) 38 #define FT5406_TOUCH4_YH (0x17U) 39 #define FT5406_TOUCH4_YL (0x18U) 40 41 #define FT5406_TOUCH5_XH (0x1BU) 42 #define FT5406_TOUCH5_XL (0x1CU) 43 #define FT5406_TOUCH5_YH (0x1DU) 44 #define FT5406_TOUCH5_YL (0x1EU) 45 46 #define FT5406_ID_G_THGROUP (0x80U) 47 #define FT5406_ID_G_THPEAK (0x81U) 48 #define FT5406_ID_G_THCAL (0x82U) 49 #define FT5406_ID_G_THWARTER (0x83U) 50 #define FT5406_ID_G_THTEMP (0x84U) 51 52 #define FT5406_ID_G_CTRL (0x86U) 53 #define FT5406_ID_G_TIME_ENTER_MONITOR (0x87U) 54 #define FT5406_ID_G_PERIODACTIVE (0x88U) 55 #define FT5406_ID_G_PERIODMONITOR (0x89U) 56 57 #define FT5406_ID_G_AUTO_CLB_MODE (0xA0U) 58 #define FT5406_ID_G_LIB_VERSION_H (0xA1U) 59 #define FT5406_ID_G_LIB_VERSION_L (0xA2U) 60 #define FT5406_ID_G_CIPHER (0xA3U) 61 #define FT5406_ID_G_MODE (0xA4U) 62 #define FT5406_ID_G_PMODE (0xA5U) 63 #define FT5406_ID_G_FIRM_ID (0xA6U) 64 #define FT5406_ID_G_STATE (0xA7U) 65 #define FT5406_ID_G_FT5201ID (0xA8U) 66 #define FT5406_ID_G_ERR (0xA9U) 67 #define FT5406_ID_G_CLB (0xAAU) 68 #define FT5406_ID_G_B_AREA_TH (0xAEU) 69 70 #define FT5406_DEVICE_MODE_NORMAL (0) 71 #define FT5406_DEVICE_MODE_SYS_INFO (1U) 72 #define FT5406_DEVICE_MODE_TEST (2U) 73 74 #define FT5406_STATUS_CONFIGURE (0) 75 #define FT5406_STATUS_WORK (1U) 76 #define FT5406_STATUS_CALIBRATION (2U) 77 #define FT5406_STATUS_FACTORY (3U) 78 #define FT5406_STATUS_AUTO_CALIBRATION (4U) 79 80 #define FT5406_GESTURE_NO_GESTURE (0) 81 #define FT5406_GESTURE_MOVE_UP (0x10U) 82 #define FT5406_GESTURE_MOVE_LEFT (0x14U) 83 #define FT5406_GESTURE_MOVE_DOWN (0x18U) 84 #define FT5406_GESTURE_MOVE_RIGHT (0x1CU) 85 #define FT5406_GESTURE_ZOOM_IN (0x48U) 86 #define FT5406_GESTURE_ZOOM_OUT (0x49U) 87 88 #define FT5406_MAX_TOUCH_POINTS (5U) 89 90 typedef struct { 91 uint8_t x_h; 92 uint8_t x_l; 93 uint8_t y_h; 94 uint8_t y_l; 95 uint16_t reserved; 96 } ft5406_touch_point_t; 97 98 typedef struct { 99 uint8_t gesture; 100 uint8_t status; 101 ft5406_touch_point_t points[FT5406_MAX_TOUCH_POINTS]; 102 } ft5406_touch_data_t; 103 104 typedef struct { 105 I2C_Type *ptr; 106 } ft5406_context_t; 107 108 typedef struct { 109 uint8_t mode; 110 uint8_t bist_comm; 111 uint8_t bist_stat; 112 uint8_t reserved0[4]; 113 uint8_t uid[8]; 114 uint8_t bl_verh; 115 uint8_t bl_verl; 116 uint8_t fts_ic_verh; 117 uint8_t fts_ic_verl; 118 uint8_t app_idh; 119 uint8_t app_idl; 120 uint8_t app_verh; 121 uint8_t app_verl; 122 uint8_t reserved1[4]; 123 uint8_t cid[5]; 124 } ft5406_sys_info_t; 125 126 #ifdef __cplusplus 127 extern "C" { 128 #endif 129 130 /* 131 * ft5406 initialization routine 132 */ 133 hpm_stat_t ft5406_init(ft5406_context_t *context); 134 135 /* 136 * ft5406 set working mode 137 */ 138 hpm_stat_t ft5406_set_mode(ft5406_context_t *context, uint8_t mode); 139 140 /* 141 * ft5406 get system information 142 */ 143 hpm_stat_t ft5406_get_sys_info(ft5406_context_t *context, 144 ft5406_sys_info_t *info); 145 146 /* 147 * ft5406 read touch data 148 */ 149 hpm_stat_t ft5406_read_touch_data(ft5406_context_t *context, 150 ft5406_touch_data_t *touch_data); 151 152 /* 153 * ft5406 read data 154 */ 155 hpm_stat_t ft5406_read_data(ft5406_context_t *context, uint8_t addr, 156 uint8_t *buf, uint32_t size); 157 158 /* 159 * ft5406 write value to given register 160 */ 161 hpm_stat_t ft5406_write_register(ft5406_context_t *context, 162 uint8_t reg, uint8_t val); 163 164 /* 165 * ft5406 read value of given register 166 */ 167 hpm_stat_t ft5406_read_register(ft5406_context_t *context, uint8_t reg, uint8_t *buf); 168 169 #ifdef __cplusplus 170 } 171 #endif 172 #endif /* HPM_FT5406_H */ 173