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 111:efe436c43aba, committed 2016-04-25
- Comitter:
- WiredHome
- Date:
- Mon Apr 25 01:43:59 2016 +0000
- Parent:
- 110:39f22e0c8de4
- Child:
- 112:325ca91bc03d
- Commit message:
- Soft fonts are now restricted by the window( ) setting, just as hard fonts were. Wraps right edge back to left and cycles from bottom edge back to top.
Changed in this revision
--- a/GraphicsDisplay.cpp Sat Mar 19 20:49:14 2016 +0000 +++ b/GraphicsDisplay.cpp Mon Apr 25 01:43:59 2016 +0000 @@ -9,7 +9,7 @@ #include "Bitmap.h" #include "string.h" -//#define DEBUG "GD" +//#define DEBUG "GD " // ... // INFO("Stuff to show %d", var); // new-line is automatically appended // @@ -100,16 +100,21 @@ return fontblit(x, y, c); } -RetCode_t GraphicsDisplay::window(loc_t x, loc_t y, dim_t w, dim_t h) +RetCode_t GraphicsDisplay::window(rect_t r) { + return window(r.p1.x, r.p1.y, r.p2.x + 1 - r.p1.x, r.p2.y + 1 - r.p1.y); +} + +RetCode_t GraphicsDisplay::window(loc_t x, loc_t y, dim_t width, dim_t height) +{ + // Save the window metrics + windowrect.p1.x = x; + windowrect.p1.y = y; + windowrect.p2.x = x + width - 1; + windowrect.p2.y = y + height - 1; // current pixel location _x = x; _y = y; - // window settings - _x1 = x; - _x2 = x + w - 1; - _y1 = y; - _y2 = y + h - 1; return noerror; } @@ -123,11 +128,11 @@ pixel(_x, _y, color); // update pixel location based on window settings _x++; - if(_x > _x2) { - _x = _x1; + if(_x > windowrect.p2.x) { + _x = windowrect.p1.x; _y++; - if(_y > _y2) { - _y = _y1; + if(_y > windowrect.p2.y) { + _y = windowrect.p1.y; } } return noerror; @@ -145,13 +150,15 @@ RetCode_t GraphicsDisplay::blit(loc_t x, loc_t y, dim_t w, dim_t h, const int * color) { + rect_t restore = windowrect; window(x, y, w, h); _StartGraphicsStream(); for (int i=0; i<w*h; i++) { _putp(color[i]); } _EndGraphicsStream(); - return WindowMax(); + //return WindowMax(); + return window(restore); } // 8 byte "info" section @@ -331,6 +338,7 @@ } while ((PixelWidth * recordSize + padd) % 4 != 0); // Define window for top to bottom and left to right so writing auto-wraps + rect_t restore = windowrect; window(x,y, PixelWidth,PixelHeight); SetGraphicsCursor(x, y); _StartGraphicsStream(); @@ -363,7 +371,7 @@ pixelStream(pixelBuffer, PixelWidth, x, y++); } _EndGraphicsStream(); - WindowMax(); + window(restore); free(pixelBuffer); // don't leak memory free(lineBuffer); if (colorPalette)
--- a/GraphicsDisplay.h Sat Mar 19 20:49:14 2016 +0000 +++ b/GraphicsDisplay.h Mon Apr 25 01:43:59 2016 +0000 @@ -141,6 +141,17 @@ /// and down a row. If the initial write is outside the window, it will /// be captured into the window when it crosses a boundary. /// + /// @param[in] r is the rect_t rect to define the window. + /// @returns success/failure code. @see RetCode_t. + /// + virtual RetCode_t window(rect_t r); + + /// Set the window, which controls where items are written to the screen. + /// + /// When something hits the window width, it wraps back to the left side + /// and down a row. If the initial write is outside the window, it will + /// be captured into the window when it crosses a boundary. + /// /// @param[in] x is the left edge in pixels. /// @param[in] y is the top edge in pixels. /// @param[in] w is the window width in pixels. @@ -149,6 +160,15 @@ /// virtual RetCode_t window(loc_t x, loc_t y, dim_t w, dim_t h); + /// method to set the window region to the full screen. + /// + /// This restores the 'window' to the full screen, so that + /// other operations (@see cls) would clear the whole screen. + /// + /// @returns success/failure code. @see RetCode_t. + /// + virtual RetCode_t WindowMax(void); + /// Clear the screen. /// /// The behavior is to clear the whole screen. @@ -159,15 +179,6 @@ /// virtual RetCode_t cls(uint16_t layers = 0); - /// method to set the window region to the full screen. - /// - /// This restores the 'window' to the full screen, so that - /// other operations (@see cls) would clear the whole screen. - /// - /// @returns success/failure code. @see RetCode_t. - /// - virtual RetCode_t WindowMax(void); - /// method to put a single color pixel to the screen. /// /// This method may be called as many times as necessary after @@ -432,11 +443,7 @@ short _x; short _y; - // window location - short _x1; - short _x2; - short _y1; - short _y2; + rect_t windowrect; ///< window commands are held here for speed of access }; #endif
--- a/RA8875.cpp Sat Mar 19 20:49:14 2016 +0000 +++ b/RA8875.cpp Mon Apr 25 01:43:59 2016 +0000 @@ -856,7 +856,7 @@ { if (c) { if (c == '\r') { - cursor_x = 0; + cursor_x = windowrect.p1.x; } else if (c == '\n') { cursor_y += extFontHeight; } else { @@ -865,15 +865,17 @@ charRecord = getCharMetrics(c, &charWidth, &charHeight); //int advance = charwidth(c); - INFO("(%d,%d) ,charWidth: %d '%c", cursor_x, cursor_y, charWidth, c); + INFO("(%d,%d) - (%d,%d):(%d,%d), charWidth: %d '%c", cursor_x, cursor_y, + windowrect.p1.x, windowrect.p1.y, windowrect.p2.x, windowrect.p2.y, + charWidth, c); if (charRecord) { //cursor_x += advance; - if (cursor_x + charWidth >= screenwidth) { - cursor_x = 0; + if (cursor_x + charWidth >= windowrect.p2.x) { + cursor_x = windowrect.p1.x; cursor_y += charHeight; } - if (cursor_y + charHeight >= screenheight) { - cursor_y = 0; // @todo Should it scroll? + if (cursor_y + charHeight >= windowrect.p2.y) { + cursor_y = windowrect.p1.y; // @todo Should it scroll? } (void)character(cursor_x, cursor_y, c); cursor_x += charWidth; @@ -972,15 +974,29 @@ return noerror; } +RetCode_t RA8875::window(rect_t r) +{ + return window(r.p1.x, r.p1.y, r.p2.x + 1 - r.p1.x, r.p2.y + 1 - r.p1.y); +} RetCode_t RA8875::window(loc_t x, loc_t y, dim_t width, dim_t height) { + INFO("window(%d,%d,%d,%d)", x, y, width, height); + if (width == (dim_t)-1) + width = screenwidth - x; + if (height == (dim_t)-1) + height = screenheight - y; + windowrect.p1.x = x; + windowrect.p1.y = y; + windowrect.p2.x = x + width - 1; + windowrect.p2.y = y + height - 1; GraphicsDisplay::window(x,y, width,height); WriteCommandW(0x30, x); WriteCommandW(0x32, y); WriteCommandW(0x34, (x+width-1)); WriteCommandW(0x36, (y+height-1)); - SetGraphicsCursor(x,y); + //SetTextCursor(x,y); + //SetGraphicsCursor(x,y); return noerror; } @@ -1080,6 +1096,8 @@ RetCode_t RA8875::booleanStream(loc_t x, loc_t y, dim_t w, dim_t h, const uint8_t * boolStream) { PERFORMANCE_RESET; + rect_t restore = windowrect; + window(x, y, w, h); SetGraphicsCursor(x, y); _StartGraphicsStream(); @@ -1091,7 +1109,7 @@ while (pixels) { uint8_t byte = *boolStream; - INFO("byte, mask: %02X, %02X", byte, bitmask); + //INFO("byte, mask: %02X, %02X", byte, bitmask); color_t c = (byte & bitmask) ? _foreground : _background; if (screenbpp == 16) { _spiwrite(c >> 8); @@ -1110,7 +1128,7 @@ } _select(false); _EndGraphicsStream(); - WindowMax(); + window(restore); REGISTERPERFORMANCE(PRF_BOOLSTREAM); return(noerror); }
--- a/RA8875.h Sat Mar 19 20:49:14 2016 +0000 +++ b/RA8875.h Mon Apr 25 01:43:59 2016 +0000 @@ -157,7 +157,6 @@ /// @endcode /// /// @todo Add Scroll support for text. -/// @todo Improve sync between internal and external font support - cursor, window, scroll. /// @todo Add Hardware reset signal - but testing to date indicates it is not needed. /// @todo Add high level objects - x-y graph, meter, others... but these will /// probably be best served in another class, since they may not @@ -1208,15 +1207,50 @@ /// virtual RetCode_t SetGraphicsCursorRead(loc_t x, loc_t y); - /// Set the window, which controls where items are written to the screen. + /// Set the window, constraining where items are written to the screen. + /// + /// After setting the window, text and graphics are constrained to this + /// window. Text will wrap from the right edge back to the left and down + /// one row and from the bottom to the top. Graphics drawing will be clipped + /// at the edge of the window. + /// + /// @note If the initial text write is outside the window, it will be shown + /// where the cursor position it. Once the write hits the right edge of + /// the defined window, it will then wrap back to the left edge. Once it + /// hits the bottom, it wraps to the top of the window. For this reason, + /// it is common to set the text cursor to the window. /// - /// When something hits the window width, it wraps back to the left side - /// and down a row. If the initial write is outside the window, it will - /// be captured into the window when it crosses a boundary. + /// @code + /// rect_t r = {10,10, 90,90}; + /// lcd.window(r); + /// lcd.SetTextCursor(r.p1.x, r.p1.y); + /// lcd.puts("012345678901234567890123456789012345678901234567890"); + /// lcd.window(); restore to full screen + /// @endcode + /// + /// @param[in] r is the rect_t used to set the window. + /// @returns success/failure code. See @ref RetCode_t. + /// + virtual RetCode_t window(rect_t r); + + /// Set the window, constraining where items are written to the screen. + /// + /// After setting the window, text and graphics are constrained to this + /// window. Text will wrap from the right edge back to the left and down + /// one row and from the bottom to the top. Graphics drawing will be clipped + /// at the edge of the window. + /// + /// @note If the initial text write is outside the window, it will be shown + /// where the cursor position it. Once the write hits the right edge of + /// the defined window, it will then wrap back to the left edge. Once it + /// hits the bottom, it wraps to the top of the window. For this reason, + /// it is common to set the text cursor to the window. /// /// @code /// lcd.window(10,10, 80,80); + /// lcd.SetTextCursor(10,10); /// lcd.puts("012345678901234567890123456789012345678901234567890"); + /// lcd.window(); restore to full screen /// @endcode /// /// @param[in] x is the left edge in pixels. @@ -1225,7 +1259,7 @@ /// @param[in] height is the window height in pixels. /// @returns success/failure code. See @ref RetCode_t. /// - virtual RetCode_t window(loc_t x, loc_t y, dim_t width, dim_t height); + virtual RetCode_t window(loc_t x = 0, loc_t y = 0, dim_t width = (dim_t)-1, dim_t height = (dim_t)-1); /// Clear either the specified layer, or the active layer. /// @@ -2194,6 +2228,7 @@ uint8_t screenbpp; ///< configured bits per pixel dim_t screenwidth; ///< configured screen width dim_t screenheight; ///< configured screen height + rect_t windowrect; ///< window commands are held here for speed of access bool portraitmode; ///< set true when in portrait mode (w,h are reversed) const unsigned char * font; ///< reference to an external font somewhere in memory