summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/fat.c29
-rw-r--r--firmware/drivers/lcd.c315
-rw-r--r--firmware/drivers/lcd.h17
3 files changed, 20 insertions, 341 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index c43807b25f..f0a2089367 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -1049,10 +1049,6 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry)
1049 for (j=longs-1; j>=0; j--) { 1049 for (j=longs-1; j>=0; j--) {
1050 unsigned char* ptr = dir->cached_buf; 1050 unsigned char* ptr = dir->cached_buf;
1051 int index = longarray[j]; 1051 int index = longarray[j];
1052#ifdef LOADABLE_FONTS
1053 int offset_idx = 0;
1054 unsigned char uni_char[2];
1055#endif
1056 /* current or cached sector? */ 1052 /* current or cached sector? */
1057 if ( sectoridx >= SECTOR_SIZE ) { 1053 if ( sectoridx >= SECTOR_SIZE ) {
1058 if ( sectoridx >= SECTOR_SIZE*2 ) { 1054 if ( sectoridx >= SECTOR_SIZE*2 ) {
@@ -1070,30 +1066,6 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry)
1070 index &= SECTOR_SIZE-1; 1066 index &= SECTOR_SIZE-1;
1071 } 1067 }
1072 1068
1073 /* piece together the name subcomponents. */
1074#ifdef LOADABLE_FONTS
1075 for (k=0; k<5; k++)
1076 {
1077 offset_idx = index + k*2 + 1;
1078 uni_char[0] = ptr[offset_idx+1];
1079 uni_char[1] = ptr[offset_idx];
1080 entry->name[l++] = from_unicode(uni_char);
1081 }
1082 for (k=0; k<6; k++)
1083 {
1084 offset_idx = index + k*2 + 14;
1085 uni_char[0] = ptr[offset_idx+1];
1086 uni_char[1] = ptr[offset_idx];
1087 entry->name[l++] = from_unicode(uni_char);
1088 }
1089 for (k=0; k<2; k++)
1090 {
1091 offset_idx = index + k*2 + 28;
1092 uni_char[0] = ptr[offset_idx+1];
1093 uni_char[1] = ptr[offset_idx];
1094 entry->name[l++] = from_unicode(uni_char);
1095 }
1096#else
1097 /* names are stored in unicode, but we 1069 /* names are stored in unicode, but we
1098 only grab the low byte (iso8859-1). */ 1070 only grab the low byte (iso8859-1). */
1099 for (k=0; k<5; k++) 1071 for (k=0; k<5; k++)
@@ -1102,7 +1074,6 @@ int fat_getnext(struct fat_dir *dir, struct fat_direntry *entry)
1102 entry->name[l++] = ptr[index + k*2 + 14]; 1074 entry->name[l++] = ptr[index + k*2 + 14];
1103 for (k=0; k<2; k++) 1075 for (k=0; k<2; k++)
1104 entry->name[l++] = ptr[index + k*2 + 28]; 1076 entry->name[l++] = ptr[index + k*2 + 28];
1105#endif
1106 } 1077 }
1107 entry->name[l]=0; 1078 entry->name[l]=0;
1108 } 1079 }
diff --git a/firmware/drivers/lcd.c b/firmware/drivers/lcd.c
index e3248878da..5240dfda42 100644
--- a/firmware/drivers/lcd.c
+++ b/firmware/drivers/lcd.c
@@ -26,17 +26,12 @@
26#include "file.h" 26#include "file.h"
27#include "debug.h" 27#include "debug.h"
28#include "system.h" 28#include "system.h"
29 29#include "font.h"
30#ifdef LOADABLE_FONTS
31#include "ajf.h"
32#include "panic.h"
33#endif
34 30
35#if defined(SIMULATOR) 31#if defined(SIMULATOR)
36#include "sim_icons.h" 32#include "sim_icons.h"
37#endif 33#endif
38 34
39
40/*** definitions ***/ 35/*** definitions ***/
41 36
42#define LCDR (PBDR_ADDR+1) 37#define LCDR (PBDR_ADDR+1)
@@ -513,9 +508,6 @@ void lcd_init (void)
513{ 508{
514 create_thread(scroll_thread, scroll_stack, 509 create_thread(scroll_thread, scroll_stack,
515 sizeof(scroll_stack), scroll_name); 510 sizeof(scroll_stack), scroll_name);
516#if defined(LOADABLE_FONTS) && defined(SIMULATOR)
517 lcd_init_fonts();
518#endif
519} 511}
520#endif 512#endif
521 513
@@ -568,17 +560,11 @@ static int ymargin=0;
568#define ASCII_MIN 0x20 /* First char in table */ 560#define ASCII_MIN 0x20 /* First char in table */
569#define ASCII_MAX 0x7f /* Last char in table */ 561#define ASCII_MAX 0x7f /* Last char in table */
570 562
571extern unsigned char char_gen_6x8[][5];
572extern unsigned char char_gen_8x12[][14];
573extern unsigned char char_gen_12x16[][22];
574
575/* All zeros and ones bitmaps for area filling */ 563/* All zeros and ones bitmaps for area filling */
576static unsigned char zeros[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 564static unsigned char zeros[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
577 0x00, 0x00 }; 565 0x00, 0x00 };
578static unsigned char ones[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 566static unsigned char ones[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
579 0xff, 0xff }; 567 0xff, 0xff };
580static char fonts[] = { 6,8,12 };
581static char fontheight[] = { 8,12,16 };
582 568
583#ifndef SIMULATOR 569#ifndef SIMULATOR
584 570
@@ -696,175 +682,14 @@ int lcd_getymargin(void)
696 return ymargin; 682 return ymargin;
697} 683}
698 684
699
700
701#ifdef LOADABLE_FONTS
702
703static unsigned char* _font = NULL;
704
705int lcd_init_fonts(void)
706{
707 if (!_font)
708 _font = ajf_read_font("/system.ajf");
709
710 if (!_font)
711 {
712 lcd_putsxy(0,0,"No font", 0);
713 return -1;
714 }
715
716 return 0;
717}
718
719void lcd_setldfont(unsigned char* f)
720{
721 _font = f;
722}
723
724unsigned char* lcd_getcurrentldfont()
725{
726 if (!_font)
727 panicf("No font loaded!");
728 return _font;
729}
730
731/*
732 * Return width and height of a string with a given font.
733 */
734int lcd_getstringsize(unsigned char *str, unsigned char* font, int *w, int *h)
735{
736 int width=0;
737 int height=0;
738 unsigned char ch;
739
740 if (!font)
741 panicf("No font specified");
742
743 while((ch = *str++))
744 {
745 int dw,dh;
746 ajf_get_charsize(ch, font, &dw, &dh);
747 if (dh>height)
748 height = dh;
749 width+=dw;
750 }
751 *w = width;
752 *h = height;
753
754 return width;
755}
756
757/*
758 * Put a string at specified bit position
759 */
760
761void lcd_putsldfxy(int x, int y, unsigned char *str)
762{
763 unsigned char ch;
764 int nx;
765 int ny=8;
766 int lcd_x = x;
767 int lcd_y = y;
768 if (!_font)
769 {
770 lcd_putsxy(0,0,"No font", 0);
771 return;
772 }
773 ny = (int)_font[2];
774 while (((ch = *str++) != '\0'))
775 {
776 unsigned char *char_buf = ajf_get_charbuf(ch, _font, &nx, &ny);
777 if (!char_buf)
778 {
779 char_buf = ajf_get_charbuf('?', _font, &nx, &ny);
780 if (!char_buf)
781 panicf("Bad font");
782 }
783 if(lcd_x + nx > LCD_WIDTH)
784 break;
785
786 lcd_bitmap (&char_buf[0], lcd_x, lcd_y, nx, ny, true);
787 lcd_x += nx;
788 }
789}
790#endif
791
792
793#ifdef LCD_PROPFONTS
794
795extern unsigned char char_dw_8x8_prop[][9];
796
797/*
798 * Return width and height of a given font.
799 */
800int lcd_getstringsize(unsigned char *str, unsigned int font, int *w, int *h)
801{
802 int width=0;
803 unsigned char ch, byte;
804 (void)font;
805
806 while((ch = *str++)) {
807 /* Limit to char generation table */
808 if (ch < ASCII_MIN)
809 /* replace unsupported letters with question marks */
810 ch = ' '-ASCII_MIN;
811 else
812 ch -= ASCII_MIN;
813
814 byte = char_dw_8x8_prop[ch][8];
815 width += (byte>>4) + 1;
816 }
817 *w = width;
818 *h = 8;
819
820 return width;
821}
822
823/*
824 * Put a string at specified bit position
825 */
826
827void lcd_putspropxy(int x, int y, unsigned char *str, int thisfont)
828{
829 unsigned int ch;
830 int nx;
831 int ny=8;
832 unsigned char *src;
833 int lcd_x = x;
834 int lcd_y = y;
835
836 (void)thisfont;
837
838 while (((ch = *str++) != '\0'))
839 {
840 /* Limit to char generation table */
841 if (ch < ASCII_MIN)
842 /* replace unsupported letters with question marks */
843 ch = ' '-ASCII_MIN;
844 else
845 ch -= ASCII_MIN;
846
847 nx = char_dw_8x8_prop[ch][8] >> 4;
848
849 if(lcd_x + nx > LCD_WIDTH)
850 break;
851
852 src = char_dw_8x8_prop[ch];
853 lcd_clearrect (lcd_x+nx, lcd_y, 1, ny );
854 lcd_bitmap (src, lcd_x, lcd_y, nx, ny, true);
855
856 lcd_x += nx+1;
857 }
858}
859
860#endif
861
862/* 685/*
863 * Put a string at specified character position 686 * Put a string at specified character position
864 */ 687 */
688//FIXME require font parameter
865void lcd_puts(int x, int y, unsigned char *str) 689void lcd_puts(int x, int y, unsigned char *str)
866{ 690{
867 int xpos,ypos,w,h; 691 int xpos,ypos,w,h;
692
868#if defined(SIMULATOR) && defined(HAVE_LCD_CHARCELLS) 693#if defined(SIMULATOR) && defined(HAVE_LCD_CHARCELLS)
869 /* We make the simulator truncate the string if it reaches the right edge, 694 /* We make the simulator truncate the string if it reaches the right edge,
870 as otherwise it'll wrap. The real target doesn't wrap. */ 695 as otherwise it'll wrap. The real target doesn't wrap. */
@@ -882,23 +707,10 @@ void lcd_puts(int x, int y, unsigned char *str)
882 if(!str || !str[0]) 707 if(!str || !str[0])
883 return; 708 return;
884 709
885#ifdef LCD_PROPFONTS
886 lcd_getstringsize(str, font, &w, &h); 710 lcd_getstringsize(str, font, &w, &h);
887 xpos = xmargin + x * fonts[font]; 711 xpos = xmargin + x*w / strlen(str); //FIXME why strlen?
888 ypos = ymargin + y * fontheight[font]; 712 ypos = ymargin + y*h;
889 lcd_putspropxy(xpos, ypos, str, font); 713 lcd_putsxy( xpos, ypos, str, font);
890#elif LOADABLE_FONTS
891 lcd_getstringsize(str,_font,&w,&h);
892 xpos = xmargin + x * w / strlen(str);
893 ypos = ymargin + y * h;
894 lcd_putsldfxy(xpos, ypos, str);
895#else
896 xpos = xmargin + x * fonts[font];
897 ypos = ymargin + y * fontheight[font];
898 lcd_putsxy(xpos, ypos, str, font);
899 w = strlen(str) * fonts[font];
900 h = fontheight[font];
901#endif
902 lcd_clearrect(xpos + w, ypos, LCD_WIDTH - (xpos + w), h); 714 lcd_clearrect(xpos + w, ypos, LCD_WIDTH - (xpos + w), h);
903#if defined(SIMULATOR) && defined(HAVE_LCD_CHARCELLS) 715#if defined(SIMULATOR) && defined(HAVE_LCD_CHARCELLS)
904 /* this function is being used when simulating a charcell LCD and 716 /* this function is being used when simulating a charcell LCD and
@@ -907,58 +719,6 @@ void lcd_puts(int x, int y, unsigned char *str)
907#endif 719#endif
908} 720}
909 721
910
911/*
912 * Put a string at specified bit position
913 */
914void lcd_putsxy(int x, int y, unsigned char *str, int thisfont)
915{
916#ifdef LCD_PROPFONTS
917 lcd_putspropxy(x,y,str,thisfont);
918#else
919
920 int nx = fonts[thisfont];
921 int ny = fontheight[thisfont];
922 int ch;
923 unsigned char *src;
924 int lcd_x = x;
925 int lcd_y = y;
926
927#ifdef LOADABLE_FONTS
928 if ( _font ) {
929 lcd_putsldfxy(x,y,str);
930 return;
931 }
932#endif
933
934 while (((ch = *str++) != '\0') && (lcd_x + nx <= LCD_WIDTH))
935 {
936 if (lcd_y + ny > LCD_HEIGHT)
937 return;
938
939 /* Limit to char generation table */
940 if ((ch < ASCII_MIN) || (ch > ASCII_MAX))
941 /* replace unsupported letters with question marks */
942 ch = '?' - ASCII_MIN;
943 else
944 ch -= ASCII_MIN;
945
946 if (thisfont == 2)
947 src = char_gen_12x16[ch];
948 else if (thisfont == 1)
949 src = char_gen_8x12[ch];
950 else
951 src = char_gen_6x8[ch];
952
953 lcd_bitmap (src, lcd_x, lcd_y, nx-1, ny, true);
954 lcd_bitmap (zeros, lcd_x+nx-1, lcd_y, 1, ny, true);
955
956 lcd_x += nx;
957
958 }
959#endif
960}
961
962/* 722/*
963 * Display a bitmap at (x, y), size (nx, ny) 723 * Display a bitmap at (x, y), size (nx, ny)
964 * clear is true to clear destination area first 724 * clear is true to clear destination area first
@@ -1265,17 +1025,6 @@ void lcd_invertpixel(int x, int y)
1265 INVERT_PIXEL(x,y); 1025 INVERT_PIXEL(x,y);
1266} 1026}
1267 1027
1268/*
1269 * Return width and height of a given font.
1270 */
1271void lcd_getfontsize(unsigned int font, int *width, int *height)
1272{
1273 if(font < sizeof(fonts)) {
1274 *width = fonts[font];
1275 *height = fontheight[font];
1276 }
1277}
1278
1279#else 1028#else
1280/* no LCD defined, no code to use */ 1029/* no LCD defined, no code to use */
1281#endif 1030#endif
@@ -1286,47 +1035,31 @@ void lcd_puts_scroll(int x, int y, unsigned char* string )
1286#ifdef HAVE_LCD_CHARCELLS 1035#ifdef HAVE_LCD_CHARCELLS
1287 s->space = 11 - x; 1036 s->space = 11 - x;
1288#else 1037#else
1289
1290#if defined(LCD_PROPFONTS) || defined(LOADABLE_FONTS)
1291 unsigned char ch[2]; 1038 unsigned char ch[2];
1292 int w, h; 1039 int w, h;
1293#endif
1294 int width, height; 1040 int width, height;
1295 lcd_getfontsize(font, &width, &height); 1041 lcd_getfontsize(font, &width, &height);
1296#if defined(LCD_PROPFONTS) || defined(LOADABLE_FONTS) 1042
1297 ch[1] = 0; /* zero terminate */ 1043 ch[1] = 0; /* zero terminate */
1298 ch[0] = string[0]; 1044 ch[0] = string[0];
1299 width = 0; 1045 width = 0;
1300 s->space = 0; 1046 s->space = 0;
1301 while ( ch[0] && 1047 while ( ch[0] &&
1302#ifdef LCD_PROPFONTS
1303 (width + lcd_getstringsize(ch, 0, &w, &h) < 1048 (width + lcd_getstringsize(ch, 0, &w, &h) <
1304 (LCD_WIDTH - x*8))) { 1049 (LCD_WIDTH - x*8))) {
1305#else
1306 (width + lcd_getstringsize(ch, _font, &w, &h) <
1307 (LCD_WIDTH - x*8))) {
1308#endif
1309 width += w; 1050 width += w;
1310 s->space++; 1051 s->space++;
1311 ch[0]=string[s->space]; 1052 ch[0]=string[s->space];
1312 } 1053 }
1313#else
1314 s->space = (LCD_WIDTH - xmargin - x*width) / width;
1315#endif
1316#endif 1054#endif
1317 1055
1318 lcd_puts(x,y,string); 1056 lcd_puts(x,y,string);
1319 s->textlen = strlen(string); 1057 s->textlen = strlen(string);
1320 1058
1321 1059#ifdef HAVE_LCD_BITMAP
1322#if defined(LCD_PROPFONTS)
1323 s->space += 2; 1060 s->space += 2;
1324 lcd_getstringsize(string,0,&w,&h); 1061 lcd_getstringsize(string,0,&w,&h);
1325 if ( w > LCD_WIDTH - xmargin ) { 1062 if ( w > LCD_WIDTH - xmargin ) {
1326#elif defined(LOADABLE_FONTS)
1327 s->space += 2;
1328 lcd_getstringsize(string,_font,&w,&h);
1329 if ( w > LCD_WIDTH - xmargin ) {
1330#else 1063#else
1331 if ( s->textlen > s->space ) { 1064 if ( s->textlen > s->space ) {
1332#endif 1065#endif
@@ -1344,32 +1077,24 @@ void lcd_puts_scroll(int x, int y, unsigned char* string )
1344 } 1077 }
1345} 1078}
1346 1079
1080
1347void lcd_stop_scroll(void) 1081void lcd_stop_scroll(void)
1348{ 1082{
1349 if ( scroll_count ) { 1083 if ( scroll_count ) {
1350 struct scrollinfo* s = &scroll; 1084 struct scrollinfo* s = &scroll;
1351 scroll_count = 0; 1085 scroll_count = 0;
1352
1353#ifdef LCD_PROPFONTS
1354 1086
1355 lcd_clearrect(xmargin + s->startx*fonts[font], 1087#ifdef HAVE_LCD_BITMAP
1356 ymargin + s->starty*fontheight[font],
1357 LCD_WIDTH - xmargin,
1358 fontheight[font]);
1359
1360#elif defined(LOADABLE_FONTS)
1361 { 1088 {
1362 int w,h; 1089 int w,h;
1363 lcd_getstringsize( s->text, _font, &w, &h); 1090 /* FIXME no font index */
1091 lcd_getstringsize( s->text, FONT_UI, &w, &h);
1364 lcd_clearrect(xmargin + s->startx*w/s->textlen, 1092 lcd_clearrect(xmargin + s->startx*w/s->textlen,
1365 ymargin + s->starty*h, 1093 ymargin + s->starty*h,
1366 LCD_WIDTH - xmargin, 1094 LCD_WIDTH - xmargin,
1367 h); 1095 h);
1368
1369 } 1096 }
1370#endif 1097#endif
1371
1372
1373 /* restore scrolled row */ 1098 /* restore scrolled row */
1374 lcd_puts(s->startx,s->starty,s->text); 1099 lcd_puts(s->startx,s->starty,s->text);
1375 lcd_update(); 1100 lcd_update();
@@ -1420,20 +1145,16 @@ static void scroll_thread(void)
1420 s->offset = 0; 1145 s->offset = 0;
1421 } 1146 }
1422 1147
1423#ifdef LCD_PROPFONTS 1148#ifdef HAVE_LCD_BITMAP
1424 lcd_clearrect(xmargin + s->startx*fonts[font], 1149 {
1425 ymargin + s->starty*fontheight[font], 1150 /* FIXME no font index */
1426 LCD_WIDTH - xmargin, 1151 int w, h;
1427 fontheight[font]); 1152 lcd_getstringsize( s->text, FONT_UI, &w, &h);
1428#elif defined(LOADABLE_FONTS)
1429 {
1430 int w,h;
1431 lcd_getstringsize( s->text, _font, &w, &h);
1432 lcd_clearrect(xmargin + s->startx*w/s->textlen, 1153 lcd_clearrect(xmargin + s->startx*w/s->textlen,
1433 ymargin + s->starty*h, 1154 ymargin + s->starty*h,
1434 LCD_WIDTH - xmargin, 1155 LCD_WIDTH - xmargin,
1435 h); 1156 h);
1436 } 1157 }
1437#endif 1158#endif
1438 lcd_puts(s->startx,s->starty,s->line); 1159 lcd_puts(s->startx,s->starty,s->line);
1439 lcd_update(); 1160 lcd_update();
diff --git a/firmware/drivers/lcd.h b/firmware/drivers/lcd.h
index 552de9a74f..23b3d75e76 100644
--- a/firmware/drivers/lcd.h
+++ b/firmware/drivers/lcd.h
@@ -101,7 +101,7 @@ extern unsigned char lcd_framebuffer[LCD_WIDTH][LCD_HEIGHT/8];
101 101
102extern void lcd_putsxy(int x, int y, unsigned char *string, int font); 102extern void lcd_putsxy(int x, int y, unsigned char *string, int font);
103extern void lcd_setfont(int font); 103extern void lcd_setfont(int font);
104extern void lcd_getfontsize(unsigned int font, int *width, int *height); 104extern void lcd_getfontsize(int font, int *width, int *height);
105extern void lcd_setmargins(int xmargin, int ymargin); 105extern void lcd_setmargins(int xmargin, int ymargin);
106extern int lcd_getxmargin(void); 106extern int lcd_getxmargin(void);
107extern int lcd_getymargin(void); 107extern int lcd_getymargin(void);
@@ -119,19 +119,6 @@ extern void lcd_invertpixel(int x, int y);
119 119
120#endif /* CHARCELLS / BITMAP */ 120#endif /* CHARCELLS / BITMAP */
121 121
122#ifdef LOADABLE_FONTS 122extern int lcd_getstringsize(unsigned char *str, int font, int *w, int *h);
123extern int lcd_init_fonts(void);
124extern void lcd_putsldfxy(int x, int y, unsigned char *str);
125extern int lcd_getstringsize(unsigned char *str,
126 unsigned char* font,
127 int *w, int *h);
128extern void lcd_setldfont(unsigned char* f);
129
130extern unsigned char* lcd_getcurrentldfont(void);
131#endif
132
133#ifdef LCD_PROPFONTS
134extern int lcd_getstringsize(unsigned char *str, unsigned int font, int *w, int *h);
135#endif
136 123
137#endif /* __LCD_H__ */ 124#endif /* __LCD_H__ */