almost complete cli for msc

This commit is contained in:
hathach 2013-09-25 19:52:05 +07:00
parent 1fee50b9fe
commit 89898acd5d
5 changed files with 154 additions and 101 deletions

View File

@ -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>

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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.