diff duart28/main.c @ 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 df284688d0c8
children f5847be43d35
line wrap: on
line diff
--- 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;
 }