changeset 12:5eaf832d57d0

lcdtest program started, skeleton compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 06 Apr 2018 06:15:11 +0000
parents 03017bfeb3ce
children 238a77db4134
files .hgignore doc/LCD-test-wiring lcdtest/Makefile lcdtest/busops.c lcdtest/commands.c lcdtest/dispatch.c lcdtest/main.c
diffstat 7 files changed, 246 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Apr 06 02:07:04 2018 +0000
+++ b/.hgignore	Fri Apr 06 06:15:11 2018 +0000
@@ -5,3 +5,5 @@
 ^ee2232/ee2232-gen$
 ^ee2232/ee2232-prog$
 ^ee2232/ee2232-read$
+
+^lcdtest/lcdtest$
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/LCD-test-wiring	Fri Apr 06 06:15:11 2018 +0000
@@ -0,0 +1,4 @@
+Our LCD test program is written assuming the following GPIO wiring:
+
+I/O0 (ACBUS0) is wired to the register select pin
+I/O1 (ACBUS1) is wired to the reset pin
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lcdtest/Makefile	Fri Apr 06 06:15:11 2018 +0000
@@ -0,0 +1,12 @@
+CC=	gcc
+CFLAGS=	-O2
+PROG=	lcdtest
+OBJS=	busops.o commands.o dispatch.o main.o
+
+all:	${PROG}
+
+${PROG}:	${OBJS}
+	${CC} -o $@ ${OBJS} -lftdi
+
+clean:
+	rm -f ${PROG} *.o *errs *.out
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lcdtest/busops.c	Fri Apr 06 06:15:11 2018 +0000
@@ -0,0 +1,74 @@
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <ftdi.h>
+
+extern struct ftdi_context ftdi;
+
+do_ftdi_write(cmd, cmdlen)
+	u_char *cmd;
+{
+	if (ftdi_write_data(&ftdi, cmd, cmdlen) != cmdlen) {
+		fprintf(stderr, "FTDI write error: %s\n", ftdi.error_str);
+		exit(1);
+	}
+}
+
+set_gpio_pins(rs, reset)
+{
+	u_char cmd[3];
+
+	cmd[0] = 0x82;
+	cmd[1] = (rs ? 1 : 0) | (reset ? 2 : 0);
+	cmd[2] = 0x03;
+	do_ftdi_write(cmd, 3);
+}
+
+reset_pulse()
+{
+	set_gpio_pins(0, 0);
+	usleep(50000);
+	set_gpio_pins(0, 1);
+	return(0);
+}
+
+write_ir(val16)
+	unsigned val16;
+{
+	u_char cmd[9];
+
+	/* set RS low */
+	cmd[0] = 0x82;
+	cmd[1] = 0x02;
+	cmd[2] = 0x03;
+	/* write upper byte */
+	cmd[3] = 0x92;
+	cmd[4] = 0;	/* dummy addr */
+	cmd[5] = val16 >> 8;
+	/* write lower byte */
+	cmd[6] = 0x92;
+	cmd[7] = 0;	/* dummy addr */
+	cmd[8] = val16;
+	do_ftdi_write(cmd, 9);
+}
+
+write_dr(val16)
+	unsigned val16;
+{
+	u_char cmd[9];
+
+	/* set RS high */
+	cmd[0] = 0x82;
+	cmd[1] = 0x03;
+	cmd[2] = 0x03;
+	/* write upper byte */
+	cmd[3] = 0x92;
+	cmd[4] = 0;	/* dummy addr */
+	cmd[5] = val16 >> 8;
+	/* write lower byte */
+	cmd[6] = 0x92;
+	cmd[7] = 0;	/* dummy addr */
+	cmd[8] = val16;
+	do_ftdi_write(cmd, 9);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lcdtest/commands.c	Fri Apr 06 06:15:11 2018 +0000
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+cmd_wi(argc, argv)
+	char **argv;
+{
+	write_ir(strtoul(argv[1], 0, 16));
+	return(0);
+}
+
+cmd_wd(argc, argv)
+	char **argv;
+{
+	write_dr(strtoul(argv[1], 0, 16));
+	return(0);
+}
+
+cmd_wr(argc, argv)
+	char **argv;
+{
+	write_ir(strtoul(argv[1], 0, 16));
+	write_dr(strtoul(argv[2], 0, 16));
+	return(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lcdtest/dispatch.c	Fri Apr 06 06:15:11 2018 +0000
@@ -0,0 +1,77 @@
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+
+extern int cmd_wd();
+extern int cmd_wi();
+extern int cmd_wr();
+
+extern int reset_pulse();
+
+cmd_exit()
+{
+	exit(0);
+}
+
+static struct cmdtab {
+	char *cmd;
+	int minargs;
+	int maxargs;
+	int (*func)();
+} cmdtab[] = {
+	{"exit", 0, 0, cmd_exit},
+	{"quit", 0, 0, cmd_exit},
+	{"reset", 0, 0, reset_pulse},
+	{"wd", 1, 1, cmd_wd},
+	{"wi", 1, 1, cmd_wi},
+	{"wr", 2, 2, cmd_wr},
+	{0, 0, 0, 0}
+};
+
+dispatch_cmd(cmd)
+	char *cmd;
+{
+	char *argv[10];
+	char *cp, **ap;
+	struct cmdtab *tp;
+
+	for (cp = cmd; isspace(*cp); cp++)
+		;
+	if (!*cp || *cp == '#')
+		return(0);
+	argv[0] = cp;
+	while (*cp && !isspace(*cp))
+		cp++;
+	if (*cp)
+		*cp++ = '\0';
+	for (tp = cmdtab; tp->cmd; tp++)
+		if (!strcmp(tp->cmd, argv[0]))
+			break;
+	if (!tp->func) {
+		fprintf(stderr, "error: no such command\n");
+		return(-1);
+	}
+	for (ap = argv + 1; ; ) {
+		while (isspace(*cp))
+			cp++;
+		if (!*cp || *cp == '#')
+			break;
+		if (ap - argv - 1 >= tp->maxargs) {
+			fprintf(stderr, "error: too many arguments\n");
+			return(-1);
+		}
+		*ap++ = cp;
+		while (*cp && !isspace(*cp))
+			cp++;
+		if (*cp)
+			*cp++ = '\0';
+	}
+	if (ap - argv - 1 < tp->minargs) {
+		fprintf(stderr, "error: too few arguments\n");
+		return(-1);
+	}
+	*ap = 0;
+	return tp->func(ap - argv, argv);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lcdtest/main.c	Fri Apr 06 06:15:11 2018 +0000
@@ -0,0 +1,53 @@
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <ftdi.h>
+
+char *device_selector = "i:0x0403:0x6010";
+struct ftdi_context ftdi;
+
+process_cmdline(argc, argv)
+	char **argv;
+{
+	int c;
+	extern char *optarg;
+
+	while ((c = getopt(argc, argv, "d:")) != EOF) {
+		switch (c) {
+		case 'd':
+			device_selector = optarg;
+			continue;
+		default:
+			/* error msg already printed */
+			exit(1);
+		}
+	}
+}
+
+main(argc, argv)
+	char **argv;
+{
+	char command[512];
+
+	process_cmdline(argc, argv);
+	ftdi_init(&ftdi);
+	if (ftdi_usb_open_string(&ftdi, device_selector) < 0) {
+		fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str);
+		exit(1);
+	}
+	if (ftdi_set_bitmode(&ftdi, 0, BITMODE_MCU) < 0) {
+		fprintf(stderr, "unable to enter MCU mode: %s\n",
+			ftdi.error_str);
+		exit(1);
+	}
+	for (;;) {
+		if (isatty(0)) {
+			fputs("lcdtest> ", stdout);
+			fflush(stdout);
+		}
+		if (!fgets(command, sizeof command, stdin))
+			exit(0);
+		dispatch_cmd(command);
+	}
+}