FreeCalypso > hg > fc-usbser-tools
comparison cp2102/read_partno.c @ 50:a5c4a82d01ab
cp2102-read-partno program written, compiles
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Mon, 11 Sep 2023 17:41:24 +0000 |
| parents | |
| children | 9a15eb300ab0 |
comparison
equal
deleted
inserted
replaced
| 49:9ca4f9fa415b | 50:a5c4a82d01ab |
|---|---|
| 1 /* | |
| 2 * This program locates a presumed-CP2102 device via libusb and reads its | |
| 3 * vendor-specific part number register, seeking to distinguish between | |
| 4 * the original CP2102 and the later CP2102N. | |
| 5 */ | |
| 6 | |
| 7 #include <sys/types.h> | |
| 8 #include <string.h> | |
| 9 #include <strings.h> | |
| 10 #include <stdio.h> | |
| 11 #include <stdlib.h> | |
| 12 #include <unistd.h> | |
| 13 #include <usb.h> | |
| 14 #include "../libuwrap/find_dev.h" | |
| 15 #include "cp210x_defs.h" | |
| 16 | |
| 17 main(argc, argv) | |
| 18 char **argv; | |
| 19 { | |
| 20 struct usb_device *dev; | |
| 21 usb_dev_handle *usbh; | |
| 22 u_char partno; | |
| 23 int rc; | |
| 24 | |
| 25 if (argc != 2) { | |
| 26 fprintf(stderr, "usage: %s device-selector\n", argv[0]); | |
| 27 exit(1); | |
| 28 } | |
| 29 dev = find_usbdev_by_desc_string(argv[1]); | |
| 30 if (!dev) { | |
| 31 fprintf(stderr, "error: specified USB device not found\n"); | |
| 32 exit(1); | |
| 33 } | |
| 34 usbh = usb_open(dev); | |
| 35 if (!usbh) { | |
| 36 fprintf(stderr, "error: usb_open() failed\n"); | |
| 37 exit(1); | |
| 38 } | |
| 39 rc = usb_control_msg(usbh, DEVICE_IN_REQTYPE, CP210x_CONFIG, 0, | |
| 40 REG_PART_NUMBER, (char *) &partno, 1, | |
| 41 USB_READ_TIMEOUT); | |
| 42 if (rc != 1) { | |
| 43 fprintf(stderr, | |
| 44 "REG_PART_NUMBER read error: usb_control_msg() returned %d\n", | |
| 45 rc); | |
| 46 exit(1); | |
| 47 } | |
| 48 usb_close(usbh); | |
| 49 printf("0x%02X\n", partno); | |
| 50 exit(0); | |
| 51 } |
