view lcdtest/busops.c @ 23:2127e6fdeab2

lcdtest: simplify USB device selection by serial string
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 14 Apr 2018 06:32:41 +0000
parents 5a602e512b12
children 4b7cac119fb5
line wrap: on
line source

#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);
}