annotate libftmini/ft232r_magic.c @ 59:672c7adc8bc9

cp2102-decode-baudtab: works after a little fix
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 11 Sep 2023 20:38:51 +0000
parents 4e5c8ac4d508
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Programming of FT232R internal EEPROM requires a special magic sequence
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * of non-EEPROM-specific commands to be issued prior to actual EEPROM write
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * commands. This module implements this magic command sequence.
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <usb.h>
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "ftdi_defs.h"
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "ftdi_tune.h"
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "eeprom_func.h"
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 void ft232r_eeprom_magic(usb_dev_handle *usbh)
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 u_char buf[2];
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 int rc;
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 /* equivalent of ftdi_usb_reset() */
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 rc = usb_control_msg(usbh, FTDI_DEVICE_OUT_REQTYPE, SIO_RESET_REQUEST,
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 SIO_RESET_SIO, 0, NULL, 0, USB_WRITE_TIMEOUT);
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (rc != 0) {
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 fprintf(stderr,
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 "ftdi_usb_reset error: usb_control_msg() returned %d\n",
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 rc);
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 exit(1);
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 /* equivalent of ftdi_poll_modem_status() */
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 rc = usb_control_msg(usbh, FTDI_DEVICE_IN_REQTYPE,
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 SIO_POLL_MODEM_STATUS_REQUEST, 0, 0, (char *) buf,
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 2, USB_READ_TIMEOUT);
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (rc != 2) {
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 fprintf(stderr,
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 "ftdi_poll_modem_status error: usb_control_msg() returned %d\n",
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 rc);
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 exit(1);
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 /* equivalent of ftdi_set_latency_timer() */
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 rc = usb_control_msg(usbh, FTDI_DEVICE_OUT_REQTYPE,
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 SIO_SET_LATENCY_TIMER_REQUEST, 0x77, 0, NULL, 0,
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 USB_WRITE_TIMEOUT);
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (rc != 0) {
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 fprintf(stderr,
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 "ftdi_set_latency_timer error: usb_control_msg() returned %d\n",
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 rc);
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 exit(1);
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
4e5c8ac4d508 libftmini: add function for FT232R magic
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }