/**
  * @brief  CDC data transmit callback.
  * @param  phost: Host handle
  * @retval None
  */
void USBH_CDC_TransmitCallback(USBH_HandleTypeDef *phost)
{
   uint32_t bytesread;
  
  if(use_file == 1)
  {
    if( MyFile.fptr >= MyFile.fsize)
    {
      f_close(&MyFile);
      LCD_DbgLog (">> File sent\n" );
      use_file = 0;
    }
    else
    {
      /* Fill the buffer to Send */
      f_read(&MyFile, CDC_TX_Buffer, TX_BUFF_SIZE, (void *)&bytesread);
      /* Send File */
      USBH_CDC_Transmit(&hUSBHost, CDC_TX_Buffer, bytesread);
    }
  }
  else
  {
    LCD_DbgLog (">> Data sent\n" );
  }
}
Beispiel #2
0
/**
  * @brief  Shows audio file (*.wav) on the root
  * @param  None
  * @retval None
  */
uint8_t AUDIO_ShowWavFiles(void)
{
  uint8_t i = 0;
  uint8_t line_idx = 0;
  if(AUDIO_StorageInit() == FR_OK)
  {
    if(AUDIO_StorageParse() ==  FR_OK)
    {
      if(FileList.ptr > 0)
      {
        BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
        LCD_UsrLog("audio file(s) [ROOT]:\n\n");
        
        for(i = 0; i < FileList.ptr; i++)
        {
          line_idx++;
          LCD_DbgLog("   |__");
          LCD_DbgLog((char *)FileList.file[i].name);
          LCD_DbgLog("\n");
        }
        BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
        LCD_UsrLog("\nEnd of files list.\n");
        return 0;
      }
      return 1;
    }
    return 2;
  }
  else
  {
    return 3;
  }
}
/**
  * @brief  Files operations: Read/Write and compare
  * @param  None
  * @retval None
  */
