stm32f469_fw/src/hw/driver/ts.c
bool tsUpdateTouchData(void)
{
  static uint32_t _x[TS_MAX_NB_TOUCH] = {0, 0};
  static uint32_t _y[TS_MAX_NB_TOUCH] = {0, 0};
  err_code_t ts_status = OK;
  bool ret = false;
  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_MULTI_TOUCH_SUPPORTED == 1 */

  /* Check and update the number of touches active detected */
  ts_data.detect_cnt = ts_driver->DetectTouch(i2c_addr);
  if(ts_data.detect_cnt)
  {
    for(index=0; index < ts_data.detect_cnt; index++)
    {
      /* Get each touch coordinates */
      ts_driver->GetXY(i2c_addr, &(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_X)
      {
        Raw_x[index] = FT_6206_MAX_WIDTH - 1 - Raw_x[index];
      }

      if(ts_orientation & TS_SWAP_Y)
      {
        Raw_y[index] = FT_6206_MAX_HEIGHT - 1 - Raw_y[index];
      }

      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];
      }

      ts_data.x_axis[index] = _x[index];
      ts_data.y_axis[index] = _y[index];

#if (TS_MULTI_TOUCH_SUPPORTED == 1)
      /* Get touch info related to the current touch */
      ft6x06_TS_GetTouchInfo(i2c_addr, index, &weight, &area, &event);

      /* Update ts_data structure */
      ts_data.weight[index] = weight;
      ts_data.area[index]   = area;

      /* Remap touch event */
      switch(event)
      {
        case FT6206_TOUCH_EVT_FLAG_PRESS_DOWN  :
          ts_data.event_id[index] = TOUCH_EVENT_PRESS_DOWN;
          break;
        case FT6206_TOUCH_EVT_FLAG_LIFT_UP :
          ts_data.event_id[index] = TOUCH_EVENT_LIFT_UP;
          break;
        case FT6206_TOUCH_EVT_FLAG_CONTACT :
          ts_data.event_id[index] = TOUCH_EVENT_CONTACT;
          break;
        case FT6206_TOUCH_EVT_FLAG_NO_EVENT :
          ts_data.event_id[index] = TOUCH_EVENT_NO_EVT;
          break;
        default :
          ts_status = ERR_TS;
          break;
      } /* of switch(event) */

#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */
    } /* of for(index=0; index < ts_data->detect_cnt; index++) */

#if (TS_MULTI_TOUCH_SUPPORTED == 1)
    /* Get gesture Id */
    ts_status = drvTsUpdateGestureId();
#endif /* TS_MULTI_TOUCH_SUPPORTED == 1 */

  } /* end of if(ts_data->detect_cnt != 0) */

  if (ts_status == OK)
  {
    ret = true;
  }
  return ret;
}
/**
  * @brief  Returns status and positions of the touch screen.
  * @param  ts_data: Pointer to touch screen current state structure
  * @retval OK if all initializations are OK. Other value if error.
  */
