Example #1
0
/**
* @brief  USBD_HID_GetPos
* @param  None
* @retval Pointer to report
*/
static uint8_t *USBD_HID_GetPos (void)
{
  int8_t  x = 0 , y = 0 ;
  static uint8_t HID_Buffer [4];
  
  switch (IOE_JoyStickGetState())
  {
  case JOY_LEFT:
    x -= CURSOR_STEP;
    break;  
    
  case JOY_RIGHT:
    x += CURSOR_STEP;
    break;
    
  case JOY_UP:
    y -= CURSOR_STEP;
    break;
    
  case JOY_DOWN:
    y += CURSOR_STEP;
    break;
  }
  
  HID_Buffer[0] = 0;
  HID_Buffer[1] = x;
  HID_Buffer[2] = y;
  HID_Buffer[3] = 0;
  
  return HID_Buffer;
}
Example #2
0
/**
  * @brief  This function handles External line 10 interrupt request.
  * @param  None
  * @retval None
  */
void EXTI2_IRQHandler(void)
{
#if 0
  static JOY_State_TypeDef JoyState = JOY_NONE;

  if(EXTI_GetITStatus(IOE_IT_EXTI_LINE) != RESET)
  {
    if(IOE_GetGITStatus(IOE_2_ADDR, IOE_GIT_GPIO))
    {
      /* Get the Joystick State */
      JoyState = IOE_JoyStickGetState();

      switch (JoyState)
      {
        case JOY_NONE:
        break;

        case JOY_UP:
        {
          PressedKey =  UP;
          break;
        }
        case JOY_DOWN:
        {
          PressedKey =  DOWN;
          break;
        }
        case JOY_RIGHT :
        {
          PressedKey =  JOY_NONE;
          break;
        }
        case JOY_LEFT:
        {
          PressedKey =  JOY_NONE;
          break;
        }
        case JOY_CENTER:
        {
          PressedKey =  SEL;
          break;
        }
        default:
        {
          PressedKey =  JOY_NONE;
          LCD_DisplayStringLine(LINE(17), (uint8_t*)"     JOY  ERROR     ");
          break;
        }
      }
    }
    /* Clear the interrupt pending bits */
    IOE_ClearGITPending(IOE_2_ADDR, IOE_GIT_GPIO);
    IOE_ClearIOITPending(IOE_2_ADDR, IOE_JOY_IT);
  }
  /* Clear interrupt pending bit */
  EXTI_ClearITPendingBit(IOE_IT_EXTI_LINE);
#endif
}
Example #3
0
/**
  * @brief  Reads key from demoboard.
  * @param  None
  * @retval Return JOY_RIGHT, JOY_LEFT, JOY_CENTER, JOY_UP, JOY_DOWN or JOY_NONE
  */
JOY_State_TypeDef ReadKey(void)
{
#ifndef USE_STM3210C_EVAL
  /* "right" key is pressed */
  if(!STM_EVAL_PBGetState(Button_RIGHT))
  {
    while(STM_EVAL_PBGetState(Button_RIGHT) == Bit_RESET);
    return JOY_RIGHT; 
  }
  /* "left" key is pressed */
  if(!STM_EVAL_PBGetState(Button_LEFT))
  {
    while(STM_EVAL_PBGetState(Button_LEFT) == Bit_RESET);
    return JOY_LEFT; 
  }
  /* "up" key is pressed */
  if(!STM_EVAL_PBGetState(Button_UP))
  {
    while(STM_EVAL_PBGetState(Button_UP) == Bit_RESET);
    return JOY_UP; 
  }
  /* "down" key is pressed */
  if(!STM_EVAL_PBGetState(Button_DOWN))
  {
    while(STM_EVAL_PBGetState(Button_DOWN) == Bit_RESET);
    return JOY_DOWN; 
  }
  /* "sel" key is pressed */
  if(!STM_EVAL_PBGetState(Button_SEL))
  {
    while(STM_EVAL_PBGetState(Button_SEL) == Bit_RESET);
    return JOY_CENTER; 
  }
  /* No key is pressed */
  else 
  {
    return JOY_NONE;
  }
#else
  return IOE_JoyStickGetState();
#endif  
}
Example #4
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /* Initialize LEDs and push-buttons mounted on STM3210X-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);
  
   /* Initialize the LCD */
#ifdef USE_STM3210C_EVAL
  STM3210C_LCD_Init();
#elif defined (USE_STM32100E_EVAL)
  STM32100E_LCD_Init();  
#endif /* USE_STM3210C_EVAL */
 
  /* Clear the LCD */ 
  LCD_Clear(White);
  
  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);    
 
  /* Display messages on the LCD */
  LCD_DisplayStringLine(Line0, MESSAGE1);
  LCD_DisplayStringLine(Line1, MESSAGE2);
  LCD_DisplayStringLine(Line2, MESSAGE3);
  
  /* Configure the IO Expander */
  if (IOE_Config() == IOE_OK)
  {
    /* Display "IO Expander OK" on the LCD */
    LCD_DisplayStringLine(Line4, "   IO Expander OK   ");
  }
  else
  { 
    LCD_DisplayStringLine(Line4, "IO Expander FAILED ");
    LCD_DisplayStringLine(Line5, " Please Reset the  ");
    LCD_DisplayStringLine(Line6, "   board and start ");
    LCD_DisplayStringLine(Line7, "    again          ");
    while(1);
  }

  /* Draw a rectangle with the specifies parameters and Blue Color */
  LCD_SetTextColor(Blue);
  LCD_DrawRect(180, 310, 40, 60);
  
  /* Draw a rectangle with the specifies parameters and Red Color */
  LCD_SetTextColor(Red);
  LCD_DrawRect(180, 230, 40, 60);
  
  /* Draw a rectangle with the specifies parameters and Yellow Color */
  LCD_SetTextColor(Yellow);
  LCD_DrawRect(180, 150, 40, 60);
  
  /* Draw a rectangle with the specifies parameters and Black Color */
  LCD_SetTextColor(Black);
  LCD_DrawRect(180, 70, 40, 60);
  

#ifdef IOE_INTERRUPT_MODE

 #ifdef  USE_STM32100E_EVAL
  /* Enable the Touch Screen interrupts */
  IOE_ITConfig(IOE_ITSRC_TSC);
  
 #else
  /* Enable the Touch Screen and Joystick interrupts */
  IOE_ITConfig(IOE_ITSRC_JOYSTICK | IOE_ITSRC_TSC);
 #endif /* USE_STM32100E_EVAL */
 
