Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/input/touch.h
1476 views
1
/*
2
* Touch driver for Nintendo Switch's STM FingerTip S (4CD60D) touch controller
3
*
4
* Copyright (c) 2018 langerhans
5
* Copyright (c) 2018-2020 CTCaer
6
*
7
* This program is free software; you can redistribute it and/or modify it
8
* under the terms and conditions of the GNU General Public License,
9
* version 2, as published by the Free Software Foundation.
10
*
11
* This program is distributed in the hope it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14
* more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#ifndef __TOUCH_H_
21
#define __TOUCH_H_
22
23
#include <utils/types.h>
24
25
#define STMFTS_I2C_ADDR 0x49
26
27
/* I2C commands */
28
#define STMFTS_READ_INFO 0x80
29
#define STMFTS_READ_STATUS 0x84
30
#define STMFTS_READ_ONE_EVENT 0x85
31
#define STMFTS_READ_ALL_EVENT 0x86
32
#define STMFTS_LATEST_EVENT 0x87
33
#define STMFTS_SLEEP_IN 0x90
34
#define STMFTS_SLEEP_OUT 0x91
35
#define STMFTS_MS_MT_SENSE_OFF 0x92
36
#define STMFTS_MS_MT_SENSE_ON 0x93
37
#define STMFTS_SS_HOVER_SENSE_OFF 0x94
38
#define STMFTS_SS_HOVER_SENSE_ON 0x95
39
#define STMFTS_LP_TIMER_CALIB 0x97
40
#define STMFTS_MS_KEY_SENSE_OFF 0x9A
41
#define STMFTS_MS_KEY_SENSE_ON 0x9B
42
#define STMFTS_SYSTEM_RESET 0xA0
43
#define STMFTS_CLEAR_EVENT_STACK 0xA1
44
#define STMFTS_FULL_FORCE_CALIBRATION 0xA2
45
#define STMFTS_MS_CX_TUNING 0xA3
46
#define STMFTS_SS_CX_TUNING 0xA4
47
#define STMFTS_ITO_CHECK 0xA7
48
#define STMFTS_RELEASEINFO 0xAA
49
#define STMFTS_WRITE_REG 0xB6
50
#define STMFTS_SWITCH_SENSE_MODE 0xC3
51
#define STMFTS_NOISE_WRITE 0xC7
52
#define STMFTS_NOISE_READ 0xC8
53
#define STMFTS_RW_FRAMEBUFFER_REG 0xD0
54
#define STMFTS_SAVE_CX_TUNING 0xFC
55
56
#define STMFTS_DETECTION_CONFIG 0xB0
57
#define STMFTS_REQU_COMP_DATA 0xB8
58
#define STMFTS_VENDOR 0xCF
59
#define STMFTS_FLASH_UNLOCK 0xF7
60
#define STMFTS_FLASH_WRITE_64K 0xF8
61
#define STMFTS_FLASH_STATUS 0xF9
62
#define STMFTS_FLASH_OP 0xFA
63
#define STMFTS_UNK5 0x62
64
65
/* cmd parameters */
66
#define STMFTS_VENDOR_GPIO_STATE 0x01
67
#define STMFTS_VENDOR_SENSE_MODE 0x02
68
#define STMFTS_STYLUS_MODE 0x00
69
#define STMFTS_FINGER_MODE 0x01
70
#define STMFTS_HOVER_MODE 0x02
71
72
/* events */
73
#define STMFTS_EV_NO_EVENT 0x00
74
#define STMFTS_EV_MULTI_TOUCH_DETECTED 0x02
75
#define STMFTS_EV_MULTI_TOUCH_ENTER 0x03
76
#define STMFTS_EV_MULTI_TOUCH_LEAVE 0x04
77
#define STMFTS_EV_MULTI_TOUCH_MOTION 0x05
78
#define STMFTS_EV_HOVER_ENTER 0x07
79
#define STMFTS_EV_HOVER_LEAVE 0x08
80
#define STMFTS_EV_HOVER_MOTION 0x09
81
#define STMFTS_EV_KEY_STATUS 0x0e
82
#define STMFTS_EV_ERROR 0x0f
83
#define STMFTS_EV_NOISE_READ 0x17
84
#define STMFTS_EV_NOISE_WRITE 0x18
85
#define STMFTS_EV_VENDOR 0x20
86
87
#define STMFTS_EV_CONTROLLER_READY 0x10
88
#define STMFTS_EV_STATUS 0x16
89
#define STMFTS_EV_DEBUG 0xDB
90
91
#define STMFTS_EV_STATUS_MS_CX_TUNING_DONE 1
92
#define STMFTS_EV_STATUS_SS_CX_TUNING_DONE 2
93
#define STMFTS_EV_STATUS_WRITE_CX_TUNE_DONE 4
94
95
/* multi touch related event masks */
96
#define STMFTS_MASK_EVENT_ID 0x0F
97
#define STMFTS_MASK_TOUCH_ID 0xF0
98
#define STMFTS_MASK_LEFT_EVENT 0x0F
99
#define STMFTS_MASK_X_MSB 0x0F
100
#define STMFTS_MASK_Y_LSB 0xF0
101
102
/* key related event masks */
103
#define STMFTS_MASK_KEY_NO_TOUCH 0x00
104
#define STMFTS_MASK_KEY_MENU 0x01
105
#define STMFTS_MASK_KEY_BACK 0x02
106
107
#define STMFTS_EVENT_SIZE 8
108
#define STMFTS_STACK_DEPTH 32
109
#define STMFTS_DATA_MAX_SIZE (STMFTS_EVENT_SIZE * STMFTS_STACK_DEPTH)
110
#define STMFTS_MAX_FINGERS 10
111
112
typedef enum _touch_ito_error {
113
ITO_NO_ERROR = 0,
114
ITO_FORCE_OPEN,
115
ITO_SENSE_OPEN,
116
ITO_FORCE_SHRT_GND,
117
ITO_SENSE_SHRT_GND,
118
ITO_FORCE_SHRT_VCM,
119
ITO_SENSE_SHRT_VCM,
120
ITO_FORCE_SHRT_FORCE,
121
ITO_SENSE_SHRT_SENSE,
122
ITO_F2E_SENSE,
123
ITO_FPC_FORCE_OPEN,
124
ITO_FPC_SENSE_OPEN,
125
ITO_KEY_FORCE_OPEN,
126
ITO_KEY_SENSE_OPEN,
127
ITO_RESERVED0,
128
ITO_RESERVED1,
129
ITO_RESERVED2,
130
ITO_MAX_ERR_REACHED = 0xFF
131
} touch_ito_error;
132
133
typedef struct _touch_event {
134
u8 raw[8];
135
u16 type; // Event type.
136
u16 x; // Horizontal coordinates.
137
u16 y; // Vertical coordinates.
138
u32 z;
139
u8 fingers;
140
bool touch;
141
} touch_event;
142
143
typedef struct _touch_panel_info_t
144
{
145
u8 idx;
146
u8 gpio0;
147
u8 gpio1;
148
u8 gpio2;
149
char *vendor;
150
} touch_panel_info_t;
151
152
typedef struct _touch_info {
153
u16 chip_id;
154
u16 fw_ver;
155
u16 config_id;
156
u16 config_ver;
157
} touch_info;
158
159
typedef struct _touch_fw_info_t {
160
u32 fw_id;
161
u16 ftb_ver;
162
u16 fw_rev;
163
} touch_fw_info_t;
164
165
void touch_poll(touch_event *event);
166
touch_event touch_poll_wait();
167
touch_panel_info_t *touch_get_panel_vendor();
168
int touch_get_fw_info(touch_fw_info_t *fw);
169
touch_info touch_get_info();
170
int touch_panel_ito_test(u8 *err);
171
int touch_execute_autotune();
172
int touch_sense_enable();
173
int touch_power_on();
174
void touch_power_off();
175
176
#endif /* __TOUCH_H_ */
177