@brief  Returns status and positions of the touch screen.
@param  ts_data: Pointer to touch screen current state structure
@retval OK if all initializations are OK. Other value if error.
@brief Returns status and positions of the touch screen . @param ts_data : Pointer to touch screen current state structure @retval OK if all initializations are OK . Other value if error .
bool tsUpdateTouchData(void)
{
  static uint32_t _x[TS_MAX_NB_TOUCH] = {0, 0};
  static uint32_t _y[TS_MAX_NB_TOUCH] = {0, 0};
  err_code_t ts_status = OK;
  bool ret = false;
  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_data.detect_cnt = ts_driver->DetectTouch(i2c_addr);
  if(ts_data.detect_cnt)
  {
    for(index=0; index < ts_data.detect_cnt; index++)
    {
      ts_driver->GetXY(i2c_addr, &(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_X)
      {
        Raw_x[index] = FT_6206_MAX_WIDTH - 1 - Raw_x[index];
      }
      if(ts_orientation & TS_SWAP_Y)
      {
        Raw_y[index] = FT_6206_MAX_HEIGHT - 1 - Raw_y[index];
      }
      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];
      }
      ts_data.x_axis[index] = _x[index];
      ts_data.y_axis[index] = _y[index];
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
      ft6x06_TS_GetTouchInfo(i2c_addr, index, &weight, &area, &event);
      ts_data.weight[index] = weight;
      ts_data.area[index]   = area;
      switch(event)
      {
        case FT6206_TOUCH_EVT_FLAG_PRESS_DOWN  :
          ts_data.event_id[index] = TOUCH_EVENT_PRESS_DOWN;
          break;
        case FT6206_TOUCH_EVT_FLAG_LIFT_UP :
          ts_data.event_id[index] = TOUCH_EVENT_LIFT_UP;
          break;
        case FT6206_TOUCH_EVT_FLAG_CONTACT :
          ts_data.event_id[index] = TOUCH_EVENT_CONTACT;
          break;
        case FT6206_TOUCH_EVT_FLAG_NO_EVENT :
          ts_data.event_id[index] = TOUCH_EVENT_NO_EVT;
          break;
        default :
          ts_status = ERR_TS;
          break;
      } 
#endif 
    } 
#if (TS_MULTI_TOUCH_SUPPORTED == 1)
    ts_status = drvTsUpdateGestureId();
#endif 
  } 
  if (ts_status == OK)
  {
    ret = true;
  }
  return ret;
}
bool tsUpdateTouchData ( void ) { static uint32_t _x [ TS_MAX_NB_TOUCH ] = { 0 , 0 } ; static uint32_t _y [ TS_MAX_NB_TOUCH ] = { 0 , 0 } ; err_code_t ts_status = OK ; bool ret = false ; 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_data . detect_cnt = ts_driver -> DetectTouch ( i2c_addr ) ; if ( ts_data . detect_cnt ) { for ( index = 0 ; index < ts_data . detect_cnt ; index ++ ) { ts_driver -> GetXY ( i2c_addr , & ( 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_X ) { Raw_x [ index ] = FT_6206_MAX_WIDTH - 1 - Raw_x [ index ] ; } if ( ts_orientation & TS_SWAP_Y ) { Raw_y [ index ] = FT_6206_MAX_HEIGHT - 1 - Raw_y [ index ] ; } 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 ] ; } ts_data . x_axis [ index ] = _x [ index ] ; ts_data . y_axis [ index ] = _y [ index ] ; #if ( TS_MULTI_TOUCH_SUPPORTED == 1 ) ft6x06_TS_GetTouchInfo ( i2c_addr , index , & weight , & area , & event ) ; ts_data . weight [ index ] = weight ; ts_data . area [ index ] = area ; switch ( event ) { case FT6206_TOUCH_EVT_FLAG_PRESS_DOWN : ts_data . event_id [ index ] = TOUCH_EVENT_PRESS_DOWN ; break ; case FT6206_TOUCH_EVT_FLAG_LIFT_UP : ts_data . event_id [ index ] = TOUCH_EVENT_LIFT_UP ; break ; case FT6206_TOUCH_EVT_FLAG_CONTACT : ts_data . event_id [ index ] = TOUCH_EVENT_CONTACT ; break ; case FT6206_TOUCH_EVT_FLAG_NO_EVENT : ts_data . event_id [ index ] = TOUCH_EVENT_NO_EVT ; break ; default : ts_status = ERR_TS ; break ; } #endif } #if ( TS_MULTI_TOUCH_SUPPORTED == 1 ) ts_status = drvTsUpdateGestureId ( ) ; #endif } if ( ts_status == OK ) { ret = true ; } return ret ; }
@brief  Returns status and positions of the touch screen.
@brief Returns status and positions of the touch screen .
/* TS_MULTI_TOUCH_SUPPORTED == 1 */ /* Check and update the number of touches active detected */ /* Get each touch coordinates */ /* Get touch info related to the current touch */ /* Update ts_data structure */ /* Remap touch event */ /* of switch(event) */ /* TS_MULTI_TOUCH_SUPPORTED == 1 */ /* of for(index=0; index < ts_data->detect_cnt; index++) */ /* Get gesture Id */ /* TS_MULTI_TOUCH_SUPPORTED == 1 */ /* end of if(ts_data->detect_cnt != 0) */