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:
131:5bd6ba2ee4a1
Parent:
127:db7f2c704693
Child:
133:e36dcfc2d756
Child:
139:99ec74e3273f
--- a/RA8875.cpp	Sat Aug 06 22:44:49 2016 +0000
+++ b/RA8875.cpp	Fri Aug 12 11:30:33 2016 +0000
@@ -141,7 +141,7 @@
 //{
 //}
 
-RetCode_t RA8875::init(int width, int height, int color_bpp, bool poweron, bool keypadon, bool touchscreenon)
+RetCode_t RA8875::init(int width, int height, int color_bpp, uint8_t poweron, bool keypadon, bool touchscreenon)
 {
     font = NULL;                                // no external font, use internal.
     pKeyMap = DefaultKeyMap;                    // set default key map
@@ -198,8 +198,7 @@
     cls(3);
 
     Power(poweron);
-    if (poweron)
-        Backlight_u8(255);
+    Backlight_u8(poweron);
     if (keypadon)
         KeypadInit();
     if (touchscreenon) {
@@ -486,6 +485,22 @@
 }
 
 
+bool RA8875::Intersect(rect_t rect1, rect_t rect2)
+{
+    point_t bl, tr;
+    
+    bl.x = rect2.p1.x;
+    bl.y = rect2.p2.y;
+    tr.x = rect2.p2.x;
+    tr.y = rect2.p1.y;
+    if (Intersect(rect1, rect2.p1) || Intersect(rect1, rect2.p2)
+    || Intersect(rect1, bl) || Intersect(rect1, tr))
+        return true;
+    else
+        return false;
+}
+
+
 
 RetCode_t RA8875::WriteCommandW(uint8_t command, uint16_t data)
 {
@@ -1095,7 +1110,10 @@
 {
     PERFORMANCE_RESET;
     WriteCommand(0x8E, (region == ACTIVEWINDOW) ? 0xC0 : 0x80);
-    _WaitWhileReg(0x8E, 0x80);
+    if (!_WaitWhileReg(0x8E, 0x80)) {
+        REGISTERPERFORMANCE(PRF_CLS);
+        return external_abort;
+    }
     REGISTERPERFORMANCE(PRF_CLS);
     return noerror;
 }
@@ -1281,7 +1299,10 @@
         unsigned char drawCmd = 0x00;       // Line
         WriteCommand(0x90, drawCmd);
         WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
-        _WaitWhileReg(0x90, 0x80);
+        if (!_WaitWhileReg(0x90, 0x80)) {
+            REGISTERPERFORMANCE(PRF_DRAWLINE);
+            return external_abort;
+        }
     }
     REGISTERPERFORMANCE(PRF_DRAWLINE);
     return noerror;
@@ -1340,7 +1361,10 @@
                 drawCmd |= 0x20;
             WriteCommand(0x90, drawCmd);
             ret = WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
-            _WaitWhileReg(0x90, 0x80);
+            if (!_WaitWhileReg(0x90, 0x80)) {
+                REGISTERPERFORMANCE(PRF_DRAWRECTANGLE);
+                return external_abort;
+            }
         }
     }
     REGISTERPERFORMANCE(PRF_DRAWRECTANGLE);
@@ -1409,7 +1433,10 @@
             drawCmd |= 0x40;
         WriteCommand(0xA0, drawCmd);
         WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
-        _WaitWhileReg(0xA0, 0x80);
+        if (!_WaitWhileReg(0xA0, 0x80)) {
+            REGISTERPERFORMANCE(PRF_DRAWROUNDEDRECTANGLE);
+            return external_abort;
+        }
     }
     REGISTERPERFORMANCE(PRF_DRAWROUNDEDRECTANGLE);
     return ret;
@@ -1465,7 +1492,10 @@
             drawCmd |= 0x20;
         WriteCommand(0x90, drawCmd);
         WriteCommand(0x90, 0x80 + drawCmd); // Start drawing.
-        _WaitWhileReg(0x90, 0x80);
+        if (!_WaitWhileReg(0x90, 0x80)) {
+            REGISTERPERFORMANCE(PRF_DRAWTRIANGLE);
+            return external_abort;
+        }
     }
     REGISTERPERFORMANCE(PRF_DRAWTRIANGLE);
     return ret;
@@ -1529,7 +1559,10 @@
             drawCmd |= 0x20;
         WriteCommand(0x90, drawCmd);
         WriteCommand(0x90, 0x40 + drawCmd); // Start drawing.
-        _WaitWhileReg(0x90, 0x40);
+        if (!_WaitWhileReg(0x90, 0x40)) {
+            REGISTERPERFORMANCE(PRF_DRAWCIRCLE);
+            return external_abort;
+        }
     }
     REGISTERPERFORMANCE(PRF_DRAWCIRCLE);
     return ret;
@@ -1570,7 +1603,10 @@
             drawCmd |= 0x40;
         WriteCommand(0xA0, drawCmd);
         WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing.
-        _WaitWhileReg(0xA0, 0x80);
+        if (!_WaitWhileReg(0xA0, 0x80)) {
+            REGISTERPERFORMANCE(PRF_DRAWELLIPSE);
+            return external_abort;
+        }
     }
     REGISTERPERFORMANCE(PRF_DRAWELLIPSE);
     return ret;
@@ -1604,6 +1640,38 @@
     }
 }
 
+
+
+RetCode_t RA8875::BlockMove(uint8_t dstLayer, uint8_t dstDataSelect, point_t dstPoint,
+    uint8_t srcLayer, uint8_t srcDataSelect, point_t srcPoint,
+    uint16_t bte_width, uint16_t bte_height,
+    uint8_t bte_op_code, uint8_t bte_rop_code)
+{
+    uint8_t cmd;
+
+    PERFORMANCE_RESET;
+    srcPoint.x &= 0x3FF;    // prevent high bits from doing unexpected things
+    srcPoint.y &= 0x1FF;
+    dstPoint.x &= 0x3FF;
+    dstPoint.y &= 0x1FF;
+    WriteCommandW(0x54, srcPoint.x);
+    WriteCommandW(0x56, ((srcLayer & 1) << 7) | srcPoint.y);
+    WriteCommandW(0x58, dstPoint.x);
+    WriteCommandW(0x5A, ((dstLayer & 1) << 7) | dstPoint.y);
+    WriteCommandW(0x5C, bte_width);
+    WriteCommandW(0x5E, bte_height);
+    WriteCommand(0x51,  ((bte_rop_code & 0x0F) << 4) | (bte_op_code & 0x0F));
+    cmd = ((srcDataSelect & 1) << 6) | ((dstDataSelect & 1) << 5);
+    WriteCommand(0x50, 0x80 | cmd);     // enable the BTE
+    if (!_WaitWhileBusy(0x40)) {
+        REGISTERPERFORMANCE(PRF_BLOCKMOVE);
+        return external_abort;
+    }
+    REGISTERPERFORMANCE(PRF_BLOCKMOVE);
+    return noerror;
+}
+
+
 RetCode_t RA8875::Power(bool on)
 {
     WriteCommand(0x01, (on) ? 0x80 : 0x00);
@@ -1611,9 +1679,10 @@
 }
 
 
-RetCode_t RA8875::Backlight_u8(unsigned char brightness)
+RetCode_t RA8875::Backlight_u8(uint8_t brightness)
 {
     static bool is_enabled = false;
+    
     if (brightness == 0) {
         WriteCommand(0x8a); // Disable the PWM
         WriteData(0x00);