From cb96d2d0b0fc700df59172693d7700f4eccf8534 Mon Sep 17 00:00:00 2001 From: Jules Maselbas Date: Sat, 6 Jan 2024 19:04:20 +0100 Subject: [PATCH] Properly add "list" to the command list --- wch-isp.c | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/wch-isp.c b/wch-isp.c index 1c609a6..be34ec2 100644 --- a/wch-isp.c +++ b/wch-isp.c @@ -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) { @@ -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 @@ -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 }, @@ -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; }