FreeCalypso > hg > freecalypso-hwlab
annotate lcdtest/dispatch.c @ 56:d4357e6d6679
checking in some Calypso JTAG experiments
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 12 May 2019 04:11:30 +0000 |
parents | 0a44549a64c8 |
children |
rev | line source |
---|---|
12
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <ctype.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 <string.h> |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <strings.h> |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdlib.h> |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
19
f3671d3ad953
lcdtest: added cd command to avoid typing long pathnames for show
Mychaela Falconia <falcon@freecalypso.org>
parents:
17
diff
changeset
|
7 extern int cmd_cd(); |
16
1e94c7d4af03
lcdtest: raw FTDI command fc added
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
8 extern int cmd_fc(); |
14
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
9 extern int cmd_fr(); |
13
238a77db4134
lcdtest: read operations implemented, but don't work
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
10 extern int cmd_rd(); |
238a77db4134
lcdtest: read operations implemented, but don't work
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
11 extern int cmd_ri(); |
17
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
12 extern int cmd_show(); |
12
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern int cmd_wd(); |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern int cmd_wi(); |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern int cmd_wr(); |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 extern int reset_pulse(); |
25
0a44549a64c8
lcdtest: implemented ILI9225G register init for HT020K1QC36S
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
18 extern int init_haoran(); |
24
94521a02c33d
lcdtest: the truth about Startek and Crystalfontz LCDs
Mychaela Falconia <falcon@freecalypso.org>
parents:
20
diff
changeset
|
19 extern int init_startek(); |
12
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 cmd_exit() |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 { |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 exit(0); |
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 static struct cmdtab { |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 char *cmd; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 int minargs; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 int maxargs; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 int (*func)(); |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } cmdtab[] = { |
19
f3671d3ad953
lcdtest: added cd command to avoid typing long pathnames for show
Mychaela Falconia <falcon@freecalypso.org>
parents:
17
diff
changeset
|
32 {"cd", 1, 1, cmd_cd}, |
12
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 {"exit", 0, 0, cmd_exit}, |
16
1e94c7d4af03
lcdtest: raw FTDI command fc added
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
34 {"fc", 1, 16, cmd_fc}, |
14
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
13
diff
changeset
|
35 {"fr", 1, 1, cmd_fr}, |
25
0a44549a64c8
lcdtest: implemented ILI9225G register init for HT020K1QC36S
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
36 {"init-ht", 0, 0, init_haoran}, |
24
94521a02c33d
lcdtest: the truth about Startek and Crystalfontz LCDs
Mychaela Falconia <falcon@freecalypso.org>
parents:
20
diff
changeset
|
37 {"init-st", 0, 0, init_startek}, |
12
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 {"quit", 0, 0, cmd_exit}, |
13
238a77db4134
lcdtest: read operations implemented, but don't work
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
39 {"rd", 0, 0, cmd_rd}, |
12
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 {"reset", 0, 0, reset_pulse}, |
13
238a77db4134
lcdtest: read operations implemented, but don't work
Mychaela Falconia <falcon@freecalypso.org>
parents:
12
diff
changeset
|
41 {"ri", 0, 0, cmd_ri}, |
17
43cc53581975
lcdtest: PPM image display implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
42 {"show", 1, 1, cmd_show}, |
12
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 {"wd", 1, 1, cmd_wd}, |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 {"wi", 1, 1, cmd_wi}, |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 {"wr", 2, 2, cmd_wr}, |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 {0, 0, 0, 0} |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 }; |
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 dispatch_cmd(cmd) |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 char *cmd; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 { |
16
1e94c7d4af03
lcdtest: raw FTDI command fc added
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
52 char *argv[18]; |
12
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 char *cp, **ap; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 struct cmdtab *tp; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 for (cp = cmd; isspace(*cp); cp++) |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 ; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 if (!*cp || *cp == '#') |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 return(0); |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 argv[0] = cp; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 while (*cp && !isspace(*cp)) |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 cp++; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (*cp) |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 *cp++ = '\0'; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 for (tp = cmdtab; tp->cmd; tp++) |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (!strcmp(tp->cmd, argv[0])) |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 break; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 if (!tp->func) { |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 fprintf(stderr, "error: no such command\n"); |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 return(-1); |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 } |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 for (ap = argv + 1; ; ) { |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 while (isspace(*cp)) |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 cp++; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 if (!*cp || *cp == '#') |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 break; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (ap - argv - 1 >= tp->maxargs) { |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 fprintf(stderr, "error: too many arguments\n"); |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 return(-1); |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 *ap++ = cp; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 while (*cp && !isspace(*cp)) |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 cp++; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 if (*cp) |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 *cp++ = '\0'; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 if (ap - argv - 1 < tp->minargs) { |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 fprintf(stderr, "error: too few arguments\n"); |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 return(-1); |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 } |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 *ap = 0; |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 return tp->func(ap - argv, argv); |
5eaf832d57d0
lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 } |