FreeCalypso > hg > freecalypso-hwlab
comparison lcdtest/main.c @ 23:2127e6fdeab2
lcdtest: simplify USB device selection by serial string
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 14 Apr 2018 06:32:41 +0000 |
parents | e9df47110181 |
children |
comparison
equal
deleted
inserted
replaced
22:e9df47110181 | 23:2127e6fdeab2 |
---|---|
2 #include <stdio.h> | 2 #include <stdio.h> |
3 #include <stdlib.h> | 3 #include <stdlib.h> |
4 #include <unistd.h> | 4 #include <unistd.h> |
5 #include <ftdi.h> | 5 #include <ftdi.h> |
6 | 6 |
7 char *device_selector = "i:0x0403:0x7157"; | 7 char *device_serial; |
8 struct ftdi_context ftdi; | 8 struct ftdi_context ftdi; |
9 | 9 |
10 process_cmdline(argc, argv) | 10 process_cmdline(argc, argv) |
11 char **argv; | 11 char **argv; |
12 { | 12 { |
14 extern char *optarg; | 14 extern char *optarg; |
15 | 15 |
16 while ((c = getopt(argc, argv, "d:")) != EOF) { | 16 while ((c = getopt(argc, argv, "d:")) != EOF) { |
17 switch (c) { | 17 switch (c) { |
18 case 'd': | 18 case 'd': |
19 device_selector = optarg; | 19 device_serial = optarg; |
20 continue; | 20 continue; |
21 default: | 21 default: |
22 /* error msg already printed */ | 22 /* error msg already printed */ |
23 exit(1); | 23 exit(1); |
24 } | 24 } |
43 { | 43 { |
44 char command[512]; | 44 char command[512]; |
45 | 45 |
46 process_cmdline(argc, argv); | 46 process_cmdline(argc, argv); |
47 ftdi_init(&ftdi); | 47 ftdi_init(&ftdi); |
48 if (ftdi_usb_open_string(&ftdi, device_selector) < 0) { | 48 if (ftdi_usb_open_desc(&ftdi, 0x0403, 0x7157, 0, device_serial) < 0) { |
49 fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str); | 49 fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str); |
50 exit(1); | 50 exit(1); |
51 } | 51 } |
52 if (ftdi_set_bitmode(&ftdi, 0, BITMODE_MCU) < 0) { | 52 if (ftdi_set_bitmode(&ftdi, 0, BITMODE_MCU) < 0) { |
53 fprintf(stderr, "unable to enter MCU mode: %s\n", | 53 fprintf(stderr, "unable to enter MCU mode: %s\n", |