summaryrefslogtreecommitdiff
path: root/demos/host/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-10-01 16:11:34 +0700
committerhathach <[email protected]>2013-10-01 16:11:34 +0700
commit18b3179bc65a4080b71d3928baf5d64b43f2a53e (patch)
tree0b9fd3cd6bc8ab1ebe1dc42f98f144d73ee3ab08 /demos/host/src
parent640b0ec5467eadf153c4a09d53e0a38bae752685 (diff)
refractor msc host app examples
Diffstat (limited to 'demos/host/src')
-rw-r--r--demos/host/src/cli.c37
-rw-r--r--demos/host/src/msc_app.c10
2 files changed, 39 insertions, 8 deletions
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)