refractor msc host app examples
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user