FreeCalypso > hg > freecalypso-tools
comparison target-utils/c139explore/lcd.c @ 0:e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sat, 11 Jun 2016 00:13:35 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:e7502631a0f9 |
|---|---|
| 1 #include <sys/types.h> | |
| 2 #include "types.h" | |
| 3 | |
| 4 static void | |
| 5 send_cmd_data(cmdbyte, databyte) | |
| 6 { | |
| 7 send_via_uwire(cmdbyte); | |
| 8 send_via_uwire(databyte | 0x100); | |
| 9 } | |
| 10 | |
| 11 void | |
| 12 cmd_lcdcmd(argbulk) | |
| 13 char *argbulk; | |
| 14 { | |
| 15 char *argv[3]; | |
| 16 u_long cmd, data; | |
| 17 | |
| 18 if (parse_args(argbulk, 2, 2, argv, 0) < 0) | |
| 19 return; | |
| 20 if (parse_hexarg(argv[0], 2, &cmd) < 0) { | |
| 21 printf("ERROR: arg1 must be a valid 8-bit hex value\n"); | |
| 22 return; | |
| 23 } | |
| 24 if (parse_hexarg(argv[1], 2, &data) < 0) { | |
| 25 printf("ERROR: arg2 must be a valid 8-bit hex value\n"); | |
| 26 return; | |
| 27 } | |
| 28 send_cmd_data(cmd, data); | |
| 29 } | |
| 30 | |
| 31 static void | |
| 32 send_pixel_value(pix) | |
| 33 { | |
| 34 send_via_uwire((pix >> 8) | 0x100); | |
| 35 send_via_uwire((pix & 0xFF) | 0x100); | |
| 36 } | |
| 37 | |
| 38 void | |
| 39 cmd_lcdpix(argbulk) | |
| 40 char *argbulk; | |
| 41 { | |
| 42 char *argv[2]; | |
| 43 u_long pixval; | |
| 44 | |
| 45 if (parse_args(argbulk, 1, 1, argv, 0) < 0) | |
| 46 return; | |
| 47 if (parse_hexarg(argv[0], 4, &pixval) < 0) { | |
| 48 printf("ERROR: arg1 must be a valid 16-bit hex value\n"); | |
| 49 return; | |
| 50 } | |
| 51 send_pixel_value(pixval); | |
| 52 } | |
| 53 | |
| 54 void | |
| 55 cmd_lcdinit() | |
| 56 { | |
| 57 /* from OsmocomBB */ | |
| 58 send_cmd_data(0x3F, 0x01); | |
| 59 send_cmd_data(0x20, 0x03); | |
| 60 send_cmd_data(0x31, 0x03); | |
| 61 } | |
| 62 | |
| 63 static void | |
| 64 set_lcd_addr_region(xstart, xend, ystart, yend) | |
| 65 { | |
| 66 send_cmd_data(0x10, xstart); | |
| 67 send_cmd_data(0x11, ystart); | |
| 68 send_cmd_data(0x12, xend); | |
| 69 send_cmd_data(0x13, yend); | |
| 70 send_cmd_data(0x14, xstart); | |
| 71 send_cmd_data(0x15, ystart); | |
| 72 } | |
| 73 | |
| 74 void | |
| 75 cmd_lcdfill(argbulk) | |
| 76 char *argbulk; | |
| 77 { | |
| 78 int argc; | |
| 79 char *argv[6]; | |
| 80 u_long pixval; | |
| 81 int xstart, xend, ystart, yend; | |
| 82 int npix; | |
| 83 | |
| 84 if (parse_args(argbulk, 1, 5, argv, &argc) < 0) | |
| 85 return; | |
| 86 if (parse_hexarg(argv[0], 4, &pixval) < 0) { | |
| 87 printf("ERROR: arg1 must be a valid 16-bit hex value\n"); | |
| 88 return; | |
| 89 } | |
| 90 switch (argc) { | |
| 91 case 1: | |
| 92 xstart = ystart = 0; | |
| 93 xend = 95; | |
| 94 yend = 63; | |
| 95 break; | |
| 96 case 5: | |
| 97 xstart = atoi(argv[1]); | |
| 98 if (xstart < 0 || xstart > 95) { | |
| 99 range_err: printf("ERROR: coordinate arg out of range\n"); | |
| 100 return; | |
| 101 } | |
| 102 xend = atoi(argv[2]); | |
| 103 if (xend < 0 || xend > 95) | |
| 104 goto range_err; | |
| 105 ystart = atoi(argv[3]); | |
| 106 if (ystart < 0 || ystart > 63) | |
| 107 goto range_err; | |
| 108 yend = atoi(argv[4]); | |
| 109 if (yend < 0 || yend > 63) | |
| 110 goto range_err; | |
| 111 if (xend < xstart || yend < ystart) { | |
| 112 printf("ERROR: negative range\n"); | |
| 113 return; | |
| 114 } | |
| 115 break; | |
| 116 default: | |
| 117 printf("ERROR: wrong number of arguments\n"); | |
| 118 return; | |
| 119 } | |
| 120 set_lcd_addr_region(xstart, xend, ystart, yend); | |
| 121 npix = (xend + 1 - xstart) * (yend + 1 - ystart); | |
| 122 while (npix--) | |
| 123 send_pixel_value(pixval); | |
| 124 } | |
| 125 | |
| 126 void | |
| 127 cmd_hbars() | |
| 128 { | |
| 129 int i, j, k, p; | |
| 130 | |
| 131 /* | |
| 132 * The result of this command should be 8 horizontal bars | |
| 133 * in the natural RGB order. | |
| 134 */ | |
| 135 set_lcd_addr_region(16, 79, 0, 63); | |
| 136 for (i = 0; i < 8; i++) { | |
| 137 for (j = 0; j < 8; j++) { | |
| 138 p = 0; | |
| 139 if (i & 4) | |
| 140 p |= 0xF800; | |
| 141 if (i & 2) | |
| 142 p |= 0x07E0; | |
| 143 if (i & 1) | |
| 144 p |= 0x001F; | |
| 145 for (k = 0; k < 64; k++) | |
| 146 send_pixel_value(p); | |
| 147 } | |
| 148 } | |
| 149 } | |
| 150 | |
| 151 void | |
| 152 cmd_vbars() | |
| 153 { | |
| 154 int i, j, k, p; | |
| 155 | |
| 156 /* | |
| 157 * The result of this command should be 8 vertical bars | |
| 158 * in the natural RGB order. | |
| 159 */ | |
| 160 set_lcd_addr_region(16, 79, 0, 63); | |
| 161 for (i = 0; i < 64; i++) { | |
| 162 for (j = 0; j < 8; j++) { | |
| 163 p = 0; | |
| 164 if (j & 4) | |
| 165 p |= 0xF800; | |
| 166 if (j & 2) | |
| 167 p |= 0x07E0; | |
| 168 if (j & 1) | |
| 169 p |= 0x001F; | |
| 170 for (k = 0; k < 8; k++) | |
| 171 send_pixel_value(p); | |
| 172 } | |
| 173 } | |
| 174 } |
