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 Peter Drescher

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)

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Sun Jul 29 00:32:51 2018 +0000
Parent:
152:a013ac0133e4
Child:
154:ad2450fc3dc3
Commit message:
Soft Fonts and very preliminary GIF support.

Changed in this revision

GraphicsDisplay.cpp Show annotated file Show diff for this revision Revisions of this file
GraphicsDisplay.h Show annotated file Show diff for this revision Revisions of this file
RA8875.cpp Show annotated file Show diff for this revision Revisions of this file
RA8875.h Show annotated file Show diff for this revision Revisions of this file
--- a/GraphicsDisplay.cpp	Mon Nov 06 01:41:55 2017 +0000
+++ b/GraphicsDisplay.cpp	Sun Jul 29 00:32:51 2018 +0000
@@ -3,6 +3,8 @@
  * Released under the MIT License: http://mbed.org/license/mit
  *
  * Derivative work by D.Smart 2014
+ * 201807 Scalable soft-fonts and gif support
+ *
  */
 
 #include "GraphicsDisplay.h"
@@ -181,7 +183,6 @@
         _putp(color[i]);
     }
     _EndGraphicsStream();
-    //return WindowMax();
     return window(restore);
 }
 
@@ -229,18 +230,13 @@
 
 int GraphicsDisplay::fontblit(loc_t x, loc_t y, const unsigned char c)
 {
-    const uint8_t * charRecord;   // width, data, data, data, ...
-    dim_t charWidth, charHeight;
+    const uint8_t * charRecord;         // pointer to char data; width, data, data, data, ...
+    dim_t charWidth, charHeight;        // metrics for the raw char in the font table
     charRecord = getCharMetrics(c, &charWidth, &charHeight);
     if (charRecord) {
         INFO("hgt:%d, wdt:%d", charHeight, charWidth);
-        // clip to the edge of the screen
-        //if (x + charWidth >= width())
-        //    charWidth = width() - x;
-        //if (y + charHeight >= height())
-        //    charHeight = height() - y;
         booleanStream(x,y,charWidth, charHeight, charRecord);
-        return charWidth;
+        return charWidth * fontScaleX;
     } else {
         return 0;
     }
--- a/GraphicsDisplay.h	Mon Nov 06 01:41:55 2017 +0000
+++ b/GraphicsDisplay.h	Sun Jul 29 00:32:51 2018 +0000
@@ -665,6 +665,9 @@
     short _x;                       ///< keeps track of current X location
     short _y;                       ///< keeps track of current Y location
     
+    uint8_t fontScaleX;             ///< tracks the font scale factor for Soft fonts. Range: 1 .. 4
+    uint8_t fontScaleY;             ///< tracks the font scale factor for soft fonts. Range: 1 .. 4
+
     rect_t windowrect;              ///< window commands are held here for speed of access 
 };
 
--- a/RA8875.cpp	Mon Nov 06 01:41:55 2017 +0000
+++ b/RA8875.cpp	Sun Jul 29 00:32:51 2018 +0000
@@ -115,6 +115,7 @@
     obj_callback = NULL;
     method_callback = NULL;
     idle_callback = NULL;
+    fontScaleX = fontScaleY = 1;
 }
 
 
@@ -132,6 +133,7 @@
     obj_callback = NULL;
     method_callback = NULL;
     idle_callback = NULL;
+    fontScaleX = fontScaleY = 1;
 
     // Cap touch panel config
     m_addr = (FT5206_I2C_ADDRESS << 1);
@@ -1013,6 +1015,8 @@
     if (vScale == -1)
         vScale = hScale;
     if (hScale >= 1 && hScale <= 4 && vScale >= 1 && vScale <= 4) {
+        fontScaleX = hScale;    // save for use with a Soft Font
+        fontScaleY = vScale;
         reg &= 0xF0;    // keep the high nibble as is.
         reg |= ((hScale - 1) << 2);
         reg |= ((vScale - 1) << 0);
@@ -1077,7 +1081,7 @@
                     cursor_y = windowrect.p1.y;               // @todo Should it scroll?
                 }
                 (void)character(cursor_x, cursor_y, c);
