1 /* 2 * Copyright (c) 2021 HPMicro 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef HPM_GT911_H 9 #define HPM_GT911_H 10 #include "board.h" 11 #include "hpm_common.h" 12 #include "hpm_i2c_drv.h" 13 14 #ifdef BOARD_GT911_ADDR 15 /* if i2c addres is specified by board, use it */ 16 #define GT911_I2C_ADDR BOARD_GT911_ADDR 17 /* no auto probe in this case */ 18 #define GT911_NO_AUTO_PROBE 1 19 #else 20 #undef GT911_I2C_ADDR 21 22 /* enable auto probe */ 23 #ifndef GT911_NO_AUTO_PROBE 24 #define GT911_NO_AUTO_PROBE 0 25 #endif 26 27 /* i2c device address candidates */ 28 #define GT911_I2C_ADDR0 (0x14U) 29 #define GT911_I2C_ADDR1 (0x5DU) 30 #endif 31 32 #define GT911_PRODUCT_ID (0x313139U) 33 /* 34 * GT911 registers at operation mode 35 */ 36 37 #define GT911_CMD (0x8040U) 38 #define GT911_CMD_READ_COORD_STAT (0U) 39 #define GT911_CMD_READ_RAW_DATA (1U) 40 #define GT911_CMD_SOFT_RESET (2U) 41 #define GT911_CMD_READ_SCREEN_OFF (5U) 42 43 #define GT911_CONFIG (0x8047U) 44 45 #define GT911_ID_B0 (0x8140U) 46 #define GT911_ID_B1 (0x8141U) 47 #define GT911_ID_B2 (0x8142U) 48 #define GT911_ID_B4 (0x8143U) 49 #define GT911_FW_VERSION_L (0x8144U) 50 #define GT911_FW_VERSION_H (0x8145U) 51 #define GT911_TOUCH_XL (0x8146U) 52 #define GT911_TOUCH_XH (0x8147U) 53 #define GT911_TOUCH_YL (0x8148U) 54 #define GT911_TOUCH_YH (0x8149U) 55 #define GT911_VENDOR_ID (0x814AU) 56 #define GT911_STATUS (0x814EU) 57 #define GT911_GET_STATUS_NUM_OF_POINTS(x) ((x) & 0xFU) 58 #define GT911_GET_STATUS_LARGE_DETECT(x) (((x) & 0x40U) >> 6) 59 #define GT911_GET_STATUS_BUFFER_STAT(x) (((x) & 0x80U) >> 7) 60 #define GT911_FIRST_POINT (0x814FU) 61 62 #define GT911_MAX_TOUCH_POINTS (5U) 63 #define GT911_CONFIG_DATA_SIZE (186U) 64 #define GT911_CONFIG_DATA_RESOLUTION_XL (1U) 65 #define GT911_CONFIG_DATA_RESOLUTION_XH (2U) 66 #define GT911_CONFIG_DATA_RESOLUTION_YL (3U) 67 #define GT911_CONFIG_DATA_RESOLUTION_YH (4U) 68 #define GT911_CONFIG_DATA_TOUCH_NUMBER (5U) 69 #define GT911_CONFIG_DATA_MODULE_SWITCH1 (6U) 70 71 typedef struct { 72 uint8_t track_id; 73 uint8_t x_l; 74 uint8_t x_h; 75 uint8_t y_l; 76 uint8_t y_h; 77 uint8_t size_l; 78 uint8_t size_h; 79 uint8_t reserved; 80 } gt911_touch_point_t; 81 82 typedef struct { 83 uint8_t status; 84 gt911_touch_point_t points[GT911_MAX_TOUCH_POINTS]; 85 } gt911_touch_data_t; 86 87 typedef struct { 88 I2C_Type *ptr; 89 } gt911_context_t; 90 91 #ifdef __cplusplus 92 extern "C" { 93 #endif 94 95 /* 96 * gt911 initialization routine 97 */ 98 hpm_stat_t gt911_init(gt911_context_t *context, uint16_t width, uint16_t height); 99 100 /* 101 * gt911 read touch data 102 */ 103 hpm_stat_t gt911_read_touch_data(gt911_context_t *context, 104 gt911_touch_data_t *touch_data); 105 106 /* 107 * gt911 read data 108 */ 109 hpm_stat_t gt911_read_data(gt911_context_t *context, uint16_t addr, 110 uint8_t *buf, uint32_t size); 111 112 /* 113 * gt911 write value to given register 114 */ 115 hpm_stat_t gt911_write_register(gt911_context_t *context, 116 uint16_t reg, uint8_t val); 117 118 /* 119 * gt911 read value of given register 120 */ 121 hpm_stat_t gt911_read_register(gt911_context_t *context, uint16_t reg, uint8_t *buf); 122 123 /* 124 * gt911 read config data 125 */ 126 hpm_stat_t gt911_read_config(gt911_context_t *context, uint8_t *buf, uint8_t size); 127 #ifdef __cplusplus 128 } 129 #endif 130 #endif /* HPM_GT911_H */ 131