FreeCalypso > hg > fc-usbser-tools
changeset 39:b9ecfa54fe2b
fc-duart28-conf: replace find and check-eeprom with single show command
The original design with separate find and check-eeprom commands
was driven by the assumption that we had to bump off the ftdi_sio driver
in order to read the EEPROM, while a USB device tree check could be done
non-invasively. However, now that we know that we can read the EEPROM
non-invasively too, we can simplify the tool with a single show command.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 10 Sep 2023 19:21:20 +0000 |
parents | 6bf063ade588 |
children | f5847be43d35 |
files | duart28/find_usb.c duart28/main.c |
diffstat | 2 files changed, 27 insertions(+), 45 deletions(-) [+] |
line wrap: on
line diff
--- a/duart28/find_usb.c Sun Sep 10 07:30:01 2023 +0000 +++ b/duart28/find_usb.c Sun Sep 10 19:21:20 2023 +0000 @@ -11,6 +11,8 @@ #include <usb.h> #include "../libuwrap/prelim_init.h" +unsigned usb_presenting_pid; + static void get_string(usb_dev_handle *usbh, int index, char *buf, size_t buflen) { @@ -23,19 +25,6 @@ } } -static void -report_found_dev(struct usb_device *dev, unsigned usb_pid, char string_letter) -{ - printf("Found FreeCalypso DUART28 adapter at bus %s device %s,\n", - dev->bus->dirname, dev->filename); - if (usb_pid == 0x7152 && string_letter == 'C') - printf("presenting as DUART28C\n"); - else if (usb_pid == 0x6010 && string_letter == 'S') - printf("presenting as DUART28S\n"); - else - printf("presenting with inconsistent ID!\n"); -} - static int is_match(struct usb_device *dev) { @@ -63,7 +52,9 @@ return 0; } usb_close(usbh); - report_found_dev(dev, desc->idProduct, strbuf[7]); + printf("Found FreeCalypso DUART28 adapter at bus %s device %s\n", + dev->bus->dirname, dev->filename); + usb_presenting_pid = desc->idProduct; return 1; }
--- a/duart28/main.c Sun Sep 10 07:30:01 2023 +0000 +++ b/duart28/main.c Sun Sep 10 19:21:20 2023 +0000 @@ -11,21 +11,13 @@ #include "../libuwrap/open_close.h" extern struct usb_device *find_duart28_usbdev(); - -oper_find() -{ - struct usb_device *dev; +extern unsigned usb_presenting_pid; - dev = find_duart28_usbdev(); - if (!dev) - printf("No DUART28 adapter found\n"); - return 0; -} - -oper_check_eeprom() +oper_show() { struct usb_device *dev; usb_dev_handle *usbh; + int eeconf; dev = find_duart28_usbdev(); if (!dev) { @@ -39,7 +31,13 @@ } read_eeprom(usbh); usb_close(usbh); - analyze_eeprom(); + eeconf = analyze_eeprom(); + if (eeconf == 'C' && usb_presenting_pid != 0x7152) + printf("Visible USB device has wrong PID for C config" + " - please replug\n"); + if (eeconf == 'S' && usb_presenting_pid != 0x6010) + printf("Visible USB device has wrong PID for S config" + " - please replug\n"); return 0; } @@ -58,39 +56,34 @@ read_eeprom(usbh); prev = analyze_eeprom(); if (prev == newconf) { - printf("EEPROM is already in the right state, nothing to do\n"); + printf("EEPROM is already in the right state, nothing to program\n"); usbwrap_close_dev(usbh); + printf("Please replug the adapter to restore normal operation\n"); return 0; } printf("Reprogramming to DUART28%c configuration\n", newconf); update_eeprom(usbh, newconf); usbwrap_close_dev(usbh); - printf("EEPROM changed, replug the USB device to take effect\n"); + printf("EEPROM changed, replug the adapter to take effect\n"); return 0; } main(argc, argv) char **argv; { - if (argc < 2) - return oper_find(); - if (!strcmp(argv[1], "find")) { + if (argc < 2) { +usage: fprintf(stderr, "usage: %s show or %s set C|S\n", + argv[0], argv[0]); + exit(1); + } + if (!strcmp(argv[1], "show")) { if (argc != 2) { fprintf(stderr, - "error: %s find command takes no arguments\n", + "error: %s show command takes no arguments\n", argv[0]); exit(1); } - return oper_find(); - } - if (!strcmp(argv[1], "check-eeprom")) { - if (argc != 2) { - fprintf(stderr, - "error: %s check-eeprom command takes no arguments\n", - argv[0]); - exit(1); - } - return oper_check_eeprom(); + return oper_show(); } if (!strcmp(argv[1], "set")) { if (argc != 3) { @@ -107,7 +100,5 @@ argv[0]); exit(1); } - fprintf(stderr, "%s error: non-understood command \"%s\"\n", argv[0], - argv[1]); - exit(1); + goto usage; }