Ejemplo n.º 1
0
Archivo: mtp.c Proyecto: z80/stm32f429
/**
  * @brief  Explores Wav Files. 
  * @param  None
  * @retval Returns 0 if OK, otherwise 1.
  */
uint8_t MTP_ExploreWavFile(void)
{
  uint8_t ret = 1;
  uint32_t index;
  MTP_ObjectInfoTypedef objectinfo;
  
  MTP_Init();
  
  if(USBH_MTP_IsReady(&hUSBHost) > 0)
  {
    LCD_UsrLog("\nAvailable wav files:\n");
 
    /* Get Available WAV files number */
    if((NumObs = MTP_GetWavObjectNumber()) > 0)
    {
      /* Get objects handlers */
      if(MTP_GetWavObjectHandles() == 0)
      {
        ret = 0; 
        
        for (index = 0; index < NumObs; index ++)
        {
          if( USBH_MTP_GetObjectInfo (&hUSBHost, 
                                      WavHandles.Handler[index], 
                                      &objectinfo) == USBH_OK)
            
          {
            LCD_DbgLog(" %lu- %s\n", index, objectinfo.Filename);
          }
          else
          {
            ret = 1; 
          }
        }
      }
    }
  }
  else
  {
    LCD_ErrLog("MTP Device Not yet ready...\n");
  }
  
  return ret;
}
Ejemplo n.º 2
0
/**
  * @brief  Manages MTP Menu Process.
  * @param  None
  * @retval None
  */
void MTP_MenuProcess(void)
{
  switch(mtp_demo.state)
  {
  case MTP_DEMO_IDLE:
    MTP_SelectItem(MTP_main_menu, 0); 
    mtp_demo.state = MTP_DEMO_WAIT;
    mtp_demo.select = 0;
    BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    BSP_LCD_DisplayStringAtLine(15, (uint8_t *)"Use [Joystick Left/Right] to scroll up/down");
    BSP_LCD_DisplayStringAtLine(16, (uint8_t *)"Use [Joystick Up/Down] to scroll MTP menu");
    break;    
    
  case MTP_DEMO_WAIT:
    
    if(mtp_demo.select != prev_select)
    {
      prev_select = mtp_demo.select;
      MTP_SelectItem(MTP_main_menu, mtp_demo.select & 0x7F);
      
      /* Handle select item */
      if(mtp_demo.select & 0x80)
      {
        
        switch(mtp_demo.select & 0x7F)
        {
        case 0:
          mtp_demo.state = MTP_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;
          mtp_demo.state = MTP_DEMO_PLAYBACK;
          MTP_ChangeSelectMode(MTP_PLAYBACK_CONTROL);           
          break;
        
        case 2:
          mtp_demo.state = MTP_REENUMERATE;  
          break;
        
        default:
          break;
        }
      }
    }
    break;
    
  case MTP_DEMO_EXPLORE:  
    if(Appli_state == APPLICATION_READY)
    {
      if(MTP_Init() == 0)
      {
        if(MTP_ExploreWavFile() > 0)
        {
          LCD_ErrLog("There is no WAV file on the microSD.\n" );         
          MTP_ChangeSelectMode(MTP_SELECT_MENU); 
          mtp_demo.state = MTP_DEMO_IDLE;
        }
        else
        {
          mtp_demo.state = MTP_DEMO_WAIT;
        }
      }
    }
    else
    {
      mtp_demo.state = MTP_DEMO_WAIT;
    }
    break; 
    
  case MTP_DEMO_PLAYBACK:
    if(Appli_state == APPLICATION_READY)
    {
      if(MTP_Init() == 0)
      {
        if(audio_state == AUDIO_STATE_IDLE)
        {
          /* Start Playing */
          audio_state = AUDIO_STATE_INIT;
          if(AUDIO_Start(0) == AUDIO_ERROR_IO)
          {
            MTP_ChangeSelectMode(MTP_SELECT_MENU); 
             mtp_demo.state = MTP_DEMO_IDLE;
          }
          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)
          {
            MTP_ChangeSelectMode(MTP_SELECT_MENU);  
            mtp_demo.state = MTP_DEMO_IDLE;
          }
        }
      }
    }
    else
    {
      mtp_demo.state = MTP_DEMO_WAIT;
    }
    break; 
    
  case MTP_REENUMERATE:
    /* Force MTP Device to re-enumerate */
    USBH_ReEnumerate(&hUSBHost); 
    mtp_demo.state = MTP_DEMO_WAIT;
    break;

  default:
    break;
  }

  if(Appli_state == APPLICATION_DISCONNECT)
  {
    Appli_state = APPLICATION_IDLE;     
    BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW);
    MTP_ChangeSelectMode(MTP_SELECT_MENU);     
  }
   
  mtp_demo.select &= 0x7F;
}