This commit is contained in:
hathach 2022-11-21 11:52:51 +07:00
parent 51873cd1be
commit cab65acc46
No known key found for this signature in database
GPG Key ID: F5D50C6D51D17CBA
3 changed files with 43 additions and 10 deletions

View File

@ -43,7 +43,7 @@ int main(void)
{
board_init();
printf("TinyUSB Host MSC Explorer Example\r\n");
printf("TinyUSB Host MassStorage Explorer Example\r\n");
// init host stack on configured roothub port
tuh_init(BOARD_TUH_RHPORT);
@ -67,14 +67,12 @@ int main(void)
void tuh_mount_cb(uint8_t dev_addr)
{
// application set-up
printf("A device with address %d is mounted\r\n", dev_addr);
(void) dev_addr;
}
void tuh_umount_cb(uint8_t dev_addr)
{
// application tear-down
printf("A device with address %d is unmounted \r\n", dev_addr);
(void) dev_addr;
}

View File

@ -108,7 +108,7 @@ bool inquiry_complete_cb(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const
uint32_t const block_size = tuh_msc_get_block_size(dev_addr, cbw->lun);
printf("Disk Size: %lu MB\r\n", block_count / ((1024*1024)/block_size));
printf("Block Count = %lu, Block Size: %lu\r\n", block_count, block_size);
// printf("Block Count = %lu, Block Size: %lu\r\n", block_count, block_size);
// For simplicity: we only mount 1 LUN per device
uint8_t const drive_num = dev_addr-1;
@ -120,8 +120,15 @@ bool inquiry_complete_cb(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const
puts("mount failed");
}
f_chdrive(drive_path); // change to newly mounted drive
f_chdir("/"); // root as current dir
// change to newly mounted drive
f_chdir(drive_path);
// print the drive label
// char label[34];
// if ( FR_OK == f_getlabel(drive_path, label, NULL) )
// {
// puts(label);
// }
return true;
}
@ -137,7 +144,6 @@ void tuh_msc_mount_cb(uint8_t dev_addr)
void tuh_msc_umount_cb(uint8_t dev_addr)
{
(void) dev_addr;
printf("A MassStorage device is unmounted\r\n");
uint8_t const drive_num = dev_addr-1;
@ -273,6 +279,7 @@ void cli_cmd_cat(EmbeddedCli *cli, char *args, void *context);
void cli_cmd_cd(EmbeddedCli *cli, char *args, void *context);
void cli_cmd_cp(EmbeddedCli *cli, char *args, void *context);
void cli_cmd_ls(EmbeddedCli *cli, char *args, void *context);
void cli_cmd_pwd(EmbeddedCli *cli, char *args, void *context);
void cli_cmd_mkdir(EmbeddedCli *cli, char *args, void *context);
void cli_cmd_mv(EmbeddedCli *cli, char *args, void *context);
void cli_cmd_rm(EmbeddedCli *cli, char *args, void *context);
@ -338,6 +345,14 @@ bool cli_init(void)
cli_cmd_ls
});
embeddedCliAddBinding(_cli, (CliCommandBinding) {
"pwd",
"Usage: pwd\r\n\tPrint the name of the current working directory.",
true,
NULL,
cli_cmd_pwd
});
embeddedCliAddBinding(_cli, (CliCommandBinding) {
"mkdir",
"Usage: mkdir DIR...\r\n\tCreate the DIRECTORY(ies), if they do not already exist..",
@ -531,6 +546,26 @@ void cli_cmd_ls(EmbeddedCli *cli, char *args, void *context)
f_closedir(&dir);
}
void cli_cmd_pwd(EmbeddedCli *cli, char *args, void *context)
{
(void) cli; (void) context;
uint16_t argc = embeddedCliGetTokenCount(args);
if (argc != 0)
{
printf("invalid arguments\r\n");
return;
}
char path[256];
if (FR_OK != f_getcwd(path, sizeof(path)))
{
printf("cannot get current working directory\r\n");
}
puts(path);
}
void cli_cmd_mkdir(EmbeddedCli *cli, char *args, void *context)
{
(void) cli; (void) context;

View File

@ -153,7 +153,7 @@
/ on character encoding. When LFN is not enabled, these options have no effect. */
#define FF_FS_RPATH 1
#define FF_FS_RPATH 2
/* This option configures support for relative path.
/
/ 0: Disable relative path and remove related functions.