Library to control a Graphics TFT connected to 4-wire SPI - revised for the Raio RA8875 Display Controller.
Dependents: FRDM_RA8875_mPaint RA8875_Demo RA8875_KeyPadDemo SignalGenerator ... more
Fork of SPI_TFT by
See Components - RA8875 Based Display
Enhanced touch-screen support - where it previous supported both the Resistive Touch and Capacitive Touch based on the FT5206 Touch Controller, now it also has support for the GSL1680 Touch Controller.
Offline Help Manual (Windows chm)
/media/uploads/WiredHome/ra8875.zip.bin (download, rename to .zip and unzip)
Revision 109:7b94f06f085b, committed 2016-03-05
- Comitter:
- WiredHome
- Date:
- Sat Mar 05 19:22:13 2016 +0000
- Parent:
- 107:f9ccffcb84f1
- Child:
- 110:39f22e0c8de4
- Commit message:
- Updated some data types to more consistently use loc_t and dim_t.
; Added a booleanStream api which is handy for soft fonts. It takes a pixel stream and translates it to forecolor and backcolor.
Changed in this revision
--- a/GraphicsDisplay.cpp Sat Mar 05 16:20:11 2016 +0000 +++ b/GraphicsDisplay.cpp Sat Mar 05 19:22:13 2016 +0000 @@ -133,7 +133,7 @@ return noerror; } -RetCode_t GraphicsDisplay::fill(int x, int y, int w, int h, color_t color) +RetCode_t GraphicsDisplay::fill(loc_t x, loc_t y, dim_t w, dim_t h, color_t color) { return fillrect(x,y, x+w, y+h, color); } @@ -143,7 +143,7 @@ return fill(0, 0, width(), height(), _background); } -RetCode_t GraphicsDisplay::blit(int x, int y, int w, int h, const int * color) +RetCode_t GraphicsDisplay::blit(loc_t x, loc_t y, dim_t w, dim_t h, const int * color) { window(x, y, w, h); _StartGraphicsStream(); @@ -171,12 +171,12 @@ //... -const uint8_t * GraphicsDisplay::getCharMetrics(const unsigned char c, uint8_t * width, uint8_t * height) +const uint8_t * GraphicsDisplay::getCharMetrics(const unsigned char c, dim_t * width, dim_t * height) { uint16_t offsetToCharLookup; uint16_t firstChar = font[3] * 256 + font[2]; uint16_t lastChar = font[5] * 256 + font[4]; - uint8_t charHeight = font[6]; + dim_t charHeight = font[6]; const unsigned char * charRecord; // width, data, data, data, ... INFO("first:%d, last:%d, c:%d", firstChar, lastChar, c); @@ -185,7 +185,7 @@ // 8 bytes of preamble to the first level lookup table offsetToCharLookup = 8 + 4 * (c - firstChar); // 4-bytes: width(pixels), 16-bit offset from table start, 0 - uint8_t charWidth = font[offsetToCharLookup]; + dim_t charWidth = font[offsetToCharLookup]; charRecord = font + font[offsetToCharLookup + 2] * 256 + font[offsetToCharLookup + 1]; //INFO("hgt:%d, wdt:%d", charHeight, charWidth); if (width) @@ -195,26 +195,11 @@ return charRecord; } -int GraphicsDisplay::fontblit(int x, int y, const unsigned char c) + +int GraphicsDisplay::fontblit(loc_t x, loc_t y, const unsigned char c) { - #if 0 - uint16_t offsetToCharLookup; - uint16_t firstChar = font[3] * 256 + font[2]; - uint16_t lastChar = font[5] * 256 + font[4]; - uint8_t charHeight = font[6]; - const unsigned char * charRecord; // width, data, data, data, ... - - INFO("first:%d, last:%d, c:%d", firstChar, lastChar, c); - if (c < firstChar || c > lastChar) - return 0; // advance zero pixels since it was unprintable... - - // 8 bytes of preamble to the first level lookup table - offsetToCharLookup = 8 + 4 * (c - firstChar); // 4-bytes: width(pixels), 16-bit offset from table start, 0 - uint8_t charWidth = font[offsetToCharLookup]; - charRecord = font + font[offsetToCharLookup + 2] * 256 + font[offsetToCharLookup + 1]; -#endif - const unsigned char * charRecord; // width, data, data, data, ... - uint8_t charWidth, charHeight; + const uint8_t * charRecord; // width, data, data, data, ... + dim_t charWidth, charHeight; charRecord = getCharMetrics(c, &charWidth, &charHeight); if (charRecord) { INFO("hgt:%d, wdt:%d", charHeight, charWidth); @@ -223,28 +208,7 @@ // charWidth = width() - x; //if (y + charHeight >= height()) // charHeight = height() - y; - window(x, y, charWidth, charHeight); - _StartGraphicsStream(); - while (charHeight--) { - uint8_t pixels = charWidth; - uint8_t bitmask = 0x01; - - while (pixels) { - uint8_t byte = *charRecord; - INFO("byte, mask: %02X, %02X", byte, bitmask); - color_t c = (byte & bitmask) ? _foreground : _background; - _putp(c); - bitmask <<= 1; - if (pixels > 1 && bitmask == 0) { - bitmask = 0x01; - charRecord++; - } - pixels--; - } - charRecord++; - } - _EndGraphicsStream(); - WindowMax(); + booleanStream(x,y,charWidth, charHeight, charRecord); return charWidth; } else { return 0;
--- a/GraphicsDisplay.h Sat Mar 05 16:20:11 2016 +0000 +++ b/GraphicsDisplay.h Sat Mar 05 19:22:13 2016 +0000 @@ -189,10 +189,10 @@ /// @param[in] h specifies the height of the region. /// @returns success/failure code. @see RetCode_t. /// - virtual RetCode_t fill(int x, int y, int w, int h, color_t color); + virtual RetCode_t fill(loc_t x, loc_t y, dim_t w, dim_t h, color_t color); - virtual RetCode_t blit(int x, int y, int w, int h, const int * color); + virtual RetCode_t blit(loc_t x, loc_t y, dim_t w, dim_t h, const int * color); /// This method returns the width in pixels of the chosen character /// from the previously selected external font. @@ -206,7 +206,7 @@ /// which is convenient if you only want the width. /// @returns a pointer to the raw character data or NULL if not found. /// - virtual const uint8_t * getCharMetrics(const unsigned char c, uint8_t * width, uint8_t * height); + virtual const uint8_t * getCharMetrics(const unsigned char c, dim_t * width, dim_t * height); /// This method transfers one character from the external font data /// to the screen. @@ -224,7 +224,7 @@ /// @returns how far the cursor should advance to the right in pixels. /// @returns zero if the character could not be rendered. /// - virtual int fontblit(int x, int y, const unsigned char c); + virtual int fontblit(loc_t x, loc_t y, const unsigned char c); /// This method returns the color value from a palette. /// @@ -405,6 +405,27 @@ /// RetCode_t _RenderBitmap(loc_t x, loc_t y, uint32_t fileOffset, FILE * Image); + /// Pure virtual method to write a boolean stream to the display. + /// + /// This takes a bit stream in memory and using the current color settings + /// it will stream it to the display. Along the way, each bit is translated + /// to either the foreground or background color value and then that pixel + /// is pushed onward. + /// + /// This is similar, but different, to the @ref pixelStream API, which is + /// given a stream of color values. + /// + /// @param[in] x is the horizontal position on the display. + /// @param[in] y is the vertical position on the display. + /// @param[in] w is the width of the rectangular region to fill. + /// @param[in] h is the height of the rectangular region to fill. + /// @param[in] boolStream is the inline memory image from which to extract + /// the bitstream. + /// @returns success/failure code. See @ref RetCode_t. + /// + virtual RetCode_t booleanStream(loc_t x, loc_t y, dim_t w, dim_t h, const uint8_t * boolStream) = 0; + + const unsigned char * font; ///< reference to an external font somewhere in memory // pixel location
--- a/RA8875.cpp Sat Mar 05 16:20:11 2016 +0000 +++ b/RA8875.cpp Sat Mar 05 19:22:13 2016 +0000 @@ -45,7 +45,7 @@ #define HexDump(a, b, c) #endif - +// Defaults. Users can override this with the init() method. #define RA8875_DISPLAY_WIDTH 480 #define RA8875_DISPLAY_HEIGHT 272 #define RA8875_COLORDEPTH_BPP 16 /* Not an API */ @@ -55,7 +55,7 @@ #define REGISTERPERFORMANCE(a) RegisterPerformance(a) #define COUNTIDLETIME(a) CountIdleTime(a) static const char *metricsName[] = { - "Cls", "Pixel", "Pixel Stream", + "Cls", "Pixel", "Pixel Stream", "Boolean Stream", "Read Pixel", "Read Pixel Stream", "Line", "Rectangle", "Rounded Rectangle", @@ -860,7 +860,7 @@ } else if (c == '\n') { cursor_y += extFontHeight; } else { - uint8_t charWidth, charHeight; + dim_t charWidth, charHeight; const uint8_t * charRecord; charRecord = getCharMetrics(c, &charWidth, &charHeight); @@ -950,20 +950,9 @@ WriteCommand(0x40,0x80); // Put in Text mode if internal font } if (*string != '\0') { -#if 1 while (*string) { // @TODO calling individual _putc is slower... optimizations? _putc(*string++); } -#else - WriteCommand(0x02); - _select(true); - while (*string != '\0') { - WriteData(*string); - ++string; - _WaitWhileBusy(0x80); - } - _select(false); -#endif } } @@ -978,8 +967,6 @@ RetCode_t RA8875::SetGraphicsCursorRead(loc_t x, loc_t y) { - //WriteCommand(0x40, 0); // Graphics mode - //WriteCommand(0x45, 0); // left->right, top->bottom WriteCommandW(0x4A, x); WriteCommandW(0x4C, y); return noerror; @@ -1071,9 +1058,8 @@ RetCode_t RA8875::pixelStream(color_t * p, uint32_t count, loc_t x, loc_t y) { PERFORMANCE_RESET; - WriteCommand(0x40,0x00); // Graphics write mode SetGraphicsCursor(x, y); - WriteCommand(0x02); + _StartGraphicsStream(); _select(true); _spiwrite(0x00); // Cmd: write data while (count--) { @@ -1086,10 +1072,48 @@ p++; } _select(false); + _EndGraphicsStream(); REGISTERPERFORMANCE(PRF_PIXELSTREAM); return(noerror); } +RetCode_t RA8875::booleanStream(loc_t x, loc_t y, dim_t w, dim_t h, const uint8_t * boolStream) +{ + PERFORMANCE_RESET; + window(x, y, w, h); + SetGraphicsCursor(x, y); + _StartGraphicsStream(); + _select(true); + _spiwrite(0x00); // Cmd: write data + while (h--) { + uint8_t pixels = w; + uint8_t bitmask = 0x01; + + while (pixels) { + uint8_t byte = *boolStream; + INFO("byte, mask: %02X, %02X", byte, bitmask); + color_t c = (byte & bitmask) ? _foreground : _background; + if (screenbpp == 16) { + _spiwrite(c >> 8); + _spiwrite(c & 0xFF); + } else { + _spiwrite(_cvt16to8(c)); + } + bitmask <<= 1; + if (pixels > 1 && bitmask == 0) { + bitmask = 0x01; + boolStream++; + } + pixels--; + } + boolStream++; + } + _select(false); + _EndGraphicsStream(); + WindowMax(); + REGISTERPERFORMANCE(PRF_BOOLSTREAM); + return(noerror); +} color_t RA8875::getPixel(loc_t x, loc_t y) {
--- a/RA8875.h Sat Mar 05 16:20:11 2016 +0000 +++ b/RA8875.h Sat Mar 05 19:22:13 2016 +0000 @@ -1367,6 +1367,26 @@ /// virtual RetCode_t getPixelStream(color_t * p, uint32_t count, loc_t x, loc_t y); + /// Write a boolean stream to the display. + /// + /// This takes a bit stream in memory and using the current color settings + /// it will stream it to the display. Along the way, each bit is translated + /// to either the foreground or background color value and then that pixel + /// is pushed onward. + /// + /// This is similar, but different, to the @ref pixelStream API, which is + /// given a stream of color values. + /// + /// @param[in] x is the horizontal position on the display. + /// @param[in] y is the vertical position on the display. + /// @param[in] w is the width of the rectangular region to fill. + /// @param[in] h is the height of the rectangular region to fill. + /// @param[in] boolStream is the inline memory image from which to extract + /// the bitstream. + /// @returns success/failure code. See @ref RetCode_t. + /// + virtual RetCode_t booleanStream(loc_t x, loc_t y, dim_t w, dim_t h, const uint8_t * boolStream); + /// Draw a line in the specified color /// /// @note As a side effect, this changes the current @@ -2188,6 +2208,7 @@ PRF_CLS, PRF_DRAWPIXEL, PRF_PIXELSTREAM, + PRF_BOOLSTREAM, PRF_READPIXEL, PRF_READPIXELSTREAM, PRF_DRAWLINE,