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)

Revision:
197:853d08e2fb53
Parent:
196:56820026701b
Child:
198:9b6851107426
--- a/RA8875.cpp	Tue Feb 11 21:26:59 2020 +0000
+++ b/RA8875.cpp	Tue Feb 11 21:51:42 2020 +0000
@@ -18,7 +18,7 @@
 #define swFree free
 #endif
 
-#define DEBUG "RAIO"
+//#define DEBUG "RAIO"
 // ...
 // INFO("Stuff to show %d", var); // new-line is automatically appended
 //
@@ -108,7 +108,7 @@
     uint8_t a;
 } rgbTrio_t;
 
-/// This is defined as a "Web-Safe" color palette of 216 colors. 
+/// This is defined as a "Web-Safe" color palette of 216 colors.
 ///
 /// It is defined so it can be emitted into a BMP file as the color palette, and it is then used
 /// for downscaling from higher resolution color depth to an 8-bit format.
@@ -336,9 +336,9 @@
     } else {
         WriteCommand(RA8875_PLLC1, 0x0B);               // PLLC1 - Phase Lock Loop registers
     }
-    wait_ms(1);
+    wait_us(1000);
     WriteCommand(RA8875_PLLC2, 0x02);
-    wait_ms(1);
+    wait_us(1000);
 
     // System Config Register (SYSR)
     screenbpp = color_bpp;
@@ -351,7 +351,7 @@
     // Set Pixel Clock Setting Register (PCSR) based on display size from buy-display.com sample code
     if (width == 800) {
         WriteCommand(RA8875_PCSR, 0x81);               // PDAT on PCLK falling edge, PCLK = 4 x System Clock
-        wait_ms(1);
+        wait_us(1000);
 
         // Horizontal Settings
         screenwidth = width;
@@ -372,7 +372,7 @@
         WriteCommand(RA8875_VPWR, 0x01);                   //VPWR  //VSYNC Polarity ,VSYNC Pulse Width[6:0]
     } else {
         WriteCommand(RA8875_PCSR, 0x82);               // PDAT on PCLK falling edge, PCLK = 4 x System Clock
-        wait_ms(1);
+        wait_us(1000);
 
         // Horizontal Settings
         screenwidth = width;
@@ -434,15 +434,15 @@
     #if 0
     if (res != (PinName)NC) {
         res = 0;                            // Active low - assert reset
-        wait_ms(2);                         // must be > 1024 clock periods. (@25 MHz, this is 40.96 usec)
+        wait_us(2000);                         // must be > 1024 clock periods. (@25 MHz, this is 40.96 usec)
         res = 1;                            // de-assert reset
     }
     #endif
     ret = WriteCommand(RA8875_PWRR, 0x01);         // Apply Display Off, Reset
-    wait_ms(2);                             // no idea if I need to wait, or how long
+    wait_us(2000);                             // no idea if I need to wait, or how long
     if (ret == noerror) {
         ret = WriteCommand(RA8875_PWRR, 0x00);     // Display off, Remove reset
-        wait_ms(2);                         // no idea if I need to wait, or how long
+        wait_us(2000);                         // no idea if I need to wait, or how long
     }
     return ret;
 }
