Ejemplo n.º 1
0
/**
  * @brief  MSC class application
  * @param  None
  * @retval None
  */
static void MSC_Application(void)
{
  switch(USBH_USR_ApplicationState)
  {
  case USH_USR_FS_INIT: 
    /* Register work area for logical drives */
    if (f_mount(&USBDISK_FatFs, "", 0) != FR_OK)
    {
      LCD_ErrLog("> File System NOT initialized.\n");
      Error_Handler();
    }
    else
    {
      LCD_UsrLog("> File System initialized.\n");
      USBH_USR_ApplicationState = USH_USR_FS_READLIST;
    }
    break;
    
  case USH_USR_FS_READLIST:
    LCD_UsrLog("> Exploring disk flash ...\n");
    if (Explore_Disk("0:/", 1) != FR_OK)
    {
      LCD_ErrLog("> File cannot be explored.\n");
      Error_Handler();
    }
    else 
    {
      line_idx = 0;   
      USBH_USR_ApplicationState = USH_USR_FS_DRAW; 
      
      LCD_UsrLog("To start Image Slideshow\n");
      LCD_UsrLog("Press Key\n");
      while(BSP_PB_GetState (BUTTON_KEY) != SET)
      {
        Toggle_Leds();
      }
    }
    break;
    
  case USH_USR_FS_DRAW:
    /* USER Button in polling */
    while(BSP_PB_GetState (BUTTON_KEY) != RESET)
    {
      Toggle_Leds();
    }
    
    while(Appli_state == APPLICATION_START)
    {
      Image_Browser("0:/");
      return;
    }
    break;
    
  default: 
    break;
  }
  return;
}
Ejemplo n.º 2
0
/**
* @brief  USBH_USR_MSC_Application 
*         Demo application for mass storage
* @param  None
* @retval Staus
*/
int USBH_USR_MSC_Application(void)
{
  FRESULT res;
  uint8_t writeTextBuff[] = "STM32 Connectivity line Host Demo application using FAT_FS   ";
  uint16_t bytesWritten, bytesToWrite;
  
  switch(USBH_USR_ApplicationState)
  {
  case USH_USR_FS_INIT: 
    
    /* Initialises the File System*/
    if ( f_mount( 0, &fatfs ) != FR_OK ) {
      /* efs initialisation fails*/
      LCD_ErrLog("> Cannot initialize File System.\n");
      return(-1);
    }
    LCD_UsrLog("> File System initialized.\n");
    LCD_UsrLog("> Disk capacity : %d Bytes\n", USBH_MSC_Param.MSCapacity * \
      USBH_MSC_Param.MSPageLength); 
    
    if(USBH_MSC_Param.MSWriteProtect == DISK_WRITE_PROTECTED) {
      LCD_ErrLog((void *)MSG_WR_PROTECT);
    }
    
    USBH_USR_ApplicationState = USH_USR_FS_READLIST;
    break;
    
  case USH_USR_FS_READLIST:
    
    LCD_UsrLog((void *)MSG_ROOT_CONT);
    Explore_Disk("0:/", 1);
    line_idx = 0;   
    USBH_USR_ApplicationState = USH_USR_FS_WRITEFILE;
    
    break;
    
  case USH_USR_FS_WRITEFILE:
    
    LCD_SetTextColor(Green);
    LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 42, "                                              ");
    LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 30, "Press Key to write file");
    LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR); 
    USB_OTG_BSP_mDelay(100);
    
    /*Key B3 in polling*/
    while((HCD_IsDeviceConnected(&USB_OTG_Core)) && \
      (STM_EVAL_PBGetState (BUTTON_USER) == RESET))          
    {
      Toggle_Leds();
    }
    /* Writes a text file, STM32.TXT in the disk*/
    LCD_UsrLog("> Writing File to disk flash ...\n");
    if (USBH_MSC_Param.MSWriteProtect == DISK_WRITE_PROTECTED) {
      
      LCD_ErrLog ( "> Disk flash is write protected \n");
      USBH_USR_ApplicationState = USH_USR_FS_DRAW;
      break;
    }
    
    /* Register work area for logical drives */
    f_mount(0, &fatfs);
    
    if (f_open(&file, "0:STM32.TXT",FA_CREATE_ALWAYS | FA_WRITE) == FR_OK) { 
      /* Write buffer to file */
      bytesToWrite = sizeof(writeTextBuff); 
      res= f_write (&file, writeTextBuff, bytesToWrite, (void *)&bytesWritten);   
      
      if((bytesWritten == 0) || (res != FR_OK)) /*EOF or Error*/ {
        LCD_ErrLog("> STM32.TXT CANNOT be writen.\n");
      } else {
        LCD_UsrLog("> 'STM32.TXT' file created\n");
      }
      
      /*close file and filesystem*/
      f_close(&file);
      f_mount(0, NULL); 
    } else {
      LCD_UsrLog ("> STM32.TXT created in the disk\n");
    }

    USBH_USR_ApplicationState = USH_USR_FS_DRAW; 
    
    LCD_SetTextColor(Green);
    LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 42, "                                              ");
    LCD_DisplayStringLine( LCD_PIXEL_HEIGHT - 30, "To start Image slide show Press Key.");
    LCD_SetTextColor(LCD_LOG_DEFAULT_COLOR); 
  
    break;
    
  case USH_USR_FS_DRAW:
    
    /*Key B3 in polling*/
    while((HCD_IsDeviceConnected(&USB_OTG_Core)) && \
      (STM_EVAL_PBGetState (BUTTON_USER) == RESET))
    {
      Toggle_Leds();
    }
  
    while(HCD_IsDeviceConnected(&USB_OTG_Core))
    {
      if ( f_mount( 0, &fatfs ) != FR_OK ) {
        /* fat_fs initialisation fails*/
        return(-1);
      }
      return Image_Browser("0:/");
    }
    break;
  default: break;
  }
  return(0);
}