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