comparison ee2232/ee2232-read.c @ 3:ef43bbfa8d16

ee2232-read program written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 05 Apr 2018 21:48:05 +0000
parents
children
comparison
equal deleted inserted replaced
2:252e3d37b9e5 3:ef43bbfa8d16
1 #include <sys/types.h>
2 #include <string.h>
3 #include <strings.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <ftdi.h>
8
9 char *device_selector = "i:0x0403:0x6010";
10 unsigned eeprom_size = 64;
11
12 process_cmdline(argc, argv)
13 char **argv;
14 {
15 int c;
16 extern char *optarg;
17
18 while ((c = getopt(argc, argv, "d:t:")) != EOF) {
19 switch (c) {
20 case 'd':
21 device_selector = optarg;
22 continue;
23 case 't':
24 if (!strcmp(optarg, "46"))
25 eeprom_size = 64;
26 else if (!strcmp(optarg, "56"))
27 eeprom_size = 128;
28 else if (!strcmp(optarg, "66"))
29 eeprom_size = 256;
30 else {
31 fprintf(stderr,
32 "error: -t option invalid value \"%s\"\n",
33 optarg);
34 exit(1);
35 }
36 continue;
37 default:
38 /* error msg already printed */
39 exit(1);
40 }
41 }
42 }
43
44 main(argc, argv)
45 char **argv;
46 {
47 struct ftdi_context ftdi;
48 u_short word;
49 unsigned n, col;
50
51 process_cmdline(argc, argv);
52 ftdi_init(&ftdi);
53 if (ftdi_usb_open_string(&ftdi, device_selector) < 0) {
54 fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str);
55 exit(1);
56 }
57 for (n = 0; n < eeprom_size; n++) {
58 if (ftdi_read_eeprom_location(&ftdi, n, &word) < 0) {
59 fprintf(stderr, "EEPROM read error: %s\n",
60 ftdi.error_str);
61 exit(1);
62 }
63 col = n & 7;
64 if (col == 0)
65 printf("%02X:", n * 2);
66 printf(" %04X", word);
67 if (col == 7)
68 putchar('\n');
69 }
70 ftdi_usb_close(&ftdi);
71 exit(0);
72 }