@@ -1297,9 +1297,9 @@
 {
     if (font == NULL) {
         if (charOnly)
-            return fontwidth() * fontScaleX;
+            return fontwidth();     // *fontScaleX;  // fontScale is picked up from fontwidth()
         else
-            return fontwidth() * strlen(text) * fontScaleX;
+            return fontwidth() * strlen(text);// *fontScaleX;
     } else {
         dim_t width = 0;
 
@@ -1830,7 +1830,7 @@
         } else {
             // some diagonal, drawn rather slowly with filled circles
             // @todo draw the end-points with circles, then draw the diagonal
-            //      with 2 triangles. 
+            //      with 2 triangles.
             #if 1  // New Faster method
             //Round-caps
             if (roundCap) {
@@ -1842,7 +1842,7 @@
             //            /   + p1a                   p1a,p2a,p2b
             //           +  +p1+ .  .   .   .    .
             //       p1b  +   /  .      angle
-            //              +        . 
+            //              +        .
             //                           .
             //
             //                                   .        +
@@ -2571,8 +2571,8 @@
         #define DOUBLEBUF /* one larger buffer instead of two */
 
         #ifdef DOUBLEBUF
-        // In the "#else", pixelBuffer2 malloc returns a value, 
-        // but is actually causing a failure later. 
+        // In the "#else", pixelBuffer2 malloc returns a value,
+        // but is actually causing a failure later.
         // This test helps determine if it is truly out of memory,
         // or if malloc is broken.
         pixelBuffer = (color_t *)swMalloc(2 * w * sizeof(color_t));
@@ -2785,8 +2785,8 @@
         #define DOUBLEBUF /* one larger buffer instead of two */
 
         #ifdef DOUBLEBUF
-        // In the "#else", pixelBuffer2 malloc returns a value, 
-        // but is actually causing a failure later. 
+        // In the "#else", pixelBuffer2 malloc returns a value,
+        // but is actually causing a failure later.
         // This test helps determine if it is truly out of memory,
         // or if malloc is broken.
         pixelBuffer = (color_t *)swMalloc(2 * w * sizeof(color_t));
@@ -2976,10 +2976,10 @@
     for (int i=1; i<60; i++) {
         display.printf("L%2d\n", i % 17);
         if (!SuppressSlowStuff)
-            wait_ms(100);
+            wait_us(100000);
     }
     if (!SuppressSlowStuff)
-        wait_ms(3000);
+        wait_us(3000000);
 }
 
 
@@ -3362,10 +3362,10 @@
         r2 = rand() % (y2 - y1)/2;
         display.roundrect(x1,y1, x2,y2, r1,r2, display.DOSColor(i));
         if (!SuppressSlowStuff)
-            wait_ms(20);
+            wait_us(20000);
     }
     if (!SuppressSlowStuff)
-        wait_ms(1000);
+        wait_us(1000000);
 
     display.SelectDrawingLayer(1);
     display.background(Black);
@@ -3378,23 +3378,23 @@
         r1 = rand() % min(y1 - 20, 100);
         display.circle(x1,y1,r1, display.DOSColor(i));
         if (!SuppressSlowStuff)
-            wait_ms(20);
+            wait_us(20000);
     }
     display.SetLayerMode(RA8875::ShowLayer1);        // Show it after the build-up
     if (!SuppressSlowStuff)
-        wait_ms(2000);
+        wait_us(2000000);
 
     display.SelectDrawingLayer(0);
     display.SetLayerMode(RA8875::ShowLayer0);        // Show Layer 0 again
     if (!SuppressSlowStuff)
-        wait_ms(1000);
+        wait_us(1000000);
     display.SetLayerMode(RA8875::TransparentMode);        // Transparent mode
     if (!SuppressSlowStuff)
-        wait_ms(1000);
+        wait_us(1000000);
     for (i=0; i<=8; i++) {
         display.SetLayerTransparency(i, 8-i);
         if (!SuppressSlowStuff)
-            wait_ms(200);
+            wait_us(200000);
     }
 
     // Restore before we exit
@@ -3589,7 +3589,7 @@
             display.line(pTest[i].x-10, pTest[i].y, pTest[i].x+10, pTest[i].y, White);
             display.line(pTest[i].x, pTest[i].y-10, pTest[i].x, pTest[i].y+10, White);
             while (!display.TouchPanelA2DFiltered(&x, &y))
-                wait_ms(20);
+                wait_us(20000);
             pSample[i].x = x;
             pSample[i].y = y;
             display.line(pTest[i].x-10, pTest[i].y, pTest[i].x+10, pTest[i].y, Black);
@@ -3597,7 +3597,7 @@
             display.foreground(Blue);
             display.printf(" (%4d,%4d)\r\n", x,y);
             while (display.TouchPanelA2DFiltered(&x, &y))
-                wait_ms(20);
+                wait_us(20000);
             wait(2);
         }
         display.TouchPanelComputeCalibration(pTest, pSample, &calmatrix);
@@ -3773,7 +3773,7 @@
                 break;
             case 'r':
                 pc.printf("Resetting ...\r\n");
-                wait_ms(20);
+                wait_us(20000);
                 mbed_reset();
                 break;
             case ' ':
@@ -3786,9 +3786,9 @@
             automode++;
             if (automode >= sizeof(modelist))
                 automode = 0;
-            wait_ms(2000);
+            wait_us(2000000);
         }
-        wait_ms(200);
+        wait_us(200000);
     }
 }