changeset 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 6bae8e424a69
children db9adb7a1529
files fteeprom/fteeprom-prog.c
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/fteeprom/fteeprom-prog.c	Thu May 09 21:28:48 2019 +0000
+++ b/fteeprom/fteeprom-prog.c	Thu May 09 22:15:20 2019 +0000
@@ -72,6 +72,7 @@
 	char **argv;
 {
 	struct ftdi_context ftdi;
+	u_short modem_status;
 	unsigned n;
 
 	if (argc < 2 || argc > 3) {
@@ -88,6 +89,22 @@
 		fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str);
 		exit(1);
 	}
+	/* magic sequence apparently required for FT232R */
+	if (ftdi_usb_reset(&ftdi) < 0) {
+		fprintf(stderr, "ftdi_usb_reset() failed: %s\n",
+			ftdi.error_str);
+		exit(1);
+	}
+	if (ftdi_poll_modem_status(&ftdi, &modem_status) < 0) {
+		fprintf(stderr, "ftdi_poll_modem_status() failed: %s\n",
+			ftdi.error_str);
+		exit(1);
+	}
+	if (ftdi_set_latency_timer(&ftdi, 0x77) < 0) {
+		fprintf(stderr, "ftdi_set_latency_timer() failed: %s\n",
+			ftdi.error_str);
+		exit(1);
+	}
 	for (n = 0; n < eeprom_size; n++) {
 		if (ftdi_write_eeprom_location(&ftdi, n, eeprom[n]) < 0) {
 			fprintf(stderr, "EEPROM write error: %s\n",