changeset 700:db9a8e88e63f

target-utils lunadrv program written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 07 May 2020 02:19:51 +0000
parents c354c261f635
children 39e7b3001946
files target-utils/lunadrv/Makefile target-utils/lunadrv/backlight.c target-utils/lunadrv/cmdtab.c target-utils/lunadrv/haoran.c target-utils/lunadrv/lcdout.c target-utils/lunadrv/luna.h target-utils/lunadrv/main.c
diffstat 7 files changed, 299 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/lunadrv/Makefile	Thu May 07 02:19:51 2020 +0000
@@ -0,0 +1,29 @@
+CC=	arm-elf-gcc
+CFLAGS=	-Os -fno-builtin
+CPPFLAGS=-I../include
+LD=	arm-elf-ld
+OBJCOPY=arm-elf-objcopy
+
+PROG=	lunadrv
+OBJS=	crt0.o backlight.o cmdtab.o haoran.o lcdout.o main.o
+LIBS=	../libcommon/libcommon.a ../libprintf/libprintf.a ../libbase/libbase.a \
+	../libc/libc.a
+LIBGCC=	`${CC} -print-file-name=libgcc.a`
+LDS=	../env/iram.lds
+
+all:	${PROG}.srec
+
+crt0.S:
+	ln -s ../env/crt0.S .
+
+${PROG}.elf:	${OBJS} ${LIBS} ${LDS}
+	${LD} -N --defsym Base_addr=0x800750 --defsym stack_bottom=0x83FFFC \
+		-T ${LDS} -o $@ ${OBJS} ${LIBS} ${LIBGCC}
+
+${PROG}.srec:	${PROG}.elf
+	${OBJCOPY} -O srec --srec-forceS3 --srec-len=30 $< $@
+
+clean:
+	rm -f *.o *errs *core *.elf *.bin *.srec crt0.S
+
+FRC:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/lunadrv/backlight.c	Thu May 07 02:19:51 2020 +0000
@@ -0,0 +1,22 @@
+#include <sys/types.h>
+#include <strings.h>
+#include "types.h"
+
+#define	GPIO_OUT_REG		(*(volatile u16 *) 0xfffe4802)
+#define	BACKLIGHT_GPIO_MASK	0x0200
+
+void
+cmd_dbl(argbulk)
+	char *argbulk;
+{
+	char *argv[2];
+
+	if (parse_args(argbulk, 1, 1, argv, 0) < 0)
+		return;
+	if (!strcmp(argv[0], "on"))
+		GPIO_OUT_REG |= BACKLIGHT_GPIO_MASK;
+	else if (!strcmp(argv[0], "off"))
+		GPIO_OUT_REG &= ~BACKLIGHT_GPIO_MASK;
+	else
+		printf("ERROR: \"on\" or \"off\" argument expected\n");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/lunadrv/cmdtab.c	Thu May 07 02:19:51 2020 +0000
@@ -0,0 +1,46 @@
+#include "cmdtab.h"
+
+extern void cmd_abbr();
+extern void cmd_abbw();
+extern void cmd_baud_switch();
+extern void cmd_dbl();
+extern void cmd_fill();
+extern void cmd_jump();
+extern void cmd_mem2lcd();
+extern void cmd_r8();
+extern void cmd_r16();
+extern void cmd_r32();
+extern void cmd_rect();
+extern void cmd_w8();
+extern void cmd_w16();
+extern void cmd_w32();
+
+extern void abb_init();
+extern void abb_power_off();
+extern void abb_unlock_page2();
+extern void cmd_memdump_human();
+
+extern void init_haoran();
+
+const struct cmdtab cmdtab[] = {
+	{"abbinit", abb_init},
+	{"abbpage2", abb_unlock_page2},
+	{"abbr", cmd_abbr},
+	{"abbw", cmd_abbw},
+	{"baud", cmd_baud_switch},
+	{"dbl", cmd_dbl},
+	{"dump", cmd_memdump_human},
+	{"fill", cmd_fill},
+	{"init-ht", init_haoran},
+	{"jump", cmd_jump},
+	{"mem2lcd", cmd_mem2lcd},
+	{"poweroff", abb_power_off},
+	{"r8", cmd_r8},
+	{"r16", cmd_r16},
+	{"r32", cmd_r32},
+	{"rect", cmd_rect},
+	{"w8", cmd_w8},
+	{"w16", cmd_w16},
+	{"w32", cmd_w32},
+	{0, 0}
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/lunadrv/haoran.c	Thu May 07 02:19:51 2020 +0000
@@ -0,0 +1,53 @@
+#include "types.h"
+#include "luna.h"
+
+/*
+ * ILI9225G register init for HaoRan HT020K1QC36S LCD.
+ */
+
+init_haoran()
+{
+	/* reset pulse */
+	CNTL_RST_REG |= EXT_RESET;
+	wait_ARM_cycles(DELAY_1MS * 10);
+	CNTL_RST_REG &= ~EXT_RESET;
+	wait_ARM_cycles(DELAY_1MS * 50);
+	/* start register init */
+	LCD_REG_WR(0x0001, 0x011c); // set SS and NL bit
+	LCD_REG_WR(0x0002, 0x0100); // set 1 line inversion
+	LCD_REG_WR(0x0003, 0x1030); // set GRAM write direction and BGR=1.
+	LCD_REG_WR(0x0008, 0x0808); // set BP and FP
+	LCD_REG_WR(0x000F, 0x0901); // Set frame rate
+	wait_ARM_cycles(DELAY_1MS * 10);
+	LCD_REG_WR(0x0010, 0x0000); // Set SAP,DSTB,STB
+	LCD_REG_WR(0x0011, 0x1B41); // Set APON,PON,AON,VCI1EN,VC
+	wait_ARM_cycles(DELAY_1MS * 50);
+	LCD_REG_WR(0x0012, 0x200E); // Internal reference voltage= Vci;
+	LCD_REG_WR(0x0013, 0x0052); // Set GVDD
+	LCD_REG_WR(0x0014, 0x4B5C); // Set VCOMH/VCOML voltage
+	//------------- Set GRAM area ------------------//
+	LCD_REG_WR(0x0030, 0x0000);
+	LCD_REG_WR(0x0031, 0x00DB);
+	LCD_REG_WR(0x0032, 0x0000);
+	LCD_REG_WR(0x0033, 0x0000);
+	LCD_REG_WR(0x0034, 0x00DB);
+	LCD_REG_WR(0x0035, 0x0000);
+	LCD_REG_WR(0x0036, 0x00AF);
+	LCD_REG_WR(0x0037, 0x0000);
+	LCD_REG_WR(0x0038, 0x00DB);
+	LCD_REG_WR(0x0039, 0x0000);
+	// ----------- Adjust the Gamma Curve ----------//
+	LCD_REG_WR(0x0050, 0x0000);
+	LCD_REG_WR(0x0051, 0x0705);
+	LCD_REG_WR(0x0052, 0x0C0A);
+	LCD_REG_WR(0x0053, 0x0401);
+	LCD_REG_WR(0x0054, 0x040C);
+	LCD_REG_WR(0x0055, 0x0608);
+	LCD_REG_WR(0x0056, 0x0000);
+	LCD_REG_WR(0x0057, 0x0104);
+	LCD_REG_WR(0x0058, 0x0E06);
+	LCD_REG_WR(0x0059, 0x060E);
+	wait_ARM_cycles(DELAY_1MS * 50);
+	LCD_REG_WR(0x0007, 0x1017);
+	return(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/lunadrv/lcdout.c	Thu May 07 02:19:51 2020 +0000
@@ -0,0 +1,106 @@
+/*
+ * Generic LCD output operations are implemented here.  All of the basic
+ * LCD controller registers needed for these operations are the same
+ * between ILI9225, ILI9225G and ST7775R controllers.
+ */
+
+#include <sys/types.h>
+#include "types.h"
+#include "luna.h"
+
+set_lcd_addr_region(xstart, xend, ystart, yend)
+{
+	/* set window area */
+	LCD_REG_WR(0x36, xend);
+	LCD_REG_WR(0x37, xstart);
+	LCD_REG_WR(0x38, yend);
+	LCD_REG_WR(0x39, ystart);
+	/* set current write address */
+	LCD_REG_WR(0x20, xstart);
+	LCD_REG_WR(0x21, ystart);
+	/* set up for GRAM write */
+	LCD_IR = 0x22;
+}
+
+void
+cmd_fill(argbulk)
+	char *argbulk;
+{
+	char *argv[2];
+	u_long pixval;
+	unsigned n;
+
+	if (parse_args(argbulk, 1, 1, argv, 0) < 0)
+		return;
+	if (parse_hexarg(argv[0], 4, &pixval) < 0) {
+		printf("ERROR: arg must be a valid 16-bit hex value\n");
+		return;
+	}
+	set_lcd_addr_region(0, 175, 0, 219);
+	for (n = 0; n < 176 * 220; n++)
+		LCD_DR = pixval;
+}
+
+void
+cmd_rect(argbulk)
+	char *argbulk;
+{
+	char *argv[6];
+	u_long pixval;
+	int xstart, xend, ystart, yend;
+	int npix;
+
+	if (parse_args(argbulk, 5, 5, argv, 0) < 0)
+		return;
+	xstart = atoi(argv[0]);
+	if (xstart < 0 || xstart > 175) {
+range_err:	printf("ERROR: coordinate arg out of range\n");
+		return;
+	}
+	xend = atoi(argv[1]);
+	if (xend < 0 || xend > 175)
+		goto range_err;
+	ystart = atoi(argv[2]);
+	if (ystart < 0 || ystart > 219)
+		goto range_err;
+	yend = atoi(argv[3]);
+	if (yend < 0 || yend > 219)
+		goto range_err;
+	if (xend < xstart || yend < ystart) {
+		printf("ERROR: negative range\n");
+		return;
+	}
+	if (parse_hexarg(argv[4], 4, &pixval) < 0) {
+		printf("ERROR: pixel arg must be a valid 16-bit hex value\n");
+		return;
+	}
+	set_lcd_addr_region(xstart, xend, ystart, yend);
+	npix = (xend + 1 - xstart) * (yend + 1 - ystart);
+	while (npix--)
+		LCD_DR = pixval;
+}
+
+void
+cmd_mem2lcd(argbulk)
+	char *argbulk;
+{
+	char *argv[2];
+	u_long addr;
+	const u16 *rdmem;
+	unsigned n;
+
+	if (parse_args(argbulk, 1, 1, argv, 0) < 0)
+		return;
+	if (parse_hexarg(argv[0], 8, &addr) < 0) {
+		printf("ERROR: argument must be a valid 32-bit hex address\n");
+		return;
+	}
+	if (addr & 1) {
+		printf("ERROR: unaligned address\n");
+		return;
+	}
+	rdmem = (const u16 *) addr;
+	set_lcd_addr_region(0, 175, 0, 219);
+	for (n = 0; n < 176 * 220; n++)
+		LCD_DR = *rdmem++;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/lunadrv/luna.h	Thu May 07 02:19:51 2020 +0000
@@ -0,0 +1,20 @@
+/*
+ * This header file provides definitions for the Luna LCD hardware interface.
+ */
+
+/* reset control */
+#define	CNTL_RST_REG	(*(volatile u16 *)0xFFFFFD04)
+#define	EXT_RESET	0x0004
+
+/* the LCD is connected to Calypso nCS3, with A1 line as register select */
+
+#define	LCD_IR		(*(volatile u16 *)0x02000000)
+#define	LCD_DR		(*(volatile u16 *)0x02000002)
+
+/* macro for writing first IR, then DR */
+
+#define	LCD_REG_WR(reg, data)	{LCD_IR = (reg); LCD_DR = (data);}
+
+/* some init operations call for controlled delays */
+
+#define	DELAY_1MS	13000
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/lunadrv/main.c	Thu May 07 02:19:51 2020 +0000
@@ -0,0 +1,23 @@
+#include "types.h"
+
+main()
+{
+	uart_select_init();
+	printf("Luna LCD driver utility running\n");
+	print_boot_rom_info();
+	/* Calypso MEMIF setup */
+	*(volatile u16 *)0xfffffb00 = 0x00A4;
+	*(volatile u16 *)0xfffffb02 = 0x00A4;
+	*(volatile u16 *)0xfffffb04 = 0x00A4;
+	*(volatile u16 *)0xfffffb06 = 0x02A5;
+	*(volatile u16 *)0xfffef006 = 0x0008;
+	/* GPIO setup for backlight control */
+	*(volatile u16 *)0xfffef00a = 0x01E0;
+	*(volatile u16 *)0xfffe4802 = 0x0200;
+	*(volatile u16 *)0xfffe4804 = 0xFDFF;
+	for (;;) {
+		putchar('=');
+		if (command_entry())
+			command_dispatch();
+	}
+}