#endif /* IOE_INTERRUPT_MODE */
  
  /* Loop infinitely */
  while(1)
  {
#ifdef IOE_POLLING_MODE
 static TS_STATE* TS_State;
    
 #ifdef  USE_STM3210C_EVAL
 
    static JOY_State_TypeDef JoyState = JOY_NONE;
    
    /* Get the Joytick State */
    JoyState = IOE_JoyStickGetState();
    
    switch (JoyState)
    {
	/* None Joystick has been selected */
    case JOY_NONE:
      LCD_DisplayStringLine(Line5, "JOY:     ----       ");
      break; 
    case JOY_UP:
      LCD_DisplayStringLine(Line5, "JOY:     UP         ");
      break;     
    case JOY_DOWN:
      LCD_DisplayStringLine(Line5, "JOY:    DOWN        ");
      break;          
    case JOY_LEFT:
      LCD_DisplayStringLine(Line5, "JOY:    LEFT        ");
      break;         
    case JOY_RIGHT:
      LCD_DisplayStringLine(Line5, "JOY:    RIGHT       ");
      break;                 
    case JOY_CENTER:
      LCD_DisplayStringLine(Line5, "JOY:    CENTER      ");
      break; 
    default:
      LCD_DisplayStringLine(Line5, "JOY:    ERROR       ");
      break;         
    }
 #endif /* USE_STM3210C_EVAL */
    
   
    /* Update the structure with the current position of the Touch screen */
    TS_State = IOE_TS_GetState();  
    
    if ((TS_State->TouchDetected) && (TS_State->Y < 220) && (TS_State->Y > 180))
    {
      if ((TS_State->X > 10) && (TS_State->X < 70))
      { 
      /* Display LD4 on the LCD and turn on LED4 */
        LCD_DisplayStringLine(Line6, " LD4                ");
        STM_EVAL_LEDOn(LED4);
      }
      else if ((TS_State->X > 90) && (TS_State->X < 150))
      {
      /* Display LD3 on the LCD and turn on LED3 */
        LCD_DisplayStringLine(Line6, "      LD3           ");
        STM_EVAL_LEDOn(LED3);
      }
      else if ((TS_State->X > 170) && (TS_State->X < 230))
      {
      /* Display LD2 on the LCD and turn on LED2 */
        LCD_DisplayStringLine(Line6, "           LD2      ");
        STM_EVAL_LEDOn(LED2);
      } 
      else if ((TS_State->X > 250) && (TS_State->X < 310))
      {
      /* Display LD1 on the LCD and turn on LED1 */
        LCD_DisplayStringLine(Line6, "                LD1 ");
        STM_EVAL_LEDOn(LED1);
      }
      
    }
    else
    {
    /* Turn off LED1..4 */
      STM_EVAL_LEDOff(LED1);
      STM_EVAL_LEDOff(LED2);
      STM_EVAL_LEDOff(LED3);
      STM_EVAL_LEDOff(LED4);
    }

#endif /* IOE_POLLING_MODE */  
  }
}
Example #5
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */
  
  /* USART configuration -----------------------------------------------------*/
  USART_Config();
  
  /* SysTick configuration ---------------------------------------------------*/
  SysTickConfig();
  
  /* LEDs configuration ------------------------------------------------------*/
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* IO Expanderconfiguration ------------------------------------------------*/
#ifdef USART_TRANSMITTER_MODE  
  TimeOut = USER_TIMEOUT;
  while ((IOE_Config() != IOE_OK) && (TimeOut != 0))
  {
  }
  if(TimeOut == 0)
  {
    TimeOut_UserCallback();
  }
#endif /* USART_TRANSMITTER_MODE */
 
  while (1)
  {
/******************************************************************************/
/*                      USART in Transmitter Mode                             */           
/******************************************************************************/
#ifdef USART_TRANSMITTER_MODE  
    
    /* Clear Buffers */
    Fill_Buffer(CmdBuffer, 2);
    
    DMA_DeInit(USARTx_TX_DMA_STREAM);
    DMA_InitStructure.DMA_Channel = USARTx_TX_DMA_CHANNEL;
    DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;  
    
    /****************** USART will Transmit Specific Command ******************/ 
    /* Prepare the DMA to transfer the transaction command (2bytes) from the
       memory to the USART */  
    DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)CmdBuffer;
    DMA_InitStructure.DMA_BufferSize = (uint16_t)2;
    DMA_Init(USARTx_TX_DMA_STREAM, &DMA_InitStructure); 
   
    /* Prepare Command to be transmitted */
    /* Waiting joystick pressed */  
    PressedButton = JOY_NONE;  
    while (PressedButton == JOY_NONE)
    {
      PressedButton = IOE_JoyStickGetState();
    }
    
    /* Waiting joystick released */  
    ReleasedButton = IOE_JoyStickGetState();  
    while ((PressedButton == ReleasedButton) && (ReleasedButton != JOY_NONE))
    {
      ReleasedButton = IOE_JoyStickGetState();    
    }

    
    if(PressedButton != JOY_NONE)
    {
      /* For each joystick state correspond a command to be sent through USART */      
      switch (PressedButton)
      {
        /* JOY_RIGHT button pressed */
        case JOY_RIGHT:
          CmdBuffer[0] = CMD_RIGHT;
          CmdBuffer[1] = CMD_RIGHT_SIZE;
          break;
        /* JOY_LEFT button pressed */
        case JOY_LEFT:
          CmdBuffer[0] = CMD_LEFT;
          CmdBuffer[1]  = CMD_LEFT_SIZE;
          break;
        /* JOY_UP button pressed */
        case JOY_UP:
          CmdBuffer[0] = CMD_UP;
          CmdBuffer[1] = CMD_UP_SIZE;
          break;
        /* JOY_DOWN button pressed */          
        case JOY_DOWN:
          CmdBuffer[0] = CMD_DOWN;
          CmdBuffer[1] = CMD_DOWN_SIZE;
          break;
        /* JOY_SEL button pressed */
        case JOY_SEL:
          CmdBuffer[0] = CMD_SEL;
          CmdBuffer[1] = CMD_SEL_SIZE;
          break;
        default:
          break;
      }
      
      /* Enable the USART DMA requests */
      USART_DMACmd(USARTx, USART_DMAReq_Tx, ENABLE);
      
      /* Clear the TC bit in the SR register by writing 0 to it */
      USART_ClearFlag(USARTx, USART_FLAG_TC);

      /* Enable the DMA TX Stream, USART will start sending the command code (2bytes) */
      DMA_Cmd(USARTx_TX_DMA_STREAM, ENABLE);
      
      /* Wait the USART DMA Tx transfer complete or time out */
      TimeOut = USER_TIMEOUT; 
      while ((DMA_GetFlagStatus(USARTx_TX_DMA_STREAM, USARTx_TX_DMA_FLAG_TCIF) == RESET)&&(TimeOut != 0))
      {
      }
      
      if(TimeOut == 0)
      {
        TimeOut_UserCallback();
      } 
      
      /* The software must wait until TC=1. The TC flag remains cleared during all data
         transfers and it is set by hardware at the last frame’s end of transmission*/
      TimeOut = USER_TIMEOUT;
      while ((USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET)&&(TimeOut != 0))
      {
      }
      if(TimeOut == 0)
      {
        TimeOut_UserCallback();
      }      
      
      /* Clear DMA Streams flags */
      DMA_ClearFlag(USARTx_TX_DMA_STREAM, USARTx_TX_DMA_FLAG_HTIF | USARTx_TX_DMA_FLAG_TCIF);                                    
                                          
      /* Disable the DMA Streams */
      DMA_Cmd(USARTx_TX_DMA_STREAM, DISABLE);
      
      /* Disable the USART Tx DMA request */
      USART_DMACmd(USARTx, USART_DMAReq_Tx, DISABLE);
      
      /******************* USART will Transmit Data Buffer ********************/
      /* Prepare the DMA to transfer the transaction data (length defined by 
         CmdBuffer[1] variable) from the memory to the USART */   
      DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)TxBuffer;
      DMA_InitStructure.DMA_BufferSize = (uint16_t)CmdBuffer[1];
      DMA_Init(USARTx_TX_DMA_STREAM, &DMA_InitStructure); 
      
      /* Enable the USART Tx DMA request */                
      USART_DMACmd(USARTx, USART_DMAReq_Tx, ENABLE);
      
      /* Clear the TC bit in the SR register by writing 0 to it */
      USART_ClearFlag(USARTx, USART_FLAG_TC);
      
      /* Enable DMA USART Tx Stream */
      DMA_Cmd(USARTx_TX_DMA_STREAM, ENABLE);
      
      /* Wait the USART DMA Tx transfer complete or time out */
      TimeOut = USER_TIMEOUT;
      while ((DMA_GetFlagStatus(USARTx_TX_DMA_STREAM, USARTx_TX_DMA_FLAG_TCIF) == RESET)&&(TimeOut != 0))
      {
      }
      if(TimeOut == 0)
      {
        TimeOut_UserCallback();
      }
      
      /* The software must wait until TC=1, The TC flag remains cleared during all data
         transfers and it is set by hardware at the last frame’s end of transmission */
      TimeOut = USER_TIMEOUT;
      while ((USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET)&&(TimeOut != 0))
      {
      }
      if(TimeOut == 0)
      {
        TimeOut_UserCallback();
      }
       
      /* Clear all DMA Streams flags */
      DMA_ClearFlag(USARTx_TX_DMA_STREAM, USARTx_TX_DMA_FLAG_HTIF | USARTx_TX_DMA_FLAG_TCIF);
                                          
      /* Disable the DMA Stream */
      DMA_Cmd(USARTx_TX_DMA_STREAM, DISABLE);
      
      /* Disable the USART Tx DMA request */
      USART_DMACmd(USARTx, USART_DMAReq_Tx, DISABLE);
    }
  