void MSC_File_Operations(void)
{
  uint16_t bytesread;
  
  LCD_UsrLog("INFO : FatFs Initialized \n");
  
  if(f_open(&MyFile, "0:USBHost.txt",FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) 
  {
    LCD_ErrLog("Cannot Open 'USBHost.txt' file \n");
  }
  else
  {
    LCD_UsrLog("INFO : 'USBHost.txt' opened for write  \n");
    res= f_write (&MyFile, wtext, sizeof(wtext), (void *)&bytesWritten); 
    f_close(&MyFile);
    
    if((bytesWritten == 0) || (res != FR_OK)) /*EOF or Error*/
    {
      LCD_ErrLog("Cannot Write on the  'USBHost.txt' file \n");
    }
    else
    {
      if(f_open(&MyFile, "0:USBHost.txt", FA_READ) != FR_OK) 
      {
        LCD_ErrLog("Cannot Open 'USBHost.txt' file for read.\n"); 
      }
      else
      {
        LCD_UsrLog("INFO : Text written on the 'USBHost.txt' file \n");
        
        res = f_read(&MyFile, rtext, sizeof(rtext), (void *)&bytesread);
        
        if((bytesread == 0) || (res != FR_OK)) /*EOF or Error*/
        {
          LCD_ErrLog("Cannot Read from the  'USBHost.txt' file \n"); 
        }
        else
        {
          LCD_UsrLog("Read Text : \n"); 
          LCD_DbgLog((char *)rtext); 
          LCD_DbgLog("\n"); 
        }
        f_close(&MyFile);
      }
      /* Compare read data with the expected data */
      if((bytesread == bytesWritten))
      {
        LCD_UsrLog("INFO : FatFs data compare SUCCES");
        LCD_UsrLog("\n"); 
      }
      else
      {
        LCD_ErrLog("FatFs data compare ERROR");
        LCD_ErrLog("\n"); 
      }
    }
  }
}
Beispiel #4
0
/**
  * @brief  Initializes the SD Storage.
  * @param  None
  * @retval Status
  */
uint8_t SD_StorageInit(void)
{
  /*Initializes the SD card device*/
  BSP_SD_Init();
  
  /* Check if the SD card is plugged in the slot */
  if(BSP_SD_IsDetected() == SD_PRESENT )
  {
    /* Link the SD Card disk I/O driver */
    if(FATFS_LinkDriver(&SD_Driver, SD_Path) == 0)
    {
      if((f_mount(&SD_FatFs, (TCHAR const*)SD_Path, 0) != FR_OK))
      {
        /* FatFs Initialization Error */
        LCD_ErrLog("Cannot Initialize FatFs! \n");
        return 1;
      }
      else
      {
        LCD_DbgLog ("INFO : FatFs Initialized! \n");
      }
    }  
  }
  else
  {
    LCD_ErrLog("SD card NOT plugged \n");
    return 1;
  }
  return 0;
}
Beispiel #5
0
/**
  * @brief  Handles CDC Receive Menu. 
  * @param  None
  * @retval None
  */
void CDC_Handle_Receive_Menu(void)
{
  switch(CdcDemo.Receive_state)
  {
  case CDC_RECEIVE_IDLE:
    /* Start Reception */
    LCD_LOG_ClearTextZone();
    CdcDemo.Receive_state = CDC_RECEIVE_WAIT;
    USBH_CDC_Stop(&hUSBHost);
    LCD_DbgLog("Receiving data ...\n");
    
    xPos = 0;
    yLinePos = 5;
    
    memset(CDC_RX_Buffer, 0, RX_BUFF_SIZE); 
    USBH_CDC_Receive(&hUSBHost, CDC_RX_Buffer, RX_BUFF_SIZE);
    
    BSP_LCD_ClearStringLine(19);
    BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
    BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to start sending data ");
    break;
    
  case CDC_RECEIVE_WAIT:
    if((BSP_PB_GetState(BUTTON_KEY) == SET) && (Appli_state != APPLICATION_DISCONNECT))
    {
      CdcDemo.state =  CDC_DEMO_WAIT;
      CdcDemo.Receive_state = CDC_RECEIVE_IDLE;
    }
    break;
    
  default:
    break;
  }
}
/**
  * @brief  Shows audio file (*.wav) on the root
  * @param  None
  * @retval None
  */
uint8_t AUDIO_ShowWavFiles(void)
{
  uint8_t i = 0;
  uint8_t line_idx = 0;
  if(AUDIO_StorageInit() == FR_OK)
  {
    if(AUDIO_StorageParse() ==  FR_OK)
    {
      if(FileList.ptr > 0)
      {
        BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
        LCD_UsrLog("audio file(s) [ROOT]:\n\n");
        
        for(i = 0; i < FileList.ptr; i++)
        {
          line_idx++;
          if(line_idx > 9)
          {
            line_idx = 0;
            LCD_UsrLog("> Press [Key] To Continue.\n");
            
            /* KEY Button in polling */
            while(BSP_PB_GetState(BUTTON_KEY) != RESET)
            {
              /* Wait for User Input */
            }
          } 
          LCD_DbgLog("   |__");
          LCD_DbgLog((char *)FileList.file[i].name);
          LCD_DbgLog("\n");
        }
        BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
        LCD_UsrLog("\nEnd of files list.\n");
        return 0;
      }
      return 1;
    }
    return 2;
  }
  else
  {
    return 3;
  }
}
/**
  * @brief  Shows audio file (*.wav) on the root
  * @param  None
  * @retval None
  */
static uint8_t Audio_ShowWavFiles(void)
{
  uint8_t i;
  uint8_t line_idx = 0;

  if((FileList.ptr > 0) && (BSP_SD_IsDetected()))
  {
    BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
    LCD_UsrLog("audio file(s) [ROOT]:\n\n");

    for( i = 0; i < FileList.ptr; i++)
    {
      line_idx++;
      if(line_idx > 9)
      {
        line_idx = 0;
        LCD_UsrLog("> Press [Key] To Continue.\n");
        
        /* KEY Button in polling */
        while(BSP_PB_GetState(BUTTON_KEY) != RESET)
        {
          /* Wait for User Input */
        }
      } 
      LCD_DbgLog("   |__");
      LCD_DbgLog((char *)FileList.file[i].name);
      LCD_DbgLog("\n");
    }
    BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
    LCD_UsrLog("\nEnd of files list.\n");
    return 0;
  }
  else
  {
    return 1;
  }
}
Beispiel #8
0
/**
  * @brief  Initializes the USB KEY Storage.
  * @param  None
  * @retval Status
  */
uint8_t AUDIO_StorageInit(void)
{
  /* Link the USB Key disk I/O driver */
  if((f_mount(&USBH_FatFs, (TCHAR const*)USBKey_Path, 0) != FR_OK))
  {
    /* FatFs Initialization Error */
    LCD_ErrLog("Cannot Initialize FatFs! \n");
    return 1;
  }
  else
  {
    LCD_DbgLog ("INFO : FatFs Initialized! \n");
    return 0;
  }
}
Beispiel #9
0
/**
* @brief  USR_MOUSE_ProcessData
*         Process Mouse data
* @param  data : Mouse data to be displayed
* @retval None
*/
void USR_MOUSE_ProcessData(HID_MOUSE_Data_TypeDef *data)
{
  
  uint8_t idx = 1;   
  static uint8_t b_state[3] = { 0, 0 , 0};
  char temp[20];

  if(DEMO_HID_ShowData == 0)
  {  
  if ((data->x != 0) && (data->y != 0))
  {
    HID_MOUSE_UpdatePosition(data->x , data->y);
  }
  
  for ( idx = 0 ; idx < 3 ; idx ++)
  {
    
    if(data->button & 1 << idx) 
    {
      if(b_state[idx] == 0)
      {
        HID_MOUSE_ButtonPressed (idx);
        b_state[idx] = 1;
      }
    }
    else
    {
      if(b_state[idx] == 1)
      {
        HID_MOUSE_ButtonReleased (idx);
        b_state[idx] = 0;
      }
    }
  }
  }
  else
  {
    sprintf(temp ,"> %02xh %02xh %02xh %02xh\n" , HID_Machine.buff[0],  
                                         HID_Machine.buff[1],  
                                         HID_Machine.buff[2],  
                                         HID_Machine.buff[3]);
    LCD_DbgLog(temp);
    
  }
  
  
}
Beispiel #10
0
/**
  * @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;
}
Beispiel #11
0
/**
  * @brief  Handles CDC Send Menu. 
  * @param  None
  * @retval None
*/
void CDC_Handle_Send_Menu(void)
{
  switch(CdcDemo.Send_state)
  {
  case CDC_SEND_IDLE:
    CdcDemo.Send_state = CDC_SEND_WAIT;
    CDC_SendState = 0;
    USBH_CDC_Stop(&hUSBHost);
    memset(CDC_TX_Buffer, 0x5A, TX_BUFF_SIZE);
    LCD_LOG_ClearTextZone();
    LCD_DbgLog("Sending data ...\n"); 
    USBH_CDC_Transmit(&hUSBHost, CDC_TX_Buffer, TX_BUFF_SIZE);
    break;
  
  case CDC_SEND_WAIT:
    if(CDC_SendState == 1) /* Data sent */
    {
      BSP_LCD_ClearStringLine(19);
      BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
      BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to start receiving data ");
      
      /* Wait for User Input */
      while((BSP_PB_GetState(BUTTON_KEY) != SET) && (Appli_state != APPLICATION_DISCONNECT))
      {
      }
      HAL_Delay(400);
      
      CdcDemo.state = CDC_DEMO_RECEIVE;
      CdcDemo.Send_state = CDC_SEND_IDLE;
    }
    break;
    
  default:
    break;
  }
}
/**
  * @brief  Handles CDC Send Menu. 
  * @param  None
  * @retval None
  */
void CDC_Handle_Send_Menu(void)
{ 
  if(CdcSelectMode == CDC_SELECT_MENU)
  {
    switch(CdcDemo.Send_state)
    {
    case CDC_SEND_IDLE:
      CdcDemo.Send_state = CDC_SEND_WAIT;
      CDC_SelectItem (DEMO_SEND_menu, 0);
      CdcDemo.select = 0; 

      PrevPos = 0;
      USBH_CDC_Stop(&hUSBHost);
      break;
      
    case CDC_SEND_WAIT:
      if(CdcDemo.select != PrevSelect)
      {
        PrevSelect = CdcDemo.select;
        CDC_SelectItem (DEMO_SEND_menu, CdcDemo.select & 0x7F);
        
        /* Handle select item */
        if(CdcDemo.select & 0x80)
        {
          switch(CdcDemo.select & 0x7F)
          {
          case 0:
            memset(CDC_TX_Buffer, 0x5A, TX_BUFF_SIZE);
            LCD_DbgLog("Sending data ...\n"); 
            USBH_CDC_Transmit(&hUSBHost, CDC_TX_Buffer, TX_BUFF_SIZE);
            use_file = 0;
            break;
            
          case 1:
            if(FileList.ptr > 0)
            {
              SendFileMenu_Init();
              if(FilePos >= 9)
              {
                CDC_ShowFiles(FileOffset, 9);
              }
              
              else
              {
                CDC_ShowFiles(FileOffset, FilePos);
              }
              CdcDemo.Send_state = CDC_SEND_SELECT_FILE;
            }
            else
            {
             LCD_ErrLog("No file on the microSD\n"); 
            }
            break;
            
          case 2: /* Return */
            ReturnFromSendMenu();
            break;
          default:
            break;
          }
        }
      }
      break; 

    default:
      break;
    }
  }
  else if(CdcSelectMode == CDC_SELECT_FILE)
  {
    switch(CdcDemo.Send_state)
    {
    case  CDC_SEND_SELECT_FILE: 
      if(CdcDemo.select & 0x80)
      {
        CdcDemo.select &= 0x7F;
        CdcDemo.Send_state = CDC_SEND_TRANSMIT_FILE;        
      }
      break;
      
    case CDC_SEND_TRANSMIT_FILE: 
      LCD_DbgLog("Sending file ...\n"); 
      use_file = 1;
      CDC_SendFile(FilePos);
      CDC_ChangeSelectMode(CDC_SELECT_MENU);
      LCD_LOG_UpdateDisplay();
      CdcDemo.Send_state = CDC_SEND_WAIT;
      break;
      
    default:
      break;      
    }
    
    if(FilePos != PrevPos)
    {
      
      if(((FilePos > 9)&&(FilePos > PrevPos)) ||
         ((FilePos >= 9)&&(FilePos < PrevPos)))
      {
        if(FilePos > PrevPos)
        {
          FileOffset++;
        }
        else
        {
          FileOffset--;
        }
        CDC_ShowFiles(FileOffset, 9);        
      }
      else
      {
        CDC_ShowFiles(0, FilePos);
      }
      PrevPos = FilePos;      
    }
  }
  CdcDemo.select &= 0x7F;
}
Beispiel #13
0
/**
  * @brief  CDC data transmit callback.
  * @param  phost: Host handle
  * @retval None
  */
void USBH_CDC_TransmitCallback(USBH_HandleTypeDef *phost)
{
  LCD_DbgLog (">> Data sent\n" );
  CDC_SendState = 1;
}
/**
  * @brief  Informs user that Settings have been changed.
  * @param  phost: Host handle
  * @retval None
  */
void USBH_CDC_LineCodingChanged(USBH_HandleTypeDef *phost)
{
  LCD_DbgLog("New CDC Settings applied!\n"); 
}
Beispiel #15
0
/**
  * @brief  Manages DUAL Menu Process.
  * @param  None
  * @retval None
  */
void DUAL_MenuProcess(void)
{
  switch(demo.state)
  {
  case DEMO_IDLE:
    Demo_SelectItem(DEMO_main_menu, 0); 
    LCD_UsrLog("Select an operation to continue.\n");
    demo.state = DEMO_WAIT;
    demo.select = 0;
    break;    
  case DEMO_WAIT:
    
    if(demo.select != prev_select)
    {
      prev_select = demo.select;
      Demo_SelectItem(DEMO_main_menu, demo.select & 0x7F);
      
      /* Handle select item */
      if(demo.select & 0x80)
      {
        demo.select &= 0x7F;
        
        switch(demo.select)
        {
        case 0:
          demo.state = DEMO_MSC_START;  
          break;
          
        case 1:
          demo.state = DEMO_HID_START;  
          break;
          
        case 2:
          demo.state = DEMO_MSC_REENUMERATE;
          break;
          
        case 3:
          demo.state = DEMO_HID_REENUMERATE;
          break;
          
        default:
          break;
        }
      }
    }
    break;
    
  case DEMO_MSC_START:
    if(Appli_HS_state == APPLICATION_HS_READY) 
    {
      /* If HS device connected*/
      demo.state = DEMO_MSC; 
      demo.msc_state = APPLI_MSC_IDLE;
    }
    else
    {
      LCD_ErrLog("No Mass storage device connected.\n");
      demo.state = DEMO_WAIT; 
    }
    break;
    
  case DEMO_HID_START:
    if(Appli_FS_state == APPLICATION_FS_READY)
    {
      /*if FS device connected*/
      demo.state = DEMO_HID; 
      demo.hid_state = APPLI_HID_IDLE;
    }
    else
    {
      LCD_ErrLog("No HID device connected.\n");
      demo.state = DEMO_WAIT; 
    }
    break;
    
  case DEMO_MSC: 
    MSC_MenuProcess();
    break;
    
  case DEMO_HID:
    HID_MenuProcess();
    break;
    
  case DEMO_MSC_REENUMERATE: /* Re-Enumeration MSC */
    LCD_DbgLog("Starting Enumeration MSC...."); 
    LCD_DbgLog("\n");
    USBH_ReEnumerate(&hUSBHost_HS); 
    demo.state = DEMO_WAIT;
    break;
    
  case DEMO_HID_REENUMERATE: /* Re-Enumeration HID */
    LCD_DbgLog("Starting Enumeration HID...."); 
    LCD_DbgLog("\n");
    USBH_ReEnumerate(&hUSBHost_FS);
    demo.state = DEMO_WAIT;
    break;
    
  default:
    break;
  }
  
  if(Appli_FS_state == APPLICATION_FS_DISCONNECT)
  {
    Appli_FS_state = APPLICATION_IDLE; 
    LCD_LOG_ClearTextZone();
    LCD_ErrLog("device FS disconnected!\n");
    demo.state = DEMO_IDLE;
    demo.select = 0; 
  }
  
  if(Appli_HS_state == APPLICATION_HS_DISCONNECT)
  {
    Appli_HS_state = APPLICATION_IDLE; 
    LCD_LOG_ClearTextZone();
    LCD_ErrLog("device HS disconnected!\n");
    demo.state = DEMO_IDLE;
    demo.select = 0; 
  }
}
Beispiel #16
0
/**
* @brief  USR_KEYBRD_ProcessData
*         Process Keyboard data
* @param  data : Keyboard data to be displayed
* @retval None
*/
void  USR_KEYBRD_ProcessData (uint8_t data)
{
 
  char temp[20];
    
  if(DEMO_HID_ShowData == 0)
  {
  LCD_SetTextColor(LCD_COLOR_GREEN);
  
  if(data == '\n')
  {
    

    Ypos = KYBRD_FIRST_COLUMN;
    
    /*Increment char X position*/
    Xpos+=SMALL_FONT_LINE_WIDTH;
    
  }
  else if (data == '\r')
  {
    /* Manage deletion of character and update cursor location*/
    if( Ypos == KYBRD_FIRST_COLUMN) 
    {
      /*First character of first line to be deleted*/
      if(Xpos == KYBRD_FIRST_LINE)
      {  
        Ypos =KYBRD_FIRST_COLUMN; 
      }
      else
      {
        Xpos-=SMALL_FONT_LINE_WIDTH;
        Ypos =(KYBRD_LAST_COLUMN+SMALL_FONT_COLUMN_WIDTH); 
      }
    }
    else
    {
      Ypos +=SMALL_FONT_COLUMN_WIDTH;                  
      
    } 
    LCD_DisplayChar(Xpos,Ypos, ' '); 
  }
  else
  {
    LCD_DisplayChar(Xpos,Ypos, data);    
    /* Update the cursor position on LCD */
    
    /*Increment char Y position*/
    Ypos -=SMALL_FONT_COLUMN_WIDTH;
    
    /*Check if the Y position has reached the last column*/
    if(Ypos == KYBRD_LAST_COLUMN)
    {
      
      Ypos = KYBRD_FIRST_COLUMN;
      
      /*Increment char X position*/
      
      
      Xpos+=SMALL_FONT_LINE_WIDTH;
      
            
      if( Xpos > KYBRD_LAST_LINE) 
      {
        Xpos =KYBRD_FIRST_LINE;
      }
      
    }
  }
  }
  else
  {
    sprintf(temp ,"> %02xh %02xh %02xh %02xh\n" , HID_Machine.buff[0],  
                                         HID_Machine.buff[1],  
                                         HID_Machine.buff[2],  
                                         HID_Machine.buff[3]);
    LCD_DbgLog(temp);
  }
}
Beispiel #17
0
/**
  * @brief  Displays disk content
  * @param  path: pointer to root path
  * @param  recu_level: explorer level
  * @retval None
  */
static uint8_t Explore_Disk(char* path , uint8_t recu_level)
{
  FRESULT res;
  FILINFO fno;
  DIR dir;
  char *fn;
  char tmp[14];
  
  res = f_opendir(&dir, path);
  
  if (res == FR_OK) 
  {
    /* USER Button in polling */
    LCD_UsrLog("To see the disk root content:\n" );
    LCD_UsrLog("Press Key...\n");
    while((BSP_PB_GetState (BUTTON_KEY) != SET))          
    {
      Toggle_Leds();
    }
    while((BSP_PB_GetState (BUTTON_KEY) != RESET))          
    {
      Toggle_Leds();
    }
    while(Appli_state == APPLICATION_START) 
    {
      res = f_readdir(&dir, &fno);
      if (res != FR_OK || fno.fname[0] == 0) 
      {
        break;
      }
      if (fno.fname[0] == '.')
      {
        continue;
      }
      
      fn = fno.fname;
      strcpy(tmp, fn); 
      
      line_idx++;
      if(line_idx > 12)
      {
        line_idx = 0;
        LCD_UsrLog("Press Key to continue...\n");
        
        /* USER Button in polling */
        while((Appli_state == APPLICATION_START) && \
          (BSP_PB_GetState (BUTTON_KEY) != SET))
        {
          Toggle_Leds();
        }
      } 
      if(recu_level == 1)
      {
        LCD_DbgLog("   |__");
      }
      else if(recu_level == 2)
      {
        LCD_DbgLog("   |   |__");
      }
      if((fno.fattrib & AM_MASK) == AM_DIR)
      {
        strcat(tmp, "\n"); 
        LCD_UsrLog((void *)tmp);
      }
      else
      {
        strcat(tmp, "\n"); 
        LCD_DbgLog((void *)tmp);
      }
      
      if(((fno.fattrib & AM_MASK) == AM_DIR)&&(recu_level == 1))
      {
        Explore_Disk(fn, 2);
      }
    }
  }
  f_closedir(&dir);
  return res;
}
Beispiel #18
0
/**
  * @brief  Displays disk content.
  * @param  path: Pointer to root path
  * @param  recu_level: Disk content level 
  * @retval Operation result
  */
FRESULT Explore_Disk(char *path, uint8_t recu_level)
{
  FRESULT res = FR_OK;
  FILINFO fno;
  DIR dir;
  char *fn;
  char tmp[14];
  uint8_t line_idx = 0;
  
#if _USE_LFN
  static char lfn[_MAX_LFN + 1];   /* Buffer to store the LFN */
  fno.lfname = lfn;
  fno.lfsize = sizeof lfn;
#endif
  
  res = f_opendir(&dir, path);
  if(res == FR_OK) 
  {
    while(USBH_MSC_IsReady(&hUSBHost))
    {
      res = f_readdir(&dir, &fno);
      if(res != FR_OK || fno.fname[0] == 0) 
      {
        break;
      }
      if(fno.fname[0] == '.')
      {
        continue;
      }
      
#if _USE_LFN
      fn = *fno.lfname ? fno.lfname : fno.fname;
#else
      fn = fno.fname;
#endif
      strcpy(tmp, fn); 
      
      line_idx++;
      if(line_idx > 9)
      {
        line_idx = 0;
        LCD_UsrLog("> Press [Key] To Continue.\n");
        
        /* KEY Button in polling */
        while(BSP_PB_GetState(BUTTON_KEY) != RESET)
        {
          /* Wait for User Input */
        }
      } 
      
      if(recu_level == 1)
      {
        LCD_DbgLog("   |__");
      }
      else if(recu_level == 2)
      {
        LCD_DbgLog("   |   |__");
      }
      if((fno.fattrib & AM_MASK) == AM_DIR)
      {
        strcat(tmp, "\n"); 
        LCD_UsrLog((void *)tmp);
        Explore_Disk(fn, 2);
      }
      else
      {
        strcat(tmp, "\n"); 
        LCD_DbgLog((void *)tmp);
      }
      
      if(((fno.fattrib & AM_MASK) == AM_DIR)&&(recu_level == 2))
      {
        Explore_Disk(fn, 2);
      }
    }
    f_closedir(&dir);
	LCD_UsrLog("> Select an operation to Continue.\n" );
  }
  return res;
}
Beispiel #19
0
/**
* @brief  Explore_Disk 
*         Displays disk content
* @param  path: pointer to root path
* @retval None
*/
static uint8_t Explore_Disk (char* path , uint8_t recu_level)
{

  FRESULT res;
  FILINFO fno;
  DIR dir;
  char *fn;
  char tmp[14];
  
  res = f_opendir(&dir, path);
  if (res == FR_OK) {
    while(HCD_IsDeviceConnected(&USB_OTG_Core)) 
    {
      res = f_readdir(&dir, &fno);
      if (res != FR_OK || fno.fname[0] == 0) 
      {
        break;
      }
      if (fno.fname[0] == '.') {
        continue;
      }

      fn = fno.fname;
      strcpy(tmp, fn); 

      line_idx++;
      if (line_idx > 9) {
        line_idx = 0;
        LCD_SetTextColor(Green);
        LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 42, "                                              ");
        LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 30, "Press Key to continue...");
        LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR); 
        
        /*Key B3 in polling*/
        while((HCD_IsDeviceConnected(&USB_OTG_Core)) && \
          (STM_EVAL_PBGetState (BUTTON_USER) == RESET)) {
          Toggle_Leds();
          
        }
      } 
      
      if (recu_level == 1) {
        LCD_DbgLog("   |__");
      } else if(recu_level == 2) {
        LCD_DbgLog("   |   |__");
      }
      if ((fno.fattrib & AM_MASK) == AM_DIR) {
        strcat(tmp, "\n"); 
        LCD_UsrLog((void *)tmp);
      } else {
        strcat(tmp, "\n"); 
        LCD_DbgLog((void *)tmp);
      }

      if (((fno.fattrib & AM_MASK) == AM_DIR)&&(recu_level == 1)) {
        Explore_Disk(fn, 2);
      }
    }
  }
  return res;
}