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
62
63
66
67
70
71
74
77
78
81
84
85
88
91
92
95
98
99
102
103
104
105
106
107
112
113
114
115
116
117
118
119
120
121
122
123
126
127
130
131
134
135
138
139
146
147
148
149
150
151
152
153
154
155
156
157
158
163
167
168
169
170
171
172
173
174
175
176
180
184
185
186
187
188
189
190
191
192
193
194
195
199
200
201
202
203
207
208
209
210
211
212
213
214
218
219
220
221
222
223
227
228
229
230
231
232
233
234
235
236
237
238
239
243
244
245
246
247
248
249
250
251
255
256
257
258
259
260
265
266
267
268
269
270
271
272
273
274
275
276
277
280
281
282
283
284
285
286
287
288
289
290
291
297
298
302
303
307
308
309
310
311
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
336
339
342
345
348
349
350
351
352
353
354
355
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
384
387
390
393
396
399
402
405
406
407
408
409
410
411
412
415
420
421
424
425
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
465
466
469
470
473
474
/* ... */
/* ... */
#include "stm32469i_eval.h"
#include "stm32469i_eval_ts.h"
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
static TS_DrvTypeDef *ts_driver;
static uint8_t ts_orientation;
uint8_t I2C_Address = 0;
char * ts_event_string_tab[TOUCH_EVENT_NB_MAX] = { "None",
"Press down",
"Lift up",
"Contact"
...};
char * ts_gesture_id_string_tab[GEST_ID_NB_MAX] = { "None",
"Move Up",
"Move Right",
"Move Down",
"Move Left",
"Zoom In",
"Zoom Out"
...};
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
uint8_t BSP_TS_Init(uint16_t ts_SizeX, uint16_t ts_SizeY)
{
uint8_t ts_status = TS_OK;
uint8_t ts_id1, ts_id2 = 0;
ft6x06_ts_drv.Init(I2C_Address);
ts_id1 = ft6x06_ts_drv.ReadID(TS_I2C_ADDRESS);
if(ts_id1 != FT6206_ID_VALUE)
{
ts_id2 = ft6x06_ts_drv.ReadID(TS_I2C_ADDRESS_A02);
I2C_Address = TS_I2C_ADDRESS_A02;
}if (ts_id1 != FT6206_ID_VALUE) { ... }
else
{
I2C_Address = TS_I2C_ADDRESS;
}else { ... }
if((ts_id1 == FT6206_ID_VALUE) || (ts_id2 == FT6x36_ID_VALUE))
{
ts_driver = &ft6x06_ts_drv;
if(ts_SizeX < ts_SizeY)
{
ts_orientation = TS_SWAP_NONE;
}if (ts_SizeX < ts_SizeY) { ... }
else
{
ts_orientation = TS_SWAP_XY | TS_SWAP_Y;
}else { ... }
if(ts_status == TS_OK)
{
ts_driver->Reset(I2C_Address);
ts_driver->Start(I2C_Address);
}if (ts_status == TS_OK) { ... }
}if ((ts_id1 == FT6206_ID_VALUE) || (ts_id2 == FT6x36_ID_VALUE)) { ... }
else
{
ts_status = TS_DEVICE_NOT_FOUND;
}else { ... }
return (ts_status);
}{ ... }
/* ... */
uint8_t BSP_TS_ITConfig(void)
{
uint8_t ts_status = TS_ERROR;
uint8_t io_status = IO_ERROR;
io_status = BSP_IO_Init();
if(io_status != IO_OK)
{
return (ts_status);
}if (io_status != IO_OK) { ... }
io_status = BSP_IO_ConfigPin(TS_INT_PIN, IO_MODE_IT_LOW_LEVEL_PU);
if(io_status != IO_OK)
{
return (ts_status);
}if (io_status != IO_OK) { ... }
ts_driver->EnableIT(I2C_Address);
ts_status = TS_OK;
return (ts_status);
}{ ... }
/* ... */
uint8_t BSP_TS_ITGetStatus(void)
{
uint8_t itStatus = TS_NO_IRQ_PENDING;
uint32_t mfx_irq_status = 0;
mfx_irq_status = BSP_IO_ITGetStatus(TS_INT_PIN);
if(mfx_irq_status != 0)
{
itStatus = TS_IRQ_PENDING;
...}
return (itStatus);
}{ ... }
/* ... */
uint8_t BSP_TS_GetState(TS_StateTypeDef *TS_State)
{
static uint32_t _x[TS_MAX_NB_TOUCH] = {0, 0};
static uint32_t _y[TS_MAX_NB_TOUCH] = {0, 0};
uint8_t ts_status = TS_OK;
uint16_t tmp;
uint16_t Raw_x[TS_MAX_NB_TOUCH];
uint16_t Raw_y[TS_MAX_NB_TOUCH];
uint16_t xDiff;
uint16_t yDiff;
uint32_t index;
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
uint32_t weight = 0;
uint32_t area = 0;
uint32_t event = 0;/* ... */
#endif
TS_State->touchDetected = ts_driver->DetectTouch(I2C_Address);
if(TS_State->touchDetected)
{
for(index=0; index < TS_State->touchDetected; index++)
{
ts_driver->GetXY(I2C_Address, &(Raw_x[index]), &(Raw_y[index]));
if(ts_orientation & TS_SWAP_XY)
{
tmp = Raw_x[index];
Raw_x[index] = Raw_y[index];
Raw_y[index] = tmp;
}if (ts_orientation & TS_SWAP_XY) { ... }
if(ts_orientation & TS_SWAP_X)
{
Raw_x[index] = FT_6206_MAX_WIDTH - 1 - Raw_x[index];
}if (ts_orientation & TS_SWAP_X) { ... }
if(ts_orientation & TS_SWAP_Y)
{
Raw_y[index] = FT_6206_MAX_HEIGHT - 1 - Raw_y[index];
}if (ts_orientation & TS_SWAP_Y) { ... }
xDiff = Raw_x[index] > _x[index]? (Raw_x[index] - _x[index]): (_x[index] - Raw_x[index]);
yDiff = Raw_y[index] > _y[index]? (Raw_y[index] - _y[index]): (_y[index] - Raw_y[index]);
if ((xDiff + yDiff) > 5)
{
_x[index] = Raw_x[index];
_y[index] = Raw_y[index];
}if ((xDiff + yDiff) > 5) { ... }
TS_State->touchX[index] = _x[index];
TS_State->touchY[index] = _y[index];
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
ft6x06_TS_GetTouchInfo(I2C_Address, index, &weight, &area, &event);
TS_State->touchWeight[index] = weight;
TS_State->touchArea[index] = area;
switch(event)
{
case FT6206_TOUCH_EVT_FLAG_PRESS_DOWN :
TS_State->touchEventId[index] = TOUCH_EVENT_PRESS_DOWN;
break;case FT6206_TOUCH_EVT_FLAG_PRESS_DOWN :
case FT6206_TOUCH_EVT_FLAG_LIFT_UP :
TS_State->touchEventId[index] = TOUCH_EVENT_LIFT_UP;
break;case FT6206_TOUCH_EVT_FLAG_LIFT_UP :
case FT6206_TOUCH_EVT_FLAG_CONTACT :
TS_State->touchEventId[index] = TOUCH_EVENT_CONTACT;
break;case FT6206_TOUCH_EVT_FLAG_CONTACT :
case FT6206_TOUCH_EVT_FLAG_NO_EVENT :
TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT;
break;case FT6206_TOUCH_EVT_FLAG_NO_EVENT :
default :
ts_status = TS_ERROR;
break;default
}switch (event) { ... }
/* ... */
#endif
}for (index=0; index < TS_State->touchDetected; index++) { ... }
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
ts_status = BSP_TS_Get_GestureId(TS_State);/* ... */
#endif
}if (TS_State->touchDetected) { ... }
return (ts_status);
}{ ... }
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
/* ... */
uint8_t BSP_TS_Get_GestureId(TS_StateTypeDef *TS_State)
{
uint32_t gestureId = 0;
uint8_t ts_status = TS_OK;
ft6x06_TS_GetGestureID(I2C_Address, &gestureId);
switch(gestureId)
{
case FT6206_GEST_ID_NO_GESTURE :
TS_State->gestureId = GEST_ID_NO_GESTURE;
break;case FT6206_GEST_ID_NO_GESTURE :
case FT6206_GEST_ID_MOVE_UP :
TS_State->gestureId = GEST_ID_MOVE_UP;
break;case FT6206_GEST_ID_MOVE_UP :
case FT6206_GEST_ID_MOVE_RIGHT :
TS_State->gestureId = GEST_ID_MOVE_RIGHT;
break;case FT6206_GEST_ID_MOVE_RIGHT :
case FT6206_GEST_ID_MOVE_DOWN :
TS_State->gestureId = GEST_ID_MOVE_DOWN;
break;case FT6206_GEST_ID_MOVE_DOWN :
case FT6206_GEST_ID_MOVE_LEFT :
TS_State->gestureId = GEST_ID_MOVE_LEFT;
break;case FT6206_GEST_ID_MOVE_LEFT :
case FT6206_GEST_ID_ZOOM_IN :
TS_State->gestureId = GEST_ID_ZOOM_IN;
break;case FT6206_GEST_ID_ZOOM_IN :
case FT6206_GEST_ID_ZOOM_OUT :
TS_State->gestureId = GEST_ID_ZOOM_OUT;
break;case FT6206_GEST_ID_ZOOM_OUT :
default :
ts_status = TS_ERROR;
break;default
}switch (gestureId) { ... }
return(ts_status);
}BSP_TS_Get_GestureId (TS_StateTypeDef *TS_State) { ... }
/* ... */#endif
/* ... */
void BSP_TS_ITClear(void)
{
BSP_IO_ITClearPin(TS_INT_PIN);
}{ ... }
/* ... */
/* ... */
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
/* ... */
uint8_t BSP_TS_ResetTouchData(TS_StateTypeDef *TS_State)
{
uint8_t ts_status = TS_ERROR;
uint32_t index;
if (TS_State != (TS_StateTypeDef *)NULL)
{
TS_State->gestureId = GEST_ID_NO_GESTURE;
TS_State->touchDetected = 0;
for(index = 0; index < TS_MAX_NB_TOUCH; index++)
{
TS_State->touchX[index] = 0;
TS_State->touchY[index] = 0;
TS_State->touchArea[index] = 0;
TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT;
TS_State->touchWeight[index] = 0;
}for (index = 0; index < TS_MAX_NB_TOUCH; index++) { ... }
ts_status = TS_OK;
}if (TS_State != (TS_StateTypeDef *)NULL) { ... }
return (ts_status);
}BSP_TS_ResetTouchData (TS_StateTypeDef *TS_State) { ... }
/* ... */#endif
/* ... */
/* ... */
/* ... */
/* ... */