• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef __TOUCH_FTS_H__
16 #define __TOUCH_FTS_H__
17 
18 #include "touch.h"
19 
20 #define FTS_CHIP_TYPE 0x6336D003 //_FT6336U
21 #define FLAGBIT(x) (0x00000001 << (x))
22 #define FLAGBITS(x, y) ((0xFFFFFFFF >> (32 - (y)-1)) << (x))
23 
24 #define FLAG_ICSERIALS_LEN 8
25 #define FLAG_HID_BIT 10
26 #define FLAG_IDC_BIT 11
27 
28 #define FTS_CHIP_IDC ((FTS_CHIP_TYPE & FLAGBIT(FLAG_IDC_BIT)) == FLAGBIT(FLAG_IDC_BIT))
29 #define FTS_HID_SUPPORTTED ((FTS_CHIP_TYPE & FLAGBIT(FLAG_HID_BIT)) == FLAGBIT(FLAG_HID_BIT))
30 #define FTS_CHIP_TYPE_MAPPING {{0x03,0x64, 0x26, 0x64, 0x26, 0x00, 0x00, 0x79, 0x1C}}
31 
32 #define I2C_BUFFER_LENGTH_MAXINUM 256
33 #define FILE_NAME_LENGTH 128
34 #define ENABLE 1
35 #define DISABLE 0
36 #define VALID 1
37 
38 #define FTS_CMD_START1 0x55
39 #define FTS_CMD_START2 0xAA
40 #define FTS_CMD_START_DELAY 10
41 #define FTS_CMD_READ_ID 0x90
42 #define FTS_CMD_READ_ID_LEN 4
43 #define FTS_CMD_READ_ID_LEN_INCELL 1
44 /*register address*/
45 #define FTS_REG_INT_CNT 0x8F
46 #define FTS_REG_FLOW_WORK_CNT 0x91
47 #define FTS_REG_WORKMODE 0x00
48 #define FTS_REG_WORKMODE_FACTORY_VALUE 0x40
49 #define FTS_REG_WORKMODE_WORK_VALUE 0x00
50 #define FTS_REG_ESDCHECK_DISABLE 0x8D
51 #define FTS_REG_CHIP_ID 0xA3
52 #define FTS_REG_CHIP_ID2 0x9F
53 #define FTS_REG_POWER_MODE 0xA5
54 #define FTS_REG_POWER_MODE_SLEEP_VALUE 0x03
55 #define FTS_REG_FW_VER 0xA6
56 #define FTS_REG_VENDOR_ID 0xA8
57 #define FTS_REG_LCD_BUSY_NUM 0xAB
58 #define FTS_REG_FACE_DEC_MODE_EN 0xB0
59 #define FTS_REG_FACE_DEC_MODE_STATUS 0x01
60 #define FTS_REG_IDE_PARA_VER_ID 0xB5
61 #define FTS_REG_IDE_PARA_STATUS 0xB6
62 #define FTS_REG_GLOVE_MODE_EN 0xC0
63 #define FTS_REG_COVER_MODE_EN 0xC1
64 #define FTS_REG_CHARGER_MODE_EN 0x8B
65 #define FTS_REG_GESTURE_EN 0xD0
66 #define FTS_REG_GESTURE_OUTPUT_ADDRESS 0xD3
67 #define FTS_REG_MODULE_ID 0xE3
68 #define FTS_REG_LIC_VER 0xE4
69 #define FTS_REG_ESD_SATURATE 0xED
70 
71 #define FTS_MAX_POINTS_SUPPORT 10 /* constant value, can't be changed */
72 #define FTS_MAX_ID 0x0A
73 #define FTS_ONE_TCH_LEN 6
74 #define FTS_FACE_DETECT_POS 1
75 #define FTS_TOUCH_X_H_POS 3
76 #define FTS_TOUCH_X_L_POS 4
77 #define FTS_TOUCH_Y_H_POS 5
78 #define FTS_TOUCH_Y_L_POS 6
79 #define FTS_TOUCH_PRE_POS 7
80 #define FTS_TOUCH_AREA_POS 8
81 #define FTS_TOUCH_EVENT_POS 3
82 #define FTS_TOUCH_ID_POS 5
83 #define FTS_TOUCH_POINT_NUM 2
84 #define FTS_TOUCH_XY_POS 7
85 #define FTS_TOUCH_MISC 8
86 #define FTS_COORDS_ARR_SIZE 4
87 #define FT_FW_NAME_MAX_LEN 50
88 
89 #define TPD_RES_X 480
90 #define TPD_RES_Y 480
91 
92 #define FTS_TOUCH_DOWN 0
93 #define FTS_TOUCH_UP 1
94 #define FTS_TOUCH_CONTACT 2
95 #define EVENT_DOWN(flag) ((FTS_TOUCH_DOWN == flag) || (FTS_TOUCH_CONTACT == flag))
96 #define EVENT_UP(flag) (FTS_TOUCH_UP == flag)
97 #define EVENT_NO_DOWN(data) (!data->point_num)
98 #define KEY_EN 0 //(tpd_dts_data.use_tpd_button)
99 #define TOUCH_IS_KEY(y, key_y) (y > key_y)
100 
101 #ifndef RTPM_PRIO_TPD
102 #define RTPM_PRIO_TPD 0x04
103 #endif
104 
105 #define FTX_MAX_COMPATIBLE_TYPE 4
106 
107 /*****************************************************************************
108 * Private enumerations, structures and unions using typedef
109 *****************************************************************************/
110 struct i2c_client {
111     DevHandle handle;
112     uint16_t id;
113     uint16_t addr;
114 };
115 
116 struct ft_chip_t {
117     uint64_t type;
118     uint8_t chip_idh;
119     uint8_t chip_idl;
120     uint8_t rom_idh;
121     uint8_t rom_idl;
122     uint8_t pb_idh;
123     uint8_t pb_idl;
124     uint8_t bl_idh;
125     uint8_t bl_idl;
126 };
127 
128 struct ts_ic_info {
129     bool is_incell;
130     bool hid_supported;
131     struct ft_chip_t ids;
132 };
133 
134 /*touch event info*/
135 struct ts_event {
136     int x;    /*x coordinate */
137     int y;    /*y coordinate */
138     int p;    /* pressure */
139     int flag; /* touch event flag: 0 -- down; 1-- up; 2 -- contact */
140     int id;   /*touch ID */
141     int area;
142 };
143 struct fts_ts_data {
144     struct i2c_client *client;
145     struct ts_ic_info ic_info;
146     osMutexId_t report_mutex;
147     int irq;
148     bool suspended;
149     bool fw_loading;
150     bool irq_disabled;
151     bool power_disabled;
152     /* multi-touch */
153     struct ts_event *events;
154     uint8_t *point_buf;
155     int pnt_buf_size;
156     int touchs;
157     bool key_down;
158     int touch_point;
159     int point_num;
160 };
161 
162 #endif
163