/**
  * @brief  Return Touch Screen X position value
  * @param  None
  * @retval X position.
  */
uint16_t IOE_TS_Read_X(void)
{
#if 0
  int32_t x, xr;
	
  x = I2C_ReadDataBuffer(IOE_1_ADDR, IOE_REG_TSC_DATA_X);
	
  /* first correction */
  xr =  (x * 320) >> 12;
  /* second correction */
  xr = ((xr * 32)/29) - 17;

  if (xr <= 0) {
    xr = 0;
  }

  return (uint16_t)(xr); 
#else
  int32_t icount, sum = 0;
	
  for (icount = 0; icount < 16; icount++) {
    sum += I2C_ReadDataBuffer(IOE_1_ADDR, IOE_REG_TSC_DATA_X);
  }
  sum >>= 4;
	
  if (sum <= 0) {
    sum = 0;
  }
	
  return (uint16_t)(sum); 	
#endif
}
/**
  * @brief  Return Touch Screen Y position value
  * @param  None
  * @retval Y position.
  */
uint16_t IOE_TS_Read_Y(void)
{
#if 0

  int32_t y, yr;
  y= I2C_ReadDataBuffer(IOE_1_ADDR, IOE_REG_TSC_DATA_Y);
	
  yr= (y * 240) >> 12;
  yr = ((yr * 240) / 217) - 12;
	
  if (yr <= 0) {
    yr = 0;
  }
  return (uint16_t)(yr); 
#else
  int32_t icount, sum = 0;
	
  for (icount = 0; icount < 16; icount++) {
    sum += I2C_ReadDataBuffer(IOE_1_ADDR, IOE_REG_TSC_DATA_Y);
  }
  sum >>= 4;
	
  if (sum <= 0) {
    sum = 0;
  }

  return (uint16_t)(sum); 	
#endif
}
/**
  * @brief  Return Touch Panel Y position value
  * @param  None
  * @retval Y position.
  */
static uint16_t IOE_TP_Read_Y(void)
{
  int32_t y, yr;
  
  /* Read y value from DATA_Y register */
  y = I2C_ReadDataBuffer(IOE_REG_TP_DATA_Y);
  
  /* y value first correction */

  y -= 360;  
  
  /* y value second correction */
  yr = y / 11;
  
  /* return y position value */
  if(yr <= 0)
  {
    yr = 0;
  }
  else if (yr > 320)
  {
    yr = 319;
  }
  else
  {}
  return (uint16_t)(yr); 
}
/**
  * @brief  Return Touch Panel X position value
  * @param  None
  * @retval X position.
  */
static uint16_t IOE_TP_Read_X(void)
{
  int32_t x, xr;
  
  /* Read x value from DATA_X register */
  x = I2C_ReadDataBuffer(IOE_REG_TP_DATA_X);
  
  /* x value first correction */
  if(x <= 3000)
  {
  x = 3870 - x;
  }
  else
  {
   x = 3800 - x;
  }
  
  /* x value second correction */  
  xr = x / 15;
  
  /* return x position value */
  if(xr <= 0)
  {
    xr = 0;
  }
  else if (xr > 240)
  {
    xr = 239;
  }
  else 
  {}
  return (uint16_t)(xr); 
}
示例#5
0
文件: TscHal.c 项目: Leon0820/stm32
/**
  * @brief  Read the coordinate of the point touched and assign their
  *         value to the variables u32_TSXCoordinate and u32_TSYCoordinate
  * @param  None
  * @retval None
  */
