FreeCalypso > hg > fc-usbser-tools
annotate cp2102/read_baudtab.c @ 104:866eae65dbea
LICENSE: same as other FreeCalypso tools
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 29 Sep 2023 18:20:04 +0000 |
parents | 1cacc1ae56f0 |
children |
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 |
97
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
17 extern struct usb_device *find_cp2102_device(); |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
60
diff
changeset
|
18 |
53
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 u_char eeprom[SIZE_EEPROM]; |
98
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
20 char *device_selector; |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
21 |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
22 process_cmdline(argc, argv) |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
23 char **argv; |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
24 { |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
25 int c; |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
26 extern int optind; |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
27 extern char *optarg; |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
28 |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
29 while ((c = getopt(argc, argv, "d:")) != EOF) { |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
30 switch (c) { |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
31 case 'd': |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
32 device_selector = optarg; |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
33 continue; |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
34 default: |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
35 usage: |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
36 fprintf(stderr, "usage: %s [-d device-selector]\n", |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
37 argv[0]); |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
38 exit(1); |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
39 } |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
40 } |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
41 if (argc != optind) |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
42 goto usage; |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
43 } |
53
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 main(argc, argv) |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 char **argv; |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 { |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 struct usb_device *dev; |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 usb_dev_handle *usbh; |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
98
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
51 process_cmdline(argc, argv); |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
52 dev = find_cp2102_device(device_selector); |
53
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 usbh = usb_open(dev); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 if (!usbh) { |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 fprintf(stderr, "error: usb_open() failed\n"); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 exit(1); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 read_eeprom(usbh); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 usb_close(usbh); |
60
ae8075bcc029
cp2102-read-baudtab program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
60 decode_baud_table(stdout); |
53
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 exit(0); |
d4d3531d342a
cp2102-read-eeprom program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |