comparison lcdtest/main.c @ 12:5eaf832d57d0

lcdtest program started, skeleton compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 06 Apr 2018 06:15:11 +0000
parents
children 4194b6744890
comparison
equal deleted inserted replaced
11:03017bfeb3ce 12:5eaf832d57d0
1 #include <sys/types.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <ftdi.h>
6
7 char *device_selector = "i:0x0403:0x6010";
8 struct ftdi_context ftdi;
9
10 process_cmdline(argc, argv)
11 char **argv;
12 {
13 int c;
14 extern char *optarg;
15
16 while ((c = getopt(argc, argv, "d:")) != EOF) {
17 switch (c) {
18 case 'd':
19 device_selector = optarg;
20 continue;
21 default:
22 /* error msg already printed */
23 exit(1);
24 }
25 }
26 }
27
28 main(argc, argv)
29 char **argv;
30 {
31 char command[512];
32
33 process_cmdline(argc, argv);
34 ftdi_init(&ftdi);
35 if (ftdi_usb_open_string(&ftdi, device_selector) < 0) {
36 fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str);
37 exit(1);
38 }
39 if (ftdi_set_bitmode(&ftdi, 0, BITMODE_MCU) < 0) {
40 fprintf(stderr, "unable to enter MCU mode: %s\n",
41 ftdi.error_str);
42 exit(1);
43 }
44 for (;;) {
45 if (isatty(0)) {
46 fputs("lcdtest> ", stdout);
47 fflush(stdout);
48 }
49 if (!fgets(command, sizeof command, stdin))
50 exit(0);
51 dispatch_cmd(command);
52 }
53 }