FreeCalypso > hg > freecalypso-tools
view target-utils/c139explore/lcd.c @ 988:5a6019ed7e72
pln-ppb-test: implement read-id
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 03 Dec 2023 00:04:18 +0000 |
parents | e7502631a0f9 |
children |
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_lcdcmd(argbulk) char *argbulk; { char *argv[3]; u_long cmd, data; if (parse_args(argbulk, 2, 2, argv, 0) < 0) return; if (parse_hexarg(argv[0], 2, &cmd) < 0) { printf("ERROR: arg1 must be a valid 8-bit hex value\n"); return; } if (parse_hexarg(argv[1], 2, &data) < 0) { printf("ERROR: arg2 must be a valid 8-bit hex value\n"); return; } send_cmd_data(cmd, data); } static void send_pixel_value(pix) { send_via_uwire((pix >> 8) | 0x100); send_via_uwire((pix & 0xFF) | 0x100); } void cmd_lcdpix(argbulk) char *argbulk; { char *argv[2]; u_long pixval; if (parse_args(argbulk, 1, 1, argv, 0) < 0) return; if (parse_hexarg(argv[0], 4, &pixval) < 0) { printf("ERROR: arg1 must be a valid 16-bit hex value\n"); return; } send_pixel_value(pixval); } 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); } 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); } void cmd_hbars() { int i, j, k, p; /* * The result of this command should be 8 horizontal bars * in the natural RGB order. */ set_lcd_addr_region(16, 79, 0, 63); for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { p = 0; if (i & 4) p |= 0xF800; if (i & 2) p |= 0x07E0; if (i & 1) p |= 0x001F; for (k = 0; k < 64; k++) send_pixel_value(p); } } } void cmd_vbars() { int i, j, k, p; /* * The result of this command should be 8 vertical bars * in the natural RGB order. */ set_lcd_addr_region(16, 79, 0, 63); for (i = 0; i < 64; i++) { for (j = 0; j < 8; j++) { p = 0; if (j & 4) p |= 0xF800; if (j & 2) p |= 0x07E0; if (j & 1) p |= 0x001F; for (k = 0; k < 8; k++) send_pixel_value(p); } } }