Exemple #1
0
/**
  * @brief  User Process
  * @param  phost: Host Handle
  * @param  id: Host Library user message ID
  * @retval None
  */
static void USBH_UserProcess(USBH_HandleTypeDef *phost, uint8_t id)
{  
  switch(id)
  { 
  case HOST_USER_SELECT_CONFIGURATION:
    break;
    
  case HOST_USER_DISCONNECTION:
    Appli_state = APPLICATION_DISCONNECT;
    if(USBH_GetActiveClass(phost) == AC_CLASS)
    {
      Audio_ChangeSelectMode(AUDIO_SELECT_MENU); 
    }
    break;
    
  case HOST_USER_CONNECTION:
    break;
    
  case HOST_USER_CLASS_ACTIVE:
    switch(USBH_GetActiveClass(phost))
    {
    case USB_MSC_CLASS:
      Appli_state = APPLICATION_MSC;
      /* Link the USB disk I/O driver */
      FATFS_LinkDriver(&USBH_Driver, USBDISKPath);
      break;
      
    case AC_CLASS:
      Appli_state = APPLICATION_AUDIO;
      /* Init SD Storage */
      if (SD_StorageInit() == 0)
      {
        SD_StorageParse();
      }
      break;
      
    case USB_HID_CLASS:
      Appli_state = APPLICATION_HID;    
      break;      
    }
    break;
  }
}
Exemple #2
0
/**
  * @brief  EXTI line detection callbacks.
  * @param  GPIO_Pin: Specifies the pins connected EXTI line
  * @retval None
  */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  static JOYState_TypeDef JoyState = JOY_NONE;
  static uint32_t debounce_time = 0;
  
  if(GPIO_Pin == GPIO_PIN_8)
  {    
    /* Get the Joystick State */
    JoyState = BSP_JOY_GetState();
    HAL_Delay(200);
    
    /* Clear joystick interrupt pending bits */
    BSP_IO_ITClear();
    
    if(Appli_state == APPLICATION_MSC)
    {
      MSC_DEMO_ProbeKey(JoyState); 
    }
    else if(Appli_state == APPLICATION_HID)
    {
      HID_DEMO_ProbeKey(JoyState); 
    }
    else if(Appli_state == APPLICATION_AUDIO)
    {
      if(audio_select_mode == AUDIO_SELECT_MENU)
      {  
        AUDIO_MenuProbeKey(JoyState); 
      }
      else if(audio_select_mode == AUDIO_PLAYBACK_CONTROL)
      {
        AUDIO_PlaybackProbeKey(JoyState);
      }
    }
    switch(JoyState)
    {
    case JOY_LEFT:
      LCD_LOG_ScrollBack();
      break;
           
    case JOY_RIGHT:
      LCD_LOG_ScrollForward();
      break;          
      
    default:
      break;           
    }
  }
  
  if(audio_demo.state == AUDIO_DEMO_PLAYBACK)
  {
    if(GPIO_Pin == KEY_BUTTON_PIN)
    { 
      /* Prevent debounce effect for user key */
      if((HAL_GetTick() - debounce_time) > 50)
      {
        debounce_time = HAL_GetTick();
      }
      else
      {
        return;
      }
      
      /* Change the selection type */
      if(audio_select_mode == AUDIO_SELECT_MENU)
      {
        Audio_ChangeSelectMode(AUDIO_PLAYBACK_CONTROL); 
      }
      else if(audio_select_mode == AUDIO_PLAYBACK_CONTROL)
      {       
        Audio_ChangeSelectMode(AUDIO_SELECT_MENU);
      }
    }
  }
} 
/**
  * @brief  Manages Audio Menu Process.
  * @param  None
  * @retval None
  */
