예제 #1
0
/**
  * @brief  Shift cursor with defined step (CUR_STEP).
  * @param  CursorEvent: specifies direction of shift.
  *   This parameter can be one of the following values:
  *     @arg  CUR_DOWN: shift cursor down by step.
  *     @arg  CUR_UP: shift cursor up by step.
  *     @arg  CUR_RIGHT: shift cursor right by step.
  *     @arg  CUR_LEFT: shift cursor left by step.
  * @retval None
  */
void CursorStepMove(uint8_t CursorEvent)
{
  uint16_t tmpY, tmpX;

  /*Load current cursor position*/
  tmpY = Cursor->Y;
  tmpX = Cursor->X;

  /*Step cursor position with regard to desired direction.*/
  switch (CursorEvent)
  {
    case CUR_DOWN:
      tmpY -= (tmpY >= CUR_STEP) ? (CUR_STEP) : (tmpY);
      break;
    case CUR_LEFT:
      tmpY += (LCD_Width - tmpY - CursorPointer[1] >= CUR_STEP) ? (CUR_STEP) : (LCD_Width - tmpY - CursorPointer[1]);
      break;
    case CUR_RIGHT:
      tmpX += (LCD_Height - tmpX - CursorPointer[0] >= CUR_STEP) ? (CUR_STEP) : (LCD_Height - tmpX - CursorPointer[0]);
      break;
    case CUR_UP:
      tmpX -= (tmpX >= CUR_STEP) ? (CUR_STEP) : (tmpX);
      break;
    default:
      break;
  }

  /*Pass just calculated position to call what handle this change*/
  CursorPosition(tmpX, tmpY);
  GL_Delay(3);
}
예제 #2
0
/**
* @brief  Add a message in the initialization page 
* @param  msg: pointer to the string to be displayed
* @retval None
*/
void GL_State_Message (uint8_t *msg)
{
  uint8_t tmpCaption[40];

  GL_CenterCaption (tmpCaption, msg, LCD_Width / GL_FONT_SMALL_WIDTH);
  GL_DisplayAdjStringLine(3 * (LCD_Height / 5), 300, tmpCaption, GL_FALSE);
  GL_Delay(300);
}
예제 #3
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
}
예제 #4
0
/**
* @brief  display the initialization page 
* @param  None
* @retval None
*/
void GL_Startup (void)
{
  uint8_t cnt = 0;

  GL_Clear(GL_White);

  GL_DrawButtonBMP( 210, 110, 148, (LCD_Height / 10)*2, (uint8_t*) STM32Logo );

  for ( ; cnt < 2; cnt ++)
  {
    GL_DisplayAdjStringLine(144, 250, (uint8_t *)"STM32 System Initializing.  ", GL_FALSE);
    GL_Delay(100);
    GL_DisplayAdjStringLine(144, 250, (uint8_t *)"STM32 System Initializing.. ", GL_FALSE);
    GL_Delay(100);
    GL_DisplayAdjStringLine(144, 250, (uint8_t *)"STM32 System Initializing...", GL_FALSE);
    GL_Delay(100);
  }
}
예제 #5
0
/**
  * @brief  Calibrate TouchScreen coordinates by LCD touch in 5 points
  * @param  None
  * @retval None
  */
