# HG changeset patch # User Mychaela Falconia # Date 1695871571 0 # Node ID 8d35346f1d46ccaf1ed208b30e349a6d7ac162ce # Parent c6d04771bf6a3fc38582c5650fa54b0b9a4437c6 cp2102 tools: accept "default" as device-selector diff -r c6d04771bf6a -r 8d35346f1d46 cp2102/Makefile --- a/cp2102/Makefile Thu Sep 28 02:38:59 2023 +0000 +++ b/cp2102/Makefile Thu Sep 28 03:26:11 2023 +0000 @@ -17,10 +17,13 @@ DECODE_EEDESC_OBJS= decode_usb_desc.o intel_hex_in.o PATCH_FILE_OBJS= apply_eeprom_patch.o intel_hex_in.o intel_hex_out.o \ patch_ee_file.o -READ_BAUDTAB_OBJS= decode_baudtab.o read_baudtab.o read_eeprom.o -READ_EEPROM_OBJS= intel_hex_out.o read_eeprom.o read_eeprom_main.o +READ_BAUDTAB_OBJS= decode_baudtab.o find_dev.o read_baudtab.o read_eeprom.o +READ_EEPROM_OBJS= find_dev.o intel_hex_out.o read_eeprom.o \ + read_eeprom_main.o +READ_PARTNO_OBJS= find_dev.o read_partno.o RW_TEST_OBJS= intel_hex_in.o intel_hex_out.o file_rw_test.o -WRITE_EEPROM_OBJS= intel_hex_in.o write_eeprom.o write_eeprom_main.o +WRITE_EEPROM_OBJS= find_dev.o intel_hex_in.o write_eeprom.o \ + write_eeprom_main.o all: ${PROGS} ${NOINST} @@ -39,8 +42,8 @@ cp2102-read-eeprom: ${READ_EEPROM_OBJS} ${LIBS} ${CC} ${CFLAGS} -o $@ ${READ_EEPROM_OBJS} ${LIBS} -lusb -cp2102-read-partno: read_partno.o ${LIBS} - ${CC} ${CFLAGS} -o $@ read_partno.o ${LIBS} -lusb +cp2102-read-partno: ${READ_PARTNO_OBJS} ${LIBS} + ${CC} ${CFLAGS} -o $@ ${READ_PARTNO_OBJS} ${LIBS} -lusb cp2102-write-eeprom: ${WRITE_EEPROM_OBJS} ${LIBS} ${CC} ${CFLAGS} -o $@ ${WRITE_EEPROM_OBJS} ${LIBS} -lusb diff -r c6d04771bf6a -r 8d35346f1d46 cp2102/find_dev.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cp2102/find_dev.c Thu Sep 28 03:26:11 2023 +0000 @@ -0,0 +1,41 @@ +/* + * The function implemented in this module is common to all programs in + * FC CP2102 tools suite that operate on physical hardware: it asks libuwrap + * to locate either the default CP2102 VID:PID or a custom device selector + * string. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "../libuwrap/find_dev.h" + +static const struct usbdev_matchspec default_id = {0x10C4, 0xEA60}; + +struct usb_device * +find_cp2102_device(devsel_arg) + char *devsel_arg; +{ + struct usb_device *dev; + + if (!strcmp(devsel_arg, "default")) { + dev = find_usbdev_by_matchspec(&default_id); + if (!dev) { + fprintf(stderr, + "error: no default-ID CP2102 device found\n"); + exit(1); + } + } else { + dev = find_usbdev_by_desc_string(devsel_arg); + if (!dev) { + fprintf(stderr, + "error: specified USB device not found\n"); + exit(1); + } + } + return dev; +} diff -r c6d04771bf6a -r 8d35346f1d46 cp2102/read_baudtab.c --- a/cp2102/read_baudtab.c Thu Sep 28 02:38:59 2023 +0000 +++ b/cp2102/read_baudtab.c Thu Sep 28 03:26:11 2023 +0000 @@ -14,6 +14,8 @@ #include "../libuwrap/find_dev.h" #include "cp210x_defs.h" +extern struct usb_device *find_cp2102_device(); + u_char eeprom[SIZE_EEPROM]; main(argc, argv) @@ -26,11 +28,7 @@ fprintf(stderr, "usage: %s device-selector\n", argv[0]); exit(1); } - dev = find_usbdev_by_desc_string(argv[1]); - if (!dev) { - fprintf(stderr, "error: specified USB device not found\n"); - exit(1); - } + dev = find_cp2102_device(argv[1]); usbh = usb_open(dev); if (!usbh) { fprintf(stderr, "error: usb_open() failed\n"); diff -r c6d04771bf6a -r 8d35346f1d46 cp2102/read_eeprom_main.c --- a/cp2102/read_eeprom_main.c Thu Sep 28 02:38:59 2023 +0000 +++ b/cp2102/read_eeprom_main.c Thu Sep 28 03:26:11 2023 +0000 @@ -15,6 +15,8 @@ #include "../libuwrap/find_dev.h" #include "cp210x_defs.h" +extern struct usb_device *find_cp2102_device(); + u_char eeprom[SIZE_EEPROM]; main(argc, argv) @@ -29,11 +31,7 @@ argv[0]); exit(1); } - dev = find_usbdev_by_desc_string(argv[1]); - if (!dev) { - fprintf(stderr, "error: specified USB device not found\n"); - exit(1); - } + dev = find_cp2102_device(argv[1]); usbh = usb_open(dev); if (!usbh) { fprintf(stderr, "error: usb_open() failed\n"); diff -r c6d04771bf6a -r 8d35346f1d46 cp2102/read_partno.c --- a/cp2102/read_partno.c Thu Sep 28 02:38:59 2023 +0000 +++ b/cp2102/read_partno.c Thu Sep 28 03:26:11 2023 +0000 @@ -14,6 +14,8 @@ #include "../libuwrap/find_dev.h" #include "cp210x_defs.h" +extern struct usb_device *find_cp2102_device(); + main(argc, argv) char **argv; { @@ -26,11 +28,7 @@ fprintf(stderr, "usage: %s device-selector\n", argv[0]); exit(1); } - dev = find_usbdev_by_desc_string(argv[1]); - if (!dev) { - fprintf(stderr, "error: specified USB device not found\n"); - exit(1); - } + dev = find_cp2102_device(argv[1]); usbh = usb_open(dev); if (!usbh) { fprintf(stderr, "error: usb_open() failed\n"); diff -r c6d04771bf6a -r 8d35346f1d46 cp2102/write_eeprom_main.c --- a/cp2102/write_eeprom_main.c Thu Sep 28 02:38:59 2023 +0000 +++ b/cp2102/write_eeprom_main.c Thu Sep 28 03:26:11 2023 +0000 @@ -14,6 +14,8 @@ #include "../libuwrap/open_close.h" #include "cp210x_defs.h" +extern struct usb_device *find_cp2102_device(); + u_char eeprom[SIZE_EEPROM]; char *device_selector, *input_filename; int no_detach; @@ -53,11 +55,7 @@ process_cmdline(argc, argv); read_intel_hex(input_filename); - dev = find_usbdev_by_desc_string(device_selector); - if (!dev) { - fprintf(stderr, "error: specified USB device not found\n"); - exit(1); - } + dev = find_cp2102_device(device_selector); usbh = usb_open(dev); if (!usbh) { fprintf(stderr, "error: usb_open() failed\n");