void AUDIO_MenuProcess(void)
{
  switch(audio_demo.state)
  {
  case AUDIO_DEMO_IDLE:
    BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    BSP_LCD_DisplayStringAtLine(16, (uint8_t *)"                                                 ");
    BSP_LCD_DisplayStringAtLine(17, (uint8_t *)"Use [Buttons Left/Right] to scroll up/down       ");
    BSP_LCD_DisplayStringAtLine(18, (uint8_t *)"Use [Joystick Up/Down] to scroll audio menu      ");
    BSP_LCD_SetTextColor(LCD_COLOR_WHITE); 
    AUDIO_MenuSelectItem(AUDIO_main_menu, 0); 
    audio_demo.state = AUDIO_DEMO_WAIT;
    audio_demo.select = 0;
    break;    
    
  case AUDIO_DEMO_WAIT:
    if(audio_demo.select != prev_select)
    {
      prev_select = audio_demo.select;
      AUDIO_MenuSelectItem(AUDIO_main_menu, audio_demo.select & 0x7F);
      
      /* Handle select item */
      if(audio_demo.select & 0x80)
      {
        audio_demo.select &= 0x7F;
        
        switch(audio_demo.select)
        {
        case 0:
          audio_demo.state = AUDIO_DEMO_EXPLORE;  
          break;
          
        case 1:
          /* Display HMI messages */
          BSP_LCD_SetTextColor(LCD_COLOR_GREEN);          
          BSP_LCD_DisplayStringAtLine(14, (uint8_t *)"                                             ");
          BSP_LCD_DisplayStringAtLine(15, (uint8_t *)"                                             ");
          BSP_LCD_DisplayStringAtLine(16, (uint8_t *)"Use [User Key] To Stop and return from player");
          BSP_LCD_SetTextColor(LCD_COLOR_WHITE); 

          /* Set PLAYBACK state and start playing 1st file */ 
          audio_state = AUDIO_STATE_IDLE;
          audio_demo.state = AUDIO_DEMO_PLAYBACK;
          Audio_ChangeSelectMode(AUDIO_PLAYBACK_CONTROL);
          break;
          
        case 2:
          audio_demo.state = AUDIO_REENUMERATE;  
          break;
          
        default:
          break;
        }
      }
    }
    break;
    
  case AUDIO_DEMO_EXPLORE: 
    if(Appli_state == APPLICATION_AUDIO)
    {
      if(Audio_ShowWavFiles() > 0)
      {
        LCD_ErrLog("There is no WAV file on the microSD.\n");         
        Audio_ChangeSelectMode(AUDIO_SELECT_MENU);  
      }
      else
      {
        audio_demo.state = AUDIO_DEMO_WAIT;
      }
    }
    break; 
    
  case AUDIO_DEMO_PLAYBACK:
    if(Appli_state == APPLICATION_AUDIO)
    {
      if(audio_state == AUDIO_STATE_IDLE)
      {
        /* Start Playing...*/
        audio_state = AUDIO_STATE_INIT;
        if(AUDIO_Start(0) == AUDIO_ERROR_IO)
        {
          Audio_ChangeSelectMode(AUDIO_SELECT_MENU);  
        }
        else
        {
          BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); 
          BSP_LCD_DisplayStringAtLine(10, (uint8_t *)"[  UP   ] : Volume +");
          BSP_LCD_DisplayStringAtLine(11, (uint8_t *)"[ DOWN  ] : Volume -");
          BSP_LCD_DisplayStringAtLine(12, (uint8_t *)"[ LEFT  ] : Previous");
          BSP_LCD_DisplayStringAtLine(13, (uint8_t *)"[ RIGHT ] : Next");
          BSP_LCD_DisplayStringAtLine(14, (uint8_t *)"[  SEL  ] : Pause/Resume");
          BSP_LCD_SetTextColor(LCD_COLOR_WHITE);           
        }
      }
      else /* Not idle */
      {
        if(AUDIO_Process() == AUDIO_ERROR_IO)
        {
          Audio_ChangeSelectMode(AUDIO_SELECT_MENU);  
        }
      }
    }
    break;    
    
  case AUDIO_REENUMERATE:
    /* Force Audio Device to re-enumerate */   
    USBH_ReEnumerate(&hUSBHost);
    audio_demo.state = AUDIO_DEMO_WAIT;
    break;
    
  default:
    break;
  }  
}