#endif /* USART_TRANSMITTER_MODE */

/******************************************************************************/
/*                      USART in Receiver Mode                                */           
/******************************************************************************/
#ifdef USART_RECEIVER_MODE
    /* Clear Buffers */
    Fill_Buffer(RxBuffer, TXBUFFERSIZE);
    Fill_Buffer(CmdBuffer, 2);
    
    DMA_DeInit(USARTx_RX_DMA_STREAM);
    DMA_InitStructure.DMA_Channel = USARTx_RX_DMA_CHANNEL;
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; 
    /****************** USART will Receive Specific Command *******************/
    /* Configure the DMA to receive 2 bytes (transaction command), in case of USART receiver */  
    DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)CmdBuffer;
    DMA_InitStructure.DMA_BufferSize = (uint16_t)2;
    DMA_Init(USARTx_RX_DMA_STREAM, &DMA_InitStructure);
    
    /* Enable the USART Rx DMA request */
    USART_DMACmd(USARTx, USART_DMAReq_Rx, ENABLE);   
    /* Enable the DMA RX Stream */
    DMA_Cmd(USARTx_RX_DMA_STREAM, ENABLE);
    
    /* Wait the USART DMA Rx transfer complete (to receive the transaction command) */
    while (DMA_GetFlagStatus(USARTx_RX_DMA_STREAM, USARTx_RX_DMA_FLAG_TCIF) == RESET)
    {      
    }
      
    /* Clear all DMA Streams flags */
    DMA_ClearFlag(USARTx_RX_DMA_STREAM, USARTx_RX_DMA_FLAG_HTIF | USARTx_RX_DMA_FLAG_TCIF); 
                                        
    /* Disable the DMA Rx Stream */
    DMA_Cmd(USARTx_RX_DMA_STREAM, DISABLE);
      
    /* Disable the USART Rx DMA requests */
    USART_DMACmd(USARTx, USART_DMAReq_Rx, DISABLE);
   
    /************* USART will receive the the transaction data ****************/
    /* Transaction data (length defined by CmdBuffer[1] variable) */       
    DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)RxBuffer;
    DMA_InitStructure.DMA_BufferSize = (uint16_t)CmdBuffer[1];
    DMA_Init(USARTx_RX_DMA_STREAM, &DMA_InitStructure);

    /* Enable the USART Rx DMA requests */
    USART_DMACmd(USARTx, USART_DMAReq_Rx , ENABLE);
      
    /* Enable the DMA Stream */
    DMA_Cmd(USARTx_RX_DMA_STREAM, ENABLE);
      
    /* Wait the USART DMA Rx transfer complete or time out */
    TimeOut = USER_TIMEOUT;     
    while ((DMA_GetFlagStatus(USARTx_RX_DMA_STREAM, USARTx_RX_DMA_FLAG_TCIF) == RESET)&&(TimeOut != 0))
    {
    }      
    if(TimeOut == 0)
    {
      TimeOut_UserCallback();
    }
      
    /* Clear all DMA Streams flags */
    DMA_ClearFlag(USARTx_RX_DMA_STREAM, USARTx_RX_DMA_FLAG_HTIF | USARTx_RX_DMA_FLAG_TCIF);
      
    /* Disable the DMA Stream */
    DMA_Cmd(USARTx_RX_DMA_STREAM, DISABLE);
      
    /* Disable the USART Rx DMA requests */
    USART_DMACmd(USARTx, USART_DMAReq_Rx, DISABLE);
      
    switch (CmdBuffer[1])
    {
      /* CMD_RIGHT command received */
      case CMD_RIGHT_SIZE:
        if (Buffercmp(TxBuffer, RxBuffer, CMD_RIGHT_SIZE) != FAILED)
        {
          /* Turn ON LED2 and LED3 */
          STM_EVAL_LEDOn(LED2);
          STM_EVAL_LEDOn(LED3);
          /* Turn OFF LED4 */
          STM_EVAL_LEDOff(LED4);
        }
        break;
      /* CMD_LEFT command received */
      case CMD_LEFT_SIZE:
        if (Buffercmp(TxBuffer, RxBuffer, CMD_LEFT_SIZE) != FAILED)
        {
          /* Turn ON LED4 */
          STM_EVAL_LEDOn(LED4);
          /* Turn OFF LED2 and LED3 */
          STM_EVAL_LEDOff(LED2);
          STM_EVAL_LEDOff(LED3);
        }
        break;
      /* CMD_UP command received */
      case CMD_UP_SIZE:
        if (Buffercmp(TxBuffer, RxBuffer, CMD_UP_SIZE) != FAILED)
        {
          /* Turn ON LED2 */
          STM_EVAL_LEDOn(LED2);
          /* Turn OFF LED3 and LED4 */
          STM_EVAL_LEDOff(LED3);
          STM_EVAL_LEDOff(LED4);
        }
        break;
      /* CMD_DOWN command received */
      case CMD_DOWN_SIZE:
        if (Buffercmp(TxBuffer, RxBuffer, CMD_DOWN_SIZE) != FAILED)
        {
          /* Turn ON LED3 */
          STM_EVAL_LEDOn(LED3);
          /* Turn OFF LED2 and LED4 */
          STM_EVAL_LEDOff(LED2);
          STM_EVAL_LEDOff(LED4);
        }
        break;
      /* CMD_SEL command received */
      case CMD_SEL_SIZE:
        if (Buffercmp(TxBuffer, RxBuffer, CMD_SEL_SIZE) != FAILED) 
        {
          /* Turn ON all LED2, LED3 and LED4 */
          STM_EVAL_LEDOn(LED2);
          STM_EVAL_LEDOn(LED3);
          STM_EVAL_LEDOn(LED4);
        }
        break;
      default:
        break;
    }
