diff --git a/demos/host/host_os_none/host_os_none.uvopt b/demos/host/host_os_none/host_os_none.uvopt index 83c427785..89f85a6cf 100644 --- a/demos/host/host_os_none/host_os_none.uvopt +++ b/demos/host/host_os_none/host_os_none.uvopt @@ -162,7 +162,7 @@ 0 0 - 375 + 297 1
0
0 @@ -171,7 +171,23 @@ 0 0 0 - C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\tinyusb\host\usbh.c + C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\demos\host\src\cli.c + + +
+ + 1 + 0 + 116 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\demos\host\src\msc_app.c
@@ -391,7 +407,7 @@ 0 0 - 375 + 297 1
0
0 @@ -400,7 +416,23 @@ 0 0 0 - C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\tinyusb\host\usbh.c + C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\demos\host\src\cli.c + + +
+ + 1 + 0 + 116 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\demos\host\src\msc_app.c
@@ -460,7 +492,7 @@ 0 25 0 - 152 + 153 160 0 ..\src\main.c @@ -474,10 +506,10 @@ 1 0 0 - 17 + 0 0 - 126 - 129 + 1 + 1 0 ..\src\cdc_serial_app.c cdc_serial_app.c @@ -492,8 +524,8 @@ 0 0 0 - 128 - 135 + 1 + 1 0 ..\src\keyboard_app.c keyboard_app.c @@ -522,10 +554,10 @@ 1 0 0 - 1 + 0 0 - 66 - 86 + 1 + 1 0 ..\src\rndis_app.c rndis_app.c @@ -554,10 +586,10 @@ 1 0 0 - 33 + 0 0 - 74 - 77 + 1 + 1 0 ..\src\cli.c cli.c @@ -810,10 +842,10 @@ 1 0 0 - 19 + 21 0 - 1 - 18 + 2 + 8 0 ..\..\..\tinyusb\host\usbh.c usbh.c @@ -988,8 +1020,8 @@ 0 0 0 - 241 - 249 + 1 + 1 0 ..\..\..\tinyusb\class\msc_host.c msc_host.c @@ -1060,7 +1092,7 @@ 0 3 0 - 573 + 574 580 0 ..\..\bsp\lpc43xx\CMSIS_LPC43xx_DriverLib\src\lpc43xx_cgu.c @@ -1114,10 +1146,10 @@ 2 0 0 - 0 + 10 0 - 146 - 151 + 145 + 147 0 ..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s startup_LPC43xx.s @@ -1138,10 +1170,10 @@ 1 0 0 - 52 + 23 0 107 - 108 + 113 0 ..\..\..\vendor\fatfs\diskio.c diskio.c @@ -1154,10 +1186,10 @@ 1 0 0 - 0 + 66 0 - 0 - 0 + 2021 + 2037 0 ..\..\..\vendor\fatfs\ff.c ff.c diff --git a/demos/host/src/cli.c b/demos/host/src/cli.c index 80fe9f7ef..31ecbbdf0 100644 --- a/demos/host/src/cli.c +++ b/demos/host/src/cli.c @@ -142,6 +142,25 @@ static char cli_buffer[CLI_MAX_BUFFER]; uint8_t fileread_buffer[CLI_FILE_READ_BUFFER] TUSB_CFG_ATTR_USBRAM; static char volume_label[20]; +static inline void drive_number2letter(char * p_path) ATTR_ALWAYS_INLINE; +static inline void drive_number2letter(char * p_path) +{ + if (p_path[1] == ':') + { + p_path[0] = 'E' + p_path[0] - '0' ; + } +} + +static inline void drive_letter2number(char * p_path) ATTR_ALWAYS_INLINE; +static inline void drive_letter2number(char * p_path) +{ + if (p_path[1] == ':') + { + p_path[0] = p_path[0] - 'E' + '0'; + } +} + + //--------------------------------------------------------------------+ // IMPLEMENTATION //--------------------------------------------------------------------+ @@ -149,10 +168,10 @@ static char volume_label[20]; void cli_command_prompt(void) { f_getcwd(cli_buffer, CLI_MAX_BUFFER); - printf("\n%s %c%s\n$ ", + drive_number2letter(cli_buffer); + printf("\n%s %s\n$ ", (volume_label[0] !=0) ? volume_label : "No Label", - 'E'+cli_buffer[0]-'0', - cli_buffer+1); + cli_buffer); memclr_(cli_buffer, CLI_MAX_BUFFER); } @@ -294,9 +313,17 @@ cli_error_t cli_cmd_changedir(char * p_para) { if ( strlen(p_para) == 0 ) return CLI_ERROR_INVALID_PARA; - if ( FR_OK != f_chdir(p_para) ) + if ( (p_para[1] == ':') && (strlen(p_para) == 2) ) + { // change drive + p_para[0] -= 'E'; + if ( ! ( disk_is_ready(p_para[0]) && FR_OK == f_chdrive(p_para[0]) )) return CLI_ERROR_INVALID_PARA; + f_getlabel(NULL, volume_label, NULL); + }else { - return CLI_ERROR_INVALID_PATH; + if ( FR_OK != f_chdir(p_para) ) + { + return CLI_ERROR_INVALID_PATH; + } } return CLI_ERROR_NONE; diff --git a/demos/host/src/msc_app.c b/demos/host/src/msc_app.c index 99b41814d..8c1ff0dbe 100644 --- a/demos/host/src/msc_app.c +++ b/demos/host/src/msc_app.c @@ -84,13 +84,14 @@ void tusbh_msc_mounted_cb(uint8_t dev_addr) printf("LBA 0-0x%X Block Size: %d\n", last_lba, block_size); //------------- file system (only 1 LUN support) -------------// + // TODO MSC refractor this hack // DSTATUS stat = disk_initialize(0); uint8_t phy_disk = dev_addr-1; disk_state[phy_disk] = 0; if ( disk_is_ready(phy_disk) ) { - if ( f_mount(phy_disk, &fatfs[phy_disk]) != FR_OK ) // TODO multiple volume + if ( f_mount(phy_disk, &fatfs[phy_disk]) != FR_OK ) { puts("mount failed"); return; @@ -112,9 +113,12 @@ void tusbh_msc_mounted_cb(uint8_t dev_addr) void tusbh_msc_unmounted_cb(uint8_t dev_addr) { - // unmount disk - disk_state[dev_addr-1] = STA_NOINIT; puts("\na MassStorage device is unmounted"); + + uint8_t phy_disk = dev_addr-1; + + f_mount(phy_disk, NULL); // unmount disk + disk_state[phy_disk] = STA_NOINIT; } void tusbh_msc_isr(uint8_t dev_addr, tusb_event_t event, uint32_t xferred_bytes) diff --git a/vendor/fatfs/diskio.h b/vendor/fatfs/diskio.h index bd3688580..b6aa881fb 100644 --- a/vendor/fatfs/diskio.h +++ b/vendor/fatfs/diskio.h @@ -84,7 +84,8 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); static inline bool disk_is_ready(BYTE pdrv); static inline bool disk_is_ready(BYTE pdrv) { - return (disk_status(pdrv) & (STA_NOINIT | STA_NODISK)) == 0; + return (pdrv < TUSB_CFG_HOST_DEVICE_MAX) && + ( (disk_status(pdrv) & (STA_NOINIT | STA_NODISK)) == 0 ); } diff --git a/vendor/fatfs/ffconf.h b/vendor/fatfs/ffconf.h index 2ba90f251..75c5c15af 100644 --- a/vendor/fatfs/ffconf.h +++ b/vendor/fatfs/ffconf.h @@ -9,6 +9,7 @@ #ifndef _FFCONF #define _FFCONF 82786 /* Revision ID */ +#include "tusb_config.h" /*---------------------------------------------------------------------------/ / Functions and Buffer Configurations @@ -127,7 +128,7 @@ / Physical Drive Configurations /----------------------------------------------------------------------------*/ -#define _VOLUMES 1 +#define _VOLUMES TUSB_CFG_HOST_DEVICE_MAX /* Number of volumes (logical drives) to be used. */