# HG changeset patch # User Mychaela Falconia # Date 1694380438 0 # Node ID f5847be43d35e6467f29f3e47f3fa24869c33431 # Parent b9ecfa54fe2b5fc0da431dfa9a669c54ff067b5c fc-duart28-conf: bump off both ttyUSB devices on set operation diff -r b9ecfa54fe2b -r f5847be43d35 duart28/main.c --- a/duart28/main.c Sun Sep 10 19:21:20 2023 +0000 +++ b/duart28/main.c Sun Sep 10 21:13:58 2023 +0000 @@ -52,18 +52,24 @@ fprintf(stderr, "error: no DUART28 adapter found\n"); exit(1); } - usbh = usbwrap_open_dev(dev, 1); + usbh = usb_open(dev); + if (!usbh) { + fprintf(stderr, "error: usb_open() failed\n"); + exit(1); + } + usbwrap_claim_interface(usbh, 0, 1); + usbwrap_claim_interface(usbh, 1, 1); read_eeprom(usbh); prev = analyze_eeprom(); if (prev == newconf) { printf("EEPROM is already in the right state, nothing to program\n"); - usbwrap_close_dev(usbh); + usb_close(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); + usb_close(usbh); printf("EEPROM changed, replug the adapter to take effect\n"); return 0; } diff -r b9ecfa54fe2b -r f5847be43d35 libuwrap/Makefile --- a/libuwrap/Makefile Sun Sep 10 19:21:20 2023 +0000 +++ b/libuwrap/Makefile Sun Sep 10 21:13:58 2023 +0000 @@ -1,6 +1,6 @@ CC= gcc CFLAGS= -O2 -OBJS= find_busdev.o find_desc_str.o find_matchspec.o open_close.o \ +OBJS= claim_if.o find_busdev.o find_desc_str.o find_matchspec.o open_close.o \ prelim_init.o LIB= libuwrap.a diff -r b9ecfa54fe2b -r f5847be43d35 libuwrap/claim_if.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libuwrap/claim_if.c Sun Sep 10 21:13:58 2023 +0000 @@ -0,0 +1,23 @@ +/* + * When we are reprogramming the EEPROM on DUART28 or possibly other devices + * in the future where we know that we are operating on a multichannel FTDI + * chip (or perhaps a multichannel chip from some other vendor), it is most + * philosophically correct to bump off ftdi_sio from both interfaces, + * removing both ttyUSB devices. Here we implement a function for claiming + * one interface, easily callable for multiple interfaces in a row. + */ + +#include +#include +#include +#include "open_close.h" + +void usbwrap_claim_interface(usb_dev_handle *usbh, int ifnum, int detach) +{ + if (detach) + usb_detach_kernel_driver_np(usbh, ifnum); + if (usb_claim_interface(usbh, ifnum) != 0) { + fprintf(stderr, "error: usb_claim_interface() failed\n"); + exit(1); + } +} diff -r b9ecfa54fe2b -r f5847be43d35 libuwrap/open_close.h --- a/libuwrap/open_close.h Sun Sep 10 19:21:20 2023 +0000 +++ b/libuwrap/open_close.h Sun Sep 10 21:13:58 2023 +0000 @@ -1,2 +1,5 @@ extern usb_dev_handle *usbwrap_open_dev(struct usb_device *dev, int detach); extern void usbwrap_close_dev(usb_dev_handle *usbh); + +extern void +usbwrap_claim_interface(usb_dev_handle *usbh, int ifnum, int detach);