#endif /* USART_RECEIVER_MODE */      
  }
}
Example #6
0
void CSTMInput::ReadKey(InputKey inKey)
{
  static uint8_t delay = INPUT_MAX_VALUE_DELAY;
  
#if (defined(USE_STM3210C_EVAL) || defined(USE_STM322xG_EVAL) || defined(USE_STM324xG_EVAL))  
  uint8_t Button = JOY_SEL;
#else
  Button_TypeDef Button = BUTTON_SEL;
#endif
  
  static uint8_t bKeyPress = NO_BUTTON_PRESSED;

  switch (inKey)
  {
    case KEY_JOYSTICK_UP:
      
#if (defined(USE_STM3210C_EVAL) || defined(USE_STM322xG_EVAL) || defined(USE_STM324xG_EVAL))
      Button = JOY_UP;
#else
      Button = BUTTON_UP;      
#endif
      
      break;
    case KEY_JOYSTICK_DOWN:
      
#if (defined(USE_STM3210C_EVAL) || defined(USE_STM322xG_EVAL) || defined(USE_STM324xG_EVAL))
      Button = JOY_DOWN;
#else
      Button = BUTTON_DOWN;      
#endif
      
      break;
    case KEY_JOYSTICK_LEFT:
      
#if (defined(USE_STM3210C_EVAL) || defined(USE_STM322xG_EVAL) || defined(USE_STM324xG_EVAL))
      Button = JOY_LEFT;
#else
      Button = BUTTON_LEFT;      
#endif
      
      break;
    case KEY_JOYSTICK_RIGHT:
            
#if (defined(USE_STM3210C_EVAL) || defined(USE_STM322xG_EVAL) || defined(USE_STM324xG_EVAL))
      Button = JOY_RIGHT;
#else
      Button = BUTTON_RIGHT;      
#endif
      
      break;
    case KEY_JOYSTICK_SEL:
            
#if (defined(USE_STM3210C_EVAL) || defined(USE_STM322xG_EVAL) || defined(USE_STM324xG_EVAL))
      Button = JOY_SEL;
#else
      Button = BUTTON_SEL;      
#endif
      break;
   }

#if (defined(USE_STM3210C_EVAL) || defined(USE_STM322xG_EVAL) || defined(USE_STM324xG_EVAL))
  JOYState_TypeDef joystate = IOE_JoyStickGetState();
  if (joystate == Button)
#else
  if (STM_EVAL_PBGetState(Button)== JOYSTIK_ACTIVE)    
#endif
  {
    if (bKeyPress == Button)
    {
      if (delay > 0)
      {
        delay--;
      }
      else      
      {
        if (m_pMainForm)
          m_pMainForm->KeyPressed(inKey);
      }
    }
    if (bKeyPress == NO_BUTTON_PRESSED)
    {
      bKeyPress = Button;
      if (m_pMainForm)
        m_pMainForm->KeyPress(inKey);
    }
  }

#if (defined(USE_STM3210C_EVAL) || defined(USE_STM322xG_EVAL) || defined(USE_STM324xG_EVAL))
  if (joystate == JOY_NONE)
#else
  if (STM_EVAL_PBGetState(Button)== JOYSTIK_INACTIVE)
#endif
  {
    if (bKeyPress == Button)
    {
      bKeyPress = NO_BUTTON_PRESSED;
      delay = INPUT_MAX_VALUE_DELAY;
      if (m_pMainForm)
        m_pMainForm->KeyReleased(inKey);
    }
  }
}
Example #7
0
/**
  * @brief  This function handles External lines 15 to 10 interrupt request.
  * @param  None
  * @retval None
  */
