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 Aug 17 13:46:06 2014 +0000
Parent:
60:2dfd574f63bd
Child:
62:ba5d33438fda
Commit message:
Revised cls( ) to support layers.; Added a few handy color definitions.

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
TextDisplay.cpp Show annotated file Show diff for this revision Revisions of this file
TextDisplay.h Show annotated file Show diff for this revision Revisions of this file
--- a/GraphicsDisplay.cpp	Sat Aug 16 19:26:17 2014 +0000
+++ b/GraphicsDisplay.cpp	Sun Aug 17 13:46:06 2014 +0000
@@ -253,7 +253,7 @@
     fillrect(x,y, x+w, y+h, color);
 }
 
-RetCode_t GraphicsDisplay::cls()
+RetCode_t GraphicsDisplay::cls(uint16_t layers)
 {
     fill(0, 0, width(), height(), _background);
     return noerror;
--- a/GraphicsDisplay.h	Sat Aug 16 19:26:17 2014 +0000
+++ b/GraphicsDisplay.h	Sun Aug 17 13:46:06 2014 +0000
@@ -158,9 +158,11 @@
     ///
     /// The behavior is to clear the whole screen.
     ///
+    /// @param layers is ignored, but supports maintaining the same 
+    ///     API for the graphics layer.
     /// @returns success/failure code. @see RetCode_t.
     ///
-    virtual RetCode_t cls();
+    virtual RetCode_t cls(uint16_t layers = 0);
     
 
     virtual void WindowMax(void);
--- a/RA8875.cpp	Sat Aug 16 19:26:17 2014 +0000
+++ b/RA8875.cpp	Sun Aug 17 13:46:06 2014 +0000
@@ -71,6 +71,10 @@
 //{
 //}
 
+uint16_t RA8875::GetDrawingLayer(void)
+{
+    return (ReadCommand(0x41) & 0x01);
+}
 
 RetCode_t RA8875::SelectDrawingLayer(uint16_t layer)
 {
@@ -694,13 +698,30 @@
 }
 
 
-RetCode_t RA8875::cls(void)
+RetCode_t RA8875::cls(uint16_t layers)
 {
+    RetCode_t ret;
+    
     PERFORMANCE_RESET;
-    clsw(FULLWINDOW);
-    SetTextCursor(0,0);
+    if (layers == 0) {
+        ret = clsw(FULLWINDOW);
+        ret = SetTextCursor(0,0);
+    } else if (layers > 3) {
+        ret = bad_parameter;
+    } else {
+        uint16_t prevLayer = GetDrawingLayer();
+        if (layers & 1) {
+            SelectDrawingLayer(0);
+            clsw(FULLWINDOW);
+        }
+        if (layers & 2) {
+            SelectDrawingLayer(1);
+            clsw(FULLWINDOW);
+        }
+        ret = SelectDrawingLayer(prevLayer);
+    }
     REGISTERPERFORMANCE(PRF_CLS);
-    return noerror;
+    return ret;
 }
 
 
--- a/RA8875.h	Sat Aug 16 19:26:17 2014 +0000
+++ b/RA8875.h	Sun Aug 17 13:46:06 2014 +0000
@@ -32,6 +32,14 @@
 #define Yellow      (color_t)(RGB(255,255,85))
 #define White       (color_t)(RGB(255,255,255))
 
+#define DarkBlue    (color_t)(RGB(0,0,64))
+#define DarkGreen   (color_t)(RGB(0,64,0))
+#define DarkCyan    (color_t)(RGB(0,64,64))
+#define DarkRed     (color_t)(RGB(64,0,0))
+#define DarkMagenta (color_t)(RGB(64,0,64))
+#define DarkBrown   (color_t)(RGB(64,64,0))
+#define DarkGray    (color_t)(RGB(64,64,64))
+
 #define BrightRed   (color_t)(RGB(255,0,0))
 
 //namespace SW_graphics
@@ -132,10 +140,10 @@
         ACTIVEWINDOW    ///< active window/region
     } Region_t;
     
