diff target-utils/pirexplore/lcd.c @ 78:2c266d4339ff

pirexplore: lcdfill implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 01 Aug 2013 02:27:09 +0000
parents fcbe1332b197
children f65df1d640aa
line wrap: on
line diff
--- a/target-utils/pirexplore/lcd.c	Thu Aug 01 00:57:49 2013 +0000
+++ b/target-utils/pirexplore/lcd.c	Thu Aug 01 02:27:09 2013 +0000
@@ -1,3 +1,7 @@
+/*
+ * Almost all of this Pirelli LCD black magic has been lifted from OsmocomBB.
+ */
+
 #include <sys/types.h>
 #include "types.h"
 
@@ -121,3 +125,65 @@
 	GPIO_OUT_REG |= 0x0080;
 	fb_s6b33b1x_send_cmdlist(s6b33b1x_initdata);
 }
+
+set_lcd_addr_region(xstart, xend, ystart, yend)
+{
+	GPIO_OUT_REG |= 0x0080;
+	nCS4_ADDR0 = 0x42;
+	nCS4_ADDR0 = xstart;
+	nCS4_ADDR0 = xend;
+	nCS4_ADDR0 = 0x43;
+	nCS4_ADDR0 = ystart;
+	nCS4_ADDR0 = yend;
+}
+
+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 = yend = 131;
+		break;
+	case 5:
+		xstart = atoi(argv[1]);
+		if (xstart < 0 || xstart > 131) {
+range_err:		printf("ERROR: coordinate arg out of range\n");
+			return;
+		}
+		xend = atoi(argv[2]);
+		if (xend < 0 || xend > 131)
+			goto range_err;
+		ystart = atoi(argv[3]);
+		if (ystart < 0 || ystart > 131)
+			goto range_err;
+		yend = atoi(argv[4]);
+		if (yend < 0 || yend > 131)
+			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--)
+		nCS4_ADDR2 = pixval;
+}