Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "ft6x06.h"
Private typedef
#define FT6x06_MAX_INSTANCE
Private macro
ft6x06_ts_drv
ft6x06
ft6x06_handle
ft6x06_Init(uint16_t)
ft6x06_Reset(uint16_t)
ft6x06_ReadID(uint16_t)
ft6x06_TS_Start(uint16_t)
ft6x06_TS_DetectTouch(uint16_t)
ft6x06_TS_GetXY(uint16_t, uint16_t *, uint16_t *)
ft6x06_TS_EnableIT(uint16_t)
ft6x06_TS_DisableIT(uint16_t)
ft6x06_TS_ITStatus(uint16_t)
ft6x06_TS_ClearIT(uint16_t)
ft6x06_TS_GetGestureID(uint16_t, uint32_t *)
ft6x06_TS_GetTouchInfo(uint16_t, uint32_t, uint32_t *, uint32_t *, uint32_t *)
ft6x06_TS_Configure(uint16_t)
ft6x06_GetInstance(uint16_t)
Files
loading...
CodeScopeSTM32 Libraries and Samplesft6x06ft6x06.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
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
360
361
362
363
364
365
366
367
368
369
370
371
372
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file ft6x06.c * @author MCD Application Team * @brief This file provides a set of functions needed to manage the FT6X06 * IO Expander devices. ****************************************************************************** * @attention * * Copyright (c) 2016 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "ft6x06.h" /** @addtogroup BSP * @{ *//* ... */ /** @addtogroup Component * @{ *//* ... */ /** @defgroup FT6XX6 * @{ *//* ... */ Includes /* Private typedef -----------------------------------------------------------*/ /** @defgroup FT6XX6_Private_Defines FT6XX6 Private Defines * @{ *//* ... */ #define FT6x06_MAX_INSTANCE 2 /** * @} *//* ... */ Private typedef /* Private macro -------------------------------------------------------------*/ /** @defgroup FT6XX6_Private_Variables FT6XX6 Private Variables * @{ *//* ... */ /* Touch screen driver structure initialization */ 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 ...}; /* ft6xx6 instances by address */ uint8_t ft6x06[FT6x06_MAX_INSTANCE] = {0}; /* Global ft6xx6 handle */ static ft6x06_handle_TypeDef ft6x06_handle = { FT6206_I2C_NOT_INITIALIZED, 0, 0}; /** * @} *//* ... */ /** @defgroup ft6xx6_Private_Function_Prototypes ft6xx6 Private Function Prototypes * @{ *//* ... */ static uint8_t ft6x06_GetInstance(uint16_t DeviceAddr);Private macro /* Private functions prototypes-----------------------------------------------*/ #if (TS_AUTO_CALIBRATION_SUPPORTED == 1) /** * @brief Start TouchScreen calibration phase * @param DeviceAddr: FT6xx6 Device address for communication on I2C Bus. * @retval Status FT6206_STATUS_OK or FT6206_STATUS_NOT_OK. *//* ... */ static uint32_t ft6x06_TS_Calibration(uint16_t DeviceAddr);/* ... */ #endif /* TS_AUTO_CALIBRATION_SUPPORTED == 1 */ /** * @brief Basic static configuration of TouchScreen * @param DeviceAddr: FT6xx6 Device address for communication on I2C Bus. * @retval Status FT6206_STATUS_OK or FT6206_STATUS_NOT_OK. *//* ... */ static uint32_t ft6x06_TS_Configure(uint16_t DeviceAddr); /** * @} *//* ... */ /** @defgroup ft6xx6_Private_Functions ft6xx6 Private Functions * @{ *//* ... */ /** * @brief Initialize the ft6xx6 communication bus * from MCU to FT6xx6 : ie I2C channel initialization (if required). * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6xx6). * @retval None *//* ... */ void ft6x06_Init(uint16_t DeviceAddr) { uint8_t instance; uint8_t empty; /* Check if device instance already exists */ instance = ft6x06_GetInstance(DeviceAddr); /* To prevent double initialization */ if(instance == 0xFF) { /* Look for empty instance */ empty = ft6x06_GetInstance(0); if(empty < FT6x06_MAX_INSTANCE) { /* Register the current device instance */ ft6x06[empty] = DeviceAddr; /* Initialize IO BUS layer */ TS_IO_Init(); }if (empty < FT6x06_MAX_INSTANCE) { ... } }if (instance == 0xFF) { ... } }{ ... } /** * @brief Software Reset the ft6xx6. * @note : Not applicable to FT6xx6. * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6xx6). * @retval None *//* ... */ void ft6x06_Reset(uint16_t DeviceAddr) { /* Do nothing */ /* No software reset sequence available in FT6xx6 IC */ }{ ... } /** * @brief Read the ft6xx6 device ID, pre initialize I2C in case of need to be * able to read the FT6xx6 device ID, and verify this is a FT6xx6. * @param DeviceAddr: I2C FT6xx6 Slave address. * @retval The Device ID (two bytes). *//* ... */ uint16_t ft6x06_ReadID(uint16_t DeviceAddr) { /* Initialize I2C link if needed */ TS_IO_Init(); /* Return the device ID value */ return (TS_IO_Read(DeviceAddr, FT6206_CHIP_ID_REG)); }{ ... } /** * @brief Configures the touch Screen IC device to start detecting touches * It goes through an internal calibration process (Hw calibration sequence of * the touch screen). * @param DeviceAddr: Device address on communication Bus (I2C slave address). * @retval None. *//* ... */ void ft6x06_TS_Start(uint16_t DeviceAddr) { #if (TS_AUTO_CALIBRATION_SUPPORTED == 1) /* Hw Calibration sequence start : should be done once after each power up */ /* This is called internal calibration of the touch screen */ ft6x06_TS_Calibration(DeviceAddr);/* ... */ #endif /* Minimum static configuration of FT6xx6 */ ft6x06_TS_Configure(DeviceAddr); /* By default set FT6xx6 IC in Polling mode : no INT generation on FT6xx6 for new touch available */ /* Note TS_INT is active low */ ft6x06_TS_DisableIT(DeviceAddr); }{ ... } /** * @brief Return if there is touches detected or not. * Try to detect new touches and forget the old ones (reset internal global * variables). * @param DeviceAddr: Device address on communication Bus. * @retval : Number of active touches detected (can be 0, 1 or 2). *//* ... */ uint8_t ft6x06_TS_DetectTouch(uint16_t DeviceAddr) { volatile uint8_t nbTouch = 0; /* Read register FT6206_TD_STAT_REG to check number of touches detection */ nbTouch = TS_IO_Read(DeviceAddr, FT6206_TD_STAT_REG); nbTouch &= FT6206_TD_STAT_MASK; if(nbTouch > FT6206_MAX_DETECTABLE_TOUCH) { /* If invalid number of touch detected, set it to zero */ nbTouch = 0; }if (nbTouch > FT6206_MAX_DETECTABLE_TOUCH) { ... } /* Update ft6xx6 driver internal global : current number of active touches */ ft6x06_handle.currActiveTouchNb = nbTouch; /* Reset current active touch index on which to work on */ ft6x06_handle.currActiveTouchIdx = 0; return(nbTouch); }{ ... } /** * @brief Get the touch screen X and Y positions values * Manage multi touch thanks to touch Index global * variable 'ft6x06_handle.currActiveTouchIdx'. * @param DeviceAddr: Device address on communication Bus. * @param X: Pointer to X position value * @param Y: Pointer to Y position value * @retval None. *//* ... */ 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) { ... } /* Read X and Y positions */ TS_IO_ReadMultiple(DeviceAddr, regAddress, dataxy, sizeof(dataxy)); /* Send back ready X position to caller */ *X = ((dataxy[0] & FT6206_MSB_MASK) << 8) | (dataxy[1] & FT6206_LSB_MASK); /* Send back ready Y position to caller */ *Y = ((dataxy[2] & FT6206_MSB_MASK) << 8) | (dataxy[3] & FT6206_LSB_MASK); ft6x06_handle.currActiveTouchIdx++; }if (ft6x06_handle.currActiveTouchIdx < ft6x06_handle.currActiveTouchNb) { ... } }{ ... } /** * @brief Configure the FT6xx6 device to generate IT on given INT pin * connected to MCU as EXTI. * @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT6xx6). * @retval None *//* ... */ 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; /* Set interrupt trigger mode in FT6206_GMODE_REG */ TS_IO_Write(DeviceAddr, FT6206_GMODE_REG, regValue); }{ ... } /** * @brief Configure the FT6xx6 device to stop generating IT on the given INT pin * connected to MCU as EXTI. * @param DeviceAddr: Device address on communication Bus (Slave I2C address of FT6xx6). * @retval None *//* ... */ 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; /* Set interrupt polling mode in FT6206_GMODE_REG */ TS_IO_Write(DeviceAddr, FT6206_GMODE_REG, regValue); }{ ... } /** * @brief Get IT status from FT6xx6 interrupt status registers * Should be called Following an EXTI coming to the MCU to know the detailed * reason of the interrupt. * @note : This feature is not applicable to FT6xx6. * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6xx6). * @retval TS interrupts status : always return 0 here *//* ... */ uint8_t ft6x06_TS_ITStatus(uint16_t DeviceAddr) { /* Always return 0 as feature not applicable to FT6xx6 */ return 0; }{ ... } /** * @brief Clear IT status in FT6xx6 interrupt status clear registers * Should be called Following an EXTI coming to the MCU. * @note : This feature is not applicable to FT6xx6. * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6xx6). * @retval None *//* ... */ void ft6x06_TS_ClearIT(uint16_t DeviceAddr) { /* Nothing to be done here for FT6xx6 */ }{ ... } /**** NEW FEATURES enabled when Multi-touch support is enabled ****/ #if (TS_MULTI_TOUCH_SUPPORTED == 1) /** * @brief Get the last touch gesture identification (zoom, move up/down...). * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6xx6). * @param pGestureId : Pointer to get last touch gesture Identification. * @retval None. *//* ... */ 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; }{ ... } /** * @brief Get the touch detailed informations on touch number 'touchIdx' (0..1) * This touch detailed information contains : * - weight that was applied to this touch * - sub-area of the touch in the touch panel * - event of linked to the touch (press down, lift up, ...) * @param DeviceAddr: Device address on communication Bus (I2C slave address of FT6xx6). * @param touchIdx : Passed index of the touch (0..1) on which we want to get the * detailed information. * @param pWeight : Pointer to to get the weight information of 'touchIdx'. * @param pArea : Pointer to to get the sub-area information of 'touchIdx'. * @param pEvent : Pointer to to get the event information of 'touchIdx'. * @retval None. *//* ... */ 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) { ... } /* end switch(touchIdx) */ /* Read weight, area and Event Id of touch index */ TS_IO_ReadMultiple(DeviceAddr, regAddress, dataxy, sizeof(dataxy)); /* Return weight of touch index */ * pWeight = (dataxy[0] & FT6206_TOUCH_WEIGHT_MASK) >> FT6206_TOUCH_WEIGHT_SHIFT; /* Return area of touch index */ * pArea = (dataxy[1] & FT6206_TOUCH_AREA_MASK) >> FT6206_TOUCH_AREA_SHIFT; /* Return Event Id of touch index */ * pEvent = (dataxy[2] & FT6206_TOUCH_EVT_FLAG_MASK) >> FT6206_TOUCH_EVT_FLAG_SHIFT; }if (touchIdx < ft6x06_handle.currActiveTouchNb) { ... } /* of if(touchIdx < ft6x06_handle.currActiveTouchNb) */ }{ ... } /* ... */#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */ #if (TS_AUTO_CALIBRATION_SUPPORTED == 1) /** * @brief Start TouchScreen calibration phase * @param DeviceAddr: FT6xx6 Device address for communication on I2C Bus. * @retval Status FT6206_STATUS_OK or FT6206_STATUS_NOT_OK. *//* ... */ 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; /* >> Calibration sequence start */ /* Switch FT6xx6 back to factory mode to calibrate */ regValue = (FT6206_DEV_MODE_FACTORY & FT6206_DEV_MODE_MASK) << FT6206_DEV_MODE_SHIFT; TS_IO_Write(DeviceAddr, FT6206_DEV_MODE_REG, regValue); /* 0x40 */ /* Read back the same register FT6206_DEV_MODE_REG */ ucReadData = TS_IO_Read(DeviceAddr, FT6206_DEV_MODE_REG); TS_IO_Delay(300); /* Wait 300 ms */ if(((ucReadData & (FT6206_DEV_MODE_MASK << FT6206_DEV_MODE_SHIFT)) >> FT6206_DEV_MODE_SHIFT) != FT6206_DEV_MODE_FACTORY ) { /* Return error to caller */ return(FT6206_STATUS_NOT_OK); }if (((ucReadData & (FT6206_DEV_MODE_MASK << FT6206_DEV_MODE_SHIFT)) >> FT6206_DEV_MODE_SHIFT) != FT6206_DEV_MODE_FACTORY) { ... } /* Start calibration command */ TS_IO_Write(DeviceAddr, FT6206_TD_STAT_REG, 0x04); TS_IO_Delay(300); /* Wait 300 ms */ /* 100 attempts to wait switch from factory mode (calibration) to working mode */ 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) { /* Auto Switch to FT6206_DEV_MODE_WORKING : means calibration have ended */ bEndCalibration = 1; /* exit for loop */ }if (ucReadData == FT6206_DEV_MODE_WORKING) { ... } TS_IO_Delay(200); /* Wait 200 ms */ }for (nbAttempt=0; ((nbAttempt < 100) && (!bEndCalibration)) ; nbAttempt++) { ... } /* Calibration sequence end << */ return(status); }ft6x06_TS_Calibration (uint16_t DeviceAddr) { ... } /* ... */#endif /* TS_AUTO_CALIBRATION_SUPPORTED == 1 */ /** * @brief Basic static configuration of TouchScreen * @param DeviceAddr: FT6xx6 Device address for communication on I2C Bus. * @retval Status FT6206_STATUS_OK or FT6206_STATUS_NOT_OK. *//* ... */ static uint32_t ft6x06_TS_Configure(uint16_t DeviceAddr) { uint32_t status = FT6206_STATUS_OK; /* Nothing special to be done for FT6xx6 */ return(status); }{ ... } /** * @brief Check if the device instance of the selected address is already registered * and return its index * @param DeviceAddr: Device address on communication Bus. * @retval Index of the device instance if registered, 0xFF if not. *//* ... */ static uint8_t ft6x06_GetInstance(uint16_t DeviceAddr) { uint8_t idx = 0; /* Check all the registered instances */ 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; }{ ... } /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */ /** * @} *//* ... */