-                cursor_x += charWidth;
+                cursor_x += charWidth * fontScaleX;
             }
         }
     }
@@ -1309,38 +1313,48 @@
     return(noerror);
 }
 
+// With a font scale X = 1, a pixel stream is "abcdefg..."
+// With a font scale X = 2, a pixel stream is "aabbccddeeffgg..."
+// With a font scale Y = 2, a pixel stream is "abcdefg..."
+//                                            "abcdefg..."
+//
 RetCode_t RA8875::booleanStream(loc_t x, loc_t y, dim_t w, dim_t h, const uint8_t * boolStream) 
 {
     PERFORMANCE_RESET;
+    const uint8_t * rowStream;
     rect_t restore = windowrect;
-    
-    window(x, y, w, h);
+    window(x, y, w * fontScaleX, h * fontScaleY);       // Scale from font scale factors
     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));
+        for (int dy=0; dy<fontScaleY; dy++) {           // Vertical Font Scale Factor
+            uint8_t pixels = w;
+            uint8_t bitmask = 0x01;
+            rowStream = boolStream;        
+            while (pixels) {
+                uint8_t byte = *rowStream;
+                //INFO("byte, mask: %02X, %02X", byte, bitmask);
+                color_t c = (byte & bitmask) ? _foreground : _background;
+                
+                for (int dx=0; dx<fontScaleX; dx++) {   // Horizontal Font Scale Factor
+                    if (screenbpp == 16) {
+                        _spiwrite(c >> 8);
+                        _spiwrite(c & 0xFF);
+                    } else {
+                        _spiwrite(_cvt16to8(c));
+                    }
                 }
-            bitmask <<= 1;
-            if (pixels > 1 && bitmask == 0) {
-                bitmask = 0x01;
-                boolStream++;
+                bitmask <<= 1;
+                if (pixels > 1 && bitmask == 0) {
+                    bitmask = 0x01;
+                    rowStream++;
+                }
+                pixels--;
             }
-            pixels--;
         }
-        boolStream++;
+        boolStream += (rowStream - boolStream + 1);
     }
     _select(false);
     _EndGraphicsStream();
--- a/RA8875.h	Mon Nov 06 01:41:55 2017 +0000
+++ b/RA8875.h	Sun Jul 29 00:32:51 2018 +0000
@@ -1509,13 +1509,14 @@
         alignment_t alignment = align_none);
     
 
-    /// Control the font size of the RA8875 internal fonts.
+    /// Control the font size of the RA8875 rendered fonts.
     ///
     /// This command lets you set the font enlargement for both horizontal
     /// and vertical, independent of the rotation, background, and 
     /// alignment. See @ref SetTextFontControl.
     ///
-    /// @note This command only operates on the RA8875 internal fonts.
+    /// @note This command operates on the RA8875 internal fonts.
+    /// @note This command also operates on the selected soft font.
     ///
     /// @param[in] hScale defaults to 1, but can be 1, 2, 3, or 4,
     ///     and scales the font size by this amount.
@@ -1529,6 +1530,10 @@
     ///     lcd.puts("2*2 3*h");
     ///     lcd.SetTextFontSize();      // Restore to normal size in both dimensions
     ///     lcd.puts("normal");
+    ///     lcd.SelectUserFont(BPG_Arial63x63); // Large user font
+    ///     lcd.puts("B63x63");                 // Show a sample
+    ///     lcd.SetTextFontSize(2);             // Now twice as big
+    ///     lcd.puts("x2");                     // Show a sample
     /// @endcode
     ///
     /// @note if either hScale or vScale is outside of its permitted range,
@@ -1840,6 +1845,11 @@
     /// This is similar, but different, to the @ref pixelStream API, which is 
     /// given a stream of color values.
     /// 
+    /// This is most often used for Soft Fonts, and for that reason, this method
+    /// will scale the presentation based on the selected font size. 
+    /// See @ref SetTextFontSize, So, users may want to SetTextFontSize(1) for
+    /// 1:1 scaling.
+    /// 
     /// @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.