void EXTI15_10_IRQHandler(void)
{   
  /* Checks whether the IOE EXTI line is asserted or not */
  if(EXTI_GetITStatus(IOE_IT_EXTI_LINE) != RESET)
  {
    
#ifdef IOE_INTERRUPT_MODE       
    /* Check if the interrupt source is the Touch Screen */
    if (IOE_GetGITStatus(IOE_1_ADDR, IOE_TS_IT) & IOE_TS_IT)
    {
      static TS_STATE* TS_State;
      
      /* Update the structure with the current position */
      TS_State = IOE_TS_GetState();  
      
      if ((TS_State->TouchDetected) && (TS_State->Y < 220) && (TS_State->Y > 180))
      {
        if ((TS_State->X > 10) && (TS_State->X < 70))
        {
          LCD_DisplayStringLine(Line6, " LD4                ");
          STM_EVAL_LEDOn(LED4);
        }
        else if ((TS_State->X > 90) && (TS_State->X < 150))
        {
          LCD_DisplayStringLine(Line6, "      LD3           ");
          STM_EVAL_LEDOn(LED3);
        }
        else if ((TS_State->X > 170) && (TS_State->X < 230))
        {
          LCD_DisplayStringLine(Line6, "           LD2      ");
          STM_EVAL_LEDOn(LED2);
        }     
        else if ((TS_State->X > 250) && (TS_State->X < 310))
        {
          LCD_DisplayStringLine(Line6, "                LD1 ");
          STM_EVAL_LEDOn(LED1);
        }
      }
      else
      {
        STM_EVAL_LEDOff(LED1);
        STM_EVAL_LEDOff(LED2);
        STM_EVAL_LEDOff(LED3);
        STM_EVAL_LEDOff(LED4);
      }    
      
      /* Clear the interrupt pending bits */    
      IOE_ClearGITPending(IOE_1_ADDR, IOE_TS_IT);      
    }
 #ifdef USE_STM3210C_EVAL 
    else if (IOE_GetGITStatus(IOE_2_ADDR, IOE_GIT_GPIO))
    {
      static JOY_State_TypeDef JoyState = JOY_NONE;
      
      /* Get the Joytick State */
      JoyState = IOE_JoyStickGetState();
      
      switch (JoyState)
      {
      case JOY_NONE:
        LCD_DisplayStringLine(Line5, "JOY: IT  ----       ");
        break;
      case JOY_UP:
        LCD_DisplayStringLine(Line5, "JOY: IT  UP         ");
        break;     
      case JOY_DOWN:
        LCD_DisplayStringLine(Line5, "JOY: IT DOWN        ");
        break;          
      case JOY_LEFT:
        LCD_DisplayStringLine(Line5, "JOY: IT LEFT        ");
        break;         
      case JOY_RIGHT:
        LCD_DisplayStringLine(Line5, "JOY: IT  RIGHT      ");
        break;                 
      case JOY_CENTER:
        LCD_DisplayStringLine(Line5, "JOY: IT CENTER      ");
        break; 
      default:
        LCD_DisplayStringLine(Line5, "JOY: IT ERROR       ");
        break;         
      }   
      
      /* Clear the interrupt pending bits */    
      IOE_ClearGITPending(IOE_2_ADDR, IOE_GIT_GPIO);
      IOE_ClearIOITPending(IOE_2_ADDR, IOE_JOY_IT);     
    }
    /* CLear all pending interrupt */
    IOE_ClearGITPending(IOE_2_ADDR, ALL_IT);
    IOE_ClearIOITPending(IOE_2_ADDR, IOE_JOY_IT);    
 #endif /* USE_STM3210C_EVAL */
    
    /* CLear all pending interrupt */
    IOE_ClearGITPending(IOE_1_ADDR, ALL_IT);
    
#endif /* IOE_INTERRUPT_MODE */
    
    EXTI_ClearITPendingBit(IOE_IT_EXTI_LINE);
  }  
}
Example #8
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f2xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f2xx.c file
     */

  /* I2C configuration ---------------------------------------------------------*/
  I2C_Config();

  /* Initialize LEDs mounted on STM322xG-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

#if defined (I2C_MASTER)
  /* Initialize push-buttons mounted on STM322xG-EVAL board */
  TimeOut = USER_TIMEOUT;
  while ((IOE_Config() != IOE_OK) && (TimeOut != 0x00))
  {}

  if(TimeOut == 0)
  {
    TimeOut_UserCallback();
  }
#endif /* I2C_MASTER */

  /* SysTick configuration -----------------------------------------------------*/
  SysTickConfig();

/*************************************Master Code******************************/
#if defined (I2C_MASTER)
  /* I2C De-initialize */
  I2C_DeInit(I2Cx);

  /*!< I2C Struct Initialize */
  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  I2C_InitStructure.I2C_DutyCycle = I2C_DUTYCYCLE;
  I2C_InitStructure.I2C_OwnAddress1 = 0xA0;
  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
  I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED;

#ifndef I2C_10BITS_ADDRESS
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
#else
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_10bit;
#endif /* I2C_10BITS_ADDRESS */

  /*!< I2C Initialize */
  I2C_Init(I2Cx, &I2C_InitStructure);

  /* Enable Error Interrupt */
  I2C_ITConfig(I2Cx, I2C_IT_ERR , ENABLE);

  /* I2C ENABLE */
  I2C_Cmd(I2Cx, ENABLE);

  while (1)
  {
    CmdTransmitted = 0x00;
    NumberOfByte = 0x00;
    Tx_Idx = 0x00;

    /* Clear PressedButton by reading joystick */
    PressedButton = IOE_JoyStickGetState();

    /* Waiting joystick pressed */
    while (PressedButton == JOY_NONE)
    {
      PressedButton = IOE_JoyStickGetState();
    }

    /* I2C in Master Transmitter Mode ----------------------------------------*/
    switch (PressedButton)
    {
      /* JOY_RIGHT button pressed */
      case JOY_RIGHT:
        NumberOfByte = CMD_RIGHT_SIZE;
        CmdTransmitted = CMD_RIGHT;
        break;
      /* JOY_LEFT button pressed */
      case JOY_LEFT:
        NumberOfByte = CMD_LEFT_SIZE;
        CmdTransmitted = CMD_LEFT;
        break;
      /* JOY_UP button pressed */
      case JOY_UP:
        NumberOfByte = CMD_UP_SIZE;
        CmdTransmitted = CMD_UP;
        break;
      /* JOY_DOWN button pressed */
      case JOY_DOWN:
        NumberOfByte = CMD_DOWN_SIZE;
        CmdTransmitted = CMD_DOWN;
        break;
      /* JOY_SEL button pressed */
      case JOY_SEL:
        NumberOfByte = CMD_SEL_SIZE;
        CmdTransmitted = CMD_SEL;
        break;
      default:
        break;
    }

    if (CmdTransmitted != 0x00)
    {
      /* Enable Error and Buffer Interrupts */
      I2C_ITConfig(I2Cx, (I2C_IT_EVT | I2C_IT_BUF), ENABLE);
      /* Generate the Start condition */
      I2C_GenerateSTART(I2Cx, ENABLE);
      /* Data transfer is performed in the I2C interrupt routine */
      /* Wait until end of data transfer or time out */
       TimeOut = USER_TIMEOUT;
       while ((Tx_Idx < GetVar_NbrOfDataToTransfer())&&(TimeOut != 0x00))
       {}
       if(TimeOut == 0)
       {
         TimeOut_UserCallback();
       }

       TimeOut = USER_TIMEOUT;
       while ((I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY))&&(TimeOut != 0x00))
       {}
       if(TimeOut == 0)
       {
         TimeOut_UserCallback();
       }
    }
  }
