diff --git a/Makefile b/Makefile index 66552e7..0201ce5 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ DISPLAY_WIDTH = 320 DISPLAY_HEIGHT = 240 # 1 = BGR, 0 = RGB -BGR = 1 +BGR = 0 # Invert color INVERT = 1 # Flip image diff --git a/avrrfm.c b/avrrfm.c index 6b32992..cbe33af 100644 --- a/avrrfm.c +++ b/avrrfm.c @@ -37,7 +37,7 @@ #define LABEL_OFFSET 10 #ifndef RECEIVER - #define RECEIVER 0 + #define RECEIVER 1 #endif /* 1 int = 8 seconds */ @@ -169,14 +169,14 @@ x_t x; const __flash Font *unifont = &unifontFont; - x = writeString(0, yu, unifont, buf); + x = writeString(0, yu, unifont, buf, 0xffff, 0x001f); yu += unifont->height; if (yu + unifont->height > DISPLAY_HEIGHT) yu = 0; if (xl == 0) xl = x; const __flash Font *dejaVu = &dejaVuFont; if (width > 0) fillArea(xo, yo, width, dejaVu->height, 0xffff); - width = writeString(xl, yl, dejaVu, buf); + width = writeString(xl, yl, dejaVu, buf, 0xffff, 0x0000); xo = xl; yo = yl; xl += LABEL_OFFSET; diff --git a/colorspace.c b/colorspace.c index 36a5124..2f53d53 100644 --- a/colorspace.c +++ b/colorspace.c @@ -9,14 +9,20 @@ /** * Converts the given 8 pixel in 1-Bit monochrome to 16-Bit RGB (5/6/5) color - * stored in the given array of 16 bytes. + * stored in the given array of 16 bytes, with the given background and + * foreground color. * * @param mono 8 pixel in 1-Bit monochrome * @param rgb 8 pixel in 16-Bit RGB (5/6/5) color + * @param bg background color + * @param fg foreground color */ -static void mono1ToRGB16(uint8_t mono, uint8_t *rgb) { +static void mono1ToRGB16(uint8_t mono, uint8_t *rgb, + uint16_t bg, uint16_t fg) { for (uint8_t i = 0; i < 16; i++) { - rgb[i] = (mono & (1 << ((15 - i) >> 1))) ? 0x0 : 0xff; + uint8_t _bg = i % 2 == 0 ? bg >> 8 : bg; + uint8_t _fg = i % 2 == 0 ? fg >> 8 : fg; + rgb[i] = (mono & (1 << ((15 - i) >> 1))) ? _fg : _bg; } } @@ -50,13 +56,13 @@ void writeSpace(const __flash uint8_t *bitmap, width_t width, height_t height, - space_t space) { + space_t space, uint16_t bg, uint16_t fg) { switch (space) { case SPACE_MONO1: { bytes_t bytes = width * height / 8; for (uint16_t i = 0; i < bytes; i++) { uint8_t rgb[16]; - mono1ToRGB16(bitmap[i], rgb); + mono1ToRGB16(bitmap[i], rgb, bg, fg); for (uint8_t j = 0; j < 16; j++) { transmit(rgb[j]); } diff --git a/colorspace.h b/colorspace.h index 7d47e86..a590bdf 100644 --- a/colorspace.h +++ b/colorspace.h @@ -25,10 +25,12 @@ * @param width width of the bitmap in pixels * @param height height of the bitmap in pixels * @param space color space of the bitmap + * @param bg background color (used only with SPACE_MONO1) + * @param fg foreground color (used only with SPACE_MONO1) */ void writeSpace(const __flash uint8_t *bitmap, width_t width, height_t height, - space_t space); + space_t space, uint16_t bg, uint16_t fg); #endif /* COLORSPACE_H */ diff --git a/display.c b/display.c index 195fdaf..a33ed0f 100644 --- a/display.c +++ b/display.c @@ -11,23 +11,28 @@ fillArea(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT, color); } -width_t writeBitmap(x_t x, y_t y, uint16_t index) { +width_t writeBitmap(x_t x, y_t y, uint16_t index, + uint16_t bg, uint16_t fg) { const __flash Bitmap *bitmap = &bitmaps[index]; setArea(x, y, bitmap->width, bitmap->height, false, false); - writeData(bitmap->bitmap, bitmap->width, bitmap->height, bitmap->space); + writeData(bitmap->bitmap, bitmap->width, bitmap->height, + bitmap->space, bg, fg); return bitmap->width; } -width_t writeGlyph(x_t x, y_t y, const __flash Font *font, code_t code) { +width_t writeGlyph(x_t x, y_t y, const __flash Font *font, code_t code, + uint16_t bg, uint16_t fg) { const __flash Glyph *glyph = getGlyphAddress(font, code); setArea(x, y, glyph->width, font->height, false, false); - writeData(glyph->bitmap, glyph->width, font->height, font->space); + writeData(glyph->bitmap, glyph->width, font->height, + font->space, bg, fg); return glyph->width; } -width_t writeString(x_t x, y_t y, const __flash Font *font, const char *string) { +width_t writeString(x_t x, y_t y, const __flash Font *font, const char *string, + uint16_t bg, uint16_t fg) { width_t xorig = x; uint8_t offset = 0; for (; *string != '\0'; string++) { @@ -39,7 +44,7 @@ offset = 64; } else { code_t code = c + offset; - x += writeGlyph(x, y, font, code); + x += writeGlyph(x, y, font, code, bg, fg); offset = 0; } } diff --git a/display.h b/display.h index 34b516d..2f1bb29 100644 --- a/display.h +++ b/display.h @@ -36,9 +36,12 @@ * @param x * @param y * @param index + * @param bg background color (used only with SPACE_MONO1) + * @param fg foreground color (used only with SPACE_MONO1) * @return bitmap width */ -width_t writeBitmap(x_t x, y_t y, uint16_t index); +width_t writeBitmap(x_t x, y_t y, uint16_t index, + uint16_t bg, uint16_t fg); /** * Writes the glyph with the given pseudo UTF-8 code point with the given @@ -48,18 +51,26 @@ * @param y * @param font * @param code + * @param bg background color (used only with SPACE_MONO1) + * @param fg foreground color (used only with SPACE_MONO1) * @return glyph width */ -width_t writeGlyph(x_t x, y_t y, const __flash Font *font, code_t code); +width_t writeGlyph(x_t x, y_t y, const __flash Font *font, code_t code, + uint16_t bg, uint16_t fg); /** - * Writes the given string with the given font to the given row and column. + * Writes the given string with the given font to the given row and column + * and returns the width of the string. * * @param x * @param y * @param font * @param string + * @param bg background color (used only with SPACE_MONO1) + * @param fg foreground color (used only with SPACE_MONO1) + * @return glyph width */ -width_t writeString(x_t x, y_t y, const __flash Font *font, const char *string); +width_t writeString(x_t x, y_t y, const __flash Font *font, const char *string, + uint16_t bg, uint16_t fg); #endif /* DISPLAY_H */ diff --git a/tft.c b/tft.c index c6a9a11..f234642 100644 --- a/tft.c +++ b/tft.c @@ -261,8 +261,8 @@ void writeData(const __flash uint8_t *bitmap, width_t width, height_t height, - space_t space) { + space_t space, uint16_t bg, uint16_t fg) { writeStart(); - writeSpace(bitmap, width, height, space); + writeSpace(bitmap, width, height, space, bg, fg); writeEnd(); } diff --git a/tft.h b/tft.h index 12325f2..390528d 100644 --- a/tft.h +++ b/tft.h @@ -153,9 +153,11 @@ * @param width width of the bitmap in pixels * @param height height of the bitmap in pixels * @param space color space of the bitmap + * @param bg background color (used only with SPACE_MONO1) + * @param fg foreground color (used only with SPACE_MONO1) */ void writeData(const __flash uint8_t *bitmap, width_t width, height_t height, - space_t space); + space_t space, uint16_t bg, uint16_t fg); #endif /* TFT_H */