comparison fteeprom/fteeprom-prog.c @ 54:47dbfd66bd58

fteeprom-prog: added magic sequence from libftdi
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 May 2019 22:15:20 +0000
parents 2c092eb1621b
children
comparison
equal deleted inserted replaced
53:6bae8e424a69 54:47dbfd66bd58
70 70
71 main(argc, argv) 71 main(argc, argv)
72 char **argv; 72 char **argv;
73 { 73 {
74 struct ftdi_context ftdi; 74 struct ftdi_context ftdi;
75 u_short modem_status;
75 unsigned n; 76 unsigned n;
76 77
77 if (argc < 2 || argc > 3) { 78 if (argc < 2 || argc > 3) {
78 fprintf(stderr, "usage: %s device-selector [eeprom-image]\n", 79 fprintf(stderr, "usage: %s device-selector [eeprom-image]\n",
79 argv[0]); 80 argv[0]);
86 ftdi_init(&ftdi); 87 ftdi_init(&ftdi);
87 if (ftdi_usb_open_string(&ftdi, argv[1]) < 0) { 88 if (ftdi_usb_open_string(&ftdi, argv[1]) < 0) {
88 fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str); 89 fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str);
89 exit(1); 90 exit(1);
90 } 91 }
92 /* magic sequence apparently required for FT232R */
93 if (ftdi_usb_reset(&ftdi) < 0) {
94 fprintf(stderr, "ftdi_usb_reset() failed: %s\n",
95 ftdi.error_str);
96 exit(1);
97 }
98 if (ftdi_poll_modem_status(&ftdi, &modem_status) < 0) {
99 fprintf(stderr, "ftdi_poll_modem_status() failed: %s\n",
100 ftdi.error_str);
101 exit(1);
102 }
103 if (ftdi_set_latency_timer(&ftdi, 0x77) < 0) {
104 fprintf(stderr, "ftdi_set_latency_timer() failed: %s\n",
105 ftdi.error_str);
106 exit(1);
107 }
91 for (n = 0; n < eeprom_size; n++) { 108 for (n = 0; n < eeprom_size; n++) {
92 if (ftdi_write_eeprom_location(&ftdi, n, eeprom[n]) < 0) { 109 if (ftdi_write_eeprom_location(&ftdi, n, eeprom[n]) < 0) {
93 fprintf(stderr, "EEPROM write error: %s\n", 110 fprintf(stderr, "EEPROM write error: %s\n",
94 ftdi.error_str); 111 ftdi.error_str);
95 exit(1); 112 exit(1);