diff options
-rw-r--r-- | firmware/drivers/lcd.c | 105 |
1 files changed, 97 insertions, 8 deletions
diff --git a/firmware/drivers/lcd.c b/firmware/drivers/lcd.c index 9cecf56e18..3559992022 100644 --- a/firmware/drivers/lcd.c +++ b/firmware/drivers/lcd.c | |||
@@ -24,10 +24,12 @@ | |||
24 | #include <string.h> | 24 | #include <string.h> |
25 | #include <stdlib.h> | 25 | #include <stdlib.h> |
26 | #include "file.h" | 26 | #include "file.h" |
27 | #include "debug.h" | ||
28 | #include "system.h" | ||
27 | 29 | ||
28 | /*** definitions ***/ | 30 | /*** definitions ***/ |
29 | 31 | ||
30 | #define LCDR (PBDR+1) | 32 | #define LCDR (PBDR_ADDR+1) |
31 | 33 | ||
32 | /* PA14 : /LCD-BL --- backlight */ | 34 | /* PA14 : /LCD-BL --- backlight */ |
33 | #define LCD_BL 6 | 35 | #define LCD_BL 6 |
@@ -170,7 +172,7 @@ static int scroll_count = 0; | |||
170 | * | 172 | * |
171 | */ | 173 | */ |
172 | 174 | ||
173 | 175 | #define ASM_IMPLEMENTATION | |
174 | 176 | ||
175 | static void lcd_write(bool command, int byte) | 177 | static void lcd_write(bool command, int byte) |
176 | 178 | ||
@@ -196,11 +198,12 @@ static void lcd_write(bool command, int byte) | |||
196 | : | 198 | : |
197 | : /* %0 */ "r"(((unsigned)byte)<<16), | 199 | : /* %0 */ "r"(((unsigned)byte)<<16), |
198 | /* %1 */ "r"(8), | 200 | /* %1 */ "r"(8), |
199 | /* %2 */ "I"(~(LCD_SC|LCD_SD)), | 201 | /* %2 */ "I"(~(LCD_SC|LCD_SD|LCD_DS)), |
200 | /* %3 */ "I"(LCD_SD), | 202 | /* %3 */ "I"(LCD_SD), |
201 | /* %4 */ "I"(LCD_SC|LCD_DS), | 203 | /* %4 */ "I"(LCD_SC), |
202 | /* %5 */ "z"(LCDR)); | 204 | /* %5 */ "z"(LCDR)); |
203 | else | 205 | else |
206 | #if 0 | ||
204 | asm ("shll8 %0\n" | 207 | asm ("shll8 %0\n" |
205 | "0: \n\t" | 208 | "0: \n\t" |
206 | "and.b %2, @(r0,gbr)\n\t" | 209 | "and.b %2, @(r0,gbr)\n\t" |
@@ -215,10 +218,69 @@ static void lcd_write(bool command, int byte) | |||
215 | : | 218 | : |
216 | : /* %0 */ "r"(((unsigned)byte)<<16), | 219 | : /* %0 */ "r"(((unsigned)byte)<<16), |
217 | /* %1 */ "r"(8), | 220 | /* %1 */ "r"(8), |
218 | /* %2 */ "I"(~(LCD_SC|LCD_DS|LCD_SD)), | 221 | /* %2 */ "I"(~(LCD_SC|LCD_SD)), |
219 | /* %3 */ "I"(LCD_SD), | 222 | /* %3 */ "I"(LCD_SD|LCD_DS), |
220 | /* %4 */ "I"(LCD_SC), | 223 | /* %4 */ "I"(LCD_SC|LCD_DS), |
221 | /* %5 */ "z"(LCDR)); | 224 | /* %5 */ "z"(LCDR)); |
225 | #else | ||
226 | asm ("shll8 %0\n" | ||
227 | "0: \n\t" | ||
228 | "and.b %2, @(r0,gbr)\n\t" | ||
229 | "shll %0\n\t" | ||
230 | "bf 1f\n\t" | ||
231 | "or.b %3, @(r0,gbr)\n" | ||
232 | "1: \n\t" | ||
233 | "or.b %4, @(r0,gbr)\n" | ||
234 | "and.b %2, @(r0,gbr)\n\t" | ||
235 | "shll %0\n\t" | ||
236 | "bf 1f\n\t" | ||
237 | "or.b %3, @(r0,gbr)\n" | ||
238 | "1: \n\t" | ||
239 | "or.b %4, @(r0,gbr)\n" | ||
240 | "and.b %2, @(r0,gbr)\n\t" | ||
241 | "shll %0\n\t" | ||
242 | "bf 1f\n\t" | ||
243 | "or.b %3, @(r0,gbr)\n" | ||
244 | "1: \n\t" | ||
245 | "or.b %4, @(r0,gbr)\n" | ||
246 | "and.b %2, @(r0,gbr)\n\t" | ||
247 | "shll %0\n\t" | ||
248 | "bf 1f\n\t" | ||
249 | "or.b %3, @(r0,gbr)\n" | ||
250 | "1: \n\t" | ||
251 | "or.b %4, @(r0,gbr)\n" | ||
252 | "and.b %2, @(r0,gbr)\n\t" | ||
253 | "shll %0\n\t" | ||
254 | "bf 1f\n\t" | ||
255 | "or.b %3, @(r0,gbr)\n" | ||
256 | "1: \n\t" | ||
257 | "or.b %4, @(r0,gbr)\n" | ||
258 | "and.b %2, @(r0,gbr)\n\t" | ||
259 | "shll %0\n\t" | ||
260 | "bf 1f\n\t" | ||
261 | "or.b %3, @(r0,gbr)\n" | ||
262 | "1: \n\t" | ||
263 | "or.b %4, @(r0,gbr)\n" | ||
264 | "and.b %2, @(r0,gbr)\n\t" | ||
265 | "shll %0\n\t" | ||
266 | "bf 1f\n\t" | ||
267 | "or.b %3, @(r0,gbr)\n" | ||
268 | "1: \n\t" | ||
269 | "or.b %4, @(r0,gbr)\n" | ||
270 | "and.b %2, @(r0,gbr)\n\t" | ||
271 | "shll %0\n\t" | ||
272 | "bf 1f\n\t" | ||
273 | "or.b %3, @(r0,gbr)\n" | ||
274 | "1: \n\t" | ||
275 | "or.b %4, @(r0,gbr)\n" | ||
276 | : | ||
277 | : /* %0 */ "r"(((unsigned)byte)<<16), | ||
278 | /* %1 */ "r"(8), | ||
279 | /* %2 */ "I"(~(LCD_SC|LCD_SD)), | ||
280 | /* %3 */ "I"(LCD_SD|LCD_DS), | ||
281 | /* %4 */ "I"(LCD_SC|LCD_DS), | ||
282 | /* %5 */ "z"(LCDR)); | ||
283 | #endif | ||
222 | 284 | ||
223 | asm("or.b %0, @(r0,gbr)" | 285 | asm("or.b %0, @(r0,gbr)" |
224 | : | 286 | : |
@@ -496,6 +558,17 @@ void lcd_init (void) | |||
496 | PBCR2 &= 0xff00; /* MD = 00 */ | 558 | PBCR2 &= 0xff00; /* MD = 00 */ |
497 | PBIOR |= 0x000f; /* IOR = 1 */ | 559 | PBIOR |= 0x000f; /* IOR = 1 */ |
498 | 560 | ||
561 | /* We are using timer 2 */ | ||
562 | |||
563 | TSTR &= ~0x04; /* Stop the timer */ | ||
564 | TSNC &= ~0x04; /* No synchronization */ | ||
565 | TMDR &= ~0x04; /* Operate normally */ | ||
566 | |||
567 | TCNT2 = 0; /* Start counting at 0 */ | ||
568 | TCR2 = 0x03; /* sysclock/8 */ | ||
569 | |||
570 | TSTR |= 0x04; /* Start timer 2 */ | ||
571 | |||
499 | lcd_clear_display(); | 572 | lcd_clear_display(); |
500 | lcd_update(); | 573 | lcd_update(); |
501 | create_thread(scroll_thread, scroll_stack, | 574 | create_thread(scroll_thread, scroll_stack, |
@@ -509,7 +582,15 @@ void lcd_init (void) | |||
509 | void lcd_update (void) | 582 | void lcd_update (void) |
510 | { | 583 | { |
511 | int x, y; | 584 | int x, y; |
512 | 585 | #ifdef DEBUG | |
586 | int t1; | ||
587 | int t; | ||
588 | int i, d; | ||
589 | int tk1, tk2; | ||
590 | |||
591 | TCNT2 = 0; | ||
592 | tk1 = current_tick; | ||
593 | #endif | ||
513 | /* Copy display bitmap to hardware */ | 594 | /* Copy display bitmap to hardware */ |
514 | for (y = 0; y < LCD_HEIGHT/8; y++) | 595 | for (y = 0; y < LCD_HEIGHT/8; y++) |
515 | { | 596 | { |
@@ -520,6 +601,14 @@ void lcd_update (void) | |||
520 | for (x = 0; x < LCD_WIDTH; x++) | 601 | for (x = 0; x < LCD_WIDTH; x++) |
521 | lcd_write (false, display[x][y]); | 602 | lcd_write (false, display[x][y]); |
522 | } | 603 | } |
604 | #ifdef DEBUG | ||
605 | tk2 = current_tick; | ||
606 | t1 = TCNT2; | ||
607 | t = (t1 * 10) / (FREQ/8000); | ||
608 | i = t / 10; | ||
609 | d = t % 10; | ||
610 | DEBUGF("TCNT2: %d, (%d.%d ms), %d\n", t1, i, d, tk2-tk1); | ||
611 | #endif | ||
523 | } | 612 | } |
524 | 613 | ||
525 | #endif /* SIMULATOR */ | 614 | #endif /* SIMULATOR */ |