[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | glcinit.c -- LCD drivers for the Epson GLC controller chip
|
---|
| 4 | Version 5 -- 1988-08-03 -- D.N. Lynx Crowe
|
---|
| 5 | (c) Copyright 1987, 1988 -- D.N. Lynx Crowe
|
---|
| 6 |
|
---|
| 7 | GLCinit()
|
---|
| 8 |
|
---|
| 9 | Initializes the GLC.
|
---|
| 10 |
|
---|
| 11 | unsigned
|
---|
| 12 | GLCcrc(row, col)
|
---|
| 13 | unsigned row, col;
|
---|
| 14 |
|
---|
| 15 | Positions the GLC cursor at ('row', 'col') preparatory
|
---|
| 16 | to writing text. Returns the calculated cursor address.
|
---|
| 17 |
|
---|
| 18 | unsigned
|
---|
| 19 | GLCcxy(x, y)
|
---|
| 20 | unsigned x, y;
|
---|
| 21 |
|
---|
| 22 | Positions the GLC cursor at ('x', 'y') preparatory to
|
---|
| 23 | writing graphics. Returns a bit mask for the pixel.
|
---|
| 24 | Leaves the cursor address in lcdcurs.
|
---|
| 25 | Limits: 0 LE x LE 511, 0 LE y LE 63.
|
---|
| 26 |
|
---|
| 27 | GLCwrts(s)
|
---|
| 28 | char *s;
|
---|
| 29 |
|
---|
| 30 | Writes the character string pointed to by 's' at the
|
---|
| 31 | current cursor position on the LCD display.
|
---|
| 32 | Cursor must start and end on the same line.
|
---|
| 33 | No error checks are done.
|
---|
| 34 |
|
---|
| 35 | GLCtext(row, col, s)
|
---|
| 36 | unsigned row, col;
|
---|
| 37 | char *s;
|
---|
| 38 |
|
---|
| 39 | Sets the GLC cursor to ('row', 'col'), then writes the
|
---|
| 40 | character string pointed to by 's'.
|
---|
| 41 | Cursor must start and end on the same line.
|
---|
| 42 | No error checks are done.
|
---|
| 43 | |
---|
| 44 |
|
---|
| 45 | GLCdisp(dsp, crs, blk1, blk2, blk3)
|
---|
| 46 | short dsp, crs, blk1, blk2, blk3;
|
---|
| 47 |
|
---|
| 48 | Sets the overall display, cursor and block status values.
|
---|
| 49 |
|
---|
| 50 | GLCcurs(crs)
|
---|
| 51 | short crs;
|
---|
| 52 |
|
---|
| 53 | Turns the cursor on or off.
|
---|
| 54 | =============================================================================
|
---|
| 55 | */
|
---|
| 56 |
|
---|
| 57 | /* |
---|
| 58 |
|
---|
| 59 | */
|
---|
| 60 |
|
---|
| 61 | #include "stddefs.h"
|
---|
| 62 | #include "hwdefs.h"
|
---|
[7258c6a] | 63 | #include "glcdefs.h"
|
---|
| 64 |
|
---|
| 65 | uint16_t lcdbase; /* LCD graphics base address */
|
---|
| 66 | uint16_t lcdbit; /* LCD graphics pixel bit mask */
|
---|
| 67 | uint16_t lcdcol; /* LCD text column */
|
---|
| 68 | uint16_t lcdctl1; /* LCD display control -- command */
|
---|
| 69 | uint16_t lcdctl2; /* LCD display control -- data */
|
---|
| 70 | uint16_t lcdcurs; /* LCD graphics pixel byte address */
|
---|
| 71 | uint16_t lcdrow; /* LCD text row */
|
---|
[f40a309] | 72 | uint16_t lcdx; /* LCD graphics x */
|
---|
| 73 | uint16_t lcdy; /* LCD graphics y */
|
---|
| 74 |
|
---|
[7258c6a] | 75 | /* GLC initialization values */
|
---|
| 76 |
|
---|
[f40a309] | 77 | int8_t glc_is1[] = { 0x12, 0x05, 0x07, 0x54, 0x58, 0x3F, 0x55, 0x00 };
|
---|
| 78 | int8_t glc_is2[] = { 0x00, 0x00, 0x3F, 0x00, 0x20, 0x3F, 0x00, 0x00 };
|
---|
| 79 |
|
---|
| 80 | /* |
---|
| 81 |
|
---|
| 82 | */
|
---|
| 83 |
|
---|
| 84 | /*
|
---|
| 85 | =============================================================================
|
---|
| 86 | GLCdisp(dsp, crs, blk1, blk2, blk3) -- set GLC display status
|
---|
| 87 | Sets the overall display, cursor and block status values.
|
---|
[7258c6a] | 88 | =============================================================================
|
---|
[f40a309] | 89 | */
|
---|
[7258c6a] | 90 |
|
---|
[f40a309] | 91 | void GLCdisp(int16_t dsp, int16_t crs, int16_t blk1, int16_t blk2, int16_t blk3)
|
---|
| 92 | {
|
---|
| 93 | register int16_t val;
|
---|
| 94 |
|
---|
| 95 | val = ((blk3 & 3) << 6) | ((blk2 & 3) << 4) | ((blk1 & 3) << 2) |
|
---|
| 96 | (crs & 3);
|
---|
| 97 |
|
---|
| 98 | lcdctl1 = G_DSPCTL | (dsp & 1);
|
---|
| 99 | lcdctl2 = val;
|
---|
| 100 |
|
---|
| 101 | LCD_WC = lcdctl1;
|
---|
| 102 | LCD_WD = lcdctl2;
|
---|
| 103 |
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | /*
|
---|
| 107 | =============================================================================
|
---|
| 108 | GLCcurs() -- turns the cursor on or off
|
---|
[7258c6a] | 109 | =============================================================================
|
---|
[f40a309] | 110 | */
|
---|
| 111 |
|
---|
| 112 | void GLCcurs(int16_t crs)
|
---|
| 113 | {
|
---|
| 114 | lcdctl2 = (crs & 3) | (lcdctl2 & ~3);
|
---|
| 115 |
|
---|
| 116 | LCD_WC = lcdctl1;
|
---|
| 117 | LCD_WD = lcdctl2;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | /* |
---|
| 121 |
|
---|
| 122 | */
|
---|
| 123 |
|
---|
| 124 | /*
|
---|
| 125 | =============================================================================
|
---|
| 126 | GLCinit() -- initialize GLC
|
---|
[0580615] | 127 | Initializes the GLC.
|
---|
[f40a309] | 128 | =============================================================================
|
---|
[7258c6a] | 129 | */
|
---|
| 130 |
|
---|
| 131 | void GLCinit(void)
|
---|
[f40a309] | 132 | {
|
---|
| 133 | register int16_t i;
|
---|
| 134 | register int32_t ic;
|
---|
| 135 | register int8_t *gp;
|
---|
| 136 |
|
---|
| 137 | lcdbase = G_PLANE2; /* set defaults for graphics variables */
|
---|
| 138 | lcdx = 0;
|
---|
| 139 | lcdy = 0;
|
---|
| 140 | lcdbit = 0x01;
|
---|
| 141 |
|
---|
| 142 | lcdrow = 0; /* set default for text variables */
|
---|
| 143 | lcdcol = 0;
|
---|
| 144 |
|
---|
| 145 | lcdctl1 = G_DSPCTL;
|
---|
| 146 | lcdctl2 = 0;
|
---|
| 147 |
|
---|
| 148 | LCD_WC = G_INIT; /* initialize the GLC */
|
---|
| 149 | gp = &glc_is1[0];
|
---|
| 150 |
|
---|
| 151 | for (i = 0; i < 8; i++)
|
---|
| 152 | LCD_WD= *gp++;
|
---|
| 153 |
|
---|
| 154 | LCD_WC = G_SETSAD; /* setup scroll registers */
|
---|
| 155 | gp = &glc_is2[0];
|
---|
| 156 |
|
---|
| 157 | for (i = 0; i < 8; i++)
|
---|
| 158 | LCD_WD = *gp++;
|
---|
| 159 |
|
---|
| 160 | LCD_WC = G_HSCRL; /* clear the horizontal scroll counter */
|
---|
| 161 | LCD_WD = 0;
|
---|
| 162 |
|
---|
| 163 | LCD_WC = G_OVRLAY; /* setup the display mode */
|
---|
| 164 | LCD_WD = 0x08;
|
---|
| 165 |
|
---|
| 166 | GLCdisp(G_OFF, G_B2, G_ON, G_ON, G_OFF);
|
---|
| 167 |
|
---|
| 168 | /* |
---|
| 169 |
|
---|
| 170 | */
|
---|
| 171 | LCD_WC = G_CRSWR; /* set cursor at (0,0) in G_PLANE1 */
|
---|
| 172 | LCD_WD = G_PLANE1 & 0xFF;
|
---|
| 173 | LCD_WD = (G_PLANE1 >> 8) & 0xFF;
|
---|
| 174 |
|
---|
| 175 | LCD_WC = G_CRSMRT; /* set cursor motion forward */
|
---|
| 176 |
|
---|
| 177 | LCD_WC = G_MWRITE; /* write zeros to GLC RAM */
|
---|
| 178 |
|
---|
| 179 | for (ic = 0; ic < 65536L; ic++)
|
---|
| 180 | LCD_WD = 0;
|
---|
| 181 |
|
---|
| 182 | LCD_WC = G_CRSWR; /* set cursor to (0,0) in G_PLANE1 */
|
---|
| 183 | LCD_WD = G_PLANE1 & 0xFF;
|
---|
| 184 | LCD_WD = (G_PLANE1 >> 8) & 0xFF;
|
---|
| 185 |
|
---|
| 186 | LCD_WC = G_CRSFRM; /* setup a blinking underline cursor */
|
---|
| 187 | LCD_WD = 0x04;
|
---|
| 188 | LCD_WD = 0x06;
|
---|
| 189 |
|
---|
| 190 | /* enable display */
|
---|
| 191 |
|
---|
| 192 | GLCdisp(G_ON, G_B2, G_ON, G_ON, G_OFF);
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | /* |
---|
| 196 |
|
---|
| 197 | */
|
---|
| 198 |
|
---|
| 199 | /*
|
---|
| 200 | =============================================================================
|
---|
[7258c6a] | 201 | GLCcrc(row, col) -- position GLC text cursor
|
---|
[f40a309] | 202 | Positions the GLC cursor at ('row', 'col') preparatory
|
---|
[7258c6a] | 203 | to writing text. Returns calculated cursor address.
|
---|
[f40a309] | 204 | =============================================================================
|
---|
| 205 | */
|
---|
| 206 |
|
---|
| 207 | uint16_t GLCcrc(uint16_t row, uint16_t col)
|
---|
| 208 | {
|
---|
| 209 | uint16_t curad;
|
---|
| 210 |
|
---|
| 211 | curad = col + (row * 85); /* calculate cursor location */
|
---|
| 212 |
|
---|
| 213 | LCD_WC = G_CRSWR; /* send cursor address to GLC */
|
---|
| 214 | LCD_WD = curad & 0xFF;
|
---|
| 215 | LCD_WD = (curad >> 8) & 0xFF;
|
---|
| 216 |
|
---|
| 217 | lcdrow = row; /* set text cursor variables */
|
---|
| 218 | lcdcol = col;
|
---|
| 219 |
|
---|
| 220 | return(curad); /* return calculated cursor address */
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | /* |
---|
| 224 |
|
---|
| 225 | */
|
---|
| 226 |
|
---|
| 227 | /*
|
---|
| 228 | =============================================================================
|
---|
| 229 | GLCcxy(x, y) -- position GLC graphics cursor
|
---|
[7258c6a] | 230 | Positions the GLC cursor at ('x', 'y') preparatory to
|
---|
[f40a309] | 231 | writing graphics. Returns a bit mask for the pixel.
|
---|
[7258c6a] | 232 | Leaves cursor address in lcdcurs.
|
---|
[f40a309] | 233 | Limits: 0 LE x LE 511, 0 LE y LE 63.
|
---|
| 234 | =============================================================================
|
---|
| 235 | */
|
---|
| 236 |
|
---|
| 237 | uint16_t GLCcxy(uint16_t x, uint16_t y)
|
---|
| 238 | {
|
---|
| 239 | register uint16_t curad, xby6;
|
---|
| 240 |
|
---|
| 241 | /* calculate cursor address */
|
---|
| 242 |
|
---|
| 243 | xby6 = x % 6;
|
---|
| 244 | curad = lcdbase + (85 * (63 - y)) + (x / 6) + (xby6 >> 3);
|
---|
| 245 | lcdcurs = curad;
|
---|
| 246 |
|
---|
| 247 | /* send cursor address to GLC */
|
---|
| 248 |
|
---|
| 249 | LCD_WC = G_CRSWR;
|
---|
| 250 | LCD_WD = curad & 0xFF;
|
---|
| 251 | LCD_WD = (curad >> 8) & 0xFF;
|
---|
| 252 |
|
---|
| 253 | /* set graphics variables */
|
---|
| 254 |
|
---|
| 255 | lcdx = x;
|
---|
| 256 | lcdy = y;
|
---|
| 257 |
|
---|
| 258 | /* calculate bit mask */
|
---|
| 259 |
|
---|
| 260 | lcdbit = 0x01 << (xby6 & 0x07);
|
---|
| 261 |
|
---|
| 262 | return(lcdbit);
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | /* |
---|
| 266 |
|
---|
| 267 | */
|
---|
| 268 |
|
---|
| 269 | /*
|
---|
| 270 | =============================================================================
|
---|
[7258c6a] | 271 | GLCwrts(s) -- write text string to GLC
|
---|
[f40a309] | 272 | Writes the character string pointed to by 's' at the
|
---|
| 273 | current cursor position on the LCD display.
|
---|
| 274 | Cursor must start and end on the same line.
|
---|
| 275 | No error checks are done.
|
---|
| 276 | =============================================================================
|
---|
| 277 | */
|
---|
| 278 |
|
---|
| 279 | void GLCwrts(int8_t *s)
|
---|
| 280 | {
|
---|
| 281 | LCD_WC = G_CRSMRT; /* set cursor motion = right */
|
---|
| 282 |
|
---|
| 283 | LCD_WC = G_MWRITE; /* set to write data */
|
---|
| 284 |
|
---|
| 285 | while (*s) { /* write string to GLC */
|
---|
| 286 |
|
---|
| 287 | LCD_WD = *s++;
|
---|
| 288 | lcdcol++; /* keep column variable up to date */
|
---|
| 289 | }
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | /* |
---|
| 293 |
|
---|
| 294 | */
|
---|
| 295 |
|
---|
| 296 | /*
|
---|
[7258c6a] | 297 | =============================================================================
|
---|
[f40a309] | 298 | GLCtext(row, col, s) -- position GLC cursor and write text
|
---|
[7258c6a] | 299 | Sets the GLC cursor to ('row', 'col'), then writes the
|
---|
[f40a309] | 300 | character string pointed to by 's'.
|
---|
| 301 | Cursor must start and end on the same line.
|
---|
| 302 | No error checks are done.
|
---|
| 303 | =============================================================================
|
---|
| 304 | */
|
---|
| 305 |
|
---|
| 306 | void GLCtext(uint16_t row, uint16_t col, int8_t *s)
|
---|
| 307 | {
|
---|
| 308 | register uint16_t curad;
|
---|
| 309 |
|
---|
| 310 | curad = col + (row * 85); /* calculate cursor address */
|
---|
| 311 |
|
---|
| 312 | LCD_WC = G_CRSWR; /* send cursor address to GLC */
|
---|
| 313 | LCD_WD = curad & 0xFF;
|
---|
| 314 | LCD_WD = (curad >> 8) & 0xFF;
|
---|
| 315 |
|
---|
| 316 | lcdrow = row; /* set GLC text cursor variables */
|
---|
| 317 | lcdcol = col;
|
---|
| 318 |
|
---|
| 319 | LCD_WC = G_CRSMRT; /* set cursor motion = right */
|
---|
| 320 |
|
---|
| 321 | LCD_WC = G_MWRITE; /* set to write data */
|
---|
| 322 |
|
---|
| 323 | while (*s) { /* write string to GLC */
|
---|
| 324 |
|
---|
| 325 | LCD_WD = *s++;
|
---|
| 326 | lcdcol++; /* keep cursor column up to date */
|
---|
| 327 | }
|
---|
| 328 | }
|
---|
| 329 |
|
---|