FreeCalypso > hg > fc-usbser-tools
comparison cp2102/read_eeprom_main.c @ 53:d4d3531d342a
cp2102-read-eeprom program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 11 Sep 2023 18:49:07 +0000 |
parents | |
children | a378bf95c26c |
comparison
equal
deleted
inserted
replaced
52:61cdcf2eb17b | 53:d4d3531d342a |
---|---|
1 /* | |
2 * This program locates a CP2102 device via libusb, reads its internal | |
3 * 1024-byte EEPROM and emits (on stdout) an image of this EEPROM | |
4 * in the same Intel HEX format as used by cp210x-program-1.0, | |
5 * the Python-language tool from 2014. | |
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 #include "cp210x_defs.h" | |
17 | |
18 u_char eeprom[SIZE_EEPROM]; | |
19 | |
20 main(argc, argv) | |
21 char **argv; | |
22 { | |
23 struct usb_device *dev; | |
24 usb_dev_handle *usbh; | |
25 | |
26 if (argc != 2) { | |
27 fprintf(stderr, "usage: %s device-selector\n", argv[0]); | |
28 exit(1); | |
29 } | |
30 dev = find_usbdev_by_desc_string(argv[1]); | |
31 if (!dev) { | |
32 fprintf(stderr, "error: specified USB device not found\n"); | |
33 exit(1); | |
34 } | |
35 usbh = usb_open(dev); | |
36 if (!usbh) { | |
37 fprintf(stderr, "error: usb_open() failed\n"); | |
38 exit(1); | |
39 } | |
40 read_eeprom(usbh); | |
41 usb_close(usbh); | |
42 intel_hex_out(eeprom, stdout); | |
43 exit(0); | |
44 } |