FreeCalypso > hg > fc-usbser-tools
annotate cp2102/find_dev.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 |
---|---|
97
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * The function implemented in this module is common to all programs in |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * FC CP2102 tools suite that operate on physical hardware: it asks libuwrap |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * to locate either the default CP2102 VID:PID or a custom device selector |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * string. |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 */ |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <sys/types.h> |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdio.h> |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdlib.h> |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <unistd.h> |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <usb.h> |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include "../libuwrap/find_dev.h" |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 static const struct usbdev_matchspec default_id = {0x10C4, 0xEA60}; |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 struct usb_device * |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 find_cp2102_device(devsel_arg) |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 char *devsel_arg; |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 { |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 struct usb_device *dev; |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
98
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
25 if (devsel_arg) { |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
26 dev = find_usbdev_by_desc_string(devsel_arg); |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
27 if (!dev) { |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
28 fprintf(stderr, |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
29 "error: specified USB device not found\n"); |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
30 exit(1); |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
31 } |
1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
32 } else { |
97
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 dev = find_usbdev_by_matchspec(&default_id); |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (!dev) { |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 fprintf(stderr, |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 "error: no default-ID CP2102 device found\n"); |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 exit(1); |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 } |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 return dev; |
8d35346f1d46
cp2102 tools: accept "default" as device-selector
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 } |