diff --git a/demos/host/host_os_none/host_os_none.uvopt b/demos/host/host_os_none/host_os_none.uvopt
index 19453212b..a00f5f25b 100644
--- a/demos/host/host_os_none/host_os_none.uvopt
+++ b/demos/host/host_os_none/host_os_none.uvopt
@@ -158,24 +158,7 @@
-O975 -S0 -C0 -FO7 -FD10000000 -FC800 -FN2 -FF0LPC18xx43xx_512_BA -FS01A000000 -FL080000 -FF1LPC18xx43xx_512_BB -FS11B000000 -FL180000)
-
-
- 0
- 0
- 131
- 1
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\demos\host\src\main.c
-
-
-
-
+
0
@@ -407,24 +390,7 @@
-O975 -S0 -C0 -FO7 -FD10000000 -FC800 -FN2 -FF0LPC18xx43xx_512_BA -FS01A000000 -FL080000 -FF1LPC18xx43xx_512_BB -FS11B000000 -FL180000)
-
-
- 0
- 0
- 131
- 1
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\demos\host\src\main.c
-
-
-
-
+
0
@@ -468,7 +434,7 @@
app
- 0
+ 1
0
0
0
@@ -480,7 +446,7 @@
0
1
0
- 193
+ 194
200
0
..\src\main.c
@@ -496,7 +462,7 @@
0
0
0
- 127
+ 121
145
0
..\src\cdc_serial_app.c
@@ -512,7 +478,7 @@
0
0
0
- 169
+ 163
180
0
..\src\keyboard_app.c
@@ -528,7 +494,7 @@
0
44
0
- 121
+ 122
127
0
..\src\mouse_app.c
@@ -558,10 +524,10 @@
1
0
0
- 0
+ 3
0
- 1
- 1
+ 125
+ 135
0
..\src\msc_app.c
msc_app.c
@@ -576,7 +542,7 @@
0
30
0
- 68
+ 69
75
0
..\src\cli.c
@@ -616,7 +582,7 @@
0
0
0
- 137
+ 138
142
0
..\..\bsp\boards\embedded_artists\board_ea4357.c
@@ -632,7 +598,7 @@
0
6
0
- 128
+ 122
135
0
..\..\bsp\boards\printf_retarget.c
@@ -768,7 +734,7 @@
0
0
0
- 58
+ 52
76
0
..\..\..\tinyusb\tusb.c
@@ -832,7 +798,7 @@
0
0
0
- 494
+ 495
501
0
..\..\..\tinyusb\host\usbh.c
@@ -848,7 +814,7 @@
0
0
0
- 600
+ 601
605
0
..\..\..\tinyusb\host\ehci\ehci.c
@@ -1032,7 +998,7 @@
0
0
0
- 546
+ 547
553
0
..\..\bsp\lpc43xx\CMSIS_LPC43xx_DriverLib\src\lpc43xx_uart.c
@@ -1136,8 +1102,8 @@
0
26
0
- 147
- 154
+ 144
+ 152
0
..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s
startup_LPC43xx.s
@@ -1158,10 +1124,10 @@
1
0
0
- 0
+ 46
0
- 13
- 23
+ 16
+ 30
0
..\..\..\vendor\fatfs\diskio.c
diskio.c
diff --git a/demos/host/src/cli.c b/demos/host/src/cli.c
index c8e84c960..bd45da9ed 100644
--- a/demos/host/src/cli.c
+++ b/demos/host/src/cli.c
@@ -39,10 +39,15 @@
#if TUSB_CFG_HOST_MSC
+#include "ff.h"
+#include "diskio.h"
+
// command, function, description
#define CLI_COMMAND_TABLE(ENTRY) \
- ENTRY(unknow , cli_cmd_unknow, NULL) \
- ENTRY(help , cli_cmd_help, NULL) \
+ ENTRY(unknow, cli_cmd_unknow , NULL) \
+ ENTRY(help , cli_cmd_help , NULL) \
+ ENTRY(ls , cli_cmd_list , "list items in current directory") \
+ ENTRY(cd , cli_cmd_changedir, "change current directory") \
//--------------------------------------------------------------------+
// Expands the function to have the standard function signature
@@ -94,27 +99,20 @@ static cli_cmdfunc_t cli_command_tbl[] =
CLI_COMMAND_TABLE(CMD_LOOKUP_EXPAND)
};
+//--------------------------------------------------------------------+
+// INTERNAL OBJECT & FUNCTION DECLARATION
+//--------------------------------------------------------------------+
+enum {
+ ASCII_BACKSPACE = 8,
+};
+
+#define CLI_MAX_BUFFER 256
+static char cli_buffer[CLI_MAX_BUFFER];
+
+
//--------------------------------------------------------------------+
// IMPLEMENTATION
//--------------------------------------------------------------------+
-tusb_error_t cli_cmd_unknow(char const * para)
-{
- puts("unknown command, please type \"help\"");
- return TUSB_ERROR_NONE;
-}
-
-tusb_error_t cli_cmd_help(char const * para)
-{
- puts("current supported commands are:");
- puts("cd\tchange directory");
- puts("ls\tlist directory");
-
- return TUSB_ERROR_NONE;
-}
-
-
-#define CLI_MAX_BUFFER 50
-static char cli_buffer[CLI_MAX_BUFFER];
void cli_init(void)
{
@@ -124,7 +122,7 @@ void cli_init(void)
void cli_poll(char ch)
{
if ( isprint(ch) )
- {
+ { // accumulate & echo
if (strlen(cli_buffer) < CLI_MAX_BUFFER)
{
cli_buffer[ strlen(cli_buffer) ] = ch;
@@ -135,20 +133,34 @@ void cli_poll(char ch)
memclr_(cli_buffer, CLI_MAX_BUFFER);
}
}
- else if ( ch == '\r')
+ else if ( ch == ASCII_BACKSPACE && strlen(cli_buffer))
{
+ printf("\33[1D"); // move curback
+ printf("\33[0K"); // clear to the end of line
+ cli_buffer[ strlen(cli_buffer)-1 ] = 0;
+ }
+ else if ( ch == '\r')
+ { // execute command
putchar('\n');
- for(cli_cmdtype_t cmd_id = CLI_CMDTYPE_help; cmd_id < CLI_CMDTYPE_COUNT; cmd_id++)
+ char* p_space = strchr(cli_buffer, ' ');
+ uint32_t command_len = (p_space == NULL) ? strlen(cli_buffer) : (p_space - cli_buffer);
+ char* p_para = (p_space == NULL) ? NULL : (p_space+1);
+
+ cli_cmdtype_t cmd_id;
+ for(cmd_id = CLI_CMDTYPE_COUNT - 1; cmd_id > 0; cmd_id--)
{
- if( 0 == strncmp(cli_buffer, cli_string_tbl[cmd_id], CLI_MAX_BUFFER) )
+ if( 0 == strncmp(cli_buffer, cli_string_tbl[cmd_id], command_len) )
{
- cli_command_tbl[cmd_id](NULL);
- memclr_(cli_buffer, CLI_MAX_BUFFER);
- return;
+ break;
}
}
- cli_cmd_unknow(NULL);
+ cli_command_tbl[cmd_id]( p_para );
+
+ f_getcwd(cli_buffer, CLI_MAX_BUFFER);
+ printf("\nMSC %c%s\n$ ",
+ 'E'+cli_buffer[0]-'0',
+ cli_buffer+1);
memclr_(cli_buffer, CLI_MAX_BUFFER);
}
else if (ch=='\t') // \t may be used for auto-complete later
@@ -157,4 +169,72 @@ void cli_poll(char ch)
}
}
+//--------------------------------------------------------------------+
+// UNKNOWN Command
+//--------------------------------------------------------------------+
+tusb_error_t cli_cmd_unknow(char const * para)
+{
+ puts("unknown command, please type \"help\"");
+ return TUSB_ERROR_NONE;
+}
+
+//--------------------------------------------------------------------+
+// HELP command
+//--------------------------------------------------------------------+
+tusb_error_t cli_cmd_help(char const * para)
+{
+ puts("current supported commands are:");
+ for(cli_cmdtype_t cmd_id = CLI_CMDTYPE_help+1; cmd_id < CLI_CMDTYPE_COUNT; cmd_id++)
+ {
+ printf("%s\t%s\n", cli_string_tbl[cmd_id], cli_description_tbl[cmd_id]);
+ }
+
+ return TUSB_ERROR_NONE;
+}
+
+//--------------------------------------------------------------------+
+// LS Command
+//--------------------------------------------------------------------+
+tusb_error_t cli_cmd_list(const char * p_para)
+{
+ DIR target_dir;
+
+ if ( (p_para == NULL) || (strlen(p_para) == 0) ) // list current directory
+ {
+ ASSERT_INT( FR_OK, f_opendir(&target_dir, "."), TUSB_ERROR_FAILED) ;
+
+ FILINFO dir_entry;
+ while( (f_readdir(&target_dir, &dir_entry) == FR_OK) && dir_entry.fname[0] != 0)
+ {
+ if ( dir_entry.fname[0] != '.' ) // ignore . and .. entry
+ {
+ printf("%s%c\n", dir_entry.fname,
+ dir_entry.fattrib & AM_DIR ? '/' : ' ');
+ }
+ }
+ }
+ else
+ {
+ puts("ls only supports list current directory only, try to cd to that folder first");
+ }
+
+ return TUSB_ERROR_NONE;
+}
+
+//--------------------------------------------------------------------+
+// CD Command
+//--------------------------------------------------------------------+
+tusb_error_t cli_cmd_changedir(const char * p_para)
+{
+ if ( (p_para == NULL) || (strlen(p_para) == 0) ) return TUSB_ERROR_INVALID_PARA;
+
+ if ( FR_OK != f_chdir(p_para) )
+ {
+ printf("%s : No such file or directory\n", p_para);
+ return TUSB_ERROR_INVALID_PARA;
+ }
+
+ return TUSB_ERROR_NONE;
+}
+
#endif
diff --git a/demos/host/src/main.c b/demos/host/src/main.c
index d38dba3f4..d6c7e43e4 100644
--- a/demos/host/src/main.c
+++ b/demos/host/src/main.c
@@ -50,8 +50,6 @@
#include "app_os_prio.h"
#endif
-#include "cli.h"
-
#include "mouse_app.h"
#include "keyboard_app.h"
#include "msc_app.h"
@@ -115,11 +113,6 @@ void os_none_start_scheduler(void)
cdc_serial_app_task(NULL);
rndis_app_task(NULL);
- int ch = getchar();
- if ( ch > 0 )
- {
- cli_poll( (char) ch);
- }
}
}
#endif
diff --git a/demos/host/src/msc_app.c b/demos/host/src/msc_app.c
index a6a3583d7..3971d7557 100644
--- a/demos/host/src/msc_app.c
+++ b/demos/host/src/msc_app.c
@@ -47,6 +47,7 @@
#if TUSB_CFG_HOST_MSC
+#include "cli.h"
#include "ff.h"
#include "diskio.h"
@@ -71,7 +72,6 @@ void tusbh_msc_mounted_cb(uint8_t dev_addr)
uint8_t const* p_vendor = tusbh_msc_get_vendor_name(dev_addr);
uint8_t const* p_product = tusbh_msc_get_product_name(dev_addr);
- printf("Name: ");
for(uint8_t i=0; i<8; i++) putchar(p_vendor[i]);
printf(" ");
@@ -95,12 +95,13 @@ void tusbh_msc_mounted_cb(uint8_t dev_addr)
return;
}
- DIR root_dir;
- if ( f_opendir(&root_dir, "/") != FR_OK )
- {
- puts("open root dir failed");
- return;
- }
+ char volume_label[20] = {0};
+ f_getlabel(NULL, volume_label, NULL);
+ printf("Label: %s\n\n", volume_label);
+
+ f_chdrive(dev_addr-1); // change to newly mounted drive
+ f_chdir("/"); // root as current dir
+ printf("MSC %c:/\n$ ", 'E'+dev_addr-1);
}
}
@@ -112,7 +113,7 @@ void tusbh_msc_unmounted_isr(uint8_t dev_addr)
void tusbh_msc_isr(uint8_t dev_addr, tusb_event_t event, uint32_t xferred_bytes)
{
- putchar('x');
+
}
//--------------------------------------------------------------------+
@@ -126,7 +127,20 @@ void msc_app_init(void)
//------------- main task -------------//
OSAL_TASK_FUNCTION( msc_app_task ) (void* p_task_para)
{
+ OSAL_TASK_LOOP_BEGIN
+ osal_task_delay(10);
+
+ if ( disk_is_ready(0) )
+ {
+ int ch = getchar();
+ if ( ch > 0 )
+ {
+ cli_poll( (char) ch);
+ }
+ }
+
+ OSAL_TASK_LOOP_END
}
#else
diff --git a/vendor/fatfs/ffconf.h b/vendor/fatfs/ffconf.h
index 87af580a9..d11175767 100644
--- a/vendor/fatfs/ffconf.h
+++ b/vendor/fatfs/ffconf.h
@@ -48,7 +48,7 @@
/* To enable fast seek feature, set _USE_FASTSEEK to 1. */
-#define _USE_LABEL 0 /* 0:Disable or 1:Enable */
+#define _USE_LABEL 1 /* 0:Disable or 1:Enable */
/* To enable volume label functions, set _USE_LAVEL to 1 */
@@ -113,7 +113,7 @@
/ enable LFN feature and set _LFN_UNICODE to 1. */
-#define _FS_RPATH 0 /* 0 to 2 */
+#define _FS_RPATH 2 /* 0 to 2 */
/* The _FS_RPATH option configures relative path feature.
/
/ 0: Disable relative path feature and remove related functions.