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