STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
ft5336.h
Go to the documentation of this file.
1 
39 /* Define to prevent recursive inclusion -------------------------------------*/
40 #ifndef __FT5336_H
41 #define __FT5336_H
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 /* Set Multi-touch as supported */
48 #if !defined(TS_MONO_TOUCH_SUPPORTED)
49 #define TS_MULTI_TOUCH_SUPPORTED 1
50 #endif /* TS_MONO_TOUCH_SUPPORTED */
51 
52 /* Includes ------------------------------------------------------------------*/
53 #include "../Common/ts.h"
54 
55 /* Macros --------------------------------------------------------------------*/
56 
57 #if defined(FT5336_ENABLE_ASSERT)
58 /* Assert activated */
59 #define FT5336_ASSERT(__condition__) do { if(__condition__) \
60  { \
61  while(1); \
62  } \
63  }while(0)
64 #else
65 /* Assert not activated : macro has no effect */
66 #define FT5336_ASSERT(__condition__) do { if(__condition__) \
67  { \
68  ; \
69  } \
70  }while(0)
71 #endif /* FT5336_ENABLE_ASSERT == 1 */
72 
76 typedef struct
77 {
78  uint8_t i2cInitialized;
79 
80  /* field holding the current number of simultaneous active touches */
82 
83  /* field holding the touch index currently managed */
85 
87 
100  /* Exported types ------------------------------------------------------------*/
101 
106  /* Exported constants --------------------------------------------------------*/
107 
112  /* I2C Slave address of touchscreen FocalTech FT5336 */
113 #define FT5336_I2C_SLAVE_ADDRESS ((uint8_t)0x70)
114 
115  /* Maximum border values of the touchscreen pad */
116 #define FT5336_MAX_WIDTH ((uint16_t)480) /* Touchscreen pad max width */
117 #define FT5336_MAX_HEIGHT ((uint16_t)272) /* Touchscreen pad max height */
118 
119  /* Possible values of driver functions return status */
120 #define FT5336_STATUS_OK ((uint8_t)0x00)
121 #define FT5336_STATUS_NOT_OK ((uint8_t)0x01)
122 
123  /* Possible values of global variable 'TS_I2C_Initialized' */
124 #define FT5336_I2C_NOT_INITIALIZED ((uint8_t)0x00)
125 #define FT5336_I2C_INITIALIZED ((uint8_t)0x01)
126 
127  /* Max detectable simultaneous touches */
128 #define FT5336_MAX_DETECTABLE_TOUCH ((uint8_t)0x05)
129 
134  /* Current mode register of the FT5336 (R/W) */
135 #define FT5336_DEV_MODE_REG ((uint8_t)0x00)
136 
137  /* Possible values of FT5336_DEV_MODE_REG */
138 #define FT5336_DEV_MODE_WORKING ((uint8_t)0x00)
139 #define FT5336_DEV_MODE_FACTORY ((uint8_t)0x04)
140 
141 #define FT5336_DEV_MODE_MASK ((uint8_t)0x07)
142 #define FT5336_DEV_MODE_SHIFT ((uint8_t)0x04)
143 
144  /* Gesture ID register */
145 #define FT5336_GEST_ID_REG ((uint8_t)0x01)
146 
147  /* Possible values of FT5336_GEST_ID_REG */
148 #define FT5336_GEST_ID_NO_GESTURE ((uint8_t)0x00)
149 #define FT5336_GEST_ID_MOVE_UP ((uint8_t)0x10)
150 #define FT5336_GEST_ID_MOVE_RIGHT ((uint8_t)0x14)
151 #define FT5336_GEST_ID_MOVE_DOWN ((uint8_t)0x18)
152 #define FT5336_GEST_ID_MOVE_LEFT ((uint8_t)0x1C)
153 #define FT5336_GEST_ID_SINGLE_CLICK ((uint8_t)0x20)
154 #define FT5336_GEST_ID_DOUBLE_CLICK ((uint8_t)0x22)
155 #define FT5336_GEST_ID_ROTATE_CLOCKWISE ((uint8_t)0x28)
156 #define FT5336_GEST_ID_ROTATE_C_CLOCKWISE ((uint8_t)0x29)
157 #define FT5336_GEST_ID_ZOOM_IN ((uint8_t)0x40)
158 #define FT5336_GEST_ID_ZOOM_OUT ((uint8_t)0x49)
159 
160  /* Touch Data Status register : gives number of active touch points (0..5) */
161 #define FT5336_TD_STAT_REG ((uint8_t)0x02)
162 
163  /* Values related to FT5336_TD_STAT_REG */
164 #define FT5336_TD_STAT_MASK ((uint8_t)0x0F)
165 #define FT5336_TD_STAT_SHIFT ((uint8_t)0x00)
166 
167  /* Values Pn_XH and Pn_YH related */
168 #define FT5336_TOUCH_EVT_FLAG_PRESS_DOWN ((uint8_t)0x00)
169 #define FT5336_TOUCH_EVT_FLAG_LIFT_UP ((uint8_t)0x01)
170 #define FT5336_TOUCH_EVT_FLAG_CONTACT ((uint8_t)0x02)
171 #define FT5336_TOUCH_EVT_FLAG_NO_EVENT ((uint8_t)0x03)
172 
173 #define FT5336_TOUCH_EVT_FLAG_SHIFT ((uint8_t)0x06)
174 #define FT5336_TOUCH_EVT_FLAG_MASK ((uint8_t)(3 << FT5336_TOUCH_EVT_FLAG_SHIFT))
175 
176 #define FT5336_TOUCH_POS_MSB_MASK ((uint8_t)0x0F)
177 #define FT5336_TOUCH_POS_MSB_SHIFT ((uint8_t)0x00)
178 
179  /* Values Pn_XL and Pn_YL related */
180 #define FT5336_TOUCH_POS_LSB_MASK ((uint8_t)0xFF)
181 #define FT5336_TOUCH_POS_LSB_SHIFT ((uint8_t)0x00)
182 
183 #define FT5336_P1_XH_REG ((uint8_t)0x03)
184 #define FT5336_P1_XL_REG ((uint8_t)0x04)
185 #define FT5336_P1_YH_REG ((uint8_t)0x05)
186 #define FT5336_P1_YL_REG ((uint8_t)0x06)
187 
188 /* Touch Pressure register value (R) */
189 #define FT5336_P1_WEIGHT_REG ((uint8_t)0x07)
190 
191 /* Values Pn_WEIGHT related */
192 #define FT5336_TOUCH_WEIGHT_MASK ((uint8_t)0xFF)
193 #define FT5336_TOUCH_WEIGHT_SHIFT ((uint8_t)0x00)
194 
195 /* Touch area register */
196 #define FT5336_P1_MISC_REG ((uint8_t)0x08)
197 
198 /* Values related to FT5336_Pn_MISC_REG */
199 #define FT5336_TOUCH_AREA_MASK ((uint8_t)(0x04 << 4))
200 #define FT5336_TOUCH_AREA_SHIFT ((uint8_t)0x04)
201 
202 #define FT5336_P2_XH_REG ((uint8_t)0x09)
203 #define FT5336_P2_XL_REG ((uint8_t)0x0A)
204 #define FT5336_P2_YH_REG ((uint8_t)0x0B)
205 #define FT5336_P2_YL_REG ((uint8_t)0x0C)
206 #define FT5336_P2_WEIGHT_REG ((uint8_t)0x0D)
207 #define FT5336_P2_MISC_REG ((uint8_t)0x0E)
208 
209 #define FT5336_P3_XH_REG ((uint8_t)0x0F)
210 #define FT5336_P3_XL_REG ((uint8_t)0x10)
211 #define FT5336_P3_YH_REG ((uint8_t)0x11)
212 #define FT5336_P3_YL_REG ((uint8_t)0x12)
213 #define FT5336_P3_WEIGHT_REG ((uint8_t)0x13)
214 #define FT5336_P3_MISC_REG ((uint8_t)0x14)
215 
216 #define FT5336_P4_XH_REG ((uint8_t)0x15)
217 #define FT5336_P4_XL_REG ((uint8_t)0x16)
218 #define FT5336_P4_YH_REG ((uint8_t)0x17)
219 #define FT5336_P4_YL_REG ((uint8_t)0x18)
220 #define FT5336_P4_WEIGHT_REG ((uint8_t)0x19)
221 #define FT5336_P4_MISC_REG ((uint8_t)0x1A)
222 
223 #define FT5336_P5_XH_REG ((uint8_t)0x1B)
224 #define FT5336_P5_XL_REG ((uint8_t)0x1C)
225 #define FT5336_P5_YH_REG ((uint8_t)0x1D)
226 #define FT5336_P5_YL_REG ((uint8_t)0x1E)
227 #define FT5336_P5_WEIGHT_REG ((uint8_t)0x1F)
228 #define FT5336_P5_MISC_REG ((uint8_t)0x20)
229 
230 #define FT5336_P6_XH_REG ((uint8_t)0x21)
231 #define FT5336_P6_XL_REG ((uint8_t)0x22)
232 #define FT5336_P6_YH_REG ((uint8_t)0x23)
233 #define FT5336_P6_YL_REG ((uint8_t)0x24)
234 #define FT5336_P6_WEIGHT_REG ((uint8_t)0x25)
235 #define FT5336_P6_MISC_REG ((uint8_t)0x26)
236 
237 #define FT5336_P7_XH_REG ((uint8_t)0x27)
238 #define FT5336_P7_XL_REG ((uint8_t)0x28)
239 #define FT5336_P7_YH_REG ((uint8_t)0x29)
240 #define FT5336_P7_YL_REG ((uint8_t)0x2A)
241 #define FT5336_P7_WEIGHT_REG ((uint8_t)0x2B)
242 #define FT5336_P7_MISC_REG ((uint8_t)0x2C)
243 
244 #define FT5336_P8_XH_REG ((uint8_t)0x2D)
245 #define FT5336_P8_XL_REG ((uint8_t)0x2E)
246 #define FT5336_P8_YH_REG ((uint8_t)0x2F)
247 #define FT5336_P8_YL_REG ((uint8_t)0x30)
248 #define FT5336_P8_WEIGHT_REG ((uint8_t)0x31)
249 #define FT5336_P8_MISC_REG ((uint8_t)0x32)
250 
251 #define FT5336_P9_XH_REG ((uint8_t)0x33)
252 #define FT5336_P9_XL_REG ((uint8_t)0x34)
253 #define FT5336_P9_YH_REG ((uint8_t)0x35)
254 #define FT5336_P9_YL_REG ((uint8_t)0x36)
255 #define FT5336_P9_WEIGHT_REG ((uint8_t)0x37)
256 #define FT5336_P9_MISC_REG ((uint8_t)0x38)
257 
258 #define FT5336_P10_XH_REG ((uint8_t)0x39)
259 #define FT5336_P10_XL_REG ((uint8_t)0x3A)
260 #define FT5336_P10_YH_REG ((uint8_t)0x3B)
261 #define FT5336_P10_YL_REG ((uint8_t)0x3C)
262 #define FT5336_P10_WEIGHT_REG ((uint8_t)0x3D)
263 #define FT5336_P10_MISC_REG ((uint8_t)0x3E)
264 
265  /* Threshold for touch detection */
266 #define FT5336_TH_GROUP_REG ((uint8_t)0x80)
267 
268  /* Values FT5336_TH_GROUP_REG : threshold related */
269 #define FT5336_THRESHOLD_MASK ((uint8_t)0xFF)
270 #define FT5336_THRESHOLD_SHIFT ((uint8_t)0x00)
271 
272  /* Filter function coefficients */
273 #define FT5336_TH_DIFF_REG ((uint8_t)0x85)
274 
275  /* Control register */
276 #define FT5336_CTRL_REG ((uint8_t)0x86)
277 
278  /* Values related to FT5336_CTRL_REG */
279 
280  /* Will keep the Active mode when there is no touching */
281 #define FT5336_CTRL_KEEP_ACTIVE_MODE ((uint8_t)0x00)
282 
283  /* Switching from Active mode to Monitor mode automatically when there is no touching */
284 #define FT5336_CTRL_KEEP_AUTO_SWITCH_MONITOR_MODE ((uint8_t)0x01
285 
286  /* The time period of switching from Active mode to Monitor mode when there is no touching */
287 #define FT5336_TIMEENTERMONITOR_REG ((uint8_t)0x87)
288 
289  /* Report rate in Active mode */
290 #define FT5336_PERIODACTIVE_REG ((uint8_t)0x88)
291 
292  /* Report rate in Monitor mode */
293 #define FT5336_PERIODMONITOR_REG ((uint8_t)0x89)
294 
295  /* The value of the minimum allowed angle while Rotating gesture mode */
296 #define FT5336_RADIAN_VALUE_REG ((uint8_t)0x91)
297 
298  /* Maximum offset while Moving Left and Moving Right gesture */
299 #define FT5336_OFFSET_LEFT_RIGHT_REG ((uint8_t)0x92)
300 
301  /* Maximum offset while Moving Up and Moving Down gesture */
302 #define FT5336_OFFSET_UP_DOWN_REG ((uint8_t)0x93)
303 
304  /* Minimum distance while Moving Left and Moving Right gesture */
305 #define FT5336_DISTANCE_LEFT_RIGHT_REG ((uint8_t)0x94)
306 
307  /* Minimum distance while Moving Up and Moving Down gesture */
308 #define FT5336_DISTANCE_UP_DOWN_REG ((uint8_t)0x95)
309 
310  /* Maximum distance while Zoom In and Zoom Out gesture */
311 #define FT5336_DISTANCE_ZOOM_REG ((uint8_t)0x96)
312 
313  /* High 8-bit of LIB Version info */
314 #define FT5336_LIB_VER_H_REG ((uint8_t)0xA1)
315 
316  /* Low 8-bit of LIB Version info */
317 #define FT5336_LIB_VER_L_REG ((uint8_t)0xA2)
318 
319  /* Chip Selecting */
320 #define FT5336_CIPHER_REG ((uint8_t)0xA3)
321 
322  /* Interrupt mode register (used when in interrupt mode) */
323 #define FT5336_GMODE_REG ((uint8_t)0xA4)
324 
325 #define FT5336_G_MODE_INTERRUPT_MASK ((uint8_t)0x03)
326 #define FT5336_G_MODE_INTERRUPT_SHIFT ((uint8_t)0x00)
327 
328  /* Possible values of FT5336_GMODE_REG */
329 #define FT5336_G_MODE_INTERRUPT_POLLING ((uint8_t)0x00)
330 #define FT5336_G_MODE_INTERRUPT_TRIGGER ((uint8_t)0x01)
331 
332  /* Current power mode the FT5336 system is in (R) */
333 #define FT5336_PWR_MODE_REG ((uint8_t)0xA5)
334 
335  /* FT5336 firmware version */
336 #define FT5336_FIRMID_REG ((uint8_t)0xA6)
337 
338  /* FT5336 Chip identification register */
339 #define FT5336_CHIP_ID_REG ((uint8_t)0xA8)
340 
341  /* Possible values of FT5336_CHIP_ID_REG */
342 #define FT5336_ID_VALUE ((uint8_t)0x51)
343 
344  /* Release code version */
345 #define FT5336_RELEASE_CODE_ID_REG ((uint8_t)0xAF)
346 
347  /* Current operating mode the FT5336 system is in (R) */
348 #define FT5336_STATE_REG ((uint8_t)0xBC)
349 
354  /* Exported macro ------------------------------------------------------------*/
355 
360  /* Exported functions --------------------------------------------------------*/
361 
377 void ft5336_Init(uint16_t DeviceAddr);
378 
384 void ft5336_Reset(uint16_t DeviceAddr);
385 
392 uint16_t ft5336_ReadID(uint16_t DeviceAddr);
393 
399 void ft5336_TS_Start(uint16_t DeviceAddr);
400 
408 uint8_t ft5336_TS_DetectTouch(uint16_t DeviceAddr);
409 
419 void ft5336_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y);
420 
427 void ft5336_TS_EnableIT(uint16_t DeviceAddr);
428 
435 void ft5336_TS_DisableIT(uint16_t DeviceAddr);
436 
444 uint8_t ft5336_TS_ITStatus (uint16_t DeviceAddr);
445 
452 void ft5336_TS_ClearIT (uint16_t DeviceAddr);
453 
454 /**** NEW FEATURES enabled when Multi-touch support is enabled ****/
455 
456 #if (TS_MULTI_TOUCH_SUPPORTED == 1)
457 
464 void ft5336_TS_GetGestureID(uint16_t DeviceAddr, uint32_t * pGestureId);
465 
481 void ft5336_TS_GetTouchInfo(uint16_t DeviceAddr,
482  uint32_t touchIdx,
483  uint32_t * pWeight,
484  uint32_t * pArea,
485  uint32_t * pEvent);
486 
487 #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
488 
489 /* Imported TS IO functions --------------------------------------------------------*/
490 
495 /* TouchScreen (TS) external IO functions */
496 extern void TS_IO_Init(void);
497 extern void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
498 extern uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg);
499 extern void TS_IO_Delay(uint32_t Delay);
500 
505  /* Imported global variables --------------------------------------------------------*/
506 
512 /* Touch screen driver structure */
514 
519 #ifdef __cplusplus
520 }
521 #endif
522 #endif /* __FT5336_H */
523 
524 
540 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
TS_DrvTypeDef ft5336_ts_drv
Definition: ft5336.c:79
uint8_t ft5336_TS_DetectTouch(uint16_t DeviceAddr)
Return if there is touches detected or not. Try to detect new touches and forget the old ones (reset ...
Definition: ft5336.c:224
uint16_t ft5336_ReadID(uint16_t DeviceAddr)
Read the ft5336 device ID, pre initialize I2C in case of need to be able to read the FT5336 device ID...
Definition: ft5336.c:175
void TS_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value)
Writes a single data.
uint8_t currActiveTouchIdx
Definition: ft5336.h:84
uint8_t ft5336_TS_ITStatus(uint16_t DeviceAddr)
Get IT status from FT5336 interrupt status registers Should be called Following an EXTI coming to the...
Definition: ft5336.c:409
uint8_t currActiveTouchNb
Definition: ft5336.h:81
void ft5336_TS_GetGestureID(uint16_t DeviceAddr, uint32_t *pGestureId)
Get the last touch gesture identification (zoom, move up/down...).
Definition: ft5336.c:437
void ft5336_Reset(uint16_t DeviceAddr)
Software Reset the ft5336.
Definition: ft5336.c:163
void ft5336_TS_ClearIT(uint16_t DeviceAddr)
Clear IT status in FT5336 interrupt status clear registers Should be called Following an EXTI coming ...
Definition: ft5336.c:422
void ft5336_TS_GetXY(uint16_t DeviceAddr, uint16_t *X, uint16_t *Y)
Get the touch screen X and Y positions values Manage multi touch thanks to touch Index global variabl...
Definition: ft5336.c:256
uint8_t TS_IO_Read(uint8_t Addr, uint8_t Reg)
Reads a single data.
void ft5336_TS_DisableIT(uint16_t DeviceAddr)
Configure the FT5336 device to stop generating IT on the given INT pin connected to MCU as EXTI...
Definition: ft5336.c:392
void TS_IO_Delay(uint32_t Delay)
Delay function used in TouchScreen low level driver.
void ft5336_TS_EnableIT(uint16_t DeviceAddr)
Configure the FT5336 device to generate IT on given INT pin connected to MCU as EXTI.
Definition: ft5336.c:377
void ft5336_TS_Start(uint16_t DeviceAddr)
Configures the touch Screen IC device to start detecting touches.
Definition: ft5336.c:207
void ft5336_TS_GetTouchInfo(uint16_t DeviceAddr, uint32_t touchIdx, uint32_t *pWeight, uint32_t *pArea, uint32_t *pEvent)
Get the touch detailed informations on touch number &#39;touchIdx&#39; (0..1) This touch detailed information...
Definition: ft5336.c:461
void ft5336_Init(uint16_t DeviceAddr)
ft5336 Control functions
Definition: ft5336.c:147
void TS_IO_Init(void)
Initializes Touchscreen low level.
uint8_t i2cInitialized
Definition: ft5336.h:78