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 Dec 19 15:55:09 2015 +0000
Parent:
99:66edf771373a
Child:
101:e0aad446094a
Commit message:
Corrected a defect where the portrait mode might be incorrectly inferred - then limits many commands to partial screen.; Remove set_font(). Use SelectUserFont() instead.; Removed unnecessary code in several places (redundant work).

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	Thu Dec 17 12:19:01 2015 +0000
+++ b/GraphicsDisplay.cpp	Sat Dec 19 15:55:09 2015 +0000
@@ -85,12 +85,6 @@
     font = NULL;
 }
 
-RetCode_t GraphicsDisplay::set_font(const unsigned char * _font)
-{
-    font = _font;     // trusting them, but it might be good to put some checks in here...
-    return noerror;
-}
-
 RetCode_t GraphicsDisplay::SelectUserFont(const unsigned char * _font)
 {
     font = _font;     // trusting them, but it might be good to put some checks in here...
--- a/GraphicsDisplay.h	Thu Dec 17 12:19:01 2015 +0000
+++ b/GraphicsDisplay.h	Sat Dec 19 15:55:09 2015 +0000
@@ -333,32 +333,8 @@
     ///    
     virtual int rows(void);
     
-    /// Select a bitmap font (provided by the user) for all subsequent text.
-    ///
-    /// @caution This function is deprecated. @see SelectUserFont.
-    ///
-    /// @note Tool to create the fonts is accessible from its creator
-    ///     available at http://www.mikroe.com. 
-    ///     Change the data to an array of type char[].
-    ///
-    /// This special font array is modified from the mikroe tool output,
-    /// to include a special 4-byte header, which has this data:
-    ///   - the number of bytes per char
-    ///   - the vertical size in pixels for each character
-    ///   - the horizontal size in pixels for each character
-    ///   - the number of bytes per vertical line (width of the array)
-    ///   - following this special header is the normal data stream.
-    ///
-    /// @param[in] font is a pointer to a specially formed font array.
-    /// @returns error code.
-    ///
-    virtual RetCode_t set_font(const unsigned char * font = NULL);
-    
-    
     /// Select a User Font for all subsequent text.
     ///
-    /// @note This function is replaces the obsolete function @see set_font.
-    ///
     /// @note Tool to create the fonts is accessible from its creator
     ///     available at http://www.mikroe.com. 
     ///     For version 1.2.0.0, choose the "Export for TFT and new GLCD"
--- a/RA8875.cpp	Thu Dec 17 12:19:01 2015 +0000
+++ b/RA8875.cpp	Sat Dec 19 15:55:09 2015 +0000
@@ -146,6 +146,8 @@
     WriteCommand(0x1e, 0x06);                   //VSTR1 //VSYNC Start Position[8]
     WriteCommand(0x1f, 0x01);                   //VPWR  //VSYNC Polarity ,VSYNC Pulse Width[6:0]
 
+    portraitmode = false;
+    
     if (width >= 800 && height >= 480 && color_bpp > 8) {
         WriteCommand(0x20, 0x00);               // DPCR - 1-layer mode when the resolution is too high
     } else {
@@ -386,9 +388,13 @@
 #ifdef PERF_METRICS
 void RA8875::ClearPerformance()
 {
-    for (int i=0; i<METRICCOUNT; i++)
+    int i;
+    
+    for (i=0; i<METRICCOUNT; i++)
         metrics[i] = 0;
     idletime_usec = 0;
+    for (i=0; i<256; i++)
+        commandsUsed[i] = 0;
 }
 
 
@@ -409,14 +415,16 @@
 
 void RA8875::ReportPerformance(Serial & pc)
 {
+    int i;
+    
     pc.printf("\r\nPerformance Metrics\r\n");
-    for (int i=0; i<METRICCOUNT; i++) {
+    for (i=0; i<METRICCOUNT; i++) {
         pc.printf("%10d uS %s\r\n", metrics[i], metricsName[i]);
     }
     pc.printf("%10d uS Idle time polling display for ready.\r\n", idletime_usec);
     for (i=0; i<256; i++) {
         if (commandsUsed[i])
-            pc.printf("Command %02X used %5d times.\r\n", i, commandsUsed[i])
+            pc.printf("Command %02X used %5d times.\r\n", i, commandsUsed[i]);
     }
 }
 #endif
@@ -738,6 +746,7 @@
         default:
             return bad_parameter;
     }
+    INFO("Orientation: %d, %d", angle, portraitmode);
     WriteCommand(0x22, fncr1Val);
     return WriteCommand(0x20, dpcrVal);
 }
@@ -882,14 +891,8 @@
 
 void RA8875::puts(const char * string)
 {
-    unsigned char mwcr0 = ReadCommand(0x40);
-
     if (font == NULL) {
-        if ((mwcr0 & 0x80) == 0x00) {
-            WriteCommand(0x40,0x80);    // Put in Text mode if not already
-        }
-    //} else {
-    //    _StartGraphicsStream();
+        WriteCommand(0x40,0x80);    // Put in Text mode if internal font
     }
     if (*string != '\0') {
 #if 1
@@ -907,8 +910,6 @@
         _select(false);
 #endif
     }
-    //if (font)
-    //    _EndGraphicsStream();
 }
 
 
@@ -1162,9 +1163,9 @@
     PERFORMANCE_RESET;
     // check for bad_parameter
     if (x1 < 0 || x1 >= width() || x2 < 0 || x2 >= width() 
-    || y1 < 0 || y1 >= height() || y2 < 0 || y2 >= height())
+    || y1 < 0 || y1 >= height() || y2 < 0 || y2 >= height()) {
         ret = bad_parameter;
-    else {
+    } else {
         if (x1 == x2 && y1 == y2) {
             pixel(x1, y1);
         } else if (x1 == x2) {
@@ -1476,15 +1477,6 @@
     return (float)(GetBacklight_u8())/255;
 }
 
-RetCode_t RA8875::set_font(const unsigned char * _font)
-{
-    if (font && ! _font) {
-        SetTextCursor(cursor_x, cursor_y);  // soft-font cursor -> hw cursor
-    }
-    font = _font;
-    return GraphicsDisplay::set_font(_font);    // trusting them, but it might be good to put some checks in here...
-}
-
 RetCode_t RA8875::SelectUserFont(const uint8_t * _font)
 {
     INFO("Cursor(%d,%d)  %p", cursor_x, cursor_y, _font);
@@ -1716,8 +1708,6 @@
             if (pixelBuffer)
                 free(pixelBuffer);
             free(lineBuffer);
-            if (pixelBuffer)
-                free(pixelBuffer);
             return(not_enough_ram);
         }
 
@@ -1812,8 +1802,6 @@
         if (pixelBuffer)
             free(pixelBuffer);
         free(lineBuffer);
-        if (pixelBuffer)
-            free(pixelBuffer);
         INFO("Image closed");
         return noerror;
     } else {
@@ -1883,8 +1871,6 @@
             if (pixelBuffer)
                 free(pixelBuffer);
             free(lineBuffer);
-            if (pixelBuffer)
-                free(pixelBuffer);
             return(not_enough_ram);
         }
 
@@ -1898,8 +1884,6 @@
             if (pixelBuffer)
                 free(pixelBuffer);
             free(lineBuffer);
-            if (pixelBuffer)
-                free(pixelBuffer);
             return(file_not_found);
         }
 
@@ -1986,8 +1970,6 @@
         if (pixelBuffer)
             free(pixelBuffer);
         free(lineBuffer);
-        if (pixelBuffer)
-            free(pixelBuffer);
         INFO("Image closed");
         return noerror;
     } else {
@@ -2026,7 +2008,7 @@
     display.foreground(Blue);
     display.cls();
     display.Backlight_u8(255);
-    display.puts(0,0, "Text Wrap Test.\r\n");
+    display.puts("Text Wrap Test.\r\n");
     for (int i=1; i<60; i++) {
         display.printf("L%2d\n", i % 17);
         if (!SuppressSlowStuff)
@@ -2080,7 +2062,7 @@
     display.foreground(Blue);
     display.cls();
     display.Backlight_u8(255);
-    display.puts(0,0, "KeyPad Test. Touch the keypad...");
+    display.puts("KeyPad Test. Touch the keypad...");
     pc.printf("\r\n"
               "Raw KeyPad Test. Keypad returns the key-number.\r\n"
               "Press [most] any PC keyboard key to advance to next test.\r\n");
@@ -2129,7 +2111,7 @@
     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;
-    int delay = 100;
+    int delay = 60;
 
     if (!SuppressSlowStuff)
         pc.printf("Text Cursor Test\r\n");
@@ -2139,7 +2121,7 @@
     display.foreground(Blue);
     display.cls();
     display.Backlight_u8(255);
-    display.puts(0,0, "Text Cursor Test.");
+    display.puts("Text Cursor Test.");
 
     // visible, non-blinking
     display.SetTextCursor(0,20);
@@ -2191,8 +2173,8 @@
     display.background(White);
     display.foreground(Blue);
     display.cls();
+    display.puts("RA8875 Backlight Test - Ramp up.");
     wait_ms(delay);
-    display.puts(0,0, "RA8875 Backlight Test - Ramp up.");
     for (int i=0; i <= 255; i++) {
         sprintf(buf, "%3d, %4d", i, w);
         display.puts(100,100,buf);
@@ -2230,8 +2212,8 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
+    display.puts("External Font Test.");
     display.Backlight(1);
-    display.puts(0,0, "External Font Test.");
 
     display.SelectUserFont(BPG_Arial08x08);
     display.puts(0,30, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
@@ -2240,7 +2222,6 @@
     display.puts("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\r\n");
     
     display.SelectUserFont();
-    //display.set_font();     // restore to internal
 
     display.puts("Normal font again.");
     //display.window(0,0, display.width(), display.height());
@@ -2254,7 +2235,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "DOS Colors - Fore");
+    display.puts("DOS Colors - Fore");
     display.puts(280,0, "Back");
     display.background(Gray);
     for (int i=0; i<16; i++) {
@@ -2306,7 +2287,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Pixel Test");
+    display.puts("Pixel Test");
     for (i=0; i<1000; i++) {
         x = rand() % 480;
         y = 16 + rand() % (272-16);
@@ -2326,7 +2307,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Line Test");
+    display.puts("Line Test");
     for (i=0; i<16; i++) {
         // Lines
         x = rand() % 480;
@@ -2379,7 +2360,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Rectangle Test");
+    display.puts("Rectangle Test");
     for (i=0; i<16; i++) {
         x1 = rand() % 240;
         y1 = 50 + rand() % 200;
@@ -2407,7 +2388,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Layer 0");
+    display.puts("Layer 0");
     for (i=0; i<16; i++) {
         x1 = rand() % 240;
         y1 = 50 + rand() % 200;
@@ -2467,7 +2448,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Rounded Rectangle Test");
+    display.puts("Rounded Rectangle Test");
 
     for (i=0; i<16; i++) {
         x1 = rand() % 240;
@@ -2560,7 +2541,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Circle Test");
+    display.puts("Circle Test");
     for (i=0; i<16; i++) {
         x = 100 + rand() % 100;
         y = 70 + rand() % 200;
@@ -2586,7 +2567,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Ellipse Test");
+    display.puts("Ellipse Test");
     for (i=0; i<16; i++) {
         x = 100 + rand() % 100;
         y = 70 + rand() % 200;
@@ -2611,7 +2592,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Graphics Test, loading /local/TestPat.bmp");
+    display.puts("Graphics Test, loading /local/TestPat.bmp");
     wait(3);
 
     int r = display.RenderBitmapFile(0,0, "/local/TestPat.bmp");
@@ -2629,7 +2610,7 @@
     display.background(Black);
     display.foreground(Blue);
     display.cls();
-    display.puts(0,0, "Touch Panel Test\r\n");
+    display.puts("Touch Panel Test\r\n");
     pc.printf("Touch Panel Test\r\n");
     display.TouchPanelInit();
     pc.printf("  TP: c - calibrate, r - restore, t - test\r\n");
--- a/RA8875.h	Thu Dec 17 12:19:01 2015 +0000
+++ b/RA8875.h	Sat Dec 19 15:55:09 2015 +0000
@@ -1745,32 +1745,8 @@
     /// 
     float GetBacklight(void);
 
-    /// Select a bitmap font (provided by the user) for all subsequent text.
-    ///
-    /// @caution This function is deprecated. @see SelectUserFont.
-    ///
-    /// @note Tool to create the fonts is accessible from its creator
-    ///     available at http://www.mikroe.com. 
-    ///     Change the data to an array of type char[].
-    ///
-    /// This special font array is modified from the mikroe tool output,
-    /// to include a special 4-byte header, which has this data:
-    ///   - the number of bytes per char
-    ///   - the vertical size in pixels for each character
-    ///   - the horizontal size in pixels for each character
-    ///   - the number of bytes per vertical line (width of the array)
-    ///   - following this special header is the normal data stream.
-    ///
-    /// @param[in] font is a pointer to a specially formed font array.
-    /// @returns error code.
-    ///
-    virtual RetCode_t set_font(const unsigned char * font = NULL);
-    
-    
     /// Select a User Font for all subsequent text.
     ///
-    /// @note This function is replaces the obsolete function @see set_font.
-    ///
     /// @note Tool to create the fonts is accessible from its creator
     ///     available at http://www.mikroe.com. 
     ///     For version 1.2.0.0, choose the "Export for TFT and new GLCD"