Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
Properly add "list" to the command list
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaselbas committed Jan 6, 2024
1 parent 3c0ab5f commit cb96d2d
Showing 1 changed file with 33 additions and 18 deletions.
51 changes: 33 additions & 18 deletions wch-isp.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,37 @@ cmd_reset(struct isp_dev *dev, __unused int argc, __unused char **argv)
isp_cmd_isp_end(dev, 1);
}

static void
print_dev(struct isp_dev *dev)
{
printf("BTVER v%d.%d UID %s [0x%.2x%.2x] %s",
dev->btver >> 8, dev->btver & 0xff,
dev->uid_str, dev->type, dev->id,
dev->name);
if (dev->flash_size != SZ_UNKNOWN)
printf(" (flash %dK)", dev->flash_size / SZ_1K);
else
printf(" (flash size unknown)");
}

static void
list_devices(void)
{
size_t i;

for (i = 0; i < dev_count; i++) {
printf("%zd: ", i);
print_dev(&dev_list[i]);
printf("\n");
}
}

static void
cmd_list_devices(__unused struct isp_dev *dev, __unused int argc, __unused char **argv)
{
list_devices();
}

static struct isp_dev *
dev_by_uid(const char *uid)
{
Expand Down Expand Up @@ -862,19 +893,6 @@ dev_by_index(const char *s)
return NULL;
}

static void
print_dev(struct isp_dev *dev)
{
printf("BTVER v%d.%d UID %s [0x%.2x%.2x] %s",
dev->btver >> 8, dev->btver & 0xff,
dev->uid_str, dev->type, dev->id,
dev->name);
if (dev->flash_size != SZ_UNKNOWN)
printf(" (flash %dK)", dev->flash_size / SZ_1K);
else
printf(" (flash size unknown)");
}

char *argv0;

static void
Expand Down Expand Up @@ -909,6 +927,7 @@ static const struct {
const char *name;
void (*func)(struct isp_dev *dev, int argc, char **argv);
} cmds[] = {
{ "list", cmd_list_devices },
{ "flash", cmd_write_flash },
{ "write", cmd_write_flash },
{ "verify", cmd_verify_flash },
Expand Down Expand Up @@ -977,11 +996,7 @@ main(int argc, char **argv)
isp_init(&dev_list[i]);

if (argc < 1 || streq(argv[0], "list")) {
for (i = 0; i < dev_count; i++) {
printf("%zd: ", i);
print_dev(&dev_list[i]);
printf("\n");
}
list_devices();
goto out;
}

Expand Down

0 comments on commit cb96d2d

Please sign in to comment.