changeset 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 df1dccc0ef9c
children eb27543ce18e
files target-utils/c139explore/Makefile target-utils/c139explore/cmdtab.c target-utils/c139explore/lcd.c target-utils/c139explore/main.c target-utils/c139explore/uwire.c
diffstat 5 files changed, 186 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/target-utils/c139explore/Makefile	Wed Nov 04 00:46:36 2015 +0000
+++ b/target-utils/c139explore/Makefile	Wed Nov 04 01:43:44 2015 +0000
@@ -5,7 +5,7 @@
 OBJCOPY=arm-elf-objcopy
 
 PROG=	c139explore
-OBJS=	crt0.o backlight.o cmdtab.o main.o mygetchar.o
+OBJS=	crt0.o backlight.o cmdtab.o lcd.o main.o mygetchar.o uwire.o
 LIBS=	../libcommon/libcommon.a ../libprintf/libprintf.a
 LDS=	../env/compalram.lds
 
--- a/target-utils/c139explore/cmdtab.c	Wed Nov 04 00:46:36 2015 +0000
+++ b/target-utils/c139explore/cmdtab.c	Wed Nov 04 01:43:44 2015 +0000
@@ -4,6 +4,8 @@
 extern void cmd_abbw();
 extern void cmd_dbl();
 extern void cmd_kpbl();
+extern void cmd_lcdfill();
+extern void cmd_lcdinit();
 extern void cmd_r8();
 extern void cmd_r16();
 extern void cmd_r32();
@@ -20,6 +22,8 @@
 	{"abbw", cmd_abbw},
 	{"dbl", cmd_dbl},
 	{"kpbl", cmd_kpbl},
+	{"lcdfill", cmd_lcdfill},
+	{"lcdinit", cmd_lcdinit},
 	{"poweroff", abb_power_off},
 	{"r8", cmd_r8},
 	{"r16", cmd_r16},
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/c139explore/lcd.c	Wed Nov 04 01:43:44 2015 +0000
@@ -0,0 +1,88 @@
+#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);
+}
--- a/target-utils/c139explore/main.c	Wed Nov 04 00:46:36 2015 +0000
+++ b/target-utils/c139explore/main.c	Wed Nov 04 01:43:44 2015 +0000
@@ -13,6 +13,7 @@
 	*(volatile u16 *)0xfffe4802 = 0x0002;
 	*(volatile u16 *)0xfffe4804 = 0xFFF5;
 	abb_init();
+	uwire_init();
 	for (;;) {
 		putchar('=');
 		if (command_entry())
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/c139explore/uwire.c	Wed Nov 04 01:43:44 2015 +0000
@@ -0,0 +1,92 @@
+/* Driver for uWire Master Controller inside TI Calypso */
+/* lifted from OsmocomBB and ported to FreeCalypso target-utils environment */
+
+/* (C) 2010 by Sylvain Munaut <tnt@246tNt.com>
+ *
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include "types.h"
+
+struct uwire_regs {
+	u16	reg_data;
+	u16	reg_csr;
+	u16	reg_sr1;
+	u16	reg_sr2;
+	u16	reg_sr3;
+};
+
+#define	UWIRE_REGS	(*(volatile struct uwire_regs *) 0xFFFE4000)
+
+#define UWIRE_CSR_BITS_RD(n)	(((n) & 0x1f) << 0)
+#define UWIRE_CSR_BITS_WR(n)	(((n) & 0x1f) << 5)
+#define UWIRE_CSR_IDX(n)	(((n) & 3) << 10)
+#define UWIRE_CSR_CS_CMD	(1 << 12)
+#define UWIRE_CSR_START		(1 << 13)
+#define UWIRE_CSR_CSRB		(1 << 14)
+#define UWIRE_CSR_RDRB		(1 << 15)
+
+#define UWIRE_CSn_EDGE_RD	(1 << 0)	/* 1=falling 0=rising */
+#define UWIRE_CSn_EDGE_WR	(1 << 1)	/* 1=falling 0=rising */
+#define UWIRE_CSn_CS_LVL	(1 << 2)
+#define UWIRE_CSn_FRQ_DIV2	(0 << 3)
+#define UWIRE_CSn_FRQ_DIV4	(1 << 3)
+#define UWIRE_CSn_FRQ_DIV8	(2 << 3)
+#define UWIRE_CSn_CKH
+
+#define UWIRE_CSn_SHIFT(n)	(((n) & 1) ? 6 : 0)
+#define UWIRE_CSn_REG(n)	(((n) & 2) ? REG_SR2 : REG_SR1)
+
+#define UWIRE_SR3_CLK_EN	(1 << 0)
+#define UWIRE_SR3_CLK_DIV2	(0 << 1)
+#define UWIRE_SR3_CLK_DIV4	(1 << 1)
+#define UWIRE_SR3_CLK_DIV7	(2 << 1)
+#define UWIRE_SR3_CLK_DIV10	(3 << 1)
+
+static inline void _uwire_wait(int mask, int val)
+{
+	while ((UWIRE_REGS.reg_csr & mask) != val);
+}
+
+void uwire_init(void)
+{
+	UWIRE_REGS.reg_sr3 = UWIRE_SR3_CLK_EN | UWIRE_SR3_CLK_DIV2;
+	UWIRE_REGS.reg_sr1 = UWIRE_CSn_CS_LVL | UWIRE_CSn_FRQ_DIV2;
+	UWIRE_REGS.reg_csr = UWIRE_CSR_IDX(0) | UWIRE_CSR_CS_CMD;
+	_uwire_wait(UWIRE_CSR_CSRB, 0);
+}
+
+send_via_uwire(word)
+	unsigned word;
+{
+	u16 tmp = 0;
+
+	/* select the chip */
+	UWIRE_REGS.reg_csr = UWIRE_CSR_IDX(0) | UWIRE_CSR_CS_CMD;
+	_uwire_wait(UWIRE_CSR_CSRB, 0);
+
+	UWIRE_REGS.reg_data = word << 7;
+	UWIRE_REGS.reg_csr = UWIRE_CSR_BITS_WR(9) | UWIRE_CSR_START;
+	_uwire_wait(UWIRE_CSR_CSRB, 0);
+
+	/* unselect the chip */
+	UWIRE_REGS.reg_csr = UWIRE_CSR_IDX(0) | 0;
+	_uwire_wait(UWIRE_CSR_CSRB, 0);
+
+	return 0;
+}