STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
stm32f769i_discovery_ts.c
Go to the documentation of this file.
1 
39 /* File Info : -----------------------------------------------------------------
40  User NOTES
41 1. How To use this driver:
42 --------------------------
43  - This driver is used to drive the touch screen module of the STM32F769I-DISCOVERY
44  discoveryuation board on the K.O.D Optica Technology 480x800 TFT-LCD mounted on
45  MB1166 daughter board. The touch screen driver IC inside the K.O.D module KM-040TMP-02
46  is a FT6206 by Focal Tech.
47 
48 2. Driver description:
49 ---------------------
50  + Initialization steps:
51  o Initialize the TS module using the BSP_TS_Init() function. This
52  function includes the MSP layer hardware resources initialization and the
53  communication layer configuration to start the TS use. The LCD size properties
54  (x and y) are passed as parameters.
55  o If TS interrupt mode is desired, you must configure the TS interrupt mode
56  by calling the function BSP_TS_ITConfig(). The TS interrupt mode is generated
57  as an external interrupt whenever a touch is detected.
58  The interrupt mode internally uses the IO functionalities driver driven by
59  the IO expander, to configure the IT line.
60 
61  + Touch screen use
62  o The touch screen state is captured whenever the function BSP_TS_GetState() is
63  used. This function returns information about the last LCD touch occurred
64  in the TS_StateTypeDef structure.
65  o The IT is handled using the corresponding external interrupt IRQ handler,
66  the user IT callback treatment is implemented on the same external interrupt
67  callback.
68 
69 ------------------------------------------------------------------------------*/
70 
71 /* Includes ------------------------------------------------------------------*/
72 #include "stm32f769i_discovery.h"
74 
118 static TS_DrvTypeDef *ts_driver;
119 static uint8_t ts_orientation;
120 static uint8_t I2C_Address = 0;
121 
122 /* Table for touchscreen event information display on LCD : table indexed on enum @ref TS_TouchEventTypeDef information */
124  "Press down",
125  "Lift up",
126  "Contact"
127  };
128 
129 /* Table for touchscreen gesture Id information display on LCD : table indexed on enum @ref TS_GestureIdTypeDef information */
131  "Move Up",
132  "Move Right",
133  "Move Down",
134  "Move Left",
135  "Zoom In",
136  "Zoom Out"
137  };
138 
162 uint8_t BSP_TS_Init(uint16_t ts_SizeX, uint16_t ts_SizeY)
163 {
164  uint8_t ts_status = TS_OK;
165 
166  /* Note : I2C_Address is un-initialized here, but is not used at all in init function */
167  /* but the prototype of Init() is like that in template and should be respected */
168 
169  /* Initialize the communication channel to sensor (I2C) if necessary */
170  /* that is initialization is done only once after a power up */
171  ft6x06_ts_drv.Init(I2C_Address);
172 
173  /* Scan FT6x06 TouchScreen IC controller ID register by I2C Read */
174  /* Verify this is a FT6x06, otherwise this is an error case */
176  {
177  /* Found FT6206 : Initialize the TS driver structure */
178  ts_driver = &ft6x06_ts_drv;
179 
180  I2C_Address = TS_I2C_ADDRESS;
181 
182  /* Get LCD chosen orientation */
183  if(ts_SizeX < ts_SizeY)
184  {
185  ts_orientation = TS_SWAP_NONE;
186  }
187  else
188  {
189  ts_orientation = TS_SWAP_XY | TS_SWAP_Y;
190  }
191 
192  if(ts_status == TS_OK)
193  {
194  /* Software reset the TouchScreen */
195  ts_driver->Reset(I2C_Address);
196 
197  /* Calibrate, Configure and Start the TouchScreen driver */
198  ts_driver->Start(I2C_Address);
199 
200  } /* of if(ts_status == TS_OK) */
201  }
202  else
203  {
204  ts_status = TS_DEVICE_NOT_FOUND;
205  }
206 
207  return (ts_status);
208 }
209 
214 uint8_t BSP_TS_ITConfig(void)
215 {
216  uint8_t ts_status = TS_OK;
217  GPIO_InitTypeDef gpio_init_structure;
218 
219  /* Msp Init of GPIO used for TS_INT pin coming from TouchScreen driver IC FT6x06 */
220  /* When touchscreen is operated in interrupt mode */
222 
223  /* Configure Interrupt mode for TS_INT pin falling edge : when a new touch is available */
224  /* TS_INT pin is active on low level on new touch available */
225  gpio_init_structure.Pin = TS_INT_PIN;
226  gpio_init_structure.Pull = GPIO_PULLUP;
227  gpio_init_structure.Speed = GPIO_SPEED_FAST;
228  gpio_init_structure.Mode = GPIO_MODE_IT_FALLING;
229  HAL_GPIO_Init(TS_INT_GPIO_PORT, &gpio_init_structure);
230 
231  /* Enable and set the TS_INT EXTI Interrupt to an intermediate priority */
234 
235  /* Enable the TS in interrupt mode */
236  /* In that case the INT output of FT6206 when new touch is available */
237  /* is active on low level and directed on EXTI */
238  ts_driver->EnableIT(I2C_Address);
239 
240  return (ts_status);
241 }
242 
249 {
250  static uint32_t _x[TS_MAX_NB_TOUCH] = {0, 0};
251  static uint32_t _y[TS_MAX_NB_TOUCH] = {0, 0};
252  uint8_t ts_status = TS_OK;
253  uint16_t tmp;
254  uint16_t Raw_x[TS_MAX_NB_TOUCH];
255  uint16_t Raw_y[TS_MAX_NB_TOUCH];
256  uint16_t xDiff;
257  uint16_t yDiff;
258  uint32_t index;
259 #if (TS_MULTI_TOUCH_SUPPORTED == 1)
260  uint32_t weight = 0;
261  uint32_t area = 0;
262  uint32_t event = 0;
263 #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
264 
265  /* Check and update the number of touches active detected */
266  TS_State->touchDetected = ts_driver->DetectTouch(I2C_Address);
267  if(TS_State->touchDetected)
268  {
269  for(index=0; index < TS_State->touchDetected; index++)
270  {
271  /* Get each touch coordinates */
272  ts_driver->GetXY(I2C_Address, &(Raw_x[index]), &(Raw_y[index]));
273 
274  if(ts_orientation & TS_SWAP_XY)
275  {
276  tmp = Raw_x[index];
277  Raw_x[index] = Raw_y[index];
278  Raw_y[index] = tmp;
279  }
280 
281  if(ts_orientation & TS_SWAP_X)
282  {
283  Raw_x[index] = FT_6206_MAX_WIDTH - 1 - Raw_x[index];
284  }
285 
286  if(ts_orientation & TS_SWAP_Y)
287  {
288  Raw_y[index] = FT_6206_MAX_HEIGHT - 1 - Raw_y[index];
289  }
290 
291  xDiff = Raw_x[index] > _x[index]? (Raw_x[index] - _x[index]): (_x[index] - Raw_x[index]);
292  yDiff = Raw_y[index] > _y[index]? (Raw_y[index] - _y[index]): (_y[index] - Raw_y[index]);
293 
294  if ((xDiff + yDiff) > 5)
295  {
296  _x[index] = Raw_x[index];
297  _y[index] = Raw_y[index];
298  }
299 
300 
301  TS_State->touchX[index] = _x[index];
302  TS_State->touchY[index] = _y[index];
303 
304 #if (TS_MULTI_TOUCH_SUPPORTED == 1)
305 
306  /* Get touch info related to the current touch */
307  ft6x06_TS_GetTouchInfo(I2C_Address, index, &weight, &area, &event);
308 
309  /* Update TS_State structure */
310  TS_State->touchWeight[index] = weight;
311  TS_State->touchArea[index] = area;
312 
313  /* Remap touch event */
314  switch(event)
315  {
317  TS_State->touchEventId[index] = TOUCH_EVENT_PRESS_DOWN;
318  break;
320  TS_State->touchEventId[index] = TOUCH_EVENT_LIFT_UP;
321  break;
323  TS_State->touchEventId[index] = TOUCH_EVENT_CONTACT;
324  break;
326  TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT;
327  break;
328  default :
329  ts_status = TS_ERROR;
330  break;
331  } /* of switch(event) */
332 
333 #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
334 
335  } /* of for(index=0; index < TS_State->touchDetected; index++) */
336 
337 #if (TS_MULTI_TOUCH_SUPPORTED == 1)
338  /* Get gesture Id */
339  ts_status = BSP_TS_Get_GestureId(TS_State);
340 #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
341 
342  } /* end of if(TS_State->touchDetected != 0) */
343 
344  return (ts_status);
345 }
346 
347 #if (TS_MULTI_TOUCH_SUPPORTED == 1)
348 
353 uint8_t BSP_TS_Get_GestureId(TS_StateTypeDef *TS_State)
354 {
355  uint32_t gestureId = 0;
356  uint8_t ts_status = TS_OK;
357 
358  /* Get gesture Id */
359  ft6x06_TS_GetGestureID(I2C_Address, &gestureId);
360 
361  /* Remap gesture Id to a TS_GestureIdTypeDef value */
362  switch(gestureId)
363  {
365  TS_State->gestureId = GEST_ID_NO_GESTURE;
366  break;
368  TS_State->gestureId = GEST_ID_MOVE_UP;
369  break;
371  TS_State->gestureId = GEST_ID_MOVE_RIGHT;
372  break;
374  TS_State->gestureId = GEST_ID_MOVE_DOWN;
375  break;
377  TS_State->gestureId = GEST_ID_MOVE_LEFT;
378  break;
380  TS_State->gestureId = GEST_ID_ZOOM_IN;
381  break;
383  TS_State->gestureId = GEST_ID_ZOOM_OUT;
384  break;
385  default :
386  ts_status = TS_ERROR;
387  break;
388  } /* of switch(gestureId) */
389 
390  return(ts_status);
391 }
392 #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
393 
394 
399 #if (TS_MULTI_TOUCH_SUPPORTED == 1)
400 
406 uint8_t BSP_TS_ResetTouchData(TS_StateTypeDef *TS_State)
407 {
408  uint8_t ts_status = TS_ERROR;
409  uint32_t index;
410 
411  if (TS_State != (TS_StateTypeDef *)NULL)
412  {
413  TS_State->gestureId = GEST_ID_NO_GESTURE;
414  TS_State->touchDetected = 0;
415 
416  for(index = 0; index < TS_MAX_NB_TOUCH; index++)
417  {
418  TS_State->touchX[index] = 0;
419  TS_State->touchY[index] = 0;
420  TS_State->touchArea[index] = 0;
421  TS_State->touchEventId[index] = TOUCH_EVENT_NO_EVT;
422  TS_State->touchWeight[index] = 0;
423  }
424 
425  ts_status = TS_OK;
426 
427  } /* of if (TS_State != (TS_StateTypeDef *)NULL) */
428 
429  return (ts_status);
430 }
431 #endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
432 
438 __weak void BSP_TS_INT_MspInit(void)
439 {
440  GPIO_InitTypeDef gpio_init_structure;
441 
443 
444  /* GPIO configuration in input for TouchScreen interrupt signal on TS_INT pin */
445  gpio_init_structure.Pin = TS_INT_PIN;
446 
447  gpio_init_structure.Mode = GPIO_MODE_INPUT;
448  gpio_init_structure.Pull = GPIO_PULLUP;
449  gpio_init_structure.Speed = GPIO_SPEED_HIGH;
450  HAL_GPIO_Init(TS_INT_GPIO_PORT, &gpio_init_structure);
451 }
452 
473 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define FT6206_TOUCH_EVT_FLAG_CONTACT
Definition: ft6x06.h:152
__weak void BSP_TS_INT_MspInit(void)
Initializes the TS_INT pin MSP.
#define FT6206_TOUCH_EVT_FLAG_PRESS_DOWN
Definition: ft6x06.h:150
uint8_t BSP_TS_ITConfig(void)
Configures and enables the touch screen interrupts.
This file contains definitions for STM32F769I-Discovery LEDs, push-buttons hardware resources...
void(* Init)(uint16_t)
Definition: ts.h:70
TS_StateTypeDef Define TS State structure.
void(* Start)(uint16_t)
Definition: ts.h:73
#define TS_SWAP_NONE
#define GPIO_MODE_INPUT
#define GPIO_PULLUP
#define FT6206_ID_VALUE
Definition: ft6x06.h:268
#define FT_6206_MAX_HEIGHT
Definition: ft6x06.h:103
#define NULL
Definition: usbd_def.h:53
void(* Reset)(uint16_t)
Definition: ts.h:72
char * ts_event_string_tab[TOUCH_EVENT_NB_MAX]
Table for touchscreen event information display on LCD : table indexed on enum TS_TouchEventTypeDef i...
#define TS_SWAP_Y
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
#define FT6206_GEST_ID_MOVE_UP
Definition: ft6x06.h:135
#define TS_INT_EXTI_IRQn
#define FT6206_GEST_ID_ZOOM_OUT
Definition: ft6x06.h:140
IRQn_Type
STM32F7xx Interrupt Number Definition, according to the selected device in Library_configuration_sect...
Definition: stm32f745xx.h:67
void(* GetXY)(uint16_t, uint16_t *, uint16_t *)
Definition: ts.h:75
#define TS_MAX_NB_TOUCH
With FT6206 : maximum 2 touches detected simultaneously.
#define TS_INT_GPIO_CLK_ENABLE()
#define TS_INT_PIN
TS_INT signal from TouchScreen when it is configured in interrupt mode GPIOI13 is used for that purpo...
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
uint8_t BSP_TS_Init(uint16_t ts_SizeX, uint16_t ts_SizeY)
Initializes and configures the touch screen functionalities and configures all necessary hardware res...
#define TS_INT_GPIO_PORT
GPIO Init structure definition.
#define TS_SWAP_XY
uint16_t(* ReadID)(uint16_t)
Definition: ts.h:71
uint8_t(* DetectTouch)(uint16_t)
Definition: ts.h:74
uint8_t BSP_TS_GetState(TS_StateTypeDef *TS_State)
Returns status and positions of the touch screen.
uint16_t touchY[TS_MAX_NB_TOUCH]
#define FT6206_GEST_ID_MOVE_RIGHT
Definition: ft6x06.h:136
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
#define FT6206_GEST_ID_MOVE_DOWN
Definition: ft6x06.h:137
#define FT_6206_MAX_WIDTH
Definition: ft6x06.h:102
This file contains the common defines and functions prototypes for the stm32f769i_discovery_ts.c driver.
#define FT6206_GEST_ID_ZOOM_IN
Definition: ft6x06.h:139
#define TS_I2C_ADDRESS
TouchScreen FT6206 Slave I2C address.
char * ts_gesture_id_string_tab[GEST_ID_NB_MAX]
Table for touchscreen gesture Id information display on LCD : table indexed on enum TS_GestureIdTypeD...
void(* EnableIT)(uint16_t)
Definition: ts.h:76
TS_DrvTypeDef ft6x06_ts_drv
Definition: ft6x06.c:71
#define FT6206_GEST_ID_NO_GESTURE
Definition: ft6x06.h:134
#define FT6206_TOUCH_EVT_FLAG_NO_EVENT
Definition: ft6x06.h:153
#define FT6206_TOUCH_EVT_FLAG_LIFT_UP
Definition: ft6x06.h:151
#define GPIO_MODE_IT_FALLING
#define FT6206_GEST_ID_MOVE_LEFT
Definition: ft6x06.h:138
uint16_t touchX[TS_MAX_NB_TOUCH]
#define TS_SWAP_X