Fork of David Smart's RA8875 library
Fork of RA8875 by
Revision 37:f19b7e7449dc, committed 2014-01-25
- Comitter:
- WiredHome
- Date:
- Sat Jan 25 19:47:33 2014 +0000
- Parent:
- 36:300f6ee0b2cf
- Child:
- 38:38d503b4fad6
- Commit message:
- major API tweak to use typedef's for pixel locations, dimensions, and text locations.
Changed in this revision
--- a/DisplayDefs.h Sat Jan 25 00:00:02 2014 +0000 +++ b/DisplayDefs.h Sat Jan 25 19:47:33 2014 +0000 @@ -17,11 +17,22 @@ not_enough_ram, ///< could not allocate ram for scanline } RetCode_t; +/// type that manages locations, which is typically an x or y pixel location, +/// which can range from -N to +N (even if the screen is 0 to +n). @see textloc_t. +typedef int16_t loc_t; + +/// type that manages text locations, which are row or column values in +/// units of character, not pixel. @see loc_t. +typedef uint16_t textloc_t; + +/// type that manages dimensions of width or height, which range from 0 to N. +typedef uint16_t dim_t; + /// type that manages x,y pairs typedef struct { - uint16_t x; ///< x value in the point - uint16_t y; ///< y value in the point + loc_t x; ///< x value in the point + loc_t y; ///< y value in the point } point_t; /// color type definition to let the compiler help keep us honest.
--- a/GraphicsDisplay.cpp Sat Jan 25 00:00:02 2014 +0000 +++ b/GraphicsDisplay.cpp Sat Jan 25 19:47:33 2014 +0000 @@ -12,7 +12,7 @@ // provided by the super-class. #define USE_HW -//#define DEBUG "GD" +#define DEBUG "GD" // ... // INFO("Stuff to show %d", var); // new-line is automatically appended // @@ -47,8 +47,6 @@ #define HexDump(a, b, c) #endif -// #define LOCALFONT - #ifdef LOCALFONT const unsigned char FONT8x8[97][8] = { 0x08, 0x08, 0x08, 0X00, 0X00, 0X00, 0X00, 0X00, // columns, rows, num_bytes_per_char @@ -155,21 +153,17 @@ : TextDisplay(name) { font = NULL; - //foreground(0xFFFF); - //background(0x0000); } RetCode_t GraphicsDisplay::set_font(const unsigned char * _font) { - font = _font; - INFO("set_font(%lu) %lu", _font, font); - return noerror; // trusting them, but it might be good to put some checks in here... + font = _font; // trusting them, but it might be good to put some checks in here... + return noerror; } #ifdef LOCALFONT int GraphicsDisplay::character(int x, int y, int value) { - INFO("character(%d,%d,%c)", x, t, value); if (value <= 0x1F && value >= 7F) return 0; @@ -190,7 +184,7 @@ } #endif -RetCode_t GraphicsDisplay::window(unsigned int x, unsigned int y, unsigned int w, unsigned int h) +RetCode_t GraphicsDisplay::window(loc_t x, loc_t y, dim_t w, dim_t h) { // current pixel location _x = x; @@ -210,7 +204,6 @@ RetCode_t GraphicsDisplay::putp(color_t color) { - // put pixel at current pixel location pixel(_x, _y, color); // update pixel location based on window settings _x++; @@ -230,9 +223,12 @@ fillrect(x,y, x+w, y+h, color); #else window(x, y, w, h); + _StartGraphicsStream(); for(int i=0; i<w*h; i++) { putp(color); } + _EndGraphicsStream(); + WindowMax(); #endif } @@ -245,11 +241,15 @@ void GraphicsDisplay::blit(int x, int y, int w, int h, const int * color) { window(x, y, w, h); + _StartGraphicsStream(); for (int i=0; i<w*h; i++) { putp(color[i]); } + _EndGraphicsStream(); + WindowMax(); } +#ifdef LOCALFONT int GraphicsDisplay::blitbit(int x, int y, int w, int h, const char * color) { _foreground = 0xFFFF; @@ -259,6 +259,7 @@ color[0], color[1], color[2], color[3], color[4], color[5], color[6], color[7], color[8], color[9], color[10], color[11], color[12], color[13], color[14], color[15]); window(x, y, w, h); + _StartGraphicsStream(); for (int i = 0; i < w*h; i++) { char byte = color[i >> 3]; int offset = i & 0x7; @@ -267,30 +268,42 @@ int c = ((byte << offset) & 0x80) ? _foreground : _background; putp(c); } + _EndGraphicsStream(); + WindowMax(); return w; } +#endif int GraphicsDisplay::fontblit(int x, int y, const unsigned char * fontTable, const unsigned char * fontChar) { - _foreground = 0xFFFF; //int fontWidth = font[1]; // get hor size of font int fontHeight = font[2]; // get vert size of font int bytesPerLine = font[3]; // bytes per line int charWidth = fontChar[0]; // width of this character int px, py; + + //INFO("(%d,%d) %lu, %lu %X/%X", x,y, fontTable, fontChar, _foreground, _background); + //INFO("char size (%d,%d)", charWidth, fontHeight); + //HexDump("char", (uint8_t *)fontChar, 32); + //INFO("(f,b) = (%04X,%04X)", _foreground, _background) window(x, y, charWidth, fontHeight); - + _StartGraphicsStream(); + //INFO("(f,b) = (%04X,%04X)", _foreground, _background) for (py = 0; py < fontHeight; py++) { int bitmask = 1 << (py & 7); for (px = 0; px < charWidth; px++) { int offset = (py / 8) + px * bytesPerLine; unsigned char byte = fontChar[offset + 1]; // skip the char's # bits wide value - int c = (byte & bitmask) ? _foreground : _background; + color_t c = (byte & bitmask) ? _foreground : _background; + //INFO("(%2d,%2d) %02X & %02X => %04X [%04X,%04X]", px, py, byte, bitmask, c, _foreground, _background); + //pixel(x+px, y+py, c); putp(c); } } + _EndGraphicsStream(); + WindowMax(); return charWidth; } @@ -307,14 +320,11 @@ c = ((colorPalette[i].rgbBlue >> 3) << 0); c |= ((colorPalette[i].rgbGreen >> 2) << 5); c |= ((colorPalette[i].rgbRed >> 3) << 11); - c = (c >> 8) | (c << 8); - //INFO("B %02X G %02X R %02X c %04X", colorPalette[i].rgbBlue, colorPalette[i].rgbGreen, - // colorPalette[i].rgbRed, c); return c; } -RetCode_t GraphicsDisplay::RenderBitmapFile(unsigned int x, unsigned int y, const char *Name_BMP) +RetCode_t GraphicsDisplay::RenderBitmapFile(loc_t x, loc_t y, const char *Name_BMP) { #define OffsetPixelWidth 18 #define OffsetPixelHeight 22 @@ -327,7 +337,6 @@ RGBQUAD * colorPalette = NULL; int colorCount; uint8_t * lineBuffer = NULL; - uint16_t BPP_t; uint32_t PixelWidth, PixelHeight; uint32_t start_data; @@ -410,15 +419,12 @@ start_data = BMP_Header.bfOffBits; HexDump("Raw Data", (uint8_t *)&start_data, 32); - //bool tag = true; //INFO("(%d,%d) (%d,%d), [%d,%d]", x,y, PixelWidth,PixelHeight, lineBufSize, padd); for (j = PixelHeight - 1; j >= 0; j--) { //Lines bottom up offset = start_data + j * (lineBufSize + padd); // start of line fseek(Image, offset, SEEK_SET); fread(lineBuffer, 1, lineBufSize, Image); // read a line - slow ! //INFO("offset: %6X", offset); - //if (tag) - // HexDump("Line", (uint8_t *)lineBuffer, lineBufSize); for (i = 0; i < PixelWidth; i++) { // copy pixel data to TFT if (BPP_t == 4) { uint8_t dPix = lineBuffer[i/2]; @@ -431,16 +437,11 @@ } else if (BPP_t == 16) { putp(lineBuffer[i]); } else if (BPP_t == 24) { - color_t color; // BGR + color_t color; color = RGB(lineBuffer[i*3+2], lineBuffer[i*3+1], lineBuffer[i*3+0]); - //if (tag) - // INFO("color[%2d]: RGB(%02X,%02X,%02X) => %04X", - // i, lineBuffer[i*2], lineBuffer[i*3+1], lineBuffer[i*3+0], color); - color = (color >> 8) | (color << 8); putp(color); } } - //tag = false; } free(lineBuffer); free(colorPalette);
--- a/GraphicsDisplay.h Sat Jan 25 00:00:02 2014 +0000 +++ b/GraphicsDisplay.h Sat Jan 25 19:47:33 2014 +0000 @@ -16,6 +16,13 @@ #include "Bitmap.h" #include "TextDisplay.h" +// GraphicsDisplay has one "soft font" which is in a different format +// then the primary font rendering api - see set_font(...). This is +// therefore deprecated, but preserved for a time for backward +// compatibility. +// #define LOCALFONT + + /// The GraphicsDisplay class /// /// This graphics display class supports both graphics and text operations. @@ -39,7 +46,7 @@ /// @param color defines the color for the pixel. /// @returns success/failure code. @see RetCode_t. /// - virtual RetCode_t pixel(unsigned int x, unsigned int y, color_t color) = 0; + virtual RetCode_t pixel(loc_t x, loc_t y, color_t color) = 0; /// get the screen width in pixels /// @@ -66,7 +73,7 @@ /// @param y is the vertical position in pixels (from the top edge) /// @returns success/failure code. @see RetCode_t. /// - virtual RetCode_t SetGraphicsCursor(uint16_t x, uint16_t y) = 0; + virtual RetCode_t SetGraphicsCursor(loc_t x, loc_t y) = 0; /// Draw a filled rectangle in the specified color /// @@ -83,7 +90,7 @@ /// @param fillit is optional to NOFILL the rectangle. default is FILL. /// @returns success/failure code. @see RetCode_t. /// - virtual RetCode_t fillrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + virtual RetCode_t fillrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color, fill_t fillit = FILL) = 0; @@ -102,7 +109,7 @@ /// @param h is the window height in pixels. /// @returns success/failure code. @see RetCode_t. /// - virtual RetCode_t window(unsigned int x, unsigned int y, unsigned int w, unsigned int h); + virtual RetCode_t window(loc_t x, loc_t y, dim_t w, dim_t h); /// Clear the screen. /// @@ -130,8 +137,6 @@ virtual void fill(int x, int y, int w, int h, color_t color); virtual void blit(int x, int y, int w, int h, const int * color); - virtual int blitbit(int x, int y, int w, int h, const char * color); - /// This method transfers one character from the external font data /// to the screen. /// @@ -200,7 +205,7 @@ /// @param Name_BMP is the filename on the local file system. /// @returns success or error code. /// - RetCode_t RenderBitmapFile(unsigned int x, unsigned int y, const char *Name_BMP); + RetCode_t RenderBitmapFile(loc_t x, loc_t y, const char *Name_BMP); /// prints one character at the specified coordinates. /// @@ -280,6 +285,10 @@ /// virtual RetCode_t _EndGraphicsStream(void) = 0; + #ifdef LOCALFONT + virtual int blitbit(int x, int y, int w, int h, const char * color); + #endif + const unsigned char * font; ///< reference to an external font somewhere in memory // pixel location
--- a/RA8875.cpp Sat Jan 25 00:00:02 2014 +0000 +++ b/RA8875.cpp Sat Jan 25 19:47:33 2014 +0000 @@ -143,7 +143,7 @@ return data; } -unsigned int RA8875::fontwidth(void) +dim_t RA8875::fontwidth(void) { if (font == NULL) return (((ReadCommand(0x22) >> 2) & 0x3) + 1) * 16; @@ -151,7 +151,7 @@ return font[1]; } -unsigned int RA8875::fontheight(void) +dim_t RA8875::fontheight(void) { if (font == NULL) return (((ReadCommand(0x22) >> 0) & 0x3) + 1) * 16; @@ -159,7 +159,7 @@ return font[2]; } -RetCode_t RA8875::locate(unsigned int column, unsigned int row) +RetCode_t RA8875::locate(textloc_t column, textloc_t row) { return SetTextCursor(column * fontwidth(), row * fontheight()); } @@ -184,7 +184,7 @@ return (ReadCommand(0x19) | (ReadCommand(0x1A) << 8)) + 1; } -RetCode_t RA8875::SetTextCursor(unsigned int x, unsigned int y) +RetCode_t RA8875::SetTextCursor(loc_t x, loc_t y) { cursor_x = x; cursor_y = y; // for non-internal fonts WriteCommand(0x2A, x & 0xFF); @@ -194,7 +194,7 @@ return noerror; } -unsigned int RA8875::GetTextCursor_Y(void) +loc_t RA8875::GetTextCursor_Y(void) { if (font == NULL) return ReadCommand(0x2C) | (ReadCommand(0x2D) << 8); @@ -202,7 +202,7 @@ return cursor_y; } -unsigned int RA8875::GetTextCursor_X(void) +loc_t RA8875::GetTextCursor_X(void) { if (font == NULL) return ReadCommand(0x2A) | (ReadCommand(0x2B) << 8); @@ -314,6 +314,7 @@ cursor_y += font[2]; } else { int advance = character(cursor_x, cursor_y, c); // advance tells us how many pixels we advanced + //INFO("x,y,advance %d,%d,%d", cursor_x, cursor_y, advance); if (advance) { cursor_x += advance; if (cursor_x >= width()) { @@ -339,12 +340,12 @@ WriteCommand(0x40, 0x80 | mwcr0); // Put in Text mode if not already } if (c == '\r') { - unsigned int x; + loc_t x; x = ReadCommand(0x30) | (ReadCommand(0x31) << 8); // Left edge of active window WriteCommand(0x2A, x & 0xFF); WriteCommand(0x2B, x >> 8); } else if (c == '\n') { - unsigned int y; + loc_t y; y = ReadCommand(0x2C) | (ReadCommand(0x2D) << 8); // current y location y += fontheight(); if (y > height()) // @TODO after bottom of active window, then scroll window? @@ -377,12 +378,12 @@ RetCode_t RA8875::putp(color_t pixel) { + WriteData(pixel >> 8); WriteData(pixel & 0xFF); - WriteData(pixel >> 8); return noerror; } -void RA8875::puts(unsigned int x, unsigned int y, const char * string) +void RA8875::puts(loc_t x, loc_t y, const char * string) { SetTextCursor(x,y); puts(string); @@ -391,9 +392,13 @@ void RA8875::puts(const char * string) { unsigned char mwcr0 = ReadCommand(0x40); - - if ((mwcr0 & 0x80) == 0x00) - WriteCommand(0x40,0x80); // Put in Text mode if not already + + if (font == NULL) { + if ((mwcr0 & 0x80) == 0x00) + WriteCommand(0x40,0x80); // Put in Text mode if not already + } else { + _StartGraphicsStream(); + } if (*string != '\0') { #if 1 while (*string) { // @TODO calling individual _putc is slower... optimizations? @@ -411,9 +416,11 @@ select(false); #endif } + if (font) + _EndGraphicsStream(); } -RetCode_t RA8875::SetGraphicsCursor(uint16_t x, uint16_t y) +RetCode_t RA8875::SetGraphicsCursor(loc_t x, loc_t y) { WriteCommand(0x46, x & 0xFF); WriteCommand(0x47, x >> 8); @@ -422,8 +429,9 @@ return noerror; } -RetCode_t RA8875::window(unsigned int x, unsigned int y, unsigned int width, unsigned int height) +RetCode_t RA8875::window(loc_t x, loc_t y, dim_t width, dim_t height) { + GraphicsDisplay::window(x,y, width,height); WriteCommand(0x30, x & 0xFF); // HSAW0 WriteCommand(0x31, x >> 8); // HSAW1 WriteCommand(0x32, y & 0xFF); // VSAW0 @@ -432,6 +440,7 @@ WriteCommand(0x35, (x+width-1) >> 8); // HEAW1 WriteCommand(0x36, (y+height-1) & 0xFF); // VEAW0 WriteCommand(0x37, (y+height-1) >> 8); // VEAW1 + SetGraphicsCursor(x,y); return noerror; } @@ -439,7 +448,7 @@ { PERFORMANCE_RESET; clsw(FULLWINDOW); - cursor_x = cursor_y = 0; + SetTextCursor(0,0); REGISTERPERFORMANCE(PRF_CLS); return noerror; } @@ -454,13 +463,14 @@ return noerror; } -RetCode_t RA8875::pixel(unsigned int x, unsigned int y, color_t color) +RetCode_t RA8875::pixel(loc_t x, loc_t y, color_t color) { + INFO("pixel(%d,%d, %04X)", x,y, color); foreground(color); return pixel(x,y); } -RetCode_t RA8875::pixel(unsigned int x, unsigned int y) +RetCode_t RA8875::pixel(loc_t x, loc_t y) { RetCode_t ret; @@ -468,7 +478,7 @@ color_t color = GetForeColor(); WriteCommand(0x40,0x00); // Graphics write mode SetGraphicsCursor(x, y); - WriteCommand(0x02); //start data write + WriteCommand(0x02); // start data write WriteData(color & 0xFF); WriteData(color >> 8); ret = noerror; @@ -476,13 +486,13 @@ return ret; } -RetCode_t RA8875::line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, color_t color) +RetCode_t RA8875::line(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color) { foreground(color); return line(x1,y1,x2,y2); } -RetCode_t RA8875::line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2) +RetCode_t RA8875::line(loc_t x1, loc_t y1, loc_t x2, loc_t y2) { PERFORMANCE_RESET; WriteCommand(0x91, x1 & 0xFF); @@ -503,20 +513,20 @@ return noerror; } -RetCode_t RA8875::fillrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, +RetCode_t RA8875::fillrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color, fill_t fillit) { return rect(x1,y1,x2,y2,color,fillit); } -RetCode_t RA8875::rect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, +RetCode_t RA8875::rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color, fill_t fillit) { foreground(color); return rect(x1,y1,x2,y2,fillit); } -RetCode_t RA8875::rect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, +RetCode_t RA8875::rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, fill_t fillit) { PERFORMANCE_RESET; @@ -548,22 +558,22 @@ return noerror; } -RetCode_t RA8875::fillroundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, - unsigned int radius1, unsigned int radius2, color_t color, fill_t fillit) +RetCode_t RA8875::fillroundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, + dim_t radius1, dim_t radius2, color_t color, fill_t fillit) { foreground(color); return roundrect(x1,y1,x2,y2,radius1,radius2,fillit); } -RetCode_t RA8875::roundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, - unsigned int radius1, unsigned int radius2, color_t color, fill_t fillit) +RetCode_t RA8875::roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, + dim_t radius1, dim_t radius2, color_t color, fill_t fillit) { foreground(color); return roundrect(x1,y1,x2,y2,radius1,radius2,fillit); } -RetCode_t RA8875::roundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, - unsigned int radius1, unsigned int radius2, fill_t fillit) +RetCode_t RA8875::roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, + dim_t radius1, dim_t radius2, fill_t fillit) { RetCode_t ret = noerror; @@ -610,8 +620,8 @@ return ret; } -RetCode_t RA8875::triangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, - unsigned int x3, unsigned int y3, color_t color, fill_t fillit) +RetCode_t RA8875::triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, + loc_t x3, loc_t y3, color_t color, fill_t fillit) { RetCode_t ret; @@ -620,8 +630,8 @@ return ret; } -RetCode_t RA8875::filltriangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, - unsigned int x3, unsigned int y3, color_t color, fill_t fillit) +RetCode_t RA8875::filltriangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, + loc_t x3, loc_t y3, color_t color, fill_t fillit) { RetCode_t ret; @@ -630,8 +640,8 @@ return ret; } -RetCode_t RA8875::triangle(unsigned int x1, unsigned int y1 ,unsigned int x2, unsigned int y2, - unsigned int x3, unsigned int y3, fill_t fillit) +RetCode_t RA8875::triangle(loc_t x1, loc_t y1 ,loc_t x2, loc_t y2, + loc_t x3, loc_t y3, fill_t fillit) { RetCode_t ret = noerror; @@ -666,21 +676,21 @@ return ret; } -RetCode_t RA8875::circle(unsigned int x, unsigned int y, unsigned int radius, +RetCode_t RA8875::circle(loc_t x, loc_t y, dim_t radius, color_t color, fill_t fillit) { foreground(color); return circle(x,y,radius,fillit); } -RetCode_t RA8875::fillcircle(unsigned int x, unsigned int y, unsigned int radius, +RetCode_t RA8875::fillcircle(loc_t x, loc_t y, dim_t radius, color_t color, fill_t fillit) { foreground(color); return circle(x,y,radius,fillit); } -RetCode_t RA8875::circle(unsigned int x, unsigned int y, unsigned int radius, fill_t fillit) +RetCode_t RA8875::circle(loc_t x, loc_t y, dim_t radius, fill_t fillit) { RetCode_t ret = noerror; @@ -708,19 +718,19 @@ return ret; } -RetCode_t RA8875::ellipse(unsigned int x, unsigned int y, unsigned int radius1, unsigned int radius2, color_t color, fill_t fillit) +RetCode_t RA8875::ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, color_t color, fill_t fillit) { foreground(color); return ellipse(x,y,radius1,radius2,fillit); } -RetCode_t RA8875::fillellipse(unsigned int x, unsigned int y, unsigned int radius1, unsigned int radius2, color_t color, fill_t fillit) +RetCode_t RA8875::fillellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, color_t color, fill_t fillit) { foreground(color); return ellipse(x,y,radius1,radius2,fillit); } -RetCode_t RA8875::ellipse(unsigned int x, unsigned int y, unsigned int radius1, unsigned int radius2, fill_t fillit) +RetCode_t RA8875::ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, fill_t fillit) { RetCode_t ret = noerror; @@ -811,9 +821,11 @@ return Backlight_u8(b); } - RetCode_t RA8875::set_font(const unsigned char * _font) { + if (font && ! _font) { + SetTextCursor(cursor_x, cursor_y); // soft-font cursor -> hw cursor + } font = _font; GraphicsDisplay::set_font(_font); return noerror; // trusting them, but it might be good to put some checks in here... @@ -821,6 +833,7 @@ RetCode_t RA8875::background(color_t color) { + GraphicsDisplay::background(color); WriteCommand(0x60, (color>>11)); // BGCR0 WriteCommand(0x61, (unsigned char)(color>>5)); // BGCR0 WriteCommand(0x62, (unsigned char)(color)); // BGCR0 @@ -829,29 +842,32 @@ RetCode_t RA8875::background(unsigned char r, unsigned char g, unsigned char b) { - WriteCommand(0x60, r); - WriteCommand(0x61, g); - WriteCommand(0x62, b); + background(RGB(r,g,b)); +// WriteCommand(0x60, r); +// WriteCommand(0x61, g); +// WriteCommand(0x62, b); return noerror; } RetCode_t RA8875::foreground(color_t color) { + GraphicsDisplay::foreground(color); WriteCommand(0x63, (unsigned char)(color>>11)); WriteCommand(0x64, (unsigned char)(color>>5)); WriteCommand(0x65, (unsigned char)(color)); return noerror; } -RetCode_t RA8875::foreground(unsigned char setR, unsigned char setG, unsigned char setB) +RetCode_t RA8875::foreground(unsigned char r, unsigned char g, unsigned char b) { - WriteCommand(0x63, setR); - WriteCommand(0x64, setG); - WriteCommand(0x65, setB); + foreground(RGB(r,g,b)); +// WriteCommand(0x63, r); +// WriteCommand(0x64, g); +// WriteCommand(0x65, b); return noerror; } -unsigned int RA8875::GetForeColor(void) +color_t RA8875::GetForeColor(void) { color_t color; @@ -921,15 +937,15 @@ RetCode_t RA8875::init(void) { Backlight_u8(0); - WriteCommand(0x88, 0x0a); // PLLC1 - Phase Lock Loop registers + WriteCommand(0x88, 0x0a); // PLLC1 - Phase Lock Loop registers wait_ms(1); WriteCommand(0x89, 0x02); wait_ms(1); // System Config Register (SYSR) - WriteCommand(0x10, 0x0C); // 16-bpp (65K colors) color depth, 8-bit interface + WriteCommand(0x10, 0x0C); // 16-bpp (65K colors) color depth, 8-bit interface // Pixel Clock Setting Register (PCSR) - WriteCommand(0x04, 0x82); // PDAT on PCLK falling edge, PCLK = 4 x System Clock + WriteCommand(0x04, 0x82); // PDAT on PCLK falling edge, PCLK = 4 x System Clock wait_ms(1); // Horizontal Settings @@ -949,7 +965,7 @@ WriteCommand(0x1f, 0x01); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0] // Clear ram image - window(0,0, width(), height()); // Initialize to full screen + window(0,0, width(), height()); // Initialize to full screen SetTextCursorControl(); foreground(Blue); background(Black); @@ -959,6 +975,9 @@ #ifdef TESTENABLE +#include "Arial12x12.h" +#include "Small_6.h" + // ______________ ______________ ______________ _______________ // /_____ _____/ / ___________/ / ___________/ /_____ ______/ // / / / / / / / / @@ -972,10 +991,10 @@ void TextCursorTest(RA8875 & display, Serial & pc) { - const char * iCursor = "The I-Beam cursor should be visible for this text, but it should not be blinking while writing this text.\r\n"; - const char * uCursor = "The Underscore cursor should be visible for this text, but it should not be blinking while writing this text.\r\n"; - const char * bCursor = "The Block cursor should be visible for this text, but it should not be blinking while writing this text.\r\n"; - const char * bbCursor = "The Blinking Block cursor should be visible for this text, and it should be blinking while writing this text.\r\n"; + const char * iCursor = "The I-Beam cursor should be visible for this text.\r\n"; + const char * uCursor = "The Underscore cursor should be visible for this text.\r\n"; + const char * bCursor = "The Block cursor should be visible for this text.\r\n"; + const char * bbCursor = "The Blinking Block cursor should be visible for this text.\r\n"; const char * p; pc.printf("Text Cursor Test\r\n"); @@ -1032,7 +1051,7 @@ for (int i=0; i < 255; i++) { unsigned int w = (ramptime * 1000)/ 256; sprintf(buf, "%3d, %4d", i, w); - display.puts(0,40,buf); + display.puts(100,100,buf); display.Backlight_u8(i); wait_ms(w); } @@ -1042,7 +1061,7 @@ { pc.printf("Backlight Test 2\r\n"); // Dim it out at the end of the tests. - display.foreground(Yellow); + display.foreground(Blue); display.puts(0,0, "Ramp Backlight down."); // Ramp it off for (int i=255; i != 0; i--) { @@ -1059,8 +1078,17 @@ display.foreground(Blue); display.cls(); display.Backlight(1); + display.puts(0,0, "External Font Test."); + + display.set_font(Small_6); + display.puts(0,30, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n"); + display.set_font(Arial12x12); - display.puts(0,0,"ABCDEFGHIJKLMNOPWRSTUVWXYZabcdefghijklmnopqrstuvwxyz"); + display.puts("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n"); + display.set_font(); // restore to internal + + display.puts("Normal font again."); + //display.window(0,0, display.width(), display.height()); } void DOSColorTest(RA8875 & display, Serial & pc) @@ -1103,6 +1131,24 @@ display.SetTextFontSize(1,1); } +void PixelTest(RA8875 & display, Serial & pc) +{ + int i, c, x, y; + + pc.printf("Pixel Test\r\n"); + display.background(Black); + display.foreground(Blue); + display.cls(); + display.puts(0,0, "Pixel Test"); + for (i=0; i<1000; i++) { + x = rand() % 480; + y = 16 + rand() % (272-16); + c = rand() % 16; + //pc.printf(" (%d,%d) - %d\r\n", x,y,r1); + display.pixel(x,y, display.DOSColor(c)); + } +} + void LineTest(RA8875 & display, Serial & pc) { int i, x, y, x2, y2; @@ -1146,10 +1192,9 @@ } } - void RoundRectTest(RA8875 & display, Serial & pc) { - unsigned int i, x1,y1, x2,y2, r1,r2; + loc_t i, x1,y1, x2,y2, r1,r2; pc.printf("Round Rectangle Test\r\n"); display.background(Black); @@ -1284,26 +1329,40 @@ } } +void TestGraphicsBitmap(RA8875 & display, Serial & pc) +{ + LocalFileSystem local("local"); + display.background(Black); + display.foreground(Blue); + display.cls(); + display.puts(0,0, "Graphics Test, loading /local/TestPat.bmp"); + wait(3); + + int r = display.RenderBitmapFile(0,0, "/local/TestPat.bmp"); +} + void RunTestSet(RA8875 & lcd, Serial & pc) { int q = 0; int automode = 0; - const unsigned char modelist[] = "BDWLROTCEbt"; // auto-test in this order. + const unsigned char modelist[] = "BDWtGLFROTPCEb"; // auto-test in this order. while(1) { pc.printf("\r\n" "B - Backlight up b - backlight dim\r\n" "D - DOS Colors W - Web Colors\r\n" - "t - text cursor \r\n" + "t - text cursor G - Graphics Bitmap\r\n" "L - Lines F - external Font\r\n" "R - Rectangles O - rOund rectangles\r\n" - "T - Triangles \r\n" + "T - Triangles P - Pixels \r\n" "C - Circles E - Ellipses\r\n" "A - Auto Test mode r - reset \r\n" "> "); if (automode == -1 || pc.readable()) { automode = -1; - q = getchar(); + q = pc.getc(); + while (pc.readable()) + pc.getc(); } else if (automode >= 0) { q = modelist[automode]; } @@ -1341,6 +1400,12 @@ case 'T': TriangleTest(lcd, pc); break; + case 'P': + PixelTest(lcd, pc); + break; + case 'G': + TestGraphicsBitmap(lcd, pc); + break; case 'C': CircleTest(lcd, pc); break;
--- a/RA8875.h Sat Jan 25 00:00:02 2014 +0000 +++ b/RA8875.h Sat Jan 25 19:47:33 2014 +0000 @@ -69,7 +69,7 @@ /// /// @todo Add Scroll support for text. /// @todo Add 2-Layer support. -/// @todo Improve sync between internal and externa font support - cursor, window, scroll. +/// @todo Improve sync between internal and external font support - cursor, window, scroll. /// @todo Find out why it can't shift frequency after constructor runs. /// @todo Add Hardware reset signal. /// @todo Add Touch Screen support. @@ -182,13 +182,13 @@ /// /// @returns font width in pixels. /// - unsigned int fontwidth(void); + dim_t fontwidth(void); /// get the height in pixels of the currently active font /// /// @returns font height in pixels. /// - unsigned int fontheight(void); + dim_t fontheight(void); /// get the number of colums based on the currently active font /// @@ -220,7 +220,7 @@ /// @param row is the vertical position in character positions /// @returns success/failure code. @see RetCode_t. /// - virtual RetCode_t locate(unsigned int column, unsigned int row); + virtual RetCode_t locate(textloc_t column, textloc_t row); /// Prepare the controller to write text to the screen by positioning /// the cursor. @@ -229,19 +229,25 @@ /// @param y is the vertical position in pixels (from the top edge) /// @returns success/failure code. @see RetCode_t. /// - RetCode_t SetTextCursor(unsigned int x, unsigned int y); + RetCode_t SetTextCursor(loc_t x, loc_t y); + /// Get the current cursor position in pixels. + /// + /// @returns cursor position. + /// + point_t GetTextCursor(void); + /// Get the current cursor horizontal position in pixels. /// /// @returns cursor position horizontal offset. /// - unsigned int GetTextCursor_X(void); + loc_t GetTextCursor_X(void); /// Get the current cursor vertical position in pixels. /// /// @returns cursor position vertical offset. /// - unsigned int GetTextCursor_Y(void); + loc_t GetTextCursor_Y(void); /// Configure additional Cursor Control settings. /// @@ -337,7 +343,7 @@ /// @param y is the vertical position in pixels (from the top edge) /// @param string is the null terminated string to send to the display. /// - void puts(unsigned int x, unsigned int y, const char * string); + void puts(loc_t x, loc_t y, const char * string); /// Prepare the controller to write binary data to the screen by positioning /// the memory cursor. @@ -346,7 +352,7 @@ /// @param y is the vertical position in pixels (from the top edge) /// @returns success/failure code. @see RetCode_t. /// - virtual RetCode_t SetGraphicsCursor(uint16_t x, uint16_t y); + virtual RetCode_t SetGraphicsCursor(loc_t x, loc_t y); /// Set the window, which controls where items are written to the screen. /// @@ -360,7 +366,7 @@ /// @param height is the window height in pixels. /// @returns success/failure code. @see RetCode_t. /// - virtual RetCode_t window(unsigned int x, unsigned int y, unsigned int width, unsigned int height); + virtual RetCode_t window(loc_t x, loc_t y, dim_t width, dim_t height); /// Clear the screen. /// @@ -407,18 +413,18 @@ /// Set the foreground color. /// - /// @param R is the red element of the color. - /// @param G is the green element of the color. - /// @param B is the blue element of the color. + /// @param r is the red element of the color. + /// @param g is the green element of the color. + /// @param b is the blue element of the color. /// @returns success/failure code. @see RetCode_t. /// - virtual RetCode_t foreground(unsigned char R, unsigned char G, unsigned char B); + virtual RetCode_t foreground(unsigned char r, unsigned char g, unsigned char b); /// Get the current foreground color value. /// /// @returns the current foreground color. /// - unsigned int GetForeColor(void); + color_t GetForeColor(void); /// Draw a pixel in the specified color. /// @@ -430,7 +436,7 @@ /// @param color defines the color for the pixel. /// @returns success/failure code. @see RetCode_t. /// - virtual RetCode_t pixel(unsigned int x, unsigned int y, color_t color); + virtual RetCode_t pixel(loc_t x, loc_t y, color_t color); /// Draw a pixel in the current foreground color. /// @@ -438,7 +444,7 @@ /// @param y is the veritical offset to this pixel. /// @returns success/failure code. @see RetCode_t. /// - virtual RetCode_t pixel(unsigned int x, unsigned int y); + virtual RetCode_t pixel(loc_t x, loc_t y); /// Draw a line in the specified color /// @@ -452,7 +458,7 @@ /// @param color defines the foreground color. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + RetCode_t line(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color); /// Draw a line @@ -465,7 +471,7 @@ /// @param y2 is the vertical end of the line. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2); + RetCode_t line(loc_t x1, loc_t y1, loc_t x2, loc_t y2); /// Draw a rectangle in the specified color /// @@ -480,7 +486,7 @@ /// @param fillit is optional to FILL the rectangle. default is NOFILL. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t rect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + RetCode_t rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color, fill_t fillit = NOFILL); /// Draw a filled rectangle in the specified color @@ -496,7 +502,7 @@ /// @param fillit is optional to NOFILL the rectangle. default is FILL. /// @returns success/failure code. @see RetCode_t. /// - virtual RetCode_t fillrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + virtual RetCode_t fillrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color, fill_t fillit = FILL); /// Draw a rectangle @@ -510,7 +516,7 @@ /// @param fillit is optional to FILL the rectangle. default is NOFILL. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t rect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + RetCode_t rect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, fill_t fillit = NOFILL); /// Draw a filled rectangle with rounded corners using the specified color. @@ -537,8 +543,8 @@ /// @param fillit is optional to FILL the rectangle. default is NOFILL. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t fillroundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, - unsigned int radius1, unsigned int radius2, color_t color, fill_t fillit = FILL); + RetCode_t fillroundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, + dim_t radius1, dim_t radius2, color_t color, fill_t fillit = FILL); /// Draw a rectangle with rounded corners using the specified color. /// @@ -564,8 +570,8 @@ /// @param fillit is optional to FILL the rectangle. default is NOFILL. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t roundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, - unsigned int radius1, unsigned int radius2, color_t color, fill_t fillit = NOFILL); + RetCode_t roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, + dim_t radius1, dim_t radius2, color_t color, fill_t fillit = NOFILL); /// Draw a rectangle with rounded corners. /// @@ -587,8 +593,8 @@ /// @param fillit is optional to FILL the rectangle. default is NOFILL. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t roundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, - unsigned int radius1, unsigned int radius2, fill_t fillit = NOFILL); + RetCode_t roundrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, + dim_t radius1, dim_t radius2, fill_t fillit = NOFILL); /// Draw a triangle in the specified color. /// @@ -605,8 +611,8 @@ /// @param fillit is optional to FILL the rectangle. default is NOFILL. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t triangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, - unsigned int x3, unsigned int y3, color_t color, fill_t fillit = NOFILL); + RetCode_t triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, + loc_t x3, loc_t y3, color_t color, fill_t fillit = NOFILL); /// Draw a filled triangle in the specified color. /// @@ -623,8 +629,8 @@ /// @param fillit is optional to FILL the rectangle. default is NOFILL. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t filltriangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, - unsigned int x3, unsigned int y3, color_t color, fill_t fillit = FILL); + RetCode_t filltriangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, + loc_t x3, loc_t y3, color_t color, fill_t fillit = FILL); /// Draw a triangle /// @@ -639,8 +645,8 @@ /// @param fillit is optional to FILL the rectangle. default is NOFILL. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t triangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, - unsigned int x3, unsigned int y3, fill_t fillit = NOFILL); + RetCode_t triangle(loc_t x1, loc_t y1, loc_t x2, loc_t y2, + loc_t x3, loc_t y3, fill_t fillit = NOFILL); /// Draw a circle using the specified color. /// @@ -653,7 +659,7 @@ /// @param color defines the foreground color. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t circle(unsigned int x, unsigned int y, unsigned int radius, color_t color, fill_t fillit = NOFILL); + RetCode_t circle(loc_t x, loc_t y, dim_t radius, color_t color, fill_t fillit = NOFILL); /// Draw a filled circle using the specified color. /// @@ -666,7 +672,7 @@ /// @param color defines the foreground color. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t fillcircle(unsigned int x, unsigned int y, unsigned int radius, color_t color, fill_t fillit = FILL); + RetCode_t fillcircle(loc_t x, loc_t y, dim_t radius, color_t color, fill_t fillit = FILL); /// Draw a circle. /// @@ -677,7 +683,7 @@ /// @param radius defines the size of the circle. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t circle(unsigned int x, unsigned int y, unsigned int radius, fill_t fillit = NOFILL); + RetCode_t circle(loc_t x, loc_t y, dim_t radius, fill_t fillit = NOFILL); /// Draw an Ellipse using the specified color /// @@ -692,7 +698,7 @@ /// @param fillit defines whether the circle is filled or not. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t ellipse(unsigned int x, unsigned int y, unsigned int radius1, unsigned int radius2, + RetCode_t ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, color_t color, fill_t fillit = NOFILL); /// Draw a filled Ellipse using the specified color @@ -708,7 +714,7 @@ /// @param fillit defines whether the circle is filled or not. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t fillellipse(unsigned int x, unsigned int y, unsigned int radius1, unsigned int radius2, + RetCode_t fillellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, color_t color, fill_t fillit = FILL); /// Draw an Ellipse @@ -722,7 +728,7 @@ /// @param fillit defines whether the circle is filled or not. /// @returns success/failure code. @see RetCode_t. /// - RetCode_t ellipse(unsigned int x, unsigned int y, unsigned int radius1, unsigned int radius2, fill_t fillit = NOFILL); + RetCode_t ellipse(loc_t x, loc_t y, dim_t radius1, dim_t radius2, fill_t fillit = NOFILL); /// Control display power /// @@ -910,7 +916,7 @@ DigitalOut cs; ///< chip select pin, assumed active low DigitalOut res; ///< reset pin, assumed active low const unsigned char * font; ///< reference to an external font somewhere in memory - unsigned int cursor_x, cursor_y; ///< used for external fonts only + loc_t cursor_x, cursor_y; ///< used for external fonts only #ifdef PERF_METRICS typedef enum
--- a/TextDisplay.cpp Sat Jan 25 00:00:02 2014 +0000 +++ b/TextDisplay.cpp Sat Jan 25 19:47:33 2014 +0000 @@ -65,7 +65,7 @@ return noerror; } -RetCode_t TextDisplay::locate(unsigned int column, unsigned int row) +RetCode_t TextDisplay::locate(textloc_t column, textloc_t row) { INFO("locate(%d,%d)", column, row); _column = column; @@ -80,14 +80,14 @@ RetCode_t TextDisplay::foreground(uint16_t color) { - INFO("foreground(%4X)", color); + //INFO("foreground(%4X)", color); _foreground = color; return noerror; } RetCode_t TextDisplay::background(uint16_t color) { - INFO("background(%4X)", color); + //INFO("background(%4X)", color); _background = color; return noerror; }
--- a/TextDisplay.h Sat Jan 25 00:00:02 2014 +0000 +++ b/TextDisplay.h Sat Jan 25 19:47:33 2014 +0000 @@ -20,49 +20,100 @@ #include "DisplayDefs.h" +/// A text display class that supports character based +/// presentation. +/// class TextDisplay : public Stream { public: // functions needing implementation in derived implementation class - /** Create a TextDisplay interface - * - * @param name The name used in the path to access the strean through the filesystem - */ + /// Create a TextDisplay interface + /// + /// @param name The name used in the path to access the display through + /// the stdio stream. + /// TextDisplay(const char *name = NULL); - /** output a character at the given position - * - * @param x position in pixels - * @param y position in pixels - * @param c the character to be written to the TextDisplay - * @returns number of pixels to advance the cursor. - */ + /// output a character at the given position + /// + /// @note this method may be overridden in a derived class. + /// + /// @param x position in pixels + /// @param y position in pixels + /// @param c the character to be written to the TextDisplay + /// @returns number of pixels to advance the cursor which could be the cell width + /// for non-proportional characters, or the actual character width for + /// proportional characters. + /// virtual int character(int x, int y, int c) = 0; - /** return number if rows on TextDisplay - * @result number of rows - */ + /// return number of rows on TextDisplay + /// + /// @note this method may be overridden in a derived class. + /// + /// @returns number of text rows for the display for the currently + /// active font. + /// virtual int rows() = 0; - /** return number if columns on TextDisplay - * @result number of rows - */ + /// return number if columns on TextDisplay + /// + /// @note this method may be overridden in a derived class. + /// + /// @returns number of text rows for the display for the currently + /// active font. + /// virtual int columns() = 0; // functions that come for free, but can be overwritten - /** redirect output from a stream (stoud, sterr) to display - * @param stream stream that shall be redirected to the TextDisplay - */ + /// redirect output from a stream (stoud, sterr) to display + /// + /// @note this method may be overridden in a derived class. + /// + /// @param stream that shall be redirected to the TextDisplay + /// @returns true if the claim succeeded. + /// virtual bool claim (FILE *stream); - /** clear screen - */ + /// clear screen + /// + /// @note this method may be overridden in a derived class. + /// + /// @returns error code. + /// virtual RetCode_t cls() = 0; - virtual RetCode_t locate(unsigned int column, unsigned int row) = 0; - virtual RetCode_t foreground(uint16_t color) = 0; - virtual RetCode_t background(uint16_t color) = 0; + + /// locate the cursor at a character position. + /// + /// Based on the currently active font, locate the cursor on screen. + /// + /// @note this method may be overridden in a derived class. + /// + /// @param column is the horizontal offset from the left side. + /// @param row is the vertical offset from the top. + /// @returns error code. + /// + virtual RetCode_t locate(textloc_t column, textloc_t row) = 0; + + /// set the foreground color + /// + /// @note this method may be overridden in a derived class. + /// + /// @param color is color to use for foreground drawing. + /// @returns error code. + /// + virtual RetCode_t foreground(color_t color) = 0; + + /// set the background color + /// + /// @note this method may be overridden in a derived class. + /// + /// @param color is color to use for background drawing. + /// @returns error code. + /// + virtual RetCode_t background(color_t color) = 0; // putc (from Stream) // printf (from Stream) @@ -75,8 +126,8 @@ uint16_t _row; // colors - uint16_t _foreground; - uint16_t _background; + color_t _foreground; + color_t _background; char *_path; };