diff options
| author | hathach <[email protected]> | 2013-09-25 19:52:05 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-09-25 19:52:05 +0700 |
| commit | 89898acd5d7e0551a89e90affde5502504af720c (patch) | |
| tree | 2d6712bad02d5acc2eed1512e877025a91b88829 | |
| parent | 1fee50b9fe64c32f62baa8f96e1fa3687fa7da5d (diff) | |
almost complete cli for msc
| -rw-r--r-- | demos/host/host_os_none/host_os_none.uvopt | 78 | ||||
| -rw-r--r-- | demos/host/src/cli.c | 132 | ||||
| -rw-r--r-- | demos/host/src/main.c | 7 | ||||
| -rw-r--r-- | demos/host/src/msc_app.c | 30 | ||||
| -rw-r--r-- | vendor/fatfs/ffconf.h | 4 |
5 files changed, 152 insertions, 99 deletions
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 @@ <Name>-O975 -S0 -C0 -FO7 -FD10000000 -FC800 -FN2 -FF0LPC18xx43xx_512_BA -FS01A000000 -FL080000 -FF1LPC18xx43xx_512_BB -FS11B000000 -FL180000)</Name> </SetRegEntry> </TargetDriverDllRegistry> - <Breakpoint> - <Bp> - <Number>0</Number> - <Type>0</Type> - <LineNumber>131</LineNumber> - <EnabledFlag>1</EnabledFlag> - <Address>0</Address> - <ByteObject>0</ByteObject> - <HtxType>0</HtxType> - <ManyObjects>0</ManyObjects> - <SizeOfObject>0</SizeOfObject> - <BreakByAccess>0</BreakByAccess> - <BreakIfRCount>0</BreakIfRCount> - <Filename>C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\demos\host\src\main.c</Filename> - <ExecCommand></ExecCommand> - <Expression></Expression> - </Bp> - </Breakpoint> + <Breakpoint/> <WatchWindow1> <Ww> <count>0</count> @@ -407,24 +390,7 @@ <Name>-O975 -S0 -C0 -FO7 -FD10000000 -FC800 -FN2 -FF0LPC18xx43xx_512_BA -FS01A000000 -FL080000 -FF1LPC18xx43xx_512_BB -FS11B000000 -FL180000)</Name> </SetRegEntry> </TargetDriverDllRegistry> - <Breakpoint> - <Bp> - <Number>0</Number> - <Type>0</Type> - <LineNumber>131</LineNumber> - <EnabledFlag>1</EnabledFlag> - <Address>0</Address> - <ByteObject>0</ByteObject> - <HtxType>0</HtxType> - <ManyObjects>0</ManyObjects> - <SizeOfObject>0</SizeOfObject> - <BreakByAccess>0</BreakByAccess> - <BreakIfRCount>0</BreakIfRCount> - <Filename>C:\Users\hathach\Dropbox\tinyusb\workspace\tinyusb\demos\host\src\main.c</Filename> - <ExecCommand></ExecCommand> - <Expression></Expression> - </Bp> - </Breakpoint> + <Breakpoint/> <WatchWindow1> <Ww> <count>0</count> @@ -468,7 +434,7 @@ <Group> <GroupName>app</GroupName> - <tvExp>0</tvExp> + <tvExp>1</tvExp> <tvExpOptDlg>0</tvExpOptDlg> <cbSel>0</cbSel> <RteFlg>0</RteFlg> @@ -480,7 +446,7 @@ <Focus>0</Focus> <ColumnNumber>1</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>193</TopLine> + <TopLine>194</TopLine> <CurrentLine>200</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\src\main.c</PathWithFileName> @@ -496,7 +462,7 @@ <Focus>0</Focus> <ColumnNumber>0</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>127</TopLine> + <TopLine>121</TopLine> <CurrentLine>145</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\src\cdc_serial_app.c</PathWithFileName> @@ -512,7 +478,7 @@ <Focus>0</Focus> <ColumnNumber>0</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>169</TopLine> + <TopLine>163</TopLine> <CurrentLine>180</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\src\keyboard_app.c</PathWithFileName> @@ -528,7 +494,7 @@ <Focus>0</Focus> <ColumnNumber>44</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>121</TopLine> + <TopLine>122</TopLine> <CurrentLine>127</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\src\mouse_app.c</PathWithFileName> @@ -558,10 +524,10 @@ <FileType>1</FileType> <tvExp>0</tvExp> <Focus>0</Focus> - <ColumnNumber>0</ColumnNumber> + <ColumnNumber>3</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>1</TopLine> - <CurrentLine>1</CurrentLine> + <TopLine>125</TopLine> + <CurrentLine>135</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\src\msc_app.c</PathWithFileName> <FilenameWithoutPath>msc_app.c</FilenameWithoutPath> @@ -576,7 +542,7 @@ <Focus>0</Focus> <ColumnNumber>30</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>68</TopLine> + <TopLine>69</TopLine> <CurrentLine>75</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\src\cli.c</PathWithFileName> @@ -616,7 +582,7 @@ <Focus>0</Focus> <ColumnNumber>0</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>137</TopLine> + <TopLine>138</TopLine> <CurrentLine>142</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\..\bsp\boards\embedded_artists\board_ea4357.c</PathWithFileName> @@ -632,7 +598,7 @@ <Focus>0</Focus> <ColumnNumber>6</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>128</TopLine> + <TopLine>122</TopLine> <CurrentLine>135</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\..\bsp\boards\printf_retarget.c</PathWithFileName> @@ -768,7 +734,7 @@ <Focus>0</Focus> <ColumnNumber>0</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>58</TopLine> + <TopLine>52</TopLine> <CurrentLine>76</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\..\..\tinyusb\tusb.c</PathWithFileName> @@ -832,7 +798,7 @@ <Focus>0</Focus> <ColumnNumber>0</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>494</TopLine> + <TopLine>495</TopLine> <CurrentLine>501</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\..\..\tinyusb\host\usbh.c</PathWithFileName> @@ -848,7 +814,7 @@ <Focus>0</Focus> <ColumnNumber>0</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>600</TopLine> + <TopLine>601</TopLine> <CurrentLine>605</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\..\..\tinyusb\host\ehci\ehci.c</PathWithFileName> @@ -1032,7 +998,7 @@ <Focus>0</Focus> <ColumnNumber>0</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>546</TopLine> + <TopLine>547</TopLine> <CurrentLine>553</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\..\bsp\lpc43xx\CMSIS_LPC43xx_DriverLib\src\lpc43xx_uart.c</PathWithFileName> @@ -1136,8 +1102,8 @@ <Focus>0</Focus> <ColumnNumber>26</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>147</TopLine> - <CurrentLine>154</CurrentLine> + <TopLine>144</TopLine> + <CurrentLine>152</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\..\bsp\lpc43xx\startup_keil\startup_LPC43xx.s</PathWithFileName> <FilenameWithoutPath>startup_LPC43xx.s</FilenameWithoutPath> @@ -1158,10 +1124,10 @@ <FileType>1</FileType> <tvExp>0</tvExp> <Focus>0</Focus> - <ColumnNumber>0</ColumnNumber> + <ColumnNumber>46</ColumnNumber> <tvExpOptDlg>0</tvExpOptDlg> - <TopLine>13</TopLine> - <CurrentLine>23</CurrentLine> + <TopLine>16</TopLine> + <CurrentLine>30</CurrentLine> <bDave2>0</bDave2> <PathWithFileName>..\..\..\vendor\fatfs\diskio.c</PathWithFileName> <FilenameWithoutPath>diskio.c</FilenameWithoutPath> 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 @@ -95,26 +100,19 @@ static cli_cmdfunc_t cli_command_tbl[] = }; //--------------------------------------------------------------------+ -// IMPLEMENTATION +// INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ -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"); +enum { + ASCII_BACKSPACE = 8, +}; - return TUSB_ERROR_NONE; -} +#define CLI_MAX_BUFFER 256 +static char cli_buffer[CLI_MAX_BUFFER]; -#define CLI_MAX_BUFFER 50 -static char cli_buffer[CLI_MAX_BUFFER]; +//--------------------------------------------------------------------+ +// IMPLEMENTATION +//--------------------------------------------------------------------+ 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. |
