changeset 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 238a77db4134
children 4194b6744890
files lcdtest/Makefile lcdtest/busops.c lcdtest/commands.c lcdtest/dispatch.c lcdtest/readops.c
diffstat 5 files changed, 59 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/lcdtest/Makefile	Fri Apr 06 06:43:02 2018 +0000
+++ b/lcdtest/Makefile	Sat Apr 07 01:19:14 2018 +0000
@@ -1,7 +1,7 @@
 CC=	gcc
 CFLAGS=	-O2
 PROG=	lcdtest
-OBJS=	busops.o commands.o dispatch.o main.o
+OBJS=	busops.o commands.o dispatch.o main.o readops.o
 
 all:	${PROG}
 
--- a/lcdtest/busops.c	Fri Apr 06 06:43:02 2018 +0000
+++ b/lcdtest/busops.c	Sat Apr 07 01:19:14 2018 +0000
@@ -72,27 +72,3 @@
 	cmd[8] = val16;
 	do_ftdi_write(cmd, 9);
 }
-
-bus_read(rs)
-{
-	u_char cmd[8], resp[2];
-
-	/* set RS */
-	cmd[0] = 0x82;
-	cmd[1] = rs ? 0x03 : 0x02;
-	cmd[2] = 0x03;
-	/* read upper byte */
-	cmd[3] = 0x90;
-	cmd[4] = 0;	/* dummy addr */
-	/* read lower byte */
-	cmd[5] = 0x90;
-	cmd[6] = 0;	/* dummy addr */
-	/* send immediate */
-	cmd[7] = 0x87;
-	do_ftdi_write(cmd, 8);
-	if (ftdi_read_data(&ftdi, resp, 2) != 2) {
-		fprintf(stderr, "FTDI read error: %s\n", ftdi.error_str);
-		exit(1);
-	}
-	return (resp[0] << 8) | resp[1];
-}
--- a/lcdtest/commands.c	Fri Apr 06 06:43:02 2018 +0000
+++ b/lcdtest/commands.c	Sat Apr 07 01:19:14 2018 +0000
@@ -1,18 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-cmd_ri()
-{
-	printf("%04X\n", bus_read(0));
-	return(0);
-}
-
-cmd_rd()
-{
-	printf("%04X\n", bus_read(1));
-	return(0);
-}
-
 cmd_wi(argc, argv)
 	char **argv;
 {
--- a/lcdtest/dispatch.c	Fri Apr 06 06:43:02 2018 +0000
+++ b/lcdtest/dispatch.c	Sat Apr 07 01:19:14 2018 +0000
@@ -4,6 +4,7 @@
 #include <strings.h>
 #include <stdlib.h>
 
+extern int cmd_fr();
 extern int cmd_rd();
 extern int cmd_ri();
 extern int cmd_wd();
@@ -24,6 +25,7 @@
 	int (*func)();
 } cmdtab[] = {
 	{"exit", 0, 0, cmd_exit},
+	{"fr", 1, 1, cmd_fr},
 	{"quit", 0, 0, cmd_exit},
 	{"rd", 0, 0, cmd_rd},
 	{"reset", 0, 0, reset_pulse},
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lcdtest/readops.c	Sat Apr 07 01:19:14 2018 +0000
@@ -0,0 +1,56 @@
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <ftdi.h>
+
+extern struct ftdi_context ftdi;
+
+read_command(rs)
+{
+	u_char cmd[8];
+
+	/* set RS */
+	cmd[0] = 0x82;
+	cmd[1] = rs ? 0x03 : 0x02;
+	cmd[2] = 0x03;
+	/* read upper byte */
+	cmd[3] = 0x90;
+	cmd[4] = 0;	/* dummy addr */
+	/* read lower byte */
+	cmd[5] = 0x90;
+	cmd[6] = 0;	/* dummy addr */
+	/* send immediate */
+	cmd[7] = 0x87;
+	do_ftdi_write(cmd, 8);
+}
+
+cmd_ri()
+{
+	read_command(0);
+	return(0);
+}
+
+cmd_rd()
+{
+	read_command(1);
+	return(0);
+}
+
+cmd_fr(argc, argv)
+	char **argv;
+{
+	unsigned reqlen = strtoul(argv[1], 0, 0);
+	u_char rdbuf[256];
+	int rc, i;
+
+	if (reqlen < 1 || reqlen > sizeof rdbuf) {
+		printf("error: bad read request length\n");
+		return(-1);
+	}
+	rc = ftdi_read_data(&ftdi, rdbuf, reqlen);
+	printf("FTDI read returned %d\n", rc);
+	for (i = 0; i < rc; i++)
+		printf("read byte: %02X\n", rdbuf[i]);
+	return(0);
+}