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 Mar 19 21:41:24 2017 +0000
Parent:
141:2ec78a50dc98
Child:
143:e872d65a710d
Commit message:
Breaking change on SelectDrawingLayer command, which now returns the previous layer (making it far easier to restore layers).

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 29 20:06:00 2016 +0000
+++ b/GraphicsDisplay.cpp	Sun Mar 19 21:41:24 2017 +0000
@@ -150,7 +150,17 @@
 
 RetCode_t GraphicsDisplay::cls(uint16_t layers)
 {
-    return fill(0, 0, width(), height(), _background);
+    int restore = GetDrawingLayer();
+    if (layers & 1) {
+        SelectDrawingLayer(0);
+        fill(0, 0, width(), height(), _background);
+    }
+    if (layers & 2) {
+        SelectDrawingLayer(1);
+        fill(0, 0, width(), height(), _background);
+    }
+    SelectDrawingLayer(restore);
+    return noerror;
 }
 
 RetCode_t GraphicsDisplay::blit(loc_t x, loc_t y, dim_t w, dim_t h, const int * color)
--- a/GraphicsDisplay.h	Thu Dec 29 20:06:00 2016 +0000
+++ b/GraphicsDisplay.h	Sun Mar 19 21:41:24 2017 +0000
@@ -147,6 +147,54 @@
     virtual RetCode_t fillrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 
         color_t color, fill_t fillit = FILL) = 0;
 
+    /// Select the drawing layer for subsequent commands.
+    ///
+    /// If the screen configuration is 480 x 272, or if it is 800 x 480 
+    /// and 8-bit color, the the display supports two layers, which can 
+    /// be independently drawn on and shown. Additionally, complex
+    /// operations involving both layers are permitted.
+    ///
+    /// @code
+    ///     //lcd.SetLayerMode(OnlyLayer0); // default is layer 0
+    ///     lcd.rect(400,130, 475,155,Brown);
+    ///     lcd.SelectDrawingLayer(1);
+    ///     lcd.circle(400,25, 25, BrightRed);
+    ///     wait(1);
+    ///     lcd.SetLayerMode(ShowLayer1);
+    /// @endcode
+    ///
+    /// @attention The user manual refers to Layer 1 and Layer 2, however the
+    ///     actual register values are value 0 and 1. This API as well as
+    ///     others that reference the layers use the values 0 and 1 for
+    ///     cleaner iteration in the code.
+    ///
+    /// @param[in] layer is 0 or 1 to select the layer for subsequent 
+    ///     commands.
+    /// @returns the previous drawing layer; 0 or 1.
+    ///
+    virtual uint16_t SelectDrawingLayer(uint16_t layer) = 0;
+ 
+    
+    /// Get the currently active drawing layer.
+    ///
+    /// This returns a value, 0 or 1, based on the screen configuration
+    /// and the currently active drawing layer.
+    ///
+    /// @code
+    ///     uint16_t prevLayer = lcd.SelectDrawingLayer(x);
+    ///     lcd.circle(400,25, 25, BrightRed);
+    ///     lcd.SelectDrawingLayer(prevLayer);
+    /// @endcode
+    ///
+    /// @attention The user manual refers to Layer 1 and Layer 2, however the
+    ///     actual register values are value 0 and 1. This API as well as
+    ///     others that reference the layers use the values 0 and 1 for
+    ///     cleaner iteration in the code.
+    ///
+    /// @returns the current drawing layer; 0 or 1.
+    /// 
+    virtual uint16_t GetDrawingLayer(void) = 0;
+
     /// a function to write the command and data to the RA8875 chip.
     ///
     /// @param command is the RA8875 instruction to perform
--- a/RA8875.cpp	Thu Dec 29 20:06:00 2016 +0000
+++ b/RA8875.cpp	Sun Mar 19 21:41:24 2017 +0000
@@ -281,17 +281,19 @@
 }
 
 
-RetCode_t RA8875::SelectDrawingLayer(uint16_t layer)
+uint16_t RA8875::SelectDrawingLayer(uint16_t layer)
 {
-    unsigned char mwcr1 = ReadCommand(0x41) & ~0x01; // retain all but the currently selected layer
-
+    unsigned char mwcr1 = ReadCommand(0x41); // retain all but the currently selected layer
+    uint16_t prevlayer = mwcr1 & 1;
+    
+    mwcr1 &= ~0x01; // remove the current layer
     if (screenwidth >= 800 && screenheight >= 480 && screenbpp > 8) {
-        return bad_parameter;
+        layer = 0;
     } else if (layer > 1) {
-        return bad_parameter;
-    } else { // layer == 0 ro 1
-        return WriteCommand(0x41, mwcr1 | layer);
+        layer = 0;
     }
+    WriteCommand(0x41, mwcr1 | layer);
+    return prevlayer;
 }
 
 
@@ -1193,7 +1195,7 @@
             SelectDrawingLayer(1);
             clsw(FULLWINDOW);
         }
-        ret = SelectDrawingLayer(prevLayer);
+        SelectDrawingLayer(prevLayer);
     }
     ret = SetTextCursor(0,0);
     ret = locate(0,0);
--- a/RA8875.h	Thu Dec 29 20:06:00 2016 +0000
+++ b/RA8875.h	Sun Mar 19 21:41:24 2017 +0000
@@ -545,6 +545,9 @@
     /// be independently drawn on and shown. Additionally, complex
     /// operations involving both layers are permitted.
     ///
+    /// @attention If the current display configuration does not support
+    ///     multiple layers, then layer 0 will be selected.
+    ///
     /// @code
     ///     //lcd.SetLayerMode(OnlyLayer0); // default is layer 0
     ///     lcd.rect(400,130, 475,155,Brown);
@@ -561,9 +564,9 @@
     ///
     /// @param[in] layer is 0 or 1 to select the layer for subsequent 
     ///     commands.
-    /// @returns success/failure code. See @ref RetCode_t.
-    ///
-    RetCode_t SelectDrawingLayer(uint16_t layer);
+    /// @returns the previous drawing layer; 0 or 1.
+    ///
+    virtual uint16_t SelectDrawingLayer(uint16_t layer);
  
     
     /// Get the currently active drawing layer.
@@ -585,7 +588,7 @@
     ///
     /// @returns the current drawing layer; 0 or 1.
     /// 
-    uint16_t GetDrawingLayer(void);
+    virtual uint16_t GetDrawingLayer(void);
  
     
     /// Set the Layer presentation mode.