-    /// Set the Layer 1/2 Display Mode
+    /// Set the Layer Display Mode. @ref SetLayerMode
     typedef enum
     {
-        ShowLayer0,         ///< Only layer 0 is visible, layer 1 is hidden
+        ShowLayer0,         ///< Only layer 0 is visible, layer 1 is hidden (default)
         ShowLayer1,         ///< Only layer 1 is visible, layer 0 is hidden
         LightenOverlay,     ///< Lighten-overlay mode
         TransparentMode,    ///< Transparent mode
@@ -154,6 +162,8 @@
     /// Constructor for a display based on the RAiO RA8875 
     /// display controller.
     ///
+    /// This configures the registers and calls the @ref init method.
+    ///
     /// @code
     /// #include "RA8875.h"
     /// RA8875 lcd(p5, p6, p7, p12, NC, "tft");
@@ -198,23 +208,46 @@
     ///     lcd.SetLayerMode(ShowLayer1);
     /// @endcode
     ///
-    /// @note The user manual refers to Layer 1 and Layer 2, however the
-    ///     actual register values are value 0 and 1. This and other APIs
-    ///     that reference the layers use the values 0 and 1.
+    /// @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 layer selects the layer for subsequence commands, where
-    ///     the values 0 and 1 represent layers 1 and 2 (as referred
-    ///     to in the user manual).
+    /// @param layer is 0 or 1 to select the layer for subsequent 
+    ///     commands.
     /// @returns success/failure code. @see RetCode_t.
     ///
     RetCode_t SelectDrawingLayer(uint16_t layer);
     
+    /// 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.GetDrawingLayer();
+    ///     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.
+    /// 
+    uint16_t GetDrawingLayer(void);
+    
     /// Set the Layer presentation mode.
     ///
     /// This sets the presentation mode for layers, and permits showing
     /// a single layer, or applying a mode where the two layers
     /// are combined using one of the hardware methods.
     ///
+    /// Refer to the RA8875 data sheet for full details.
+    ///
     /// @code
     ///     //lcd.SetLayerMode(OnlyLayer0); // default is layer 0
     ///     lcd.rect(400,130, 475,155,Brown);
@@ -654,17 +687,25 @@
     ///
     virtual RetCode_t window(loc_t x, loc_t y, dim_t width, dim_t height);
     
-    /// Clear the screen.
+    /// Clear either the specified layer, or the active layer.
     ///
-    /// The behavior is to clear the whole screen. @see clsw().
+    /// The behavior is to clear the whole screen for the specified
+    /// layer. When not specified, the active drawing layer is cleared.
+    /// This command can also be used to specifically clear either,
+    /// or both layers. @see clsw().
     ///
     /// @code
     ///     lcd.cls();
     /// @endcode
     ///
+    /// @param layers is optional. If not provided, the active layer
+    ///     is cleared. If bit 0 is set, layer 0 is cleared, if bit
+    ///     1 is set, layer 1 is cleared. If both are set, both layers
+    ///     are cleared. Any other value does not cause an action.
+    ///     
     /// @returns success/failure code. @see RetCode_t.
     ///
-    virtual RetCode_t cls(void);
+    virtual RetCode_t cls(uint16_t layers = 0);
     
     /// Clear the screen, or clear only the active window.
     ///
@@ -1258,7 +1299,7 @@
 
 
     /// Initialize the chip, which is normally done as part of the
-    /// constructor, so not called by the user.
+    /// constructor, so not typically called by the user.
     ///
     /// @note This API permits configuration, however it is not [yet]
     ///     available to the end user. Be sure the parameters
--- a/TextDisplay.cpp	Sat Aug 16 19:26:17 2014 +0000
+++ b/TextDisplay.cpp	Sun Aug 17 13:46:06 2014 +0000
@@ -55,7 +55,7 @@
 }
 
 // crude cls implementation, should generally be overwritten in derived class
-RetCode_t TextDisplay::cls()
+RetCode_t TextDisplay::cls(uint16_t layers)
 {
     INFO("cls()");
     locate(0, 0);
--- a/TextDisplay.h	Sat Aug 16 19:26:17 2014 +0000
+++ b/TextDisplay.h	Sun Aug 17 13:46:06 2014 +0000
@@ -80,10 +80,11 @@
     /// clear screen
     ///
     /// @note this method may be overridden in a derived class.
-    ///
+    /// @param layers is ignored, but supports maintaining the same 
+    ///     API for the graphics layer.
     /// @returns error code.
     ///
-    virtual RetCode_t cls() = 0;
+    virtual RetCode_t cls(uint16_t layers = 0) = 0;
     
     /// locate the cursor at a character position.
     ///