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