diff options
Diffstat (limited to 'firmware/drivers/lcd.c')
-rw-r--r-- | firmware/drivers/lcd.c | 680 |
1 files changed, 680 insertions, 0 deletions
diff --git a/firmware/drivers/lcd.c b/firmware/drivers/lcd.c new file mode 100644 index 0000000000..737bf92a6b --- /dev/null +++ b/firmware/drivers/lcd.c | |||
@@ -0,0 +1,680 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Alan Korr | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "config.h" | ||
21 | #include "lcd.h" | ||
22 | |||
23 | #ifndef SIMULATOR | ||
24 | /* | ||
25 | * About /CS,DS,SC,SD | ||
26 | * ------------------ | ||
27 | * | ||
28 | * LCD on JBP and JBR uses a SPI protocol to receive orders (SDA and SCK lines) | ||
29 | * | ||
30 | * - /CS -> Chip Selection line : | ||
31 | * 0 : LCD chipset is activated. | ||
32 | * - DS -> Data Selection line, latched at the rising edge | ||
33 | * of the 8th serial clock (*) : | ||
34 | * 0 : instruction register, | ||
35 | * 1 : data register; | ||
36 | * - SC -> Serial Clock line (SDA). | ||
37 | * - SD -> Serial Data line (SCK), latched at the rising edge | ||
38 | * of each serial clock (*). | ||
39 | * | ||
40 | * _ _ | ||
41 | * /CS \ / | ||
42 | * \______________________________________________________/ | ||
43 | * _____ ____ ____ ____ ____ ____ ____ ____ ____ _____ | ||
44 | * SD \/ D7 \/ D6 \/ D5 \/ D4 \/ D3 \/ D2 \/ D1 \/ D0 \/ | ||
45 | * _____/\____/\____/\____/\____/\____/\____/\____/\____/\_____ | ||
46 | * | ||
47 | * _____ _ _ _ _ _ _ _ ________ | ||
48 | * SC \ * \ * \ * \ * \ * \ * \ * \ * | ||
49 | * \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ | ||
50 | * _ _________________________________________________________ | ||
51 | * DS \/ | ||
52 | * _/\_________________________________________________________ | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* | ||
57 | * The only way to do logical operations in an atomic way | ||
58 | * on SH1 is using : | ||
59 | * | ||
60 | * or.b/and.b/tst.b/xor.b #imm,@(r0,gbr) | ||
61 | * | ||
62 | * but GCC doesn't generate them at all so some assembly | ||
63 | * codes are needed here. | ||
64 | * | ||
65 | * The Global Base Register gbr is expected to be zero | ||
66 | * and r0 is the address of one register in the on-chip | ||
67 | * peripheral module. | ||
68 | * | ||
69 | */ | ||
70 | |||
71 | /* | ||
72 | * Enter a LCD session : | ||
73 | * | ||
74 | * QI(LCDR) &= ~(LCD_CS|LCD_DS|LCD_SD|LCD_SC); | ||
75 | */ | ||
76 | static void lcd_start (void) | ||
77 | { | ||
78 | asm | ||
79 | ("and.b\t%0,@(r0,gbr)" | ||
80 | : | ||
81 | : /* %0 */ "I"(~(LCD_CS|LCD_DS|LCD_SD|LCD_SC)), | ||
82 | /* %1 */ "z"(LCDR)); | ||
83 | } | ||
84 | |||
85 | /* | ||
86 | * Leave a LCD session : | ||
87 | * | ||
88 | * QI(LCDR) |= LCD_CS|LCD_RS|LCD_SD|LCD_SC; | ||
89 | */ | ||
90 | static void lcd_stop (void) | ||
91 | { | ||
92 | asm | ||
93 | ("or.b\t%0,@(r0,gbr)" | ||
94 | : | ||
95 | : /* %0 */ "I"(LCD_CS|LCD_DS|LCD_SD|LCD_SC), | ||
96 | /* %1 */ "z"(LCDR)); | ||
97 | } | ||
98 | |||
99 | static void lcd_byte (int byte,int rs) | ||
100 | /* | ||
101 | * char j = 0x80; | ||
102 | * if (rs) | ||
103 | * do | ||
104 | * { | ||
105 | * QI(LCDR) &= ~(LCD_SC|LCD_SD); | ||
106 | * if (j & byte) | ||
107 | * QI(LCDR) |= LCD_SD; | ||
108 | * QI(LCDR) |= LCD_SC|LCD_DS; | ||
109 | * } | ||
110 | * while ((unsigned char)j >>= 1); | ||
111 | * else | ||
112 | * do | ||
113 | * { | ||
114 | * QI(LCDR) &= ~(LCD_SC|LCD_SD|LCD_DS); | ||
115 | * if (j & byte) | ||
116 | * QI(LCDR) |= LCD_SD; | ||
117 | * QI(LCDR) |= LCD_SC; | ||
118 | * } | ||
119 | * while ((unsigned char)j >>= 1); | ||
120 | */ | ||
121 | { | ||
122 | if (rs > 0) | ||
123 | asm | ||
124 | ("shll8\t%0\n" | ||
125 | "0:\n\t" | ||
126 | "and.b\t%2,@(r0,gbr)\n\t" | ||
127 | "shll\t%0\n\t" | ||
128 | "bf\t1f\n\t" | ||
129 | "or.b\t%3,@(r0,gbr)\n" | ||
130 | "1:\n\t" | ||
131 | "or.b\t%4,@(r0,gbr)\n" | ||
132 | "add\t#-1,%1\n\t" | ||
133 | "cmp/pl\t%1\n\t" | ||
134 | "bt\t0b" | ||
135 | : | ||
136 | : /* %0 */ "r"(((unsigned)byte)<<16), | ||
137 | /* %1 */ "r"(8), | ||
138 | /* %2 */ "I"(~(LCD_SC|LCD_SD)), | ||
139 | /* %3 */ "I"(LCD_SD), | ||
140 | /* %4 */ "I"(LCD_SC|LCD_DS), | ||
141 | /* %5 */ "z"(LCDR)); | ||
142 | else | ||
143 | asm | ||
144 | ("shll8\t%0\n" | ||
145 | "0:\n\t" | ||
146 | "and.b\t%2,@(r0,gbr)\n\t" | ||
147 | "shll\t%0\n\t" | ||
148 | "bf\t1f\n\t" | ||
149 | "or.b\t%3,@(r0,gbr)\n" | ||
150 | "1:\n\t" | ||
151 | "or.b\t%4,@(r0,gbr)\n" | ||
152 | "add\t#-1,%1\n\t" | ||
153 | "cmp/pl\t%1\n\t" | ||
154 | "bt\t0b" | ||
155 | : | ||
156 | : /* %0 */ "r"(((unsigned)byte)<<16), | ||
157 | /* %1 */ "r"(8), | ||
158 | /* %2 */ "I"(~(LCD_SC|LCD_DS|LCD_SD)), | ||
159 | /* %3 */ "I"(LCD_SD), | ||
160 | /* %4 */ "I"(LCD_SC), | ||
161 | /* %5 */ "z"(LCDR)); | ||
162 | } | ||
163 | |||
164 | void lcd_data (int data) | ||
165 | { | ||
166 | lcd_byte (data,1); | ||
167 | } | ||
168 | |||
169 | void lcd_instruction (int instruction) | ||
170 | { | ||
171 | lcd_byte (instruction,0); | ||
172 | } | ||
173 | |||
174 | void lcd_zero (int length) | ||
175 | { | ||
176 | length *= 8; | ||
177 | while (--length >= 0) | ||
178 | lcd_data (0); | ||
179 | } | ||
180 | |||
181 | void lcd_fill (int data,int length) | ||
182 | { | ||
183 | length *= 8; | ||
184 | while (--length >= 0) | ||
185 | lcd_data (data); | ||
186 | } | ||
187 | |||
188 | void lcd_copy (void *data,int count) | ||
189 | { | ||
190 | while (--count >= 0) | ||
191 | lcd_data (*((char *)data)++); | ||
192 | } | ||
193 | |||
194 | static void lcd_goto (int x,int y) | ||
195 | { | ||
196 | lcd_instruction (LCD_CURSOR(x,y)); | ||
197 | } | ||
198 | |||
199 | /*** BACKLIGHT ***/ | ||
200 | |||
201 | static void lcd_toggle_backlight (void) | ||
202 | { | ||
203 | PAIOR ^= LCD_BL; | ||
204 | } | ||
205 | |||
206 | static void lcd_turn_on_backlight (void) | ||
207 | { | ||
208 | PAIOR |= LCD_BL; | ||
209 | } | ||
210 | |||
211 | static void lcd_turn_off_backlight (void) | ||
212 | { | ||
213 | PAIOR &= ~LCD_BL; | ||
214 | } | ||
215 | |||
216 | /*** ICONS ***/ | ||
217 | #endif | ||
218 | |||
219 | #ifdef HAVE_LCD_CHARCELLS | ||
220 | # ifndef JBP_OLD | ||
221 | |||
222 | static char const lcd_ascii[] = | ||
223 | { | ||
224 | /*****************************************************************************************/ | ||
225 | /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */ | ||
226 | /* ************************************************************************************/ | ||
227 | /* 0x */ 0x00,0x01,0x02,0x03,0x00,0x00,0x00,0x00,0x04,0x05,0x00,0x00,0x00,0x00,0x00,0x00, | ||
228 | /* 1x */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
229 | /* 2x */ 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F, | ||
230 | /* 3x */ 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F, | ||
231 | /* 4x */ 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F, | ||
232 | /* 5x */ 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F, | ||
233 | /* 6x */ 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F, | ||
234 | /* 7x */ 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x20,0x20,0x20,0x20,0x20, | ||
235 | /* 8x */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, | ||
236 | /* 9x */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, | ||
237 | /* Ax */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, | ||
238 | /* Bx */ 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, | ||
239 | /* Cx */ 0x41,0x41,0x41,0x41,0x41,0x41,0x20,0x43,0x45,0x45,0x45,0x45,0x49,0x49,0x49,0x49, | ||
240 | /* Dx */ 0x44,0x4E,0x4F,0x4F,0x4F,0x4F,0x4F,0x20,0x20,0x55,0x55,0x55,0x55,0x59,0x20,0x20, | ||
241 | /* Ex */ 0x61,0x61,0x61,0x61,0x61,0x61,0x20,0x63,0x65,0x65,0x65,0x65,0x69,0x69,0x69,0x69, | ||
242 | /* Fx */ 0x64,0x6E,0x6F,0x6F,0x6F,0x6F,0x6F,0x20,0x20,0x75,0x75,0x75,0x75,0x79,0x79,0x79 | ||
243 | /******/ | ||
244 | }; | ||
245 | |||
246 | # else | ||
247 | |||
248 | static char const lcd_ascii[] = | ||
249 | { | ||
250 | /*****************************************************************************************/ | ||
251 | /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */ | ||
252 | /* ************************************************************************************/ | ||
253 | /* 0x */ 0x00,0x01,0x02,0x03,0x00,0x00,0x00,0x00,0x85,0x89,0x00,0x00,0x00,0x00,0x00,0x00, | ||
254 | /* 1x */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, | ||
255 | /* 2x */ 0x24,0x25,0x26,0x37,0x06,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33, | ||
256 | /* 3x */ 0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x40,0x41,0x42,0x43, | ||
257 | /* 4x */ 0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53, | ||
258 | /* 5x */ 0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0xA9,0x33,0xCE,0x00,0x15, | ||
259 | /* 6x */ 0x00,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73, | ||
260 | /* 7x */ 0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x24,0x24,0x24,0x24,0x24, | ||
261 | /* 8x */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24, | ||
262 | /* 9x */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24, | ||
263 | /* Ax */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24, | ||
264 | /* Bx */ 0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24,0x24, | ||
265 | /* Cx */ 0x45,0x45,0x45,0x45,0x45,0x45,0x24,0x47,0x49,0x49,0x49,0x49,0x4D,0x4D,0x4D,0x4D, | ||
266 | /* Dx */ 0x48,0x52,0x53,0x53,0x53,0x53,0x53,0x24,0x24,0x59,0x59,0x59,0x59,0x5D,0x24,0x24, | ||
267 | /* Ex */ 0x65,0x65,0x65,0x65,0x65,0x65,0x24,0x67,0x69,0x69,0x69,0x69,0x6D,0x6D,0x6D,0x6D, | ||
268 | /* Fx */ 0x73,0x72,0x73,0x73,0x73,0x73,0x73,0x24,0x24,0x79,0x79,0x79,0x79,0x7D,0x24,0x7D | ||
269 | /******/ | ||
270 | }; | ||
271 | |||
272 | # endif | ||
273 | |||
274 | void lcd_puts (char const *string) | ||
275 | { | ||
276 | while (*string) | ||
277 | lcd_data (LCD_ASCII(*string++)); | ||
278 | } | ||
279 | |||
280 | void lcd_putns (char const *string,int n) | ||
281 | { | ||
282 | while (n--) | ||
283 | lcd_data (LCD_ASCII(*string++)); | ||
284 | } | ||
285 | |||
286 | void lcd_putc (int character) | ||
287 | { | ||
288 | lcd_data (LCD_ASCII(character)); | ||
289 | } | ||
290 | |||
291 | void lcd_pattern (int which,char const *pattern,int count) | ||
292 | { | ||
293 | lcd_instruction (LCD_PRAM|which); | ||
294 | lcd_copy ((void *)pattern,count); | ||
295 | } | ||
296 | |||
297 | void lcd_puthex (unsigned int value,int digits) | ||
298 | { | ||
299 | switch (digits) { | ||
300 | case 8: | ||
301 | lcd_puthex (value >> 16,4); | ||
302 | case 4: | ||
303 | lcd_puthex (value >> 8,2); | ||
304 | case 2: | ||
305 | lcd_puthex (value >> 4,1); | ||
306 | case 1: | ||
307 | value &= 15; | ||
308 | lcd_putc (value+((value < 10) ? '0' : ('A'-10))); | ||
309 | } | ||
310 | } | ||
311 | |||
312 | |||
313 | /* HAVE_LCD_CHARCELLS */ | ||
314 | #elif defined(HAVE_LCD_BITMAP) | ||
315 | |||
316 | /* | ||
317 | * All bitmaps have this format: | ||
318 | * Bits within a byte are arranged veritcally, LSB at top. | ||
319 | * Bytes are stored in column-major format, with byte 0 at top left, | ||
320 | * byte 1 is 2nd from top, etc. Bytes following left-most column | ||
321 | * starts 2nd left column, etc. | ||
322 | * | ||
323 | * Note: The HW takes bitmap bytes in row-major order. | ||
324 | * | ||
325 | * Memory copy of display bitmap | ||
326 | */ | ||
327 | unsigned char display[DISP_X][DISP_Y/8]; | ||
328 | |||
329 | /* | ||
330 | * ASCII character generation tables | ||
331 | * | ||
332 | * This contains only the printable characters (0x20-0x7f). | ||
333 | * Each element in this table is a character pattern bitmap. | ||
334 | */ | ||
335 | #define ASCII_MIN 0x20 /* First char in table */ | ||
336 | #define ASCII_MAX 0x7f /* Last char in table */ | ||
337 | |||
338 | extern const unsigned char char_gen_6x8[][5][1]; | ||
339 | extern const unsigned char char_gen_8x12[][7][2]; | ||
340 | extern const unsigned char char_gen_12x16[][11][2]; | ||
341 | |||
342 | |||
343 | /* All zeros and ones bitmaps for area filling */ | ||
344 | static const unsigned char zeros[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
345 | 0x00, 0x00 }; | ||
346 | static const unsigned char ones[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
347 | 0xff, 0xff }; | ||
348 | |||
349 | static int lcd_y; /* Current pixel row */ | ||
350 | static int lcd_x; /* Current pixel column */ | ||
351 | static int lcd_size; /* Current font width */ | ||
352 | |||
353 | #ifndef SIMULATOR | ||
354 | |||
355 | /* | ||
356 | * Initialize LCD | ||
357 | */ | ||
358 | void lcd_init (void) | ||
359 | { | ||
360 | /* Initialize PB0-3 as output pins */ | ||
361 | PBCR2 &= 0xff00; /* MD = 00 */ | ||
362 | PBIOR |= 0x000f; /* IOR = 1 */ | ||
363 | |||
364 | /* Initialize LCD */ | ||
365 | lcd_write (TRUE, LCD_CNTL_RESET); | ||
366 | lcd_write (TRUE, LCD_CNTL_POWER); | ||
367 | lcd_write (TRUE, LCD_CNTL_SEGREMAP); | ||
368 | lcd_write (TRUE, LCD_CNTL_OUTSCAN); | ||
369 | lcd_write (TRUE, LCD_CNTL_CONTRAST); | ||
370 | lcd_write (TRUE, 0x30); /* Contrast parameter */ | ||
371 | lcd_write (TRUE, LCD_CNTL_DISPON); | ||
372 | |||
373 | lcd_clear_display(); | ||
374 | lcd_update(); | ||
375 | } | ||
376 | |||
377 | /* | ||
378 | * Update the display. | ||
379 | * This must be called after all other LCD funtions that change the display. | ||
380 | */ | ||
381 | void lcd_update (void) | ||
382 | { | ||
383 | int x, y; | ||
384 | |||
385 | /* Copy display bitmap to hardware */ | ||
386 | for (y = 0; y < DISP_Y/8; y++) | ||
387 | { | ||
388 | lcd_write (TRUE, LCD_CNTL_PAGE | (y & 0xf)); | ||
389 | lcd_write (TRUE, LCD_CNTL_HIGHCOL); | ||
390 | lcd_write (TRUE, LCD_CNTL_LOWCOL); | ||
391 | |||
392 | for (x = 0; x < DISP_X; x++) | ||
393 | lcd_write (FALSE, display[x][y]); | ||
394 | } | ||
395 | } | ||
396 | |||
397 | static void lcd_write (bool command, int value) | ||
398 | { | ||
399 | int bit; | ||
400 | |||
401 | /* Enable chip select, set DC if data */ | ||
402 | PBDR &= ~(PBDR_LCD_CS1|PBDR_LCD_DC); | ||
403 | if (!command) | ||
404 | PBDR |= PBDR_LCD_DC; | ||
405 | |||
406 | /* Send each bit, starting with MSB */ | ||
407 | for (bit = 0x80; bit > 0; bit >>= 1) | ||
408 | { | ||
409 | PBDR &= ~(PBDR_LCD_SDA|PBDR_LCD_SCK); | ||
410 | if (value & bit) | ||
411 | PBDR |= PBDR_LCD_SDA; | ||
412 | PBDR |= PBDR_LCD_SCK; | ||
413 | } | ||
414 | |||
415 | /* Disable chip select */ | ||
416 | PBDR |= PBDR_LCD_CS1; | ||
417 | } | ||
418 | |||
419 | #endif /* SIMULATOR */ | ||
420 | |||
421 | /* | ||
422 | * Clear the display | ||
423 | */ | ||
424 | void lcd_clear_display (void) | ||
425 | { | ||
426 | lcd_position (0, 0, 8); | ||
427 | memset (display, 0, sizeof display); | ||
428 | } | ||
429 | |||
430 | /* | ||
431 | * Set current x,y position and font size | ||
432 | */ | ||
433 | void lcd_position (int x, int y, int size) | ||
434 | { | ||
435 | if (x >= 0 && x < DISP_X && y >= 0 && y < DISP_Y) | ||
436 | { | ||
437 | lcd_x = x; | ||
438 | lcd_y = y; | ||
439 | } | ||
440 | |||
441 | lcd_size = size; | ||
442 | } | ||
443 | |||
444 | /* | ||
445 | * Display a string at current position and size | ||
446 | */ | ||
447 | void lcd_string (const char *str) | ||
448 | { | ||
449 | int x = lcd_x; | ||
450 | int nx = lcd_size; | ||
451 | int ny, ch; | ||
452 | const unsigned char *src; | ||
453 | |||
454 | if (nx == 12) | ||
455 | ny = 16; | ||
456 | else if (nx == 8) | ||
457 | ny = 12; | ||
458 | else | ||
459 | { | ||
460 | nx = 6; | ||
461 | ny = 8; | ||
462 | } | ||
463 | |||
464 | while ((ch = *str++) != '\0') | ||
465 | { | ||
466 | if (ch == '\n' || lcd_x + nx > DISP_X) | ||
467 | { | ||
468 | /* Wrap to next line */ | ||
469 | lcd_x = x; | ||
470 | lcd_y += ny; | ||
471 | } | ||
472 | |||
473 | if (lcd_y + ny > DISP_Y) | ||
474 | return; | ||
475 | |||
476 | /* Limit to char generation table */ | ||
477 | if (ch >= ASCII_MIN && ch <= ASCII_MAX) | ||
478 | { | ||
479 | if (nx == 12) | ||
480 | src = char_gen_12x16[ch-ASCII_MIN][0]; | ||
481 | else if (nx == 8) | ||
482 | src = char_gen_8x12[ch-ASCII_MIN][0]; | ||
483 | else | ||
484 | src = char_gen_6x8[ch-ASCII_MIN][0]; | ||
485 | |||
486 | lcd_bitmap (src, lcd_x, lcd_y, nx-1, ny, TRUE); | ||
487 | lcd_bitmap (zeros, lcd_x+nx-1, lcd_y, 1, ny, TRUE); | ||
488 | |||
489 | lcd_x += nx; | ||
490 | } | ||
491 | } | ||
492 | } | ||
493 | |||
494 | /* | ||
495 | * Display a bitmap at (x, y), size (nx, ny) | ||
496 | * clear is TRUE to clear destination area first | ||
497 | */ | ||
498 | void lcd_bitmap (const unsigned char *src, int x, int y, int nx, int ny, | ||
499 | bool clear) | ||
500 | { | ||
501 | unsigned char *dst; | ||
502 | unsigned char *dst2 = &display[x][y/8]; | ||
503 | unsigned int data, mask, mask2, mask3, mask4; | ||
504 | int shift = y & 7; | ||
505 | |||
506 | ny += shift; | ||
507 | |||
508 | /* Calculate bit masks */ | ||
509 | mask4 = ~(0xfe << ((ny-1) & 7)); | ||
510 | if (clear) | ||
511 | { | ||
512 | mask = ~(0xff << shift); | ||
513 | mask2 = 0; | ||
514 | mask3 = ~mask4; | ||
515 | if (ny <= 8) | ||
516 | mask3 |= mask; | ||
517 | } | ||
518 | else | ||
519 | mask = mask2 = mask3 = 0xff; | ||
520 | |||
521 | /* Loop for each column */ | ||
522 | for (x = 0; x < nx; x++) | ||
523 | { | ||
524 | dst = dst2; | ||
525 | dst2 += DISP_Y/8; | ||
526 | data = 0; | ||
527 | y = 0; | ||
528 | |||
529 | if (ny > 8) | ||
530 | { | ||
531 | /* First partial row */ | ||
532 | data = *src++ << shift; | ||
533 | *dst = (*dst & mask) ^ data; | ||
534 | data >>= 8; | ||
535 | dst++; | ||
536 | |||
537 | /* Intermediate rows */ | ||
538 | for (y = 8; y < ny-8; y += 8) | ||
539 | { | ||
540 | data |= *src++ << shift; | ||
541 | *dst = (*dst & mask2) ^ data; | ||
542 | data >>= 8; | ||
543 | dst++; | ||
544 | } | ||
545 | } | ||
546 | |||
547 | /* Last partial row */ | ||
548 | if (y + shift < ny) | ||
549 | data |= *src++ << shift; | ||
550 | *dst = (*dst & mask3) ^ (data & mask4); | ||
551 | } | ||
552 | } | ||
553 | |||
554 | /* | ||
555 | * Clear a rectangular area at (x, y), size (nx, ny) | ||
556 | */ | ||
557 | void lcd_clearrect (int x, int y, int nx, int ny) | ||
558 | { | ||
559 | int i; | ||
560 | for (i = 0; i < nx; i++) | ||
561 | lcd_bitmap (zeros, x+i, y, 1, ny, TRUE); | ||
562 | } | ||
563 | |||
564 | /* | ||
565 | * Fill a rectangular area at (x, y), size (nx, ny) | ||
566 | */ | ||
567 | void lcd_fillrect (int x, int y, int nx, int ny) | ||
568 | { | ||
569 | int i; | ||
570 | for (i = 0; i < nx; i++) | ||
571 | lcd_bitmap (ones, x+i, y, 1, ny, TRUE); | ||
572 | } | ||
573 | |||
574 | /* Invert a rectangular area at (x, y), size (nx, ny) */ | ||
575 | void lcd_invertrect (int x, int y, int nx, int ny) | ||
576 | { | ||
577 | int i; | ||
578 | for (i = 0; i < nx; i++) | ||
579 | lcd_bitmap (ones, x+i, y, 1, ny, FALSE); | ||
580 | } | ||
581 | |||
582 | #define DRAW_PIXEL(x,y) display[x][y/8] |= (1<<(y&7)) | ||
583 | #define CLEAR_PIXEL(x,y) display[x][y/8] &= ~(1<<(y&7)) | ||
584 | |||
585 | void lcd_drawline( int x1, int y1, int x2, int y2 ) | ||
586 | { | ||
587 | int numpixels; | ||
588 | int i; | ||
589 | int deltax, deltay; | ||
590 | int d, dinc1, dinc2; | ||
591 | int x, xinc1, xinc2; | ||
592 | int y, yinc1, yinc2; | ||
593 | |||
594 | deltax = abs(x2 - x1); | ||
595 | deltay = abs(y2 - y1); | ||
596 | |||
597 | if(deltax >= deltay) | ||
598 | { | ||
599 | numpixels = deltax; | ||
600 | d = 2 * deltay - deltax; | ||
601 | dinc1 = deltay * 2; | ||
602 | dinc2 = (deltay - deltax) * 2; | ||
603 | xinc1 = 1; | ||
604 | xinc2 = 1; | ||
605 | yinc1 = 0; | ||
606 | yinc2 = 1; | ||
607 | } | ||
608 | else | ||
609 | { | ||
610 | numpixels = deltay; | ||
611 | d = 2 * deltax - deltay; | ||
612 | dinc1 = deltax * 2; | ||
613 | dinc2 = (deltax - deltay) * 2; | ||
614 | xinc1 = 0; | ||
615 | xinc2 = 1; | ||
616 | yinc1 = 1; | ||
617 | yinc2 = 1; | ||
618 | } | ||
619 | numpixels++; /* include endpoints */ | ||
620 | |||
621 | if(x1 > x2) | ||
622 | { | ||
623 | xinc1 = -xinc1; | ||
624 | xinc2 = -xinc2; | ||
625 | } | ||
626 | |||
627 | if(y1 > y2) | ||
628 | { | ||
629 | yinc1 = -yinc1; | ||
630 | yinc2 = -yinc2; | ||
631 | } | ||
632 | |||
633 | x = x1; | ||
634 | y = y1; | ||
635 | |||
636 | for(i=0; i<numpixels; i++) | ||
637 | { | ||
638 | DRAW_PIXEL(x,y); | ||
639 | |||
640 | if(d < 0) | ||
641 | { | ||
642 | d += dinc1; | ||
643 | x += xinc1; | ||
644 | y += yinc1; | ||
645 | } | ||
646 | else | ||
647 | { | ||
648 | d += dinc2; | ||
649 | x += xinc2; | ||
650 | y += yinc2; | ||
651 | } | ||
652 | } | ||
653 | } | ||
654 | |||
655 | /* | ||
656 | * Set a single pixel | ||
657 | */ | ||
658 | void lcd_drawpixel(int x, int y) | ||
659 | { | ||
660 | DRAW_PIXEL(x,y); | ||
661 | } | ||
662 | |||
663 | /* | ||
664 | * Clear a single pixel | ||
665 | */ | ||
666 | void lcd_clearpixel(int x, int y) | ||
667 | { | ||
668 | CLEAR_PIXEL(x,y); | ||
669 | } | ||
670 | |||
671 | |||
672 | #else | ||
673 | /* no LCD defined, no code to use */ | ||
674 | #endif | ||
675 | |||
676 | /* ----------------------------------------------------------------- | ||
677 | * local variables: | ||
678 | * eval: (load-file "rockbox-mode.el") | ||
679 | * end: | ||
680 | */ | ||