comparison fteeprom/fteeprom-prog.c @ 68:5cbde3c80c24

fteeprom-{erase,prog}: detach logic: change to detach by default As it turns out, detaching all ttyUSB interfaces of a multichannel device does not require outside knowledge of how many channels there are, as in our previous -d option design that is being removed here - instead we can read the bNumInterfaces constant from the USB device's config descriptor and thus know how many interfaces there are in total. Based on this discovery, change the design of fteeprom-{erase,prog} as follows: * remove -d option; * flip the default to where we detach all interfaces by default; * add -n option to NOT detach any interfaces.
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 13 Sep 2023 06:37:03 +0000
parents ca2250b4833d
children
comparison
equal deleted inserted replaced
67:742c41f44658 68:5cbde3c80c24
21 21
22 extern unsigned eeprom_size; 22 extern unsigned eeprom_size;
23 extern u_short eeprom[256]; 23 extern u_short eeprom[256];
24 24
25 char *device_selector, *input_filename; 25 char *device_selector, *input_filename;
26 int detach_num, ft232r_mode; 26 int ft232r_mode, no_detach;
27 27
28 process_cmdline(argc, argv) 28 process_cmdline(argc, argv)
29 char **argv; 29 char **argv;
30 { 30 {
31 int c; 31 int c;
32 extern int optind; 32 extern int optind;
33 extern char *optarg; 33 extern char *optarg;
34 34
35 while ((c = getopt(argc, argv, "d:r")) != EOF) { 35 while ((c = getopt(argc, argv, "nr")) != EOF) {
36 switch (c) { 36 switch (c) {
37 case 'd': 37 case 'n':
38 detach_num = atoi(optarg); 38 no_detach = 1;
39 switch (detach_num) {
40 case 0:
41 case 1:
42 case 2:
43 case 4:
44 break;
45 default:
46 fprintf(stderr, "error: invalid -d argument\n");
47 exit(1);
48 }
49 continue; 39 continue;
50 case 'r': 40 case 'r':
51 ft232r_mode = 1; 41 ft232r_mode = 1;
52 detach_num = 1;
53 continue; 42 continue;
54 default: 43 default:
55 /* error msg already printed */ 44 /* error msg already printed */
56 exit(1); 45 exit(1);
57 } 46 }
86 usbh = usb_open(dev); 75 usbh = usb_open(dev);
87 if (!usbh) { 76 if (!usbh) {
88 fprintf(stderr, "error: usb_open() failed\n"); 77 fprintf(stderr, "error: usb_open() failed\n");
89 exit(1); 78 exit(1);
90 } 79 }
91 if (detach_num) 80 if (!no_detach)
92 usbwrap_claim_all_ifs(usbh, detach_num); 81 usbwrap_claim_all_ifs(usbh);
93 if (ft232r_mode) 82 if (ft232r_mode)
94 ft232r_eeprom_magic(usbh); 83 ft232r_eeprom_magic(usbh);
95 for (n = 0; n < eeprom_size; n++) 84 for (n = 0; n < eeprom_size; n++)
96 ftmini_write_eeprom_loc(usbh, n, eeprom[n]); 85 ftmini_write_eeprom_loc(usbh, n, eeprom[n]);
97 usb_close(usbh); 86 usb_close(usbh);