FreeCalypso > hg > fc-usbser-tools
comparison libftmini/ft232r_magic.c @ 22:4e5c8ac4d508
libftmini: add function for FT232R magic
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 09 Sep 2023 01:06:43 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
21:af801ab43a33 | 22:4e5c8ac4d508 |
---|---|
1 /* | |
2 * Programming of FT232R internal EEPROM requires a special magic sequence | |
3 * of non-EEPROM-specific commands to be issued prior to actual EEPROM write | |
4 * commands. This module implements this magic command sequence. | |
5 */ | |
6 | |
7 #include <sys/types.h> | |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
10 #include <usb.h> | |
11 #include "ftdi_defs.h" | |
12 #include "ftdi_tune.h" | |
13 #include "eeprom_func.h" | |
14 | |
15 void ft232r_eeprom_magic(usb_dev_handle *usbh) | |
16 { | |
17 u_char buf[2]; | |
18 int rc; | |
19 | |
20 /* equivalent of ftdi_usb_reset() */ | |
21 rc = usb_control_msg(usbh, FTDI_DEVICE_OUT_REQTYPE, SIO_RESET_REQUEST, | |
22 SIO_RESET_SIO, 0, NULL, 0, USB_WRITE_TIMEOUT); | |
23 if (rc != 0) { | |
24 fprintf(stderr, | |
25 "ftdi_usb_reset error: usb_control_msg() returned %d\n", | |
26 rc); | |
27 exit(1); | |
28 } | |
29 /* equivalent of ftdi_poll_modem_status() */ | |
30 rc = usb_control_msg(usbh, FTDI_DEVICE_IN_REQTYPE, | |
31 SIO_POLL_MODEM_STATUS_REQUEST, 0, 0, (char *) buf, | |
32 2, USB_READ_TIMEOUT); | |
33 if (rc != 2) { | |
34 fprintf(stderr, | |
35 "ftdi_poll_modem_status error: usb_control_msg() returned %d\n", | |
36 rc); | |
37 exit(1); | |
38 } | |
39 /* equivalent of ftdi_set_latency_timer() */ | |
40 rc = usb_control_msg(usbh, FTDI_DEVICE_OUT_REQTYPE, | |
41 SIO_SET_LATENCY_TIMER_REQUEST, 0x77, 0, NULL, 0, | |
42 USB_WRITE_TIMEOUT); | |
43 if (rc != 0) { | |
44 fprintf(stderr, | |
45 "ftdi_set_latency_timer error: usb_control_msg() returned %d\n", | |
46 rc); | |
47 exit(1); | |
48 } | |
49 } |