diff duart28/main.c @ 31:530ec3792de8

fc-duart28-conf: implement set command
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 09 Sep 2023 19:40:58 +0000
parents a7393d00996a
children df284688d0c8
line wrap: on
line diff
--- a/duart28/main.c	Sat Sep 09 19:39:15 2023 +0000
+++ b/duart28/main.c	Sat Sep 09 19:40:58 2023 +0000
@@ -41,8 +41,28 @@
 
 oper_program(newconf)
 {
-	fprintf(stderr, "error: set command not yet implemented\n");
-	exit(1);
+	struct usb_device *dev;
+	usb_dev_handle *usbh;
+	int prev;
+
+	dev = find_duart28_usbdev();
+	if (!dev) {
+		fprintf(stderr, "error: no DUART28 adapter found\n");
+		exit(1);
+	}
+	usbh = usbwrap_open_dev(dev, 1);
+	read_eeprom(usbh);
+	prev = analyze_eeprom();
+	if (prev == newconf) {
+		printf("EEPROM is already in the right state, nothing to do\n");
+		usbwrap_close_dev(usbh);
+		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");
+	return 0;
 }
 
 main(argc, argv)