-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFT6236.c
235 lines (205 loc) · 7.46 KB
/
FT6236.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/**
* @file FT6236.c
*
* @brief Brief description of the content of FT6236.c
* @author kevin, Juventus Techniker Schule
* @date 21.08.2023 - first implementation
* @version 1.0.0
*
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Copyright (c) 2023 Juventus Techniker Schule
*/
// ********************************************************************************
/**
* @brief Includes
*
* Section for module-specific include files
* If all include files are inserted in main.h, only the file main.h must be included here
*/
#include "main.h"
// ********************************************************************************
/**
* @brief Constant variables
*
* Section for module-specific constant variables (static) that are only valid within the module
*/
// ********************************************************************************
/**
* @brief Global variables
*
* Section for global variables
*/
st_ft6236 gst_ft6236;
// ********************************************************************************
/**
* @brief Static variables
*
* Section for module-specific variables (static) that are only valid within the module
*/
// ********************************************************************************
/**
* @brief Static function prototypes
*
* Section for module-specific function prototypes (static) for functions that are only valid within the
* module
*/
// ********************************************************************************
/**
* @brief Static functions definitions
*
* Definition area for the module-specific functions (static) previously defined within "Static function
* prototypes"
*/
// ********************************************************************************
/**
* @brief Global functions definitions
*
* Definition area for the global functions previously defined within "Global function prototypes"
*/
// .................................................................................
/*
* @brief Init FT6236 touch controller
* @note Init Chip, set threshold and read information registers
*
* @param -
* @return enFT6236_ERROS
*/
enFT6236_ERROS ft6236_init( void )
{
// Local variables
enFT6236_ERROS stat = FT_ERROR;
uint8_t id, fw_version, prate, thrs;
// Reset FT6236 ...............................................................
HAL_GPIO_WritePin(TOUCH_RST_GPIO_Port, TOUCH_RST_Pin, GPIO_PIN_RESET);
HAL_Delay(FT6236_RST_TOUT);
HAL_GPIO_WritePin(TOUCH_RST_GPIO_Port, TOUCH_RST_Pin, GPIO_PIN_SET);
HAL_Delay(10);
// Set initial values .........................................................
// Set Threshold value
stat = HAL_I2C_Mem_Write(&hi2c1, FT6236_WRITE_ADDR, FT6236_REG_THRESHHOLD, 1, (uint8_t *)FT6236_DEFAULT_THRESHOLD, 1, FT6236_I2C_TOUT);
// Set Refresh rate value
stat = HAL_I2C_Mem_Write(&hi2c1, FT6236_WRITE_ADDR, FT6236_REG_POINTRATE, 1, (uint8_t *)0xFF, 1, FT6236_I2C_TOUT);
HAL_Delay(FT6236_RST_TOUT);
// Read Chip ID from Register .................................................
stat = HAL_I2C_Mem_Read(&hi2c1, FT6236_READ_ADDR, FT6236_REG_VENDID, 1, &id, 1, FT6236_I2C_TOUT);
// If correct id read information
if( id == FT6236_VENDID )
{
#ifdef DEBUG_TOUCH
debug_printf("\tTouch Vend ID: %d", id);
// Read Chip ID
stat = HAL_I2C_Mem_Read(&hi2c1, FT6236_READ_ADDR, FT6236_REG_CHIPID, 1, &id, 1, FT6236_I2C_TOUT);
debug_printf("\tTouch Chip ID: %d", id);
// Read Firmware version
stat = HAL_I2C_Mem_Read(&hi2c1, FT6236_READ_ADDR, FT6236_REG_FIRMVERS, 1, &fw_version, 1, FT6236_I2C_TOUT);
debug_printf("\tTouch Firmware Version: %d", fw_version);
// Point Rate
stat = HAL_I2C_Mem_Read(&hi2c1, FT6236_READ_ADDR, FT6236_REG_POINTRATE, 1, &prate, 1, FT6236_I2C_TOUT);
debug_printf("\tTouch Rate Hz: %d", prate);
// Threshold
stat = HAL_I2C_Mem_Read(&hi2c1, FT6236_READ_ADDR, FT6236_REG_THRESHHOLD, 1, &thrs, 1, FT6236_I2C_TOUT);
debug_printf("\tTouch Thresh: %d", thrs);
#endif
}
// Return status value
return stat;
}
// .................................................................................
/*
* @brief Read FT6236 data register
* @note Read data register and analyze touch point
*
* @param -
* @return -
*/
void ft6236_read( void )
{
// Local variables
uint8_t i = 0;
uint8_t i2cdat[16];
// Local struct pointer
st_ft6236 *pst_ft6236 = &gst_ft6236;
// Read FT6236 data ...........................................................
HAL_I2C_Mem_Read(&hi2c1, FT6236_READ_ADDR, FT6236_MEM_READ, 1, i2cdat, sizeof(i2cdat), FT6236_I2C_TOUT);
#ifdef DEBUG_TOUCH
for(i = 0; i < 16; i++)
{
debug_printf_without_cr_lf("%02x |", i2cdat[i]);
}
debug_printf(" ");
#endif
// Read gesture ...............................................................
// IMPORTANT - Gesture is not working with standard firmware on FT6236!
// Special firmware is required on this chip
// pst_ft6236->gesture = i2cdat[1];
// #ifdef DEBUG_TOUCH
// switch( pst_ft6236->gesture )
// {
// case GST_MOVE_DOWN:
// debug_printf( "GST Down" );
// break;
// case GST_MOVE_UP:
// debug_printf( "GST UP" );
// break;
// case GST_MOVE_LEFT:
// debug_printf( "GST Left" );
// break;
// case GST_MOVE_RIGHT:
// debug_printf( "GST Right" );
// break;
// case GST_ZOOM_IN:
// debug_printf( "GST Zoom In" );
//
// break;
// case GST_ZOOM_OUT:
// debug_printf( "GST Zoom Out" );
// break;
//
// default:
// debug_printf( "No GST" );
// break;
// }
// #endif
// Get amount of touches ..........................................................
pst_ft6236->touch_point = i2cdat[2] & 0xf;
// Get X and Y position of touch point ............................................
switch (pst_ft6236->touch_point)
{
case 2:
pst_ft6236->x2 = (uint16_t)(i2cdat[9] & 0x0F)<<8 | (uint16_t)i2cdat[10];
pst_ft6236->y2 = (uint16_t)(i2cdat[11] & 0x0F)<<8 | (uint16_t)i2cdat[12];
#ifdef DEBUG_TOUCH
debug_printf("\tTouch Display at -> X2: %d | Y2: %d", pst_ft6236->x2, pst_ft6236->y2 );
#endif
case 1:
pst_ft6236->x1 = (uint16_t)(i2cdat[3] & 0x0F)<<8 | (uint16_t)i2cdat[4];
pst_ft6236->y1 = (uint16_t)(i2cdat[5] & 0x0F)<<8 | (uint16_t)i2cdat[6];
#ifdef DEBUG_TOUCH
debug_printf("\tTouch Display at -> X1: %d | Y1: %d", pst_ft6236->x1, pst_ft6236->y1 );
#endif
break;
default:
break;
}
// Reset Touch pressed .............................................................
pst_ft6236->ok = 0;
}