FreeCalypso > hg > fc-usbser-tools
annotate cp2102/read_baudtab.c @ 67:742c41f44658
doc/FTDI-chip-ID: new article
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 13 Sep 2023 00:43:14 +0000 |
parents | ae8075bcc029 |
children | 8d35346f1d46 |
rev | line source |
---|---|
53
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program locates a CP2102 device via libusb, reads its internal |
60
ae8075bcc029
cp2102-read-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
3 * 1024-byte EEPROM, decodes the baud rate table portion thereof |
ae8075bcc029
cp2102-read-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
4 * and prints the decoded table. |
53
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <sys/types.h> |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdio.h> |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <unistd.h> |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <usb.h> |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "../libuwrap/find_dev.h" |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include "cp210x_defs.h" |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 u_char eeprom[SIZE_EEPROM]; |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 main(argc, argv) |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 char **argv; |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 { |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 struct usb_device *dev; |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 usb_dev_handle *usbh; |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (argc != 2) { |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 fprintf(stderr, "usage: %s device-selector\n", argv[0]); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 exit(1); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 } |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 dev = find_usbdev_by_desc_string(argv[1]); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (!dev) { |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 fprintf(stderr, "error: specified USB device not found\n"); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 exit(1); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 usbh = usb_open(dev); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (!usbh) { |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 fprintf(stderr, "error: usb_open() failed\n"); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 exit(1); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 } |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 read_eeprom(usbh); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 usb_close(usbh); |
60
ae8075bcc029
cp2102-read-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
41 decode_baud_table(stdout); |
53
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 exit(0); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 } |