1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
35
45
46
47
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
77
78
81
82
83
84
90
91
92
97
98
99
102
103
106
107
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
144
149
150
156
157
158
159
160
161
162
163
164
165
172
173
174
175
178
179
180
181
182
183
184
185
186
187
194
195
196
197
198
199
200
201
202
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
265
266
267
268
269
270
271
272
273
274
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
302
303
310
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
418
419
420
421
422
423
424
425
426
427
428
433
434
435
436
437
438
439
440
441
442
443
448
449
450
451
452
453
454
455
456
457
463
464
465
466
467
468
475
476
477
478
479
482
483
486
487
490
491
/* ... */
#include "ft6x06.h"
/* ... */
/* ... */
/* ... */
Includes
/* ... */
#define FT6x06_MAX_INSTANCE 2
/* ... */
Private typedef
/* ... */
TS_DrvTypeDef ft6x06_ts_drv =
{
ft6x06_Init,
ft6x06_ReadID,
ft6x06_Reset,
ft6x06_TS_Start,
ft6x06_TS_DetectTouch,
ft6x06_TS_GetXY,
ft6x06_TS_EnableIT,
ft6x06_TS_ClearIT,
ft6x06_TS_ITStatus,
ft6x06_TS_DisableIT
...};
uint8_t ft6x06[FT6x06_MAX_INSTANCE] = {0};
static ft6x06_handle_TypeDef ft6x06_handle = { FT6206_I2C_NOT_INITIALIZED, 0, 0};
/* ... */
/* ... */
static uint8_t ft6x06_GetInstance(uint16_t DeviceAddr);Private macro
#if (TS_AUTO_CALIBRATION_SUPPORTED == 1)
/* ... */
static uint32_t ft6x06_TS_Calibration(uint16_t DeviceAddr);/* ... */
#endif
/* ... */
static uint32_t ft6x06_TS_Configure(uint16_t DeviceAddr);
/* ... */
/* ... */
/* ... */
void ft6x06_Init(uint16_t DeviceAddr)
{
uint8_t instance;
uint8_t empty;
instance = ft6x06_GetInstance(DeviceAddr);
if(instance == 0xFF)
{
empty = ft6x06_GetInstance(0);
if(empty < FT6x06_MAX_INSTANCE)
{
ft6x06[empty] = DeviceAddr;
TS_IO_Init();
}if (empty < FT6x06_MAX_INSTANCE) { ... }
}if (instance == 0xFF) { ... }
}{ ... }
/* ... */
void ft6x06_Reset(uint16_t DeviceAddr)
{
}{ ... }
/* ... */
uint16_t ft6x06_ReadID(uint16_t DeviceAddr)
{
TS_IO_Init();
return (TS_IO_Read(DeviceAddr, FT6206_CHIP_ID_REG));
}{ ... }
/* ... */
void ft6x06_TS_Start(uint16_t DeviceAddr)
{
#if (TS_AUTO_CALIBRATION_SUPPORTED == 1)
ft6x06_TS_Calibration(DeviceAddr);/* ... */
#endif
ft6x06_TS_Configure(DeviceAddr);
ft6x06_TS_DisableIT(DeviceAddr);
}{ ... }
/* ... */
uint8_t ft6x06_TS_DetectTouch(uint16_t DeviceAddr)
{
volatile uint8_t nbTouch = 0;
nbTouch = TS_IO_Read(DeviceAddr, FT6206_TD_STAT_REG);
nbTouch &= FT6206_TD_STAT_MASK;
if(nbTouch > FT6206_MAX_DETECTABLE_TOUCH)
{
nbTouch = 0;
}if (nbTouch > FT6206_MAX_DETECTABLE_TOUCH) { ... }
ft6x06_handle.currActiveTouchNb = nbTouch;
ft6x06_handle.currActiveTouchIdx = 0;
return(nbTouch);
}{ ... }
/* ... */
void ft6x06_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y)
{
uint8_t regAddress = 0;
uint8_t dataxy[4];
if(ft6x06_handle.currActiveTouchIdx < ft6x06_handle.currActiveTouchNb)
{
switch(ft6x06_handle.currActiveTouchIdx)
{
case 0 :
regAddress = FT6206_P1_XH_REG;
break;case 0 :
case 1 :
regAddress = FT6206_P2_XH_REG;
break;
case 1 :
default :
break;default
}switch (ft6x06_handle.currActiveTouchIdx) { ... }
TS_IO_ReadMultiple(DeviceAddr, regAddress, dataxy, sizeof(dataxy));
*X = ((dataxy[0] & FT6206_MSB_MASK) << 8) | (dataxy[1] & FT6206_LSB_MASK);
*Y = ((dataxy[2] & FT6206_MSB_MASK) << 8) | (dataxy[3] & FT6206_LSB_MASK);
ft6x06_handle.currActiveTouchIdx++;
}if (ft6x06_handle.currActiveTouchIdx < ft6x06_handle.currActiveTouchNb) { ... }
}{ ... }
/* ... */
void ft6x06_TS_EnableIT(uint16_t DeviceAddr)
{
uint8_t regValue = 0;
regValue = (FT6206_G_MODE_INTERRUPT_TRIGGER & (FT6206_G_MODE_INTERRUPT_MASK >> FT6206_G_MODE_INTERRUPT_SHIFT)) << FT6206_G_MODE_INTERRUPT_SHIFT;
TS_IO_Write(DeviceAddr, FT6206_GMODE_REG, regValue);
}{ ... }
/* ... */
void ft6x06_TS_DisableIT(uint16_t DeviceAddr)
{
uint8_t regValue = 0;
regValue = (FT6206_G_MODE_INTERRUPT_POLLING & (FT6206_G_MODE_INTERRUPT_MASK >> FT6206_G_MODE_INTERRUPT_SHIFT)) << FT6206_G_MODE_INTERRUPT_SHIFT;
TS_IO_Write(DeviceAddr, FT6206_GMODE_REG, regValue);
}{ ... }
/* ... */
uint8_t ft6x06_TS_ITStatus(uint16_t DeviceAddr)
{
return 0;
}{ ... }
/* ... */
void ft6x06_TS_ClearIT(uint16_t DeviceAddr)
{
}{ ... }
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
/* ... */
void ft6x06_TS_GetGestureID(uint16_t DeviceAddr, uint32_t * pGestureId)
{
volatile uint8_t ucReadData = 0;
ucReadData = TS_IO_Read(DeviceAddr, FT6206_GEST_ID_REG);
* pGestureId = ucReadData;
}{ ... }
/* ... */
void ft6x06_TS_GetTouchInfo(uint16_t DeviceAddr,
uint32_t touchIdx,
uint32_t * pWeight,
uint32_t * pArea,
uint32_t * pEvent)
{
uint8_t regAddress = 0;
uint8_t dataxy[3];
if(touchIdx < ft6x06_handle.currActiveTouchNb)
{
switch(touchIdx)
{
case 0 :
regAddress = FT6206_P1_WEIGHT_REG;
break;
case 0 :
case 1 :
regAddress = FT6206_P2_WEIGHT_REG;
break;
case 1 :
default :
break;
default
}switch (touchIdx) { ... }
TS_IO_ReadMultiple(DeviceAddr, regAddress, dataxy, sizeof(dataxy));
* pWeight = (dataxy[0] & FT6206_TOUCH_WEIGHT_MASK) >> FT6206_TOUCH_WEIGHT_SHIFT;
* pArea = (dataxy[1] & FT6206_TOUCH_AREA_MASK) >> FT6206_TOUCH_AREA_SHIFT;
* pEvent = (dataxy[2] & FT6206_TOUCH_EVT_FLAG_MASK) >> FT6206_TOUCH_EVT_FLAG_SHIFT;
}if (touchIdx < ft6x06_handle.currActiveTouchNb) { ... }
}{ ... }
/* ... */#endif
#if (TS_AUTO_CALIBRATION_SUPPORTED == 1)
/* ... */
static uint32_t ft6x06_TS_Calibration(uint16_t DeviceAddr)
{
uint32_t nbAttempt = 0;
volatile uint8_t ucReadData;
volatile uint8_t regValue;
uint32_t status = FT6206_STATUS_OK;
uint8_t bEndCalibration = 0;
regValue = (FT6206_DEV_MODE_FACTORY & FT6206_DEV_MODE_MASK) << FT6206_DEV_MODE_SHIFT;
TS_IO_Write(DeviceAddr, FT6206_DEV_MODE_REG, regValue);
ucReadData = TS_IO_Read(DeviceAddr, FT6206_DEV_MODE_REG);
TS_IO_Delay(300);
if(((ucReadData & (FT6206_DEV_MODE_MASK << FT6206_DEV_MODE_SHIFT)) >> FT6206_DEV_MODE_SHIFT) != FT6206_DEV_MODE_FACTORY )
{
return(FT6206_STATUS_NOT_OK);
}if (((ucReadData & (FT6206_DEV_MODE_MASK << FT6206_DEV_MODE_SHIFT)) >> FT6206_DEV_MODE_SHIFT) != FT6206_DEV_MODE_FACTORY) { ... }
TS_IO_Write(DeviceAddr, FT6206_TD_STAT_REG, 0x04);
TS_IO_Delay(300);
for (nbAttempt=0; ((nbAttempt < 100) && (!bEndCalibration)) ; nbAttempt++)
{
ucReadData = TS_IO_Read(DeviceAddr, FT6206_DEV_MODE_REG);
ucReadData = (ucReadData & (FT6206_DEV_MODE_MASK << FT6206_DEV_MODE_SHIFT)) >> FT6206_DEV_MODE_SHIFT;
if(ucReadData == FT6206_DEV_MODE_WORKING)
{
bEndCalibration = 1;
}if (ucReadData == FT6206_DEV_MODE_WORKING) { ... }
TS_IO_Delay(200);
}for (nbAttempt=0; ((nbAttempt < 100) && (!bEndCalibration)) ; nbAttempt++) { ... }
return(status);
}ft6x06_TS_Calibration (uint16_t DeviceAddr) { ... }
/* ... */#endif
/* ... */
static uint32_t ft6x06_TS_Configure(uint16_t DeviceAddr)
{
uint32_t status = FT6206_STATUS_OK;
return(status);
}{ ... }
/* ... */
static uint8_t ft6x06_GetInstance(uint16_t DeviceAddr)
{
uint8_t idx = 0;
for(idx = 0; idx < FT6x06_MAX_INSTANCE ; idx ++)
{
if(ft6x06[idx] == DeviceAddr)
{
return idx;
}if (ft6x06[idx] == DeviceAddr) { ... }
}for (idx = 0; idx < FT6x06_MAX_INSTANCE ; idx ++) { ... }
return 0xFF;
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */