view target-utils/c139explore/lcd.c @ 950:cd34e0d534b9

c139explore: LCD output implemented, does not work
author Mychaela Falconia <falcon@ivan.Harhan.ORG>
date Wed, 04 Nov 2015 01:43:44 +0000
parents
children eb27543ce18e
line wrap: on
line source

#include <sys/types.h>
#include "types.h"

static void
send_cmd_data(cmdbyte, databyte)
{
	send_via_uwire(cmdbyte);
	send_via_uwire(databyte | 0x100);
}

void
cmd_lcdinit()
{
	/* from OsmocomBB */
	send_cmd_data(0x3F, 0x01);
	send_cmd_data(0x20, 0x03);
	send_cmd_data(0x31, 0x03);
}

static void
set_lcd_addr_region(xstart, xend, ystart, yend)
{
	send_cmd_data(0x10, xstart);
	send_cmd_data(0x11, ystart);
	send_cmd_data(0x12, xend);
	send_cmd_data(0x13, yend);
	send_cmd_data(0x14, xstart);
	send_cmd_data(0x15, ystart);
}

static void
send_pixel_value(pix)
{
	send_via_uwire((pix >> 8) | 0x100);
	send_via_uwire((pix & 0xFF) | 0x100);
}

void
cmd_lcdfill(argbulk)
	char *argbulk;
{
	int argc;
	char *argv[6];
	u_long pixval;
	int xstart, xend, ystart, yend;
	int npix;

	if (parse_args(argbulk, 1, 5, argv, &argc) < 0)
		return;
	if (parse_hexarg(argv[0], 4, &pixval) < 0) {
		printf("ERROR: arg1 must be a valid 16-bit hex value\n");
		return;
	}
	switch (argc) {
	case 1:
		xstart = ystart = 0;
		xend = 95;
		yend = 63;
		break;
	case 5:
		xstart = atoi(argv[1]);
		if (xstart < 0 || xstart > 95) {
range_err:		printf("ERROR: coordinate arg out of range\n");
			return;
		}
		xend = atoi(argv[2]);
		if (xend < 0 || xend > 95)
			goto range_err;
		ystart = atoi(argv[3]);
		if (ystart < 0 || ystart > 63)
			goto range_err;
		yend = atoi(argv[4]);
		if (yend < 0 || yend > 63)
			goto range_err;
		if (xend < xstart || yend < ystart) {
			printf("ERROR: negative range\n");
			return;
		}
		break;
	default:
		printf("ERROR: wrong number of arguments\n");
		return;
	}
	set_lcd_addr_region(xstart, xend, ystart, yend);
	npix = (xend + 1 - xstart) * (yend + 1 - ystart);
	while (npix--)
		send_pixel_value(pixval);
}