#endif /* I2C_MASTER */


  /**********************************Slave Code**********************************/
#if defined (I2C_SLAVE)

  I2C_DeInit(I2Cx);

  /* Initialize I2C peripheral */
  /*!< I2C Init */
  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  I2C_InitStructure.I2C_DutyCycle = I2C_DUTYCYCLE;
  I2C_InitStructure.I2C_OwnAddress1 = SLAVE_ADDRESS;
  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
  I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED;

#ifndef I2C_10BITS_ADDRESS
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
#else
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_10bit;
#endif /* I2C_10BITS_ADDRESS */

  I2C_Init(I2Cx, &I2C_InitStructure);

  /* Enable Error Interrupt */
  I2C_ITConfig(I2Cx, (I2C_IT_ERR | I2C_IT_EVT | I2C_IT_BUF), ENABLE);

  /* I2C ENABLE */
  I2C_Cmd(I2Cx, ENABLE);

  /* Infinite Loop */
  while (1)
  {
    CmdReceived = 0x00;
    NumberOfByte = 0x00;

    /* Clear the RxBuffer */
    Fill_Buffer(RxBuffer, RXBUFFERSIZE);

    while (CmdReceived == 0x00)
    {}

    /* Wait until end of data transfer */
    while (Rx_Idx < GetVar_NbrOfDataToReceive())
    {}

    /* I2C in Slave Receiver Mode --------------------------------------------*/
    if (CmdReceived != 0x00)
    {
      switch (Rx_Idx)
      {
        /* Right button pressed */
      case CMD_RIGHT_SIZE:
        if (Buffercmp(TxBuffer, RxBuffer, CMD_RIGHT_SIZE) == PASSED)
        {
          /* Turn ON LED2 and LED3 */
          STM_EVAL_LEDOn(LED2);
          STM_EVAL_LEDOn(LED3);
          /* Turn all other LEDs off */
          STM_EVAL_LEDOff(LED4);
        }
        break;
        /* Left button pressed*/
      case CMD_LEFT_SIZE:
        if (Buffercmp(TxBuffer, RxBuffer, CMD_LEFT_SIZE) == PASSED)
        {
          /* Turn ON LED4 */
          STM_EVAL_LEDOn(LED4);
          /* Turn all other LEDs off */
          STM_EVAL_LEDOff(LED2);
          STM_EVAL_LEDOff(LED3);
        }
        break;
        /* Up button pressed */
      case CMD_UP_SIZE:
        if (Buffercmp(TxBuffer, RxBuffer, CMD_UP_SIZE) == PASSED)
        {
          /* Turn ON LED2 */
          STM_EVAL_LEDOn(LED2);
          /* Turn all other LEDs off */
          STM_EVAL_LEDOff(LED3);
          STM_EVAL_LEDOff(LED4);
        }
        break;
        /* Down button pressed */
      case CMD_DOWN_SIZE:
        if (Buffercmp(TxBuffer, RxBuffer, CMD_DOWN_SIZE) == PASSED)
        {
          /* Turn ON LED3 */
          STM_EVAL_LEDOn(LED3);
          /* Turn all other LEDs off */
          STM_EVAL_LEDOff(LED2);
          STM_EVAL_LEDOff(LED4);
        }
        break;
        /* Sel button pressed */
      case CMD_SEL_SIZE:
        if (Buffercmp(TxBuffer, RxBuffer, CMD_SEL_SIZE) == PASSED)
        {
          /* Turn ON all LEDs */
          STM_EVAL_LEDOn(LED2);
          STM_EVAL_LEDOn(LED3);
          STM_EVAL_LEDOn(LED4);
        }
        break;
      default:
        break;
      }
    }
  }
#endif /* I2C_SLAVE */
}
/**
  * @brief  This function handles External lines 15 to 10 interrupt request.
  * @param  None
  * @retval None
  */
