FreeCalypso > hg > freecalypso-hwlab
annotate lcdtest/readops.c @ 106:66f04193a906
fc-simtool: pb-dump: forgot newline at the end of record
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 25 Jan 2021 06:03:58 +0000 |
parents | 5a602e512b12 |
children |
rev | line source |
---|---|
14
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h> |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <stdio.h> |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <stdlib.h> |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <unistd.h> |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <ftdi.h> |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 extern struct ftdi_context ftdi; |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 read_command(rs) |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 { |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 u_char cmd[8]; |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 /* set RS */ |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 cmd[0] = 0x82; |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 cmd[1] = rs ? 0x03 : 0x02; |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 cmd[2] = 0x03; |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 /* read upper byte */ |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 cmd[3] = 0x90; |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 cmd[4] = 0; /* dummy addr */ |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 /* read lower byte */ |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 cmd[5] = 0x90; |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 cmd[6] = 0; /* dummy addr */ |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 /* send immediate */ |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 cmd[7] = 0x87; |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 do_ftdi_write(cmd, 8); |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 } |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 cmd_ri() |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 { |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 read_command(0); |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 return(0); |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 } |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 cmd_rd() |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 { |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 read_command(1); |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 return(0); |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 } |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 cmd_fr(argc, argv) |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 char **argv; |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 { |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 unsigned reqlen = strtoul(argv[1], 0, 0); |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 u_char rdbuf[256]; |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 int rc, i; |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (reqlen < 1 || reqlen > sizeof rdbuf) { |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 printf("error: bad read request length\n"); |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 return(-1); |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 rc = ftdi_read_data(&ftdi, rdbuf, reqlen); |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 printf("FTDI read returned %d\n", rc); |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 for (i = 0; i < rc; i++) |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 printf("read byte: %02X\n", rdbuf[i]); |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 return(0); |
5a602e512b12
lcdtest: read ops split into command issuance and FTDI read
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } |