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:
Sat Apr 14 17:48:59 2018 +0000
Parent:
150:35a4db3081c1
Commit message:
Add support for scaling soft fonts, using the SetTextFontSize api.

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	Sun Sep 24 02:09:57 2017 +0000
+++ b/GraphicsDisplay.cpp	Sat Apr 14 17:48:59 2018 +0000
@@ -178,7 +178,6 @@
         _putp(color[i]);
     }
     _EndGraphicsStream();
-    //return WindowMax();
     return window(restore);
 }
 
@@ -226,18 +225,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	Sun Sep 24 02:09:57 2017 +0000
+++ b/GraphicsDisplay.h	Sat Apr 14 17:48:59 2018 +0000
@@ -309,38 +309,6 @@
     /// 
     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.
-    ///
-    /// @param[in] c is the character of interest.
-    /// @param[in, out] width is a pointer to where the width will be stored.
-    ///     This parameter is NULL tested and will only be written if not null
-    ///     which is convenient if you only want the height.
-    /// @param[in, out] height is a pointer to where the height will be stored.
-    ///     This parameter is NULL tested and will only be written if not null
-    ///     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, dim_t * width, dim_t * height);
-    
-    /// This method transfers one character from the external font data
-    /// to the screen.
-    ///
-    /// The font being used has already been set with the SelectUserFont
-    /// API.
-    ///
-    /// @note the font data is in a special format as generate by
-    ///         the mikroe font creator.
-    ///         See http://www.mikroe.com/glcd-font-creator/
-    ///
-    /// @param[in] x is the horizontal pixel coordinate
-    /// @param[in] y is the vertical pixel coordinate
-    /// @param[in] c is the character to render
-    /// @returns how far the cursor should advance to the right in pixels.
-    /// @returns zero if the character could not be rendered.
-    ///
-    virtual int fontblit(loc_t x, loc_t y, const unsigned char c);
-    
     /// This method returns the color value from a palette.
     ///
     /// This method accepts a pointer to a Bitmap color palette, which
@@ -455,6 +423,40 @@
     RetCode_t RenderIconFile(loc_t x, loc_t y, const char *Name_ICO);
 
     
+    /// This method returns the width in pixels of the chosen character
+    /// from the previously selected external font.
+    ///
+    /// @param[in] c is the character of interest.
+    /// @param[in, out] width is a pointer to where the width will be stored.
+    ///     This parameter is NULL tested and will only be written if not null
+    ///     which is convenient if you only want the height.
+    /// @param[in, out] height is a pointer to where the height will be stored.
+    ///     This parameter is NULL tested and will only be written if not null
+    ///     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, dim_t * width, dim_t * height);
+
+    
+    /// This method transfers one character from the external font data
+    /// to the screen.
+    ///
+    /// The font being used has already been set with the SelectUserFont
+    /// API.
+    ///
+    /// @note the font data is in a special format as generate by
+    ///         the mikroe font creator.
+    ///         See http://www.mikroe.com/glcd-font-creator/
+    ///
+    /// @param[in] x is the horizontal pixel coordinate
+    /// @param[in] y is the vertical pixel coordinate
+    /// @param[in] c is the character to render
+    /// @returns how far the cursor should advance to the right in pixels.
+    /// @returns zero if the character could not be rendered.
+    ///
+    virtual int fontblit(loc_t x, loc_t y, const unsigned char c);
+    
+
     /// prints one character at the specified coordinates.
     ///
     /// This will print the character at the specified pixel coordinates.
@@ -605,13 +607,15 @@
     ///
     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
     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	Sun Sep 24 02:09:57 2017 +0000
+++ b/RA8875.cpp	Sat Apr 14 17:48:59 2018 +0000
@@ -116,6 +116,7 @@
     obj_callback = NULL;
     method_callback = NULL;
     idle_callback = NULL;
+    fontScaleX = fontScaleY = 1;
 }
 
 
@@ -133,6 +134,7 @@
     obj_callback = NULL;
     method_callback = NULL;
     idle_callback = NULL;
+    fontScaleX = fontScaleY = 1;
 
     // Cap touch panel config
     m_addr = (FT5206_I2C_ADDRESS << 1);
@@ -1014,6 +1016,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);
@@ -1078,7 +1082,7 @@
                     cursor_y = windowrect.p1.y;               // @todo Should it scroll?
                 }
                 (void)character(cursor_x, cursor_y, c);
-                cursor_x += charWidth;
+                cursor_x += charWidth * fontScaleX;
             }
         }
     }
@@ -1310,38 +1314,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	Sun Sep 24 02:09:57 2017 +0000
+++ b/RA8875.h	Sat Apr 14 17:48:59 2018 +0000
@@ -1,4 +1,4 @@
-///
+/// 
 /// @mainpage RA8875 Display Controller Driver library
 ///
 /// The RA8875 Display controller is a powerful interface for low cost displays. It
@@ -64,7 +64,8 @@
 /// @todo Figure out how to "init()" in the constructor. I ran into some issues if
 ///     the display was instantiated before main(), and the code would not run,
 ///     thus the exposure and activation of the init() function. If the constructor
-///     was within main(), then it seemed to work as expected.
+///     was within main(), then it seemed to work as expected. This was also 
+///     very mbed OS version dependent.
 ///
 #ifndef RA8875_H
 #define RA8875_H
@@ -1509,13 +1510,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 +1531,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 +1846,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 scaleing.
+    /// 
     /// @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.