add pwd
This commit is contained in:
parent
51873cd1be
commit
cab65acc46
|
@ -43,7 +43,7 @@ int main(void)
|
||||||
{
|
{
|
||||||
board_init();
|
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
|
// init host stack on configured roothub port
|
||||||
tuh_init(BOARD_TUH_RHPORT);
|
tuh_init(BOARD_TUH_RHPORT);
|
||||||
|
@ -67,14 +67,12 @@ int main(void)
|
||||||
|
|
||||||
void tuh_mount_cb(uint8_t dev_addr)
|
void tuh_mount_cb(uint8_t dev_addr)
|
||||||
{
|
{
|
||||||
// application set-up
|
(void) dev_addr;
|
||||||
printf("A device with address %d is mounted\r\n", dev_addr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tuh_umount_cb(uint8_t dev_addr)
|
void tuh_umount_cb(uint8_t dev_addr)
|
||||||
{
|
{
|
||||||
// application tear-down
|
(void) dev_addr;
|
||||||
printf("A device with address %d is unmounted \r\n", dev_addr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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);
|
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("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
|
// For simplicity: we only mount 1 LUN per device
|
||||||
uint8_t const drive_num = dev_addr-1;
|
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");
|
puts("mount failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
f_chdrive(drive_path); // change to newly mounted drive
|
// change to newly mounted drive
|
||||||
f_chdir("/"); // root as current dir
|
f_chdir(drive_path);
|
||||||
|
|
||||||
|
// print the drive label
|
||||||
|
// char label[34];
|
||||||
|
// if ( FR_OK == f_getlabel(drive_path, label, NULL) )
|
||||||
|
// {
|
||||||
|
// puts(label);
|
||||||
|
// }
|
||||||
|
|
||||||
return true;
|
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 tuh_msc_umount_cb(uint8_t dev_addr)
|
||||||
{
|
{
|
||||||
(void) dev_addr;
|
|
||||||
printf("A MassStorage device is unmounted\r\n");
|
printf("A MassStorage device is unmounted\r\n");
|
||||||
|
|
||||||
uint8_t const drive_num = dev_addr-1;
|
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_cd(EmbeddedCli *cli, char *args, void *context);
|
||||||
void cli_cmd_cp(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_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_mkdir(EmbeddedCli *cli, char *args, void *context);
|
||||||
void cli_cmd_mv(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);
|
void cli_cmd_rm(EmbeddedCli *cli, char *args, void *context);
|
||||||
|
@ -338,6 +345,14 @@ bool cli_init(void)
|
||||||
cli_cmd_ls
|
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) {
|
embeddedCliAddBinding(_cli, (CliCommandBinding) {
|
||||||
"mkdir",
|
"mkdir",
|
||||||
"Usage: mkdir DIR...\r\n\tCreate the DIRECTORY(ies), if they do not already exist..",
|
"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);
|
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_cmd_mkdir(EmbeddedCli *cli, char *args, void *context)
|
||||||
{
|
{
|
||||||
(void) cli; (void) context;
|
(void) cli; (void) context;
|
||||||
|
|
|
@ -153,7 +153,7 @@
|
||||||
/ on character encoding. When LFN is not enabled, these options have no effect. */
|
/ 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.
|
/* This option configures support for relative path.
|
||||||
/
|
/
|
||||||
/ 0: Disable relative path and remove related functions.
|
/ 0: Disable relative path and remove related functions.
|
||||||
|
|
Loading…
Reference in New Issue