void EXTI15_10_IRQHandler(void)
{  
 #ifdef USE_STM32100E_EVAL  
  if(EXTI_GetITStatus(RIGHT_BUTTON_EXTI_LINE) != RESET)
  {
    if (ReadKey == 1)
    {
      PressedKey =  RIGHT;     
    }
    else
    {
      if (GetMutex == 1)
      {
        ShowMutex = 0;
      }
      else
      {
        ReqOperation = SHOW_TEMPERATURE_OP ;
      }
    }
    
    /* Clear EXTI interrupts pending bits */
    EXTI_ClearITPendingBit(RIGHT_BUTTON_EXTI_LINE);
  }
  
  if(EXTI_GetITStatus(LEFT_BUTTON_EXTI_LINE) != RESET)
  {
    if (ReadKey == 1)
    {
      PressedKey =  LEFT;     
    }
    else
    {
      if (GetMutex == 1)
      {
        ShowMutex = 0;
      }
      else
      {
        ReqOperation = SHOW_TIME_OP;
      }
    }
    
    /* Clear EXTI interrupts pending bits */
    EXTI_ClearITPendingBit(LEFT_BUTTON_EXTI_LINE);
  }
  
  if(EXTI_GetITStatus(UP_BUTTON_EXTI_LINE) != RESET)
  {
    if (ReadKey == 1)
    {
      PressedKey =  UP;     
    }
    else
    {
      if (GetMutex == 0)
      {
        ReqOperation = GET_REPORT_OP;
      }
    }
    
    /* Clear EXTI interrupts pending bits */
    EXTI_ClearITPendingBit(UP_BUTTON_EXTI_LINE);
  }
  
  if(EXTI_GetITStatus(DOWN_BUTTON_EXTI_LINE) != RESET)
  {    
    if (ReadKey == 1)
    {
      PressedKey =  DOWN;     
    }
    else
    {
      if (GetMutex == 0)
      {
        ReqOperation = ERASE_EEPROM_OP;
      }
    }
    
    /* Clear EXTI interrupts pending bits */
    EXTI_ClearITPendingBit(DOWN_BUTTON_EXTI_LINE);
  }
 #endif /* USE_STM32100E_EVAL */ 
  
  if(EXTI_GetITStatus(IOE_IT_EXTI_LINE) != RESET)
  {     
 #ifdef  USE_STM3210C_EVAL     
    static JOY_State_TypeDef JoyState = JOY_NONE;
 #endif /* USE_STM3210C_EVAL */
    static TS_STATE* TS_State;
    
    /* Check if the interrupt source is the Touch Screen */
    if (IOE_GetGITStatus(IOE_1_ADDR, IOE_TS_IT) & IOE_TS_IT)
    { 
      /* Update the structure with the current position */
      TS_State = IOE_TS_GetState();  
      
      if ((TS_State->TouchDetected) && (TS_State->Y < 230) && (TS_State->Y > 200))
      {
        if ((TS_State->X > 10) && (TS_State->X < 70))
        {
          LCD_DisplayStringLine(Line7, (uint8_t*)" TS1                ");
        }
        else if ((TS_State->X > 90) && (TS_State->X < 150))
        {
          LCD_DisplayStringLine(Line7, (uint8_t*)"      TS2           ");
        }
        else if ((TS_State->X > 170) && (TS_State->X < 230))
        {
          LCD_DisplayStringLine(Line7, (uint8_t*)"           TS3      ");
        }     
        else if ((TS_State->X > 250) && (TS_State->X < 310))
        {
          LCD_DisplayStringLine(Line7, (uint8_t*)"                TS4 ");
        }          
      }
      else
      {
        STM_EVAL_LEDOff(LED1);
        STM_EVAL_LEDOff(LED2);
        STM_EVAL_LEDOff(LED3);
        STM_EVAL_LEDOff(LED4);
      }    
      
      /* Clear the interrupt pending bits */    
      IOE_ClearGITPending(IOE_1_ADDR, IOE_TS_IT); 
    }
 #ifdef USE_STM3210C_EVAL     
    else if (IOE_GetGITStatus(IOE_2_ADDR, IOE_GIT_GPIO))
    {       
      /* Get the Joystick State */
      JoyState = IOE_JoyStickGetState();
      
      switch (JoyState)
      {
      case JOY_NONE:
        break;
        
      case JOY_UP:
        if (ReadKey == 1)
        {
          PressedKey =  UP;     
        }
        else
        {
          if (GetMutex == 0)
          {
            ReqOperation = GET_REPORT_OP;
          }     
        }
        break;     
        
      case JOY_DOWN:
        if (ReadKey == 1)
        {
          PressedKey =  DOWN;     
        }
        else
        {
          if (GetMutex == 0)
          {
            ReqOperation = ERASE_EEPROM_OP;
          }
        }
        break;       
        
      case JOY_RIGHT :
        if (ReadKey == 1)
        {
          PressedKey =  RIGHT;     
        }
        else
        {        
          if (GetMutex == 1)
          {
            ShowMutex = 0;
          }
          else
          {
            ReqOperation = SHOW_TEMPERATURE_OP ;
          }
        }
        break;     
        
      case JOY_LEFT:
        if (ReadKey == 1)
        {
          PressedKey =  LEFT;     
        }
        else
        {        
          if (GetMutex == 1)
          {
            ShowMutex = 0;
          }
          else
          {
            ReqOperation = SHOW_TIME_OP;
          }
        }
        break;       
        
      case JOY_CENTER:
        if (ReadKey == 1)
        {
          PressedKey =  SEL;     
        }
        else
        {
          if (GetMutex == 1)
          {
            NextRep = 1;
            ExitMutex = 1; 
          }
        }
        break; 
        
      default:
        LCD_DisplayStringLine(Line9, (uint8_t*)"     JOY  ERROR     ");
        break;           
      }
      
      /* Clear the interrupt pending bits */    
      IOE_ClearGITPending(IOE_2_ADDR, IOE_GIT_GPIO);
      IOE_ClearIOITPending(IOE_2_ADDR, IOE_JOY_IT);   
    }
 #endif /* USE_STM3210C_EVAL */       
    else
    {
      /* Clear the interrupt pending bits */       
 #ifdef  USE_STM3210C_EVAL 
      IOE_ClearGITPending(IOE_1_ADDR, ALL_IT);
      IOE_ClearGITPending(IOE_2_ADDR, ALL_IT);
 #else 
      IOE_ClearGITPending(IOE_1_ADDR, ALL_IT);
 #endif /* USE_STM3210C_EVAL */   
    }    
  }
  
  /* Clear EXTI interrupts pending bits */
  EXTI_ClearITPendingBit(IOE_IT_EXTI_LINE); 
}
Example #10
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured,
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f2xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f2xx.c file
     */

  /* USART configuration -----------------------------------------------------*/
  USART_Config();

  /* SysTick configuration ---------------------------------------------------*/
  SysTickConfig();

  /* Initialize LEDs mounted on STM322xG-EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* Configure the IO Expander mounted on STM322xG-EVAL board */
  TimeOut = USER_TIMEOUT;
  while ((IOE_Config() != IOE_OK) && (TimeOut != 0x00))
  {}

  if(TimeOut == 0)
  {
    TimeOut_UserCallback();
  }

  /* Enable the USARTx Receive interrupt: this interrupt is generated when the
  USARTx receive data register is not empty */
  USART_ITConfig(USARTx, USART_IT_RXNE, ENABLE);

  while (1)
  {
    TxIndex = 0x00;
    RxIndex = 0x00;
    UsartTransactionType = USART_TRANSACTIONTYPE_CMD;
    UsartMode = USART_MODE_RECEIVER;

    Fill_Buffer(CmdBuffer, 0x02);
    Fill_Buffer(AckBuffer, 0x02);

    /* Clear the RxBuffer */
    Fill_Buffer(RxBuffer, TXBUFFERSIZE);

    PressedButton = IOE_JoyStickGetState();

    /* Waiting Joystick is pressed or transaction command is received */
    while ((PressedButton == JOY_NONE) && (CmdBuffer[0x00] == 0x00))
    {
      PressedButton = IOE_JoyStickGetState();
    }

    /*
      If the Joystick is pressed go to transmitter mode, otherwise (the transaction
      command is received) go to receiver mode
    */

/******************************************************************************/
/*                      USART in Mode Transmitter                             */
/******************************************************************************/
    if ((PressedButton != JOY_NONE) && (CmdBuffer[0x00] == 0x00))
    {
      UsartMode = USART_MODE_TRANSMITTER;
      switch (PressedButton)
      {
        /* JOY_RIGHT button pressed */
        case JOY_RIGHT:
          CmdBuffer[0x00] = CMD_RIGHT;
          CmdBuffer[0x01] = CMD_RIGHT_SIZE;
          break;
        /* JOY_LEFT button pressed */
        case JOY_LEFT:
          CmdBuffer[0x00] = CMD_LEFT;
          CmdBuffer[0x01]  = CMD_LEFT_SIZE;
          break;
        /* JOY_UP button pressed */
        case JOY_UP:
          CmdBuffer[0x00] = CMD_UP;
          CmdBuffer[0x01] = CMD_UP_SIZE;
          break;
        /* JOY_DOWN button pressed */
        case JOY_DOWN:
          CmdBuffer[0x00] = CMD_DOWN;
          CmdBuffer[0x01] = CMD_DOWN_SIZE;
          break;
        /* JOY_SEL button pressed */
        case JOY_SEL:
          CmdBuffer[0x00] = CMD_SEL;
          CmdBuffer[0x01] = CMD_SEL_SIZE;
          break;
        default:
          break;
      }

      if (CmdBuffer[0x00]!= 0x00)
      {
        /* Enable the USARTx transmit data register empty interrupt */
        USART_ITConfig(USARTx, USART_IT_TXE, ENABLE);

        /* Wait until USART sends the command or time out */
        TimeOut = USER_TIMEOUT;
        while ((TxIndex < 0x02)&&(TimeOut != 0x00))
        {}
        if(TimeOut == 0)
        {
          TimeOut_UserCallback();
        }

        /* The software must wait until TC=1. The TC flag remains cleared during all data
           transfers and it is set by hardware at the last frame’s end of transmission*/
        TimeOut = USER_TIMEOUT;
        while ((USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET)&&(TimeOut != 0x00))
        {
        }
        if(TimeOut == 0)
        {
          TimeOut_UserCallback();
        }

        /* Wait until USART receives the Ack command  or time out*/
        TimeOut = USER_TIMEOUT;
        while ((RxIndex < 0x02)&&(TimeOut != 0x00))
        {}
        if(TimeOut == 0)
        {
          TimeOut_UserCallback();
        }
        /* USART sends the data */
        UsartTransactionType = USART_TRANSACTIONTYPE_DATA;
        TxIndex = 0x00;
        RxIndex = 0x00;

        /* Enable the USARTx transmit data register empty interrupt */
        USART_ITConfig(USARTx, USART_IT_TXE, ENABLE);

        /* Wait until end of data transfer */
        TimeOut = USER_TIMEOUT;
        while ((TxIndex < GetVar_NbrOfData())&&(TimeOut != 0x00))
        {}
        if(TimeOut == 0)
        {
          TimeOut_UserCallback();
        }

        /* The software must wait until TC=1. The TC flag remains cleared during all data
           transfers and it is set by hardware at the last frame’s end of transmission*/
        TimeOut = USER_TIMEOUT;
        while ((USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET)&&(TimeOut != 0x00))
        {
        }
        if(TimeOut == 0)
        {
          TimeOut_UserCallback();
        }
      }
      CmdBuffer[0x00] = 0x00;
    }

/******************************************************************************/
/*                      USART in Receiver Mode                                */
/******************************************************************************/
    if (CmdBuffer[0x00] != 0x00)
    {
      /* Wait until USART receives the command  or time out */
      TimeOut = USER_TIMEOUT;
      while ((RxIndex < 0x02)&&(TimeOut != 0x00))
      {}
      if(TimeOut == 0)
      {
        TimeOut_UserCallback();
      }
      UsartMode = USART_MODE_RECEIVER;

      /* Enable the USARTx transmit data register empty interrupt */
      USART_ITConfig(USARTx, USART_IT_TXE, ENABLE);

      /* Wait until USART sends the ACK command or time out*/
      TimeOut = USER_TIMEOUT;
      while ((TxIndex < 0x02)&&(TimeOut != 0x00))
      {}
      if(TimeOut == 0)
      {
        TimeOut_UserCallback();
      }

      /* The software must wait until TC=1. The TC flag remains cleared during all data
         transfers and it is set by hardware at the last frame’s end of transmission*/
      TimeOut = USER_TIMEOUT;
      while ((USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET)&&(TimeOut != 0x00))
      {
      }
      if(TimeOut == 0)
      {
        TimeOut_UserCallback();
      }

      /* USART receives the data */
      UsartTransactionType = USART_TRANSACTIONTYPE_DATA;
      TxIndex = 0x00;
      RxIndex = 0x00;

      /* Wait until end of data transfer or time out */
      TimeOut = USER_TIMEOUT;
      while ((RxIndex < GetVar_NbrOfData())&&(TimeOut != 0x00))
      {}
      if(TimeOut == 0)
      {
        TimeOut_UserCallback();
      }
      switch (CmdBuffer[0x01])
      {
        /* CMD_RIGHT command received */
        case CMD_RIGHT_SIZE:
          if (Buffercmp(TxBuffer, RxBuffer, CMD_RIGHT_SIZE) != FAILED)
          {
            /* Turn ON LED2 and LED3 */
            STM_EVAL_LEDOn(LED2);
            STM_EVAL_LEDOn(LED3);
            /* Turn OFF LED4 */
            STM_EVAL_LEDOff(LED4);
          }
          break;
        /* CMD_LEFT command received */
        case CMD_LEFT_SIZE:
          if (Buffercmp(TxBuffer, RxBuffer, CMD_LEFT_SIZE) != FAILED)
          {
            /* Turn ON LED4 */
            STM_EVAL_LEDOn(LED4);
            /* Turn OFF LED2 and LED3 */
            STM_EVAL_LEDOff(LED2);
            STM_EVAL_LEDOff(LED3);
          }
          break;
        /* CMD_UP command received */
        case CMD_UP_SIZE:
          if (Buffercmp(TxBuffer, RxBuffer, CMD_UP_SIZE) != FAILED)
          {
            /* Turn ON LED2 */
            STM_EVAL_LEDOn(LED2);
            /* Turn OFF LED3 and LED4 */
            STM_EVAL_LEDOff(LED3);
            STM_EVAL_LEDOff(LED4);
          }
          break;
        /* CMD_DOWN command received */
        case CMD_DOWN_SIZE:
          if (Buffercmp(TxBuffer, RxBuffer, CMD_DOWN_SIZE) != FAILED)
          {
            /* Turn ON LED3 */
            STM_EVAL_LEDOn(LED3);
            /* Turn OFF LED2 and LED4 */
            STM_EVAL_LEDOff(LED2);
            STM_EVAL_LEDOff(LED4);
          }
          break;
        /* CMD_SEL command received */
        case CMD_SEL_SIZE:
          if (Buffercmp(TxBuffer, RxBuffer, CMD_SEL_SIZE) != FAILED)
          {
            /* Turn ON all LED2, LED3 and LED4 */
            STM_EVAL_LEDOn(LED2);
            STM_EVAL_LEDOn(LED3);
            STM_EVAL_LEDOn(LED4);
          }
          break;
        default:
          break;
      }
      CmdBuffer[0x00] = 0x00;
    }
  }
}