summaryrefslogtreecommitdiff
path: root/firmware/drivers/lcd.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/lcd.c')
-rw-r--r--firmware/drivers/lcd.c198
1 files changed, 170 insertions, 28 deletions
diff --git a/firmware/drivers/lcd.c b/firmware/drivers/lcd.c
index a9cd8c65ac..806b812b82 100644
--- a/firmware/drivers/lcd.c
+++ b/firmware/drivers/lcd.c
@@ -27,6 +27,13 @@
27#include "debug.h" 27#include "debug.h"
28#include "system.h" 28#include "system.h"
29 29
30#ifdef LOADABLE_FONTS
31#include "ajf.h"
32#include "panic.h"
33#endif
34
35
36
30/*** definitions ***/ 37/*** definitions ***/
31 38
32#define LCDR (PBDR_ADDR+1) 39#define LCDR (PBDR_ADDR+1)
@@ -296,21 +303,21 @@ static void lcd_write(bool command, int byte)
296 PBDR &= ~LCD_CS; /* enable lcd chip select */ 303 PBDR &= ~LCD_CS; /* enable lcd chip select */
297 304
298 if ( command ) { 305 if ( command ) {
299 on=~(LCD_SD|LCD_SC|LCD_DS); 306 on=~(LCD_SD|LCD_SC|LCD_DS);
300 off=LCD_SC; 307 off=LCD_SC;
301 } 308 }
302 else { 309 else {
303 on=~(LCD_SD|LCD_SC); 310 on=~(LCD_SD|LCD_SC);
304 off=LCD_SC|LCD_DS; 311 off=LCD_SC|LCD_DS;
305 } 312 }
306 313
307 /* clock out each bit, MSB first */ 314 /* clock out each bit, MSB first */
308 for (i=0x80;i;i>>=1) 315 for (i=0x80;i;i>>=1)
309 { 316 {
310 PBDR &= on; 317 PBDR &= on;
311 if (i & byte) 318 if (i & byte)
312 PBDR |= LCD_SD; 319 PBDR |= LCD_SD;
313 PBDR |= off; 320 PBDR |= off;
314 } 321 }
315 322
316 PBDR |= LCD_CS; /* disable lcd chip select */ 323 PBDR |= LCD_CS; /* disable lcd chip select */
@@ -322,9 +329,9 @@ static void lcd_write(bool command, int byte)
322void lcd_backlight(bool on) 329void lcd_backlight(bool on)
323{ 330{
324 if ( on ) 331 if ( on )
325 PAIOR |= LCD_BL; 332 PAIOR |= LCD_BL;
326 else 333 else
327 PAIOR &= ~LCD_BL; 334 PAIOR &= ~LCD_BL;
328} 335}
329 336
330#endif /* SIMULATOR */ 337#endif /* SIMULATOR */
@@ -431,7 +438,7 @@ void lcd_define_pattern (int which,char *pattern,int length)
431 int i; 438 int i;
432 lcd_write(true,LCD_PRAM|which); 439 lcd_write(true,LCD_PRAM|which);
433 for (i=0;i<length;i++) 440 for (i=0;i<length;i++)
434 lcd_write(false,pattern[i]); 441 lcd_write(false,pattern[i]);
435} 442}
436 443
437void lcd_double_height(bool on) 444void lcd_double_height(bool on)
@@ -510,7 +517,9 @@ void lcd_init (void)
510{ 517{
511 create_thread(scroll_thread, scroll_stack, 518 create_thread(scroll_thread, scroll_stack,
512 sizeof(scroll_stack), scroll_name); 519 sizeof(scroll_stack), scroll_name);
513 520#if defined(LOADABLE_FONTS) && defined(SIMULATOR)
521 lcd_init_fonts();
522#endif
514 memset(icon_mirror, sizeof(icon_mirror), 0); 523 memset(icon_mirror, sizeof(icon_mirror), 0);
515} 524}
516#endif 525#endif
@@ -541,8 +550,8 @@ static int ymargin=0;
541 * This contains only the printable characters (0x20-0x7f). 550 * This contains only the printable characters (0x20-0x7f).
542 * Each element in this table is a character pattern bitmap. 551 * Each element in this table is a character pattern bitmap.
543 */ 552 */
544#define ASCII_MIN 0x20 /* First char in table */ 553#define ASCII_MIN 0x20 /* First char in table */
545#define ASCII_MAX 0x7f /* Last char in table */ 554#define ASCII_MAX 0x7f /* Last char in table */
546 555
547extern unsigned char char_gen_6x8[][5]; 556extern unsigned char char_gen_6x8[][5];
548extern unsigned char char_gen_8x12[][14]; 557extern unsigned char char_gen_8x12[][14];
@@ -550,9 +559,9 @@ extern unsigned char char_gen_12x16[][22];
550 559
551/* All zeros and ones bitmaps for area filling */ 560/* All zeros and ones bitmaps for area filling */
552static unsigned char zeros[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 561static unsigned char zeros[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
553 0x00, 0x00 }; 562 0x00, 0x00 };
554static unsigned char ones[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 563static unsigned char ones[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
555 0xff, 0xff }; 564 0xff, 0xff };
556static char fonts[] = { 6,8,12 }; 565static char fonts[] = { 6,8,12 };
557static char fontheight[] = { 8,12,16 }; 566static char fontheight[] = { 8,12,16 };
558 567
@@ -654,6 +663,101 @@ void lcd_setmargins(int x, int y)
654 ymargin = y; 663 ymargin = y;
655} 664}
656 665
666
667
668#ifdef LOADABLE_FONTS
669
670static unsigned char* _font = NULL;
671
672int lcd_init_fonts(void)
673{
674 if (!_font)
675 _font = ajf_read_font("/system.ajf");
676
677 if (!_font)
678 {
679 lcd_putsxy(0,0,"No font", 0);
680 return -1;
681 }
682
683 return 0;
684}
685
686void lcd_setldfont(unsigned char* f)
687{
688 _font = f;
689}
690
691unsigned char* lcd_getcurrentldfont()
692{
693 if (!_font)
694 panicf("No font loaded!");
695 return _font;
696}
697
698/*
699 * Return width and height of a string with a given font.
700 */
701int lcd_getstringsize(unsigned char *str, unsigned char* font, int *w, int *h)
702{
703 int width=0;
704 int height=0;
705 unsigned char ch;
706
707 if (!font)
708 panicf("No font specified");
709
710 while((ch = *str++))
711 {
712 int dw,dh;
713 ajf_get_charsize(ch, font, &dw, &dh);
714 if (dh>height)
715 height = dh;
716 width+=dw;
717 }
718 *w = width;
719 *h = height;
720
721 return width;
722}
723
724/*
725 * Put a string at specified bit position
726 */
727
728void lcd_putsldfxy(int x, int y, unsigned char *str)
729{
730 unsigned char ch;
731 int nx;
732 int ny=8;
733 int lcd_x = x;
734 int lcd_y = y;
735 if (!_font)
736 {
737 lcd_putsxy(0,0,"No font", 0);
738 return;
739 }
740 ny = (int)_font[2];
741 while (((ch = *str++) != '\0'))
742 {
743 unsigned char *char_buf = ajf_get_charbuf(ch, _font, &nx, &ny);
744 if (!char_buf)
745 {
746 char_buf = ajf_get_charbuf('?', _font, &nx, &ny);
747 if (!char_buf)
748 panicf("Bad font");
749 }
750 if(lcd_x + nx > LCD_WIDTH)
751 break;
752
753 lcd_clearrect (lcd_x, lcd_y, 1, ny);
754 lcd_bitmap (&char_buf[0], lcd_x, lcd_y, nx, ny, true);
755 lcd_x += nx+1;
756 }
757}
758#endif
759
760
657#ifdef LCD_PROPFONTS 761#ifdef LCD_PROPFONTS
658 762
659extern unsigned char char_dw_8x8_prop[][9]; 763extern unsigned char char_dw_8x8_prop[][9];
@@ -746,10 +850,19 @@ void lcd_puts(int x, int y, unsigned char *str)
746 ymargin = 8; 850 ymargin = 8;
747#endif 851#endif
748 852
853 if(!str || !str[0])
854 return;
855
749#ifdef LCD_PROPFONTS 856#ifdef LCD_PROPFONTS
750 lcd_putspropxy( xmargin + x*fonts[font], 857 lcd_putspropxy( xmargin + x*fonts[font],
751 ymargin + y*fontheight[font], 858 ymargin + y*fontheight[font],
752 str, font ); 859 str, font );
860#elif LOADABLE_FONTS
861 {
862 int w,h;
863 lcd_getstringsize(str,_font,&w,&h);
864 lcd_putsldfxy( xmargin + x*w/strlen(str), ymargin + y*h, str );
865 }
753#else 866#else
754 lcd_putsxy( xmargin + x*fonts[font], 867 lcd_putsxy( xmargin + x*fonts[font],
755 ymargin + y*fontheight[font], 868 ymargin + y*fontheight[font],
@@ -1105,25 +1218,31 @@ void lcd_puts_scroll(int x, int y, unsigned char* string )
1105 s->space = 11 - x; 1218 s->space = 11 - x;
1106#else 1219#else
1107 1220
1108#ifdef LCD_PROPFONTS 1221#if defined(LCD_PROPFONTS) || defined(LOADABLE_FONTS)
1109 unsigned char ch[2]; 1222 unsigned char ch[2];
1110 int w, h; 1223 int w, h;
1111#endif 1224#endif
1112 int width, height; 1225 int width, height;
1113 lcd_getfontsize(font, &width, &height); 1226 lcd_getfontsize(font, &width, &height);
1114#ifndef LCD_PROPFONTS 1227#if defined(LCD_PROPFONTS) || defined(LOADABLE_FONTS)
1115 s->space = (LCD_WIDTH - xmargin - x*width) / width;
1116#else
1117 ch[1] = 0; /* zero terminate */ 1228 ch[1] = 0; /* zero terminate */
1118 ch[0] = string[0]; 1229 ch[0] = string[0];
1119 width = 0; 1230 width = 0;
1120 for (s->space = 0; 1231 s->space = 0;
1121 ch[0] && 1232 while ( ch[0] &&
1122 (width + lcd_getstringsize(ch, 0, &w, &h) < (LCD_WIDTH - x*8)); 1233#ifdef LCD_PROPFONTS
1123 ) { 1234 (width + lcd_getstringsize(ch, 0, &w, &h) <
1235 (LCD_WIDTH - x*8))) {
1236#else
1237 (width + lcd_getstringsize(ch, _font, &w, &h) <
1238 (LCD_WIDTH - x*8))) {
1239#endif
1124 width += w; 1240 width += w;
1125 ch[0]=string[(int)++s->space]; 1241 s->space++;
1242 ch[0]=string[s->space];
1126 } 1243 }
1244#else
1245 s->space = (LCD_WIDTH - xmargin - x*width) / width;
1127#endif 1246#endif
1128#endif 1247#endif
1129 1248
@@ -1148,11 +1267,25 @@ void lcd_stop_scroll(void)
1148 scroll_count = 0; 1267 scroll_count = 0;
1149 1268
1150#ifdef LCD_PROPFONTS 1269#ifdef LCD_PROPFONTS
1270
1151 lcd_clearrect(xmargin + s->startx*fonts[font], 1271 lcd_clearrect(xmargin + s->startx*fonts[font],
1152 ymargin + s->starty*fontheight[font], 1272 ymargin + s->starty*fontheight[font],
1153 LCD_WIDTH - xmargin, 1273 LCD_WIDTH - xmargin,
1154 fontheight[font]); 1274 fontheight[font]);
1275
1276#elif defined(LOADABLE_FONTS)
1277 {
1278 int w,h;
1279 lcd_getstringsize( s->text, _font, &w, &h);
1280 lcd_clearrect(xmargin + s->startx*w/s->textlen,
1281 ymargin + s->starty*h,
1282 LCD_WIDTH - xmargin,
1283 h);
1284
1285 }
1155#endif 1286#endif
1287
1288
1156 /* restore scrolled row */ 1289 /* restore scrolled row */
1157 lcd_puts(s->startx,s->starty,s->text); 1290 lcd_puts(s->startx,s->starty,s->text);
1158 lcd_update(); 1291 lcd_update();
@@ -1208,6 +1341,15 @@ static void scroll_thread(void)
1208 ymargin + s->starty*fontheight[font], 1341 ymargin + s->starty*fontheight[font],
1209 LCD_WIDTH - xmargin, 1342 LCD_WIDTH - xmargin,
1210 fontheight[font]); 1343 fontheight[font]);
1344#elif defined(LOADABLE_FONTS)
1345 {
1346 int w,h;
1347 lcd_getstringsize( s->text, _font, &w, &h);
1348 lcd_clearrect(xmargin + s->startx*w/s->textlen,
1349 ymargin + s->starty*h,
1350 LCD_WIDTH - xmargin,
1351 h);
1352 }
1211#endif 1353#endif
1212 lcd_puts(s->startx,s->starty,s->line); 1354 lcd_puts(s->startx,s->starty,s->line);
1213 lcd_update(); 1355 lcd_update();