void TS_Calibration(void)
{
  uint32_t coordinate_X1a = 0, coordinate_X2a = 0, coordinate_X3a = 0, coordinate_X4a = 0, coordinate_X5a = 0;
  uint32_t coordinate_Y1a = 0, coordinate_Y2a = 0, coordinate_Y3a = 0, coordinate_Y4a = 0, coordinate_Y5a = 0;
  uint32_t coordinate_X1b = 0, coordinate_X2b = 0, coordinate_X3b = 0, coordinate_X4b = 0, coordinate_X5b = 0;
  uint32_t coordinate_Y1b = 0, coordinate_Y2b = 0, coordinate_Y3b = 0, coordinate_Y4b = 0, coordinate_Y5b = 0;
  uint32_t coordinate_X1 = 0, coordinate_X2 = 0, coordinate_X3 = 0, coordinate_X4 = 0, coordinate_X5 = 0;
  uint32_t coordinate_Y1 = 0, coordinate_Y2 = 0, coordinate_Y3 = 0, coordinate_Y4 = 0, coordinate_Y5 = 0;
  uint16_t Xd1 = (LCD_Width / 2), Xd2 = 1 * (LCD_Width / 5), Xd3 = 4 * (LCD_Width / 5), Xd4 = 4 * (LCD_Width / 5), Xd5 = 1 * (LCD_Width / 5);
  uint16_t Yd1 = (LCD_Height / 2), Yd2 = 1 * (LCD_Height / 5), Yd3 = 1 * (LCD_Height / 5), Yd4 = 4 * (LCD_Height / 5), Yd5 = 4 * (LCD_Height / 5);
  double A = 0.0, B = 0.0, C = 0.0, D = 0.0, E = 0.0, F = 0.0;
  double d = 0.0, dx1 = 0.0, dx2 = 0.0, dx3 = 0.0, dy1 = 0.0, dy2 = 0.0, dy3 = 0.0;
  uint32_t X2_1 = 0, X2_2 = 0, X2_3 = 0, X2_4 = 0, X2_5 = 0;
  uint32_t Y2_1 = 0, Y2_2 = 0, Y2_3 = 0, Y2_4 = 0, Y2_5 = 0;
  uint32_t XxY_1 = 0, XxY_2 = 0, XxY_3 = 0, XxY_4 = 0, XxY_5 = 0;
  uint32_t XxXd_1 = 0, XxXd_2 = 0, XxXd_3 = 0, XxXd_4 = 0, XxXd_5 = 0;
  uint32_t YxXd_1 = 0, YxXd_2 = 0, YxXd_3 = 0, YxXd_4 = 0, YxXd_5 = 0;
  uint32_t XxYd_1 = 0, XxYd_2 = 0, XxYd_3 = 0, XxYd_4 = 0, XxYd_5 = 0;
  uint32_t YxYd_1 = 0, YxYd_2 = 0, YxYd_3 = 0, YxYd_4 = 0, YxYd_5 = 0;
  uint32_t alfa = 0, beta = 0, chi = 0, Kx = 0, Ky = 0, Lx = 0, Ly = 0;
  uint16_t epsilon = 0, fi = 0, Mx = 0, My = 0;

  GL_SetBackColor(GL_White);
  GL_SetTextColor(GL_Black);
  GL_Clear(White);
  GL_DisplayAdjStringLine(3 * (LCD_Height / 7), LCD_Width - 25, "Run Calibration.", GL_FALSE);
  GL_Delay(40);
  GL_DisplayAdjStringLine(3 * (LCD_Height / 7), LCD_Width - 25, "Run Calibration..", GL_FALSE);
  GL_Delay(40);
  GL_DisplayAdjStringLine(3 * (LCD_Height / 7), LCD_Width - 25, "Run Calibration...", GL_FALSE);
  GL_Delay(30);
  touch_done = 0;

  GL_Clear(White);
  GL_Cross( (LCD_Height / 2), (LCD_Width / 2) ); /* Absolute Central Point */
  while ( touch_done == 0)
  {
    TSC_Read();
  }
  coordinate_X1a = TSC_Value_X;
  coordinate_Y1a = TSC_Value_Y;

  GL_Delay(90); /* This is to catch only one touch event */
  TSC_Init();
  touch_done = 0;

  GL_Clear(White);
  GL_Cross(1*(LCD_Height / 5), 1*(LCD_Width / 5)); /* Nord-East Corner point */
  while ( touch_done == 0)
  {
    TSC_Read();
  }
  coordinate_X2a = TSC_Value_X;
  coordinate_Y2a = TSC_Value_Y;

  GL_Delay(90); /* This is to catch only one touch event */
  TSC_Init();
  touch_done = 0;

  GL_Clear(White);
  GL_Cross(1*(LCD_Height / 5), 4*(LCD_Width / 5)); /* Nord-West Corner */
  while ( touch_done == 0)
  {
    TSC_Read();
  }
  coordinate_X3a = TSC_Value_X;
  coordinate_Y3a = TSC_Value_Y;

  GL_Delay(90); /* This is to catch only one touch event */
  TSC_Init();
  touch_done = 0;

  GL_Clear(White);
  GL_Cross(4*(LCD_Height / 5), 4*(LCD_Width / 5)); /* Sud-West Corner */
  while ( touch_done == 0)
  {
    TSC_Read();
  }
  coordinate_X4a = TSC_Value_X;
  coordinate_Y4a = TSC_Value_Y;

  GL_Delay(90); /* This is to catch only one touch event */
  TSC_Init();
  touch_done = 0;

  GL_Clear(White);
  GL_Cross(4*(LCD_Height / 5), 1*(LCD_Width / 5)); /* Sud-East Corner point */
  while ( touch_done == 0)
  {
    TSC_Read();
  }
  coordinate_X5a = TSC_Value_X;
  coordinate_Y5a = TSC_Value_Y;

  GL_Delay(90); /* This is to catch only one touch event */
  TSC_Init();
  touch_done = 0;

  GL_Clear(White);
  GL_Cross( (LCD_Height / 2), (LCD_Width / 2) ); /* Absolute Central Point */
  while ( touch_done == 0)
  {
    TSC_Read();
  }
  coordinate_X1b = TSC_Value_X;
  coordinate_Y1b = TSC_Value_Y;

  GL_Delay(90); /* This is to catch only one touch event */
  TSC_Init();
  touch_done = 0;

  GL_Clear(White);
  GL_Cross(1*(LCD_Height / 5), 1*(LCD_Width / 5)); /* Nord-East Corner point */
  while ( touch_done == 0)
  {
    TSC_Read();
  }
  coordinate_X2b = TSC_Value_X;
  coordinate_Y2b = TSC_Value_Y;

  GL_Delay(90); /* This is to catch only one touch event */
  TSC_Init();
  touch_done = 0;

  GL_Clear(White);
  GL_Cross(1*(LCD_Height / 5), 4*(LCD_Width / 5)); /* Nord-West Corner */
  while ( touch_done == 0)
  {
    TSC_Read();
  }
  coordinate_X3b = TSC_Value_X;
  coordinate_Y3b = TSC_Value_Y;

  GL_Delay(90); /* This is to catch only one touch event */
  TSC_Init();
  touch_done = 0;

  GL_Clear(White);
  GL_Cross(4*(LCD_Height / 5), 4*(LCD_Width / 5)); /* Sud-West Corner */
  while ( touch_done == 0)
  {
    TSC_Read();
  }
  coordinate_X4b = TSC_Value_X;
  coordinate_Y4b = TSC_Value_Y;

  GL_Delay(90); /* This is to catch only one touch event */
  TSC_Init();
  touch_done = 0;

  GL_Clear(White);
  GL_Cross(4*(LCD_Height / 5), 1*(LCD_Width / 5)); /* Sud-East Corner point */
  while ( touch_done == 0)
  {
    TSC_Read();
  }
  coordinate_X5b = TSC_Value_X;
  coordinate_Y5b = TSC_Value_Y;

  GL_Delay(90); /* This is to catch only one touch event */
  TSC_Init();
  touch_done = 0;

  /* Average between X and Y coupled Touchscreen values */
  coordinate_X1 = (coordinate_X1a + coordinate_X1b) / 2;
  coordinate_X2 = (coordinate_X2a + coordinate_X2b) / 2;
  coordinate_X3 = (coordinate_X3a + coordinate_X3b) / 2;
  coordinate_X4 = (coordinate_X4a + coordinate_X4b) / 2;
  coordinate_X5 = (coordinate_X5a + coordinate_X5b) / 2;

  coordinate_Y1 = (coordinate_Y1a + coordinate_Y1b) / 2;
  coordinate_Y2 = (coordinate_Y2a + coordinate_Y2b) / 2;
  coordinate_Y3 = (coordinate_Y3a + coordinate_Y3b) / 2;
  coordinate_Y4 = (coordinate_Y4a + coordinate_Y4b) / 2;
  coordinate_Y5 = (coordinate_Y5a + coordinate_Y5b) / 2;

  X2_1 = (coordinate_X1 * coordinate_X1);
  X2_2 = (coordinate_X2 * coordinate_X2);
  X2_3 = (coordinate_X3 * coordinate_X3);
  X2_4 = (coordinate_X4 * coordinate_X4);
  X2_5 = (coordinate_X5 * coordinate_X5);

  Y2_1 = (coordinate_Y1 * coordinate_Y1);
  Y2_2 = (coordinate_Y2 * coordinate_Y2);
  Y2_3 = (coordinate_Y3 * coordinate_Y3);
  Y2_4 = (coordinate_Y4 * coordinate_Y4);
  Y2_5 = (coordinate_Y5 * coordinate_Y5);

  XxY_1 = (coordinate_X1 * coordinate_Y1);
  XxY_2 = (coordinate_X2 * coordinate_Y2);
  XxY_3 = (coordinate_X3 * coordinate_Y3);
  XxY_4 = (coordinate_X4 * coordinate_Y4);
  XxY_5 = (coordinate_X5 * coordinate_Y5);

  XxXd_1 = ( coordinate_X1 * Xd1 );
  XxXd_2 = ( coordinate_X2 * Xd2 );
  XxXd_3 = ( coordinate_X3 * Xd3 );
  XxXd_4 = ( coordinate_X4 * Xd4 );
  XxXd_5 = ( coordinate_X5 * Xd5 );

  YxXd_1 = ( coordinate_Y1 * Xd1 );
  YxXd_2 = ( coordinate_Y2 * Xd2 );
  YxXd_3 = ( coordinate_Y3 * Xd3 );
  YxXd_4 = ( coordinate_Y4 * Xd4 );
  YxXd_5 = ( coordinate_Y5 * Xd5 );

  XxYd_1 = ( coordinate_X1 * Yd1 );
  XxYd_2 = ( coordinate_X2 * Yd2 );
  XxYd_3 = ( coordinate_X3 * Yd3 );
  XxYd_4 = ( coordinate_X4 * Yd4 );
  XxYd_5 = ( coordinate_X5 * Yd5 );

  YxYd_1 = ( coordinate_Y1 * Yd1 );
  YxYd_2 = ( coordinate_Y2 * Yd2 );
  YxYd_3 = ( coordinate_Y3 * Yd3 );
  YxYd_4 = ( coordinate_Y4 * Yd4 );
  YxYd_5 = ( coordinate_Y5 * Yd5 );

  alfa = X2_1 + X2_2 + X2_3 + X2_4 + X2_5;
  beta = Y2_1 + Y2_2 + Y2_3 + Y2_4 + Y2_5;
  chi = XxY_1 + XxY_2 + XxY_3 + XxY_4 + XxY_5;
  epsilon = coordinate_X1 + coordinate_X2 + coordinate_X3 + coordinate_X4 + coordinate_X5;
  fi = coordinate_Y1 + coordinate_Y2 + coordinate_Y3 + coordinate_Y4 + coordinate_Y5;
  Kx = XxXd_1 + XxXd_2 + XxXd_3 + XxXd_4 + XxXd_5;
  Ky = XxYd_1 + XxYd_2 + XxYd_3 + XxYd_4 + XxYd_5;
  Lx = YxXd_1 + YxXd_2 + YxXd_3 + YxXd_4 + YxXd_5;
  Ly = YxYd_1 + YxYd_2 + YxYd_3 + YxYd_4 + YxYd_5;
  Mx = Xd1 + Xd2 + Xd3 + Xd4 + Xd5;
  My = Yd1 + Yd2 + Yd3 + Yd4 + Yd5;

  d = 5 * ( ((double)alfa * beta) - ((double)chi * chi) ) + 2 * ((double)chi * epsilon * fi) - ((double)alfa * fi * fi ) - ( (double)beta * epsilon * epsilon );
  dx1 = 5 * ( ((double)Kx * beta) - ((double)Lx * chi) ) + ((double)fi * ( ((double)Lx * epsilon) - ((double)Kx * fi) )) + ((double)Mx * ( ((double)chi * fi) - ((double)beta * epsilon) ));
  dx2 = 5 * ( ((double)Lx * alfa) - ((double)Kx * chi) ) + ((double)epsilon * ( ((double)Kx * fi) - ((double)Lx * epsilon) )) + ((double)Mx * ( ((double)chi * epsilon) - ((double)alfa * fi) ));
  dx3 = ((double)Kx * ( ((double)chi * fi) - ((double)beta * epsilon) )) + ((double)Lx * ( ((double)chi * epsilon) - ((double)alfa * fi) )) + ((double)Mx * ( ((double)alfa * beta) - ((double)chi * chi) ));
  dy1 = 5 * ( ((double)Ky * beta) - ((double)Ly * chi) ) + ((double)fi * ( ((double)Ly * epsilon) - ((double)Ky * fi) )) + ((double)My * ( ((double)chi * fi) - ((double)beta * epsilon) ));
  dy2 = 5 * ( ((double)Ly * alfa) - ((double)Ky * chi) ) + ((double)epsilon * ( ((double)Ky * fi) - ((double)Ly * epsilon) )) + ((double)My * ( ((double)chi * epsilon) - ((double)alfa * fi) ));
  dy3 = ((double)Ky * ( ((double)chi * fi) - ((double)beta * epsilon) )) + ((double)Ly * ( ((double)chi * epsilon) - ((double)alfa * fi) )) + ((double)My * ( ((double)alfa * beta) - ((double)chi * chi) ));

  A = dx1 / d;
  B = dx2 / d;
  C = dx3 / d;
  D = dy1 / d;
  E = dy2 / d;
  F = dy3 / d;

  /* To avoid computation with "double" variables A, B, C, D, E, F, we use the s32 variables
     A2, B2, C2, D2, E2, F2, multiplied for a Scale Factor equal to 100000 to retain the precision*/
  A2 = (s32)(A * RESCALE_FACTOR);
  B2 = (s32)(B * RESCALE_FACTOR);
  C2 = (s32)(C * RESCALE_FACTOR);
  D2 = (s32)(D * RESCALE_FACTOR);
  E2 = (s32)(E * RESCALE_FACTOR);
  F2 = (s32)(F * RESCALE_FACTOR);

  GL_Clear(White);
  GL_DisplayAdjStringLine(3 * (LCD_Height / 7), 10 * (LCD_Width / 11), "Calibration done!", GL_FALSE);

  GL_Delay(25); /* Now show HOME Menu */
  GL_Clear(White);
  calibration_done = 1;

  /********************* FLASH PROGRAMMING FOR SAVING "calibration_done" variable **********************/
  TSC_FlashStatus = TSC_FLASH_COMPLETE;
  TSC_MemoryProgramStatus = PASSED;
  FlashFree_Address = CalibrationAddr;

  /* Unlock the Flash Program Erase controller */
  TSC_FLASH_Unlock();

  /* Erase Flash sectors ******************************************************/
#if defined(USE_STM3210C_EVAL) || defined(USE_STM32100E_EVAL) || defined(USE_STM3220F_EVAL)
  /* Clear All pending flags */
  TSC_FLASH_ClearFlag( TSC_FLASH_FLAG_BSY | TSC_FLASH_FLAG_EOP | TSC_FLASH_FLAG_PGERR | TSC_FLASH_FLAG_WRPRTERR);

  /* Erase Last Flash Page */
  TSC_FlashStatus = TSC_FLASH_ErasePage( FlashFree_Address );

#endif

  /* Writing calibration parameters to the Flash Memory */
  TSC_FlashStatus = TSC_FLASH_ProgramWord( FlashFree_Address, calibration_done);
  /* Increasing Flash Memory Page Address */
  FlashFree_Address = FlashFree_Address + 4;
  /* Writing Calibration Parameter */
  TSC_FlashStatus = TSC_FLASH_ProgramWord( FlashFree_Address, A2);
  /* Increasing Flash Memory Page Address */
  FlashFree_Address = FlashFree_Address + 4;
  /* Writing Calibration Parameter */
  TSC_FlashStatus = TSC_FLASH_ProgramWord( FlashFree_Address, B2);
  /* Increasing Flash Memory Page Address */
  FlashFree_Address = FlashFree_Address + 4;
  /* Writing Calibration Parameter */
  TSC_FlashStatus = TSC_FLASH_ProgramWord( FlashFree_Address, C2);
  /* Increasing Flash Memory Page Address */
  FlashFree_Address = FlashFree_Address + 4;
  /* Writing Calibration Parameter */
  TSC_FlashStatus = TSC_FLASH_ProgramWord( FlashFree_Address, D2);
  /* Increasing Flash Memory Page Address */
  FlashFree_Address = FlashFree_Address + 4;
  /* Writing Calibration Parameter */
  TSC_FlashStatus = TSC_FLASH_ProgramWord( FlashFree_Address, E2);
  /* Increasing Flash Memory Page Address */
  FlashFree_Address = FlashFree_Address + 4;
  /* Writing Calibration Parameter */
  TSC_FlashStatus = TSC_FLASH_ProgramWord( FlashFree_Address, F2);
  /* Increasing Flash Memory Page Address */
  FlashFree_Address = FlashFree_Address + 4;

  /* Reading Calibration Flag from the Flash Memory */
  calibration_done = (*(__IO uint32_t*) CalibrationAddr) & 0x000000FF;
}