From 1df8b5f5c175843305fd337ff23f2559c6bf7593 Mon Sep 17 00:00:00 2001 From: bsongis Date: Mon, 30 Jun 2014 17:42:32 +0200 Subject: [PATCH] Fixes #1358 --- radio/src/fonts.cpp | 4 + radio/src/fonts.h | 1 + radio/src/lcd.cpp | 342 +++++++++++++++++++++++++----------------- radio/src/lcd.h | 19 ++- radio/util/img2lbm.py | 24 ++- 5 files changed, 238 insertions(+), 152 deletions(-) diff --git a/radio/src/fonts.cpp b/radio/src/fonts.cpp index 5c1ec8bc4..37db2a744 100755 --- a/radio/src/fonts.cpp +++ b/radio/src/fonts.cpp @@ -147,6 +147,10 @@ const pm_uchar font_8x10[] PROGMEM = { #endif }; +const pm_uchar font_22x38_num[] PROGMEM = { +#include "font_22x38_num.lbm" +}; + const pm_uchar font_4x6_extra[] PROGMEM = { #include "font_04x06_extra.lbm" }; diff --git a/radio/src/fonts.h b/radio/src/fonts.h index f254800dc..bb7bd0b18 100755 --- a/radio/src/fonts.h +++ b/radio/src/fonts.h @@ -49,6 +49,7 @@ extern const pm_uchar font_10x14[]; extern const pm_uchar font_3x5[]; extern const pm_uchar font_4x6[]; extern const pm_uchar font_8x10[]; +extern const pm_uchar font_22x38_num[]; extern const pm_uchar font_5x7_extra[]; extern const pm_uchar font_10x14_extra[]; extern const pm_uchar font_4x6_extra[]; diff --git a/radio/src/lcd.cpp b/radio/src/lcd.cpp index 70875e03b..6be30dfd2 100644 --- a/radio/src/lcd.cpp +++ b/radio/src/lcd.cpp @@ -52,35 +52,19 @@ void lcd_clear() uint8_t lcdLastPos; uint8_t lcdNextPos; -void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags flags) +#if defined(CPUARM) +void lcdPutPattern(xcoord_t x, uint8_t y, const uint8_t * pattern, uint8_t width, uint8_t height, LcdFlags flags) { uint8_t *p = &displayBuf[ y / 8 * LCD_W + x ]; -#if defined(CPUARM) && !defined(BOOT) - const pm_uchar *q = (c < 0xC0) ? &font_5x7[(c-0x20)*5] : &font_5x7_extra[(c-0xC0)*5]; -#else - const pm_uchar *q = &font_5x7[(c-0x20)*5]; -#endif - - lcdNextPos = x-1; - p--; - -#if defined(CPUARM) bool blink = false; - #define BLINKING_CHAR (blink) - #define SET_BLINKING_CHAR() blink = true -#else - #define BLINKING_CHAR (0) - #define SET_BLINKING_CHAR() return -#endif - bool inv = false; if (flags & BLINK) { if (BLINK_ON_PHASE) { if (flags & INVERS) inv = true; else { - SET_BLINKING_CHAR(); + blink = true; } } } @@ -88,7 +72,176 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags flags) inv = true; } + // we need to work on the previous byte when INVERS + p--; + + for (int8_t i=0; i0) { + b1 = b[j-1] >> (8-ym8); + } + else { + keep = ~(keepref << ym8); + } + if (j= 10) + b[j] &= 1 + (keepref << 1); + else + b[j] &= keepref; + } + } + b2 = b[j] << ym8; + } + else { + keep = ~(keepref >> (8-ym8)); + } + if (!blink) { + LCD_BYTE_FILTER(dest, keep, b1|b2); + } + dest += LCD_W; + } + } + + if (inv && height<8) { + if (ym8) + lcd_mask(p, 0x01 << (ym8-1), FORCE); + else if (y) { + ASSERT_IN_DISPLAY(p - LCD_W); + lcd_mask(p - LCD_W, 0x80, FORCE); + } + } + + p++; + lcdNextPos++; + } +} + +void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags flags) +{ #if !defined(BOOT) + const pm_uchar *q = (c < 0xC0) ? &font_5x7[(c-0x20)*5] : &font_5x7_extra[(c-0xC0)*5]; +#else + const pm_uchar *q = &font_5x7[(c-0x20)*5]; +#endif + + lcdNextPos = x-1; + +#if !defined(BOOT) + unsigned char c_remapped = 0; + + if (flags & (DBLSIZE+BOLD)) { + // To save space only some DBLSIZE and BOLD chars are available + // c has to be remapped. All non existing chars mapped to 0 (space) + if (c>=',' && c<=':') + c_remapped = c - ',' + 1; + else if (c>='A' && c<='Z') + c_remapped = c - 'A' + 16; + else if (c>='a' && c<='z') + c_remapped = c - 'a' + 42; + else if (c=='_') + c_remapped = 4; + else if (c!=' ') + flags &= ~BOLD; + if ((c>= 128) && (flags & DBLSIZE)) + c_remapped = c - 60; + } + + if (flags & DBLSIZE) { + /* each letter consists of ten top bytes followed by + * by ten bottom bytes (20 bytes per * char) */ + q = &font_10x14[((uint16_t)c_remapped)*20]; + lcdPutPattern(x, y, q, 10, 14, flags); + } + else if (flags & XXLSIZE) { + q = &font_22x38_num[((uint16_t)c-'0'+5)*110]; + lcdPutPattern(x, y, q, 22, 38, flags); + } + else if (flags & MIDSIZE) { + q = &font_8x10[((uint16_t)c-0x20)*16]; + lcdPutPattern(x, y, q, 8, 10, flags); + } + else if (flags & SMLSIZE) { + q = (c < 0xc0 ? &font_4x6[(c-0x20)*5] : &font_4x6_extra[(c-0xc0)*5]); + lcdPutPattern(x, y, q, 4, 6, flags); + } + else if (flags & TINSIZE) { + q = &font_3x5[((uint16_t)c-0x2d)*3]; + lcdPutPattern(x, y, q, 3, 5, flags); + } + else if (flags & BOLD) { + q = &font_5x7_B[c_remapped*5]; + lcdPutPattern(x, y, q, 5, 7, flags); + } + else +#endif + { + lcdPutPattern(x, y, q, 5, 7, flags); + } +} +#else +void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags flags) +{ + uint8_t *p = &displayBuf[ y / 8 * LCD_W + x ]; + const pm_uchar *q = &font_5x7[(c-0x20)*5]; + + lcdNextPos = x-1; + p--; + + bool inv = false; + if (flags & BLINK) { + if (BLINK_ON_PHASE) { + if (flags & INVERS) + inv = true; + else { + return; + } + } + } + else if (flags & INVERS) { + inv = true; + } + unsigned char c_remapped = 0; #if defined(BOLD_SPECIFIC_FONT) @@ -96,9 +249,9 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags flags) #else if (flags & DBLSIZE) { #endif - // To save space only some DBLSIZE and BOLD chars are available + // To save space only some DBLSIZE and BOLD chars are available // c has to be remapped. All non existing chars mapped to 0 (space) - + if (c>=',' && c<=':') c_remapped = c - ',' + 1; else if (c>='A' && c<='Z') @@ -111,10 +264,6 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags flags) else if (c!=' ') flags &= ~BOLD; #endif -#if defined(CPUARM) - if ((c>= 128) && (flags & DBLSIZE)) - c_remapped = c - 60; -#endif #if defined(BOLD_SPECIFIC_FONT) } @@ -141,7 +290,7 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags flags) if (inv) { b1 = ~b1; b2 = ~b2; - } + } if(&p[LCD_W+1] < DISPLAY_END) { ASSERT_IN_DISPLAY(p); ASSERT_IN_DISPLAY(p+LCD_W); @@ -149,107 +298,9 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags flags) LCD_BYTE_FILTER(p+LCD_W, 0, b2); p++; lcdNextPos++; - } - } - } -#endif - -#if defined(CPUARM) && !defined(BOOT) - else if (flags & MIDSIZE) { - /* each letter consists of ten top bytes followed by - * by ten bottom bytes (20 bytes per * char) */ - q = &font_8x10[((uint16_t)c-0x20)*16]; - for (int8_t i=0; i<=9; i++) { - uint8_t b1=0, b2=0; - if (!i) { - if (!x || !inv) { - lcdNextPos++; - p++; - continue; - } - } - if (i <= 8) { - b1 = pgm_read_byte(q++); /*top byte*/ - b2 = pgm_read_byte(q++); - } - if ((b1 == 0xff) && (b2 == 0x0f)) continue; - if (inv) { - b1 = ~b1; - b2 = ~b2; - } - const uint8_t ym8 = (y & 0x07); - if (&p[LCD_W+1] < DISPLAY_END) { - LCD_BYTE_FILTER(p, ~(0xff << ym8), b1 << ym8); - uint8_t *r = p + LCD_W; - if (r> (8-ym8)), b1 >> (8-ym8)); - LCD_BYTE_FILTER(r, ~(0x0f << ym8), (b2&0x0f) << ym8); - if (ym8) { - r = r + LCD_W; - if (r> (8-ym8)), (b2&0x0f) >> (8-ym8)); - } - } - p++; - lcdNextPos++; } } } - else if (flags & SMLSIZE) { - q = (c < 0xC0) ? &font_4x6[(c-0x20)*5] : &font_4x6_extra[(c-0xC0)*5]; - const uint8_t ym8 = (y & 0x07); - for (int8_t i=0; i<=6; i++) { - uint8_t b = 0; - if (!i) { - if (!x || !inv) { - lcdNextPos++; - p++; - continue; - } - } - else if (i <= 5) b = pgm_read_byte(q++); - if (b == 0x7f) continue; - if (inv) b = ~b & 0x7f; - if (p> (8-ym8)), b >> (8-ym8)); - } - } - p++; - lcdNextPos++; - } - } - else if (flags & TINSIZE) { - q = &font_3x5[((uint16_t)c-0x2D)*3]; - const uint8_t ym8 = (y & 0x07); - for (int8_t i=0; i<=4; i++) { - uint8_t b = 0; - if (!i) { - if (!x || !inv) { - lcdNextPos++; - p++; - continue; - } - } - else if (i <= 3) b= pgm_read_byte(q++); - if (inv) b = ~b & 0x3f; - if (p> (8-ym8)), b >> (8-ym8)); - } - } - p++; - lcdNextPos++; - } - } -#endif else { const uint8_t ym8 = (y & 0x07); #if defined(BOLD_FONT) @@ -293,7 +344,7 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags flags) if (flags & BOLD) { uint8_t a; if (inv) - a = b & bb; + a = b & bb; else a = b | bb; bb = b; @@ -301,7 +352,7 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags flags) } #endif - if (p> (8-ym8)); } -#if defined(PCBTARANIS) - if (inv) { - if (ym8) lcd_mask(p, 0x01 << (ym8-1), FORCE); - else if (y) { - ASSERT_IN_DISPLAY(p - LCD_W); - lcd_mask(p - LCD_W, 0x80, FORCE); - } - } -#else if (inv && (ym8 == 1)) *p |= 0x01; -#endif } p++; lcdNextPos++; } } } +#endif void lcd_putc(xcoord_t x, uint8_t y, const unsigned char c) { @@ -464,10 +506,14 @@ void lcd_outdezNAtt(xcoord_t x, uint8_t y, lcdint_t val, LcdFlags flags, uint8_t flags &= ~LEADING0; bool dblsize = flags & DBLSIZE; #if defined(CPUARM) + bool xxlsize = flags & XXLSIZE; bool midsize = flags & MIDSIZE; + bool smlsize = flags & SMLSIZE; bool tinsize = flags & TINSIZE; #else + #define xxlsize 0 #define midsize 0 + #define smlsize 0 #define tinsize 0 #endif @@ -499,10 +545,12 @@ void lcd_outdezNAtt(xcoord_t x, uint8_t y, lcdint_t val, LcdFlags flags, uint8_t } } - if (dblsize) { fw += FWNUM; } + else if (xxlsize) { + fw += 4*FWNUM-1; + } else if (midsize) { fw += FWNUM-3; } @@ -521,8 +569,9 @@ void lcd_outdezNAtt(xcoord_t x, uint8_t y, lcdint_t val, LcdFlags flags, uint8_t if (flags & LEFT) { x += len * fw; - if (neg) - x += ((dblsize|midsize) ? 7 : FWNUM); + if (neg) { + x += ((xxlsize|dblsize|midsize) ? 7 : FWNUM); + } } lcdLastPos = x; @@ -556,15 +605,26 @@ void lcd_outdezNAtt(xcoord_t x, uint8_t y, lcdint_t val, LcdFlags flags, uint8_t } } } + else if (xxlsize) { + x -= 17; + lcd_putcAtt(x+2, y, '.', f); + } else if (midsize) { x -= 3; xn = x; } + else if (smlsize) { + x -= 2; + lcd_plot(x+1, y+5); + if ((flags&INVERS) && ((~flags & BLINK) || BLINK_ON_PHASE)) { + lcd_vline(x+1, y, 7); + } + } else if (tinsize) { x--; lcd_plot(x-1, y+4); if ((flags&INVERS) && ((~flags & BLINK) || BLINK_ON_PHASE)) { - lcd_vline(x-1, y, 6); + lcd_vline(x-1, y-1, 7); } x--; } @@ -593,7 +653,7 @@ void lcd_outdezNAtt(xcoord_t x, uint8_t y, lcdint_t val, LcdFlags flags, uint8_t lcd_hline(xn, y+10, 2); } else { - y &= ~0x07; + // TODO needed on CPUAVR? y &= ~0x07; lcd_filled_rect(xn, y+2*FH-3, ln, 2); } } diff --git a/radio/src/lcd.h b/radio/src/lcd.h index cc1ea2789..021fcdae2 100644 --- a/radio/src/lcd.h +++ b/radio/src/lcd.h @@ -65,8 +65,8 @@ #define FWNUM 5 #define FH 8 -#define LCD_LINES (LCD_H/FH) -#define LCD_COLS (LCD_W/FW) +#define LCD_LINES (LCD_H/FH) +#define LCD_COLS (LCD_W/FW) /* lcd common flags */ #define BLINK 0x01 @@ -75,9 +75,9 @@ #define INVERS 0x02 #define DBLSIZE 0x04 #ifdef BOLD_FONT - #define BOLD 0x40 + #define BOLD 0x40 #else - #define BOLD 0x00 + #define BOLD 0x00 #endif /* lcd putc flags */ @@ -112,12 +112,12 @@ #define MIDSIZE 0x0100 #define SMLSIZE 0x0200 #define TINSIZE 0x0400 - #define STREXPANDED 0x0800 + #define XXLSIZE 0x0800 #else #define MIDSIZE DBLSIZE #define SMLSIZE 0x00 #define TINSIZE 0x00 - #define STREXPANDED 0x00 + #define XXLSIZE 0x00 #endif #if defined(PCBTARANIS) @@ -127,8 +127,11 @@ #endif #if defined(CPUARM) - #define TIMEBLINK 0x10000 - #define TIMEHOUR 0x20000 + #define TIMEBLINK 0x010000 + #define TIMEHOUR 0x020000 + #define STREXPANDED 0x040000 +#else + #define STREXPANDED 0x00 #endif #if defined(CPUARM) diff --git a/radio/util/img2lbm.py b/radio/util/img2lbm.py index a911d4fec..6d3853e94 100644 --- a/radio/util/img2lbm.py +++ b/radio/util/img2lbm.py @@ -11,7 +11,7 @@ f = open(sys.argv[2], "w") if len(sys.argv) > 3: what = sys.argv[3] else: - for s in ("03x05", "04x06", "05x07", "08x10", "10x14"): + for s in ("03x05", "04x06", "05x07", "08x10", "10x14", "22x38"): if s in sys.argv[2]: what = s break @@ -76,6 +76,8 @@ elif what == "04x06": for z in range(7): if image.pixel(x, y+z) == Qt.qRgb(0, 0, 0): value += 1 << z + if value == 0x7f: + value = 0xff f.write("0x%02x," % value) f.write("\n") elif what == "05x07": @@ -90,11 +92,17 @@ elif what == "05x07": elif what == "08x10": for y in range(0, height, 12): for x in range(width): + skip = True for l in range(0, 12, 8): value = 0 for z in range(8): - if l+z < 12 and image.pixel(x, y+l+z) == Qt.qRgb(0, 0, 0): - value += 1 << z + if l+z < 12: + if image.pixel(x, y+l+z) == Qt.qRgb(0, 0, 0): + value += 1 << z + else: + skip = False + if skip and l==8: + value = 0xff f.write("0x%02x," % value) f.write("\n") elif what == "10x14": @@ -107,5 +115,15 @@ elif what == "10x14": value += 1 << z f.write("0x%02x," % value) f.write("\n") +elif what == "22x38": + for y in range(0, height, 40): + for x in range(width): + for l in range(0, 40, 8): + value = 0 + for z in range(8): + if image.pixel(x, y+l+z) == Qt.qRgb(0, 0, 0): + value += 1 << z + f.write("0x%02x," % value) + f.write("\n") else: print("wrong argument", sys.argv[3])