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:
106:c80828f5dea4
Parent:
105:4f116006ba1f
Child:
107:f9ccffcb84f1
--- a/RA8875.cpp	Sat Feb 27 18:40:35 2016 +0000
+++ b/RA8875.cpp	Sat Feb 27 22:27:49 2016 +0000
@@ -216,7 +216,7 @@
 {
     unsigned char mwcr1 = ReadCommand(0x41) & ~0x01; // retain all but the currently selected layer
 
-    if (screenwidth >= 800 && screenheight >= 480 && screenbpp == 8) {
+    if (screenwidth >= 800 && screenheight >= 480 && screenbpp > 8) {
         return bad_parameter;
     } else if (layer > 1) {
         return bad_parameter;
@@ -568,6 +568,10 @@
         return false;
 }
 
+// RRRR RGGG GGGB BBBB
+// 4321 0543 2104 3210
+//           RRRG GGBB
+//           2102 1010
 uint8_t RA8875::_cvt16to8(color_t c16)
 {
     return ((c16 >> 8) & 0xE0)
@@ -575,15 +579,23 @@
         | ((c16 >> 3) & 0x03);
 }
 
+//           RRRG GGBB
+//           2102 1010
+// RRRR RGGG GGGB BBBB
+// 2101 0543 2104 3210
 color_t RA8875::_cvt8to16(uint8_t c8)
 {
-    color_t c16 = ((c8 & 0xE0) << 8)
-        | ((c8 & 0xC0) << 5)
-        | ((c8 & 0x1C) << 6)
-        | ((c8 & 0x1C) << 3)
-        | ((c8 & 0x03) << 3)
-        | ((c8 & 0x03) << 1)
-        | ((c8 & 0x03) >> 1);
+    color_t c16;
+    color_t temp = (color_t)c8;
+    
+    c16 = ((temp & 0xE0) << 8)
+        | ((temp & 0xC0) << 5)
+        | ((temp & 0x1C) << 6)
+        | ((temp & 0x1C) << 3)
+        | ((temp & 0x03) << 3)
+        | ((temp & 0x03) << 1)
+        | ((temp & 0x03) >> 1);
+    c16 = (c16 << 8) | (c16 >> 8);
     return c16;
 }
 
@@ -1115,7 +1127,8 @@
     _select(true);
     _spiwrite(0x40);         // Cmd: read data
     _spiwrite(0x00);         // dummy read
-    _spiwrite(0x00);         // dummy read  [20150201: Required to properly align the data stream. Not yet sure why...]
+    if (screenbpp == 16)
+        _spiwrite(0x00);     // dummy read is only necessary when in 16-bit mode
     while (count--) {
         if (screenbpp == 16) {
             pixel  = _spiread();
@@ -2866,4 +2879,3 @@
 }
 
 #endif // TESTENABLE
-