comparison fteeprom/fteeprom-prog.c @ 23:7e6dcceb5ee8

fteeprom-prog: implement -r option for FT232R mode
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 09 Sep 2023 07:05:51 +0000
parents 43b8e88dae02
children 940cde8a99b6
comparison
equal deleted inserted replaced
22:4e5c8ac4d508 23:7e6dcceb5ee8
81 } 81 }
82 82
83 main(argc, argv) 83 main(argc, argv)
84 char **argv; 84 char **argv;
85 { 85 {
86 char **ap, *devsel;
86 struct usb_device *dev; 87 struct usb_device *dev;
87 usb_dev_handle *usbh; 88 usb_dev_handle *usbh;
89 int ft232r_mode = 0;
88 unsigned n; 90 unsigned n;
89 91
90 if (argc < 2 || argc > 3) { 92 if (argc < 2) {
91 fprintf(stderr, "usage: %s device-selector [eeprom-image]\n", 93 usage: fprintf(stderr,
94 "usage: %s [-r] device-selector [eeprom-image]\n",
92 argv[0]); 95 argv[0]);
93 exit(1); 96 exit(1);
94 } 97 }
95 if (argv[2]) 98 ap = argv + 1;
96 read_eeprom_from_file(argv[2]); 99 if (!strcmp(*ap, "-r")) {
97 else 100 ft232r_mode = 1;
101 ap++;
102 }
103 if (!*ap)
104 goto usage;
105 devsel = *ap++;
106 if (*ap) {
107 if (ap[1])
108 goto usage;
109 read_eeprom_from_file(*ap);
110 } else
98 read_eeprom_from_stdin(); 111 read_eeprom_from_stdin();
99 dev = find_usbdev_by_desc_string(argv[1]); 112 dev = find_usbdev_by_desc_string(devsel);
100 if (!dev) { 113 if (!dev) {
101 fprintf(stderr, "error: specified USB device not found\n"); 114 fprintf(stderr, "error: specified USB device not found\n");
102 exit(1); 115 exit(1);
103 } 116 }
104 usbh = usbwrap_open_dev(dev, 1); 117 usbh = usbwrap_open_dev(dev, 1);
105 /* FIXME: reimplement FT232R magic sequence */ 118 if (ft232r_mode)
119 ft232r_eeprom_magic(usbh);
106 for (n = 0; n < eeprom_size; n++) 120 for (n = 0; n < eeprom_size; n++)
107 ftmini_write_eeprom_loc(usbh, n, eeprom[n]); 121 ftmini_write_eeprom_loc(usbh, n, eeprom[n]);
108 usbwrap_close_dev(usbh); 122 usbwrap_close_dev(usbh);
109 exit(0); 123 exit(0);
110 } 124 }