view lcdtest/phonemain.c @ 32:60b8cf977c3f

unbuffered JTAG adapters: ID assigned and EEPROM config created
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 Apr 2019 06:27:11 +0000
parents 60bcd401363a
children
line wrap: on
line source

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <ftdi.h>
#include <rvinterf/etm.h>
#include <rvinterf/localtypes.h>
#include "exitcodes.h"

extern int init_haoran();
extern int init_startek();

extern char *socket_pathname;

char *device_serial, *display_type;
struct ftdi_context ftdi;
int (*lcd_init_func)();
u32 framebuffer_base_addr;

process_cmdline(argc, argv)
	char **argv;
{
	int c;
	extern int optind;
	extern char *optarg;

	while ((c = getopt(argc, argv, "d:s:")) != EOF) {
		switch (c) {
		case 'd':
			device_serial = optarg;
			continue;
		case 's':
			socket_pathname = optarg;
			continue;
		default:
			/* error msg already printed */
			exit(ERROR_USAGE);
		}
	}
	if (argc != optind + 2) {
		fprintf(stderr,
		"usage: %s [options] display_type framebuffer_base_addr\n",
			argv[0]);
		exit(ERROR_USAGE);
	}
	display_type = argv[optind];
	if (!strcmp(display_type, "haoran"))
		lcd_init_func = init_haoran;
	else if (!strcmp(display_type, "startek"))
		lcd_init_func = init_startek;
	else {
		fprintf(stderr, "error: display type \"%s\" unknown\n",
			display_type);
		exit(ERROR_USAGE);
	}
	framebuffer_base_addr = strtoul(argv[optind+1], 0, 16);
}

ftdi_setup()
{
	ftdi_init(&ftdi);
	if (ftdi_usb_open_desc(&ftdi, 0x0403, 0x7157, 0, device_serial) < 0) {
		fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str);
		exit(ERROR_FTDI);
	}
	if (ftdi_set_bitmode(&ftdi, 0, BITMODE_MCU) < 0) {
		fprintf(stderr, "unable to enter MCU mode: %s\n",
			ftdi.error_str);
		exit(ERROR_FTDI);
	}
}

lcd_init()
{
	reset_pulse();
	usleep(50000);
	lcd_init_func();
	usleep(50000);
	write_ir(0x20);
	write_dr(0);
	write_ir(0x21);
	write_dr(0);
	write_ir(0x22);
	set_gpio_pins(1, 1);
}

fb_poll()
{
	unsigned row, col;
	u_char membuf[176*2], *sp;
	u_char ftbuf[176*6], *dp;
	int rc;

	for (row = 0; row < 220; row++) {
		rc = do_memory_read_32(framebuffer_base_addr + row * 356,
					membuf, 44);
		if (rc)
			exit(rc);
		rc = do_memory_read_32(framebuffer_base_addr + row * 356 + 176,
					membuf + 176, 44);
		if (rc)
			exit(rc);
		sp = membuf;
		dp = ftbuf;
		for (col = 0; col < 176; col++) {
			/* upper byte */
			*dp++ = 0x92;
			*dp++ = 0;	/* dummy addr */
			*dp++ = sp[1] ^ 0xFF;
			/* lower byte */
			*dp++ = 0x92;
			*dp++ = 0;	/* dummy addr */
			*dp++ = sp[0] ^ 0xFF;
			sp += 2;
		}
		do_ftdi_write(ftbuf, sizeof ftbuf);
	}
}

main(argc, argv)
	char **argv;
{
	process_cmdline(argc, argv);
	ftdi_setup();
	connect_local_socket();
	lcd_init();

	for (;;)
		fb_poll();
}