diff 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
line wrap: on
line diff
--- /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);
+}