void TSC_Read(void)
{
#if TOUCH_SCREEN_CAPABILITY
  TSC_Value_X = 0x00;
  TSC_Value_Y = 0x00;
  if((I2C_ReadDeviceRegister(pTscHwParam.TSC_DeviceRegister, GL_TSC_CTRL) & 0x80))
  {
      GL_Delay(TOUCH_DELAY);

      /* Stop touchscreen controller */
      I2C_WriteDeviceRegister(pTscHwParam.TSC_DeviceRegister, GL_TSC_CTRL, 0x00);
      
      TSC_Value_X = I2C_ReadDataBuffer(pTscHwParam.TSC_DeviceRegister, GL_TSC_DATA_Y);    
      TSC_Value_Y = I2C_ReadDataBuffer(pTscHwParam.TSC_DeviceRegister, GL_TSC_DATA_X);
      I2C_ReadDataBuffer(pTscHwParam.TSC_DeviceRegister, GL_TSC_DATA_Z);
      
      u32_TSXCoordinate = getDisplayCoordinateX( TSC_Value_X, TSC_Value_Y );
      u32_TSYCoordinate = getDisplayCoordinateY( TSC_Value_X, TSC_Value_Y );
      
      touch_done = 1;
      
      /* Clear the interrupt pending bit and enable the FIFO again */
      I2C_WriteDeviceRegister(pTscHwParam.TSC_DeviceRegister, GL_FIFO_CTRL_STA, 0x01);
      I2C_WriteDeviceRegister(pTscHwParam.TSC_DeviceRegister, GL_INT_STA, IOE_TS_IT);
      I2C_WriteDeviceRegister(pTscHwParam.TSC_DeviceRegister, GL_FIFO_CTRL_STA, 0x00);      
      GL_Delay(0x02);
      
      /* Enable touchscreen controller */
      I2C_WriteDeviceRegister(pTscHwParam.TSC_DeviceRegister, GL_TSC_CTRL, 0x01);
      
      GL_Delay(0x05);

      /* check if the FIFO is not empty */
      if(I2C_ReadDeviceRegister(pTscHwParam.TSC_DeviceRegister, GL_FIFO_CTRL_STA) != 0x20)
      {
        /* Flush the FIFO */
        I2C_WriteDeviceRegister(pTscHwParam.TSC_DeviceRegister, GL_FIFO_CTRL_STA, 0x01);
        I2C_WriteDeviceRegister(pTscHwParam.TSC_DeviceRegister, GL_FIFO_CTRL_STA, 0x00);
      }
  }
  else
  {
    GL_Delay(1);
  }
#endif
}
示例#6
0
/**
  * @brief  Return Touch Screen Z position value
  * @param  None
  * @retval Z position.
  */
static uint16_t IOE_TS_Read_Z(void)
{
  uint32_t z;
  z = I2C_ReadDataBuffer(IOE_1_ADDR, IOE_REG_TSC_DATA_Z);


  if(z <= 0)
    z = 0;

  return (uint16_t)(z);
}
/**
  * @brief  Return Touch Panel Z position value
  * @param  None
  * @retval Z position.
  */
static uint16_t IOE_TP_Read_Z(void)
{
  uint32_t z;
  
  /* Read z value from DATA_Z register */
  z = I2C_ReadDataBuffer(IOE_REG_TP_DATA_Z);

  /* return z position value */
  if(z <= 0)
    z = 0;
  return (uint16_t)(z); 
}
示例#8
0
/**
  * @brief  Return Touch Screen Y position value
  * @param  None
  * @retval Y position.
  */
static uint16_t IOE_TS_Read_Y(void)
{
  int32_t y, yr;
  y= I2C_ReadDataBuffer(IOE_1_ADDR, IOE_REG_TSC_DATA_X);

  yr= (y * 240) >> 12;
  yr = ((yr * 240) / 217) - 12;

  if(yr <= 0)
    yr = 0;

  return (uint16_t)(yr);
}
示例#9
0
/**
  * @brief  Return Touch Screen Y position value
  * @param  None
  * @retval Y position.s
  */
static uint16_t IOE_TS_Read_Y(void)
{
  int32_t y, yr;
  y= I2C_ReadDataBuffer(IOE_REG_TSC_DATA_Y);
  
  yr= (y * LCD_PIXEL_HEIGHT) >> 12;
  yr = ((yr * LCD_PIXEL_HEIGHT) / 217) - 12;
  
  if(yr <= 0)
    yr = 0;
  
  return (uint16_t)(yr); 
}
示例#10
0
/**
  * @brief  Return Touch Screen X position value
  * @param  None
  * @retval X position.
  */
static uint16_t IOE_TS_Read_X(void)
{
  int32_t x, xr;

  x = I2C_ReadDataBuffer(IOE_1_ADDR, IOE_REG_TSC_DATA_Y);

  /* first correction */
  xr =  (x * 320) >> 12;
  /* second correction */
  xr = ((xr * 32)/29) - 17;

  if(xr <= 0)
    xr = 0;

  return (uint16_t)(xr);
}