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:
Mon Oct 17 00:42:47 2016 +0000
Parent:
132:a5d7a8541683
Child:
134:f028ed71a0af
Commit message:
Revised how it sets the foreground and background color to correct a defect when in 8-bit mode.

Changed in this revision

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/RA8875.cpp	Sun Sep 04 16:54:34 2016 +0000
+++ b/RA8875.cpp	Mon Oct 17 00:42:47 2016 +0000
@@ -4,9 +4,8 @@
 /// which is 480 x 272 using a 4-wire SPI interface. Support is provided for
 /// both a keypad and a resistive touch-screen.
 ///
-/// This display controller is used in other display resolutions, up to 800x600.
-/// While this driver has not been tested with these variants, nothing was done
-/// to prevent easily supporting them.
+/// This dirver has been fully tested with an 800 x 480 variant (also using
+/// 4-wire SPI).
 ///
 #include "RA8875.h"
 
@@ -183,7 +182,7 @@
     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 {
@@ -295,10 +294,7 @@
 
 RetCode_t RA8875::SetBackgroundTransparencyColor(color_t color)
 {
-    WriteCommand(0x67, (color >> 11) & 0x1F);
-    WriteCommand(0x68, (color >> 5) & 0x3F);
-    WriteCommand(0x69, (color & 0x1F));
-    return noerror;
+    return _writeColorTrio(0x67, color);
 }
 
 
@@ -667,6 +663,54 @@
     return c16;
 }
 
+RetCode_t RA8875::_writeColorTrio(uint8_t regAddr, color_t color)
+{
+    RetCode_t rt = noerror;
+    
+    if (screenbpp == 16) {
+        WriteCommand(regAddr+0, (color>>11));                  // BGCR0
+        WriteCommand(regAddr+1, (unsigned char)(color>>5));    // BGCR1
+        rt = WriteCommand(regAddr+2, (unsigned char)(color));       // BGCR2
+    } else {
+        uint8_t r, g, b;
+        
+        // RRRR RGGG GGGB BBBB      RGB
+        // RRR   GGG    B B
+        r = (uint8_t)((color) >> 13);
+        g = (uint8_t)((color) >> 8);
+        b = (uint8_t)((color) >> 3);
+        WriteCommand(regAddr+0, r);  // BGCR0
+        WriteCommand(regAddr+1, g);  // BGCR1
+        rt = WriteCommand(regAddr+2, b);  // BGCR2
+    }
+    return rt;
+}
+
+color_t RA8875::_readColorTrio(uint8_t regAddr)
+{
+    color_t color;
+    uint8_t r, g, b;
+    
+    r = ReadCommand(regAddr+0);
+    g = ReadCommand(regAddr+1);
+    b = ReadCommand(regAddr+2);
+    if (screenbpp == 16) {
+        // 000R RRRR 00GG GGGG 000B BBBB
+        // RRRR RGGG GGGB BBBB
+        color  = (r & 0x1F) << 11;
+        color |= (g & 0x3F) << 5;
+        color |= (b & 0x1F);
+    } else {
+        // RRRG GGBB
+        // RRRR RGGG GGGB BBBB
+        color  = (r & 0x07) << 13;
+        color |= (g & 0x07) << 8;
+        color |= (b & 0x03) << 3;
+    }
+    return color;
+}
+
+
 dim_t RA8875::fontwidth(void)
 {
     if (font == NULL)
@@ -1219,7 +1263,6 @@
     color_t pixel;
 
     PERFORMANCE_RESET;
-    //WriteCommand(0x45,0x00);    // read left->right, top->bottom
     WriteCommand(0x40,0x00);    // Graphics write mode
     SetGraphicsCursorRead(x, y);
     WriteCommand(0x02);
@@ -1749,10 +1792,7 @@
 RetCode_t RA8875::background(color_t color)
 {
     GraphicsDisplay::background(color);
-    WriteCommand(0x60, (color>>11));                  // BGCR0
-    WriteCommand(0x61, (unsigned char)(color>>5));    // BGCR0
-    WriteCommand(0x62, (unsigned char)(color));       // BGCR0
-    return noerror;
+    return _writeColorTrio(0x60, color);
 }
 
 
@@ -1766,10 +1806,7 @@
 RetCode_t RA8875::foreground(color_t color)
 {
     GraphicsDisplay::foreground(color);
-    WriteCommand(0x63, (unsigned char)(color>>11));
-    WriteCommand(0x64, (unsigned char)(color>>5));
-    WriteCommand(0x65, (unsigned char)(color));
-    return noerror;
+    return _writeColorTrio(0x63, color);
 }
 
 
@@ -1782,12 +1819,7 @@
 
 color_t RA8875::GetForeColor(void)
 {
-    color_t color;
-
-    color  = (ReadCommand(0x63) & 0x1F) << 11;
-    color |= (ReadCommand(0x64) & 0x3F) << 5;
-    color |= (ReadCommand(0x65) & 0x1F);
-    return color;
+    return _readColorTrio(0x63);
 }
 
 
--- a/RA8875.h	Sun Sep 04 16:54:34 2016 +0000
+++ b/RA8875.h	Mon Oct 17 00:42:47 2016 +0000
@@ -2538,6 +2538,7 @@
     ///
     void AttachIdleHandler(IdleCallback_T callback = NULL) { idle_callback = callback; }
 
+
 #ifdef PERF_METRICS
     /// Clear the performance metrics to zero.
     void ClearPerformance();
@@ -2666,6 +2667,31 @@
     ///
     int _external_getCharWidth(int c);
     
+    /// Write color to an RGB register set
+    ///
+    /// This API takes a color value, and writes it into the specified
+    /// color registers, which are a trio of 3 registers. The actual
+    /// trio write is performed based on whether the display is configured
+    /// for 8 or 16 bits per pixel.
+    ///
+    /// @param[in] regAddr is the register address starting the trio
+    /// @param[in] color is the color to write
+    /// @returns success/failure code. See @ref RetCode_t.
+    ///
+    RetCode_t _writeColorTrio(uint8_t regAddr, color_t color);
+    
+    /// Read color from an RGB register set
+    ///
+    /// This API reads a color value from a trio of registers. The actual
+    /// trio write is performed based on whether the display is configured
+    /// for 8 or 16 bits per pixel.
+    ///
+    /// @param[in] regAddr is the register address starting the trio
+    /// @returns color_t value
+    ///
+    color_t _readColorTrio(uint8_t regAddr);
+    
+    
     /// Convert a 16-bit color value to an 8-bit value
     ///
     /// @param[in] c16 is the 16-bit color value to convert.