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 Feb 11 03:44:42 2019 +0000
Parent:
161:0215d0eec1a4
Child:
163:17526689a3ed
Commit message:
PrintScreen - bug fixes in header info and symmetry of RGB16toRGBQuad and RGBQuadToRGB16

Changed in this revision

GraphicsDisplay.cpp 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	Sun Jan 13 19:02:36 2019 +0000
+++ b/GraphicsDisplay.cpp	Mon Feb 11 03:44:42 2019 +0000
@@ -270,7 +270,7 @@
     RGBQUAD q;
     
     memset(&q, 0, sizeof(q));
-    c = (c << 8) | (c >> 8);    // swap
+    //c = (c << 8) | (c >> 8);    // swap
     q.rgbBlue  = ((c & 0x001F) << 3) | (c & 0x07);          /* Blue value */
     q.rgbGreen = ((c & 0x07E0) >> 3) | ((c >> 9) & 0x03);   /* Green value */
     q.rgbRed   = ((c & 0xF800) >> 8) | ((c >> 13) & 0x07);  /* Red value */
--- a/RA8875.cpp	Sun Jan 13 19:02:36 2019 +0000
+++ b/RA8875.cpp	Mon Feb 11 03:44:42 2019 +0000
@@ -2061,6 +2061,13 @@
     return noerror;
 }
 
+int RA8875::RoundUp(int value, int roundTo)
+{
+    if (roundTo == 0) 
+        return 0;
+    return ((value + roundTo - 1) / roundTo) * roundTo;
+}
+
 RetCode_t RA8875::PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h)
 {
     BITMAPFILEHEADER BMP_Header;
@@ -2076,10 +2083,14 @@
             && h > 0 && y + h <= screenheight) {
 
         BMP_Header.bfType = BF_TYPE;
-        BMP_Header.bfSize = (w * h * sizeof(RGBQUAD)) + sizeof(BMP_Header) + sizeof(BMP_Header);
+        BMP_Header.bfSize = (w * h * sizeof(RGBQUAD)) + sizeof(BMP_Header) + sizeof(BMP_Info);
         BMP_Header.bfReserved1 = 0;
         BMP_Header.bfReserved2 = 0;
-        BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Header);
+        BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Info);
+
+        // Bytes in the line buffer
+        int lineBufSize = RoundUp(3 * w, 4);    // ((24 * w + 7)/8);
+        INFO("LineBufSize: %d", lineBufSize);
 
         BMP_Info.biSize = sizeof(BMP_Info);
         BMP_Info.biWidth = w;
@@ -2087,19 +2098,19 @@
         BMP_Info.biPlanes = 1;
         BMP_Info.biBitCount = 24;
         BMP_Info.biCompression = BI_RGB;
-        BMP_Info.biSizeImage = 0;
+        BMP_Info.biSizeImage = lineBufSize * h;
         BMP_Info.biXPelsPerMeter = 0;
         BMP_Info.biYPelsPerMeter = 0;
         BMP_Info.biClrUsed = 0;
         BMP_Info.biClrImportant = 0;
 
         // Allocate the memory we need to proceed
-        int lineBufSize = ((24 * w + 7)/8);
         lineBuffer = (uint8_t *)swMalloc(lineBufSize);
         if (lineBuffer == NULL) {
             ERR("Not enough RAM for PrintScreen lineBuffer");
             return(not_enough_ram);
         }
+        memset(lineBuffer, 0, lineBufSize); // zero-Fill
 
         #define DOUBLEBUF /* one larger buffer instead of two */
         
@@ -2130,7 +2141,7 @@
         privateCallback(OPEN, (uint8_t *)&BMP_Header.bfSize, 4);
 
         // Be optimistic - don't check for errors.
-        HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header));        
+        HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header));
         //fwrite(&BMP_Header, sizeof(char), sizeof(BMP_Header), Image);
         privateCallback(WRITE, (uint8_t *)&BMP_Header, sizeof(BMP_Header));
 
@@ -2174,12 +2185,16 @@
                 }
             }
             INFO("1st Color: %04X", pixelBuffer[0]);
-            HexDump("Raster", (uint8_t *)pixelBuffer, w);
+            HexDump("Raster", (uint8_t *)pixelBuffer, w * 3);
             // Convert the local buffer to RGBQUAD format
             int lb = 0;
             for (int i=0; i<w; i++) {
-                RGBQUAD q0 = RGB16ToRGBQuad(pixelBuffer[x+i]);      // Scale to 24-bits
-                RGBQUAD q1 = RGB16ToRGBQuad(pixelBuffer2[x+i]);     // Scale to 24-bits
+                color_t tColor = pixelBuffer[x+i];
+                tColor = (tColor >> 8) | (tColor << 8);     // Byte Swap
+                RGBQUAD q0 = RGB16ToRGBQuad(tColor);        // Scale to 24-bits
+                tColor = pixelBuffer2[x+i];
+                tColor = (tColor >> 8) | (tColor << 8);     // Byte Swap
+                RGBQUAD q1 = RGB16ToRGBQuad(tColor);        // Scale to 24-bits
                 switch (ltpr0) {
                     case 0:
                     case 1:
@@ -2204,14 +2219,12 @@
                 }
             }
             if (j == h - 1) {
-                HexDump("Line", lineBuffer, lineBufSize);
+                HexDump("LineBuffer", lineBuffer, lineBufSize);
             }
             // Write to disk
-            //fwrite(lineBuffer, sizeof(char), lb, Image);
-            privateCallback(WRITE, (uint8_t *)lineBuffer, lb);
+            privateCallback(WRITE, (uint8_t *)lineBuffer, lineBufSize);
         }
         SelectDrawingLayer(prevLayer);
-        //fclose(Image);
         privateCallback(CLOSE, NULL, 0);
         
         #ifndef DOUBLEBUF
@@ -2243,10 +2256,14 @@
             && h > 0 && y + h <= screenheight) {
 
         BMP_Header.bfType = BF_TYPE;
-        BMP_Header.bfSize = (w * h * sizeof(RGBQUAD)) + sizeof(BMP_Header) + sizeof(BMP_Header);
+        BMP_Header.bfSize = (w * h * sizeof(RGBQUAD)) + sizeof(BMP_Header) + sizeof(BMP_Info);
         BMP_Header.bfReserved1 = 0;
         BMP_Header.bfReserved2 = 0;
-        BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Header);
+        BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Info);
+
+        // Bytes in the line buffer
+        int lineBufSize = RoundUp(3 * w, 4);    // ((24 * w + 7)/8);
+        INFO("LineBufSize: %d", lineBufSize);
 
         BMP_Info.biSize = sizeof(BMP_Info);
         BMP_Info.biWidth = w;
@@ -2254,19 +2271,19 @@
         BMP_Info.biPlanes = 1;
         BMP_Info.biBitCount = 24;
         BMP_Info.biCompression = BI_RGB;
-        BMP_Info.biSizeImage = 0;
+        BMP_Info.biSizeImage = lineBufSize * h;
         BMP_Info.biXPelsPerMeter = 0;
         BMP_Info.biYPelsPerMeter = 0;
         BMP_Info.biClrUsed = 0;
         BMP_Info.biClrImportant = 0;
 
         // Allocate the memory we need to proceed
-        int lineBufSize = ((24 * w + 7)/8);
         lineBuffer = (uint8_t *)swMalloc(lineBufSize);
         if (lineBuffer == NULL) {
             ERR("Not enough RAM for PrintScreen lineBuffer");
             return(not_enough_ram);
         }
+        memset(lineBuffer, 0, lineBufSize); // zero-Fill
 
         #define DOUBLEBUF /* one larger buffer instead of two */
         
@@ -2348,13 +2365,17 @@
                     ERR("getPixelStream error, and no recovery handler...");
                 }
             }
-            INFO("1st Color: %04X", pixelBuffer[0]);
-            HexDump("Raster", (uint8_t *)pixelBuffer, w);
+            INFO("Line: %3d", j);
+            HexDump("Raster", (uint8_t *)pixelBuffer, w * sizeof(color_t));
             // Convert the local buffer to RGBQUAD format
             int lb = 0;
             for (int i=0; i<w; i++) {
-                RGBQUAD q0 = RGB16ToRGBQuad(pixelBuffer[x+i]);      // Scale to 24-bits
-                RGBQUAD q1 = RGB16ToRGBQuad(pixelBuffer2[x+i]);     // Scale to 24-bits
+                color_t tColor = pixelBuffer[x+i];
+                tColor = (tColor >> 8) | (tColor << 8);     // Byte Swap
+                RGBQUAD q0 = RGB16ToRGBQuad(tColor);        // Scale to 24-bits
+                tColor = pixelBuffer2[x+i];
+                tColor = (tColor >> 8) | (tColor << 8);     // Byte Swap
+                RGBQUAD q1 = RGB16ToRGBQuad(tColor);        // Scale to 24-bits
                 switch (ltpr0) {
                     case 0:
                     case 1:
@@ -2378,11 +2399,11 @@
                         break;
                 }
             }
-            if (j == h - 1) {
+            //if (j == h - 1) {
                 HexDump("Line", lineBuffer, lineBufSize);
-            }
+            //}
             // Write to disk
-            fwrite(lineBuffer, sizeof(char), lb, Image);
+            fwrite(lineBuffer, sizeof(char), lineBufSize, Image);
         }
         SelectDrawingLayer(prevLayer);
         fclose(Image);
--- a/RA8875.h	Sun Jan 13 19:02:36 2019 +0000
+++ b/RA8875.h	Mon Feb 11 03:44:42 2019 +0000
@@ -2826,6 +2826,7 @@
 
     ////////////////// Start of Capacitive Touch Panel parameters
     
+    int RoundUp(int value, int roundTo);
     uint8_t getTouchPositions(void);
     void TouchPanelISR(void);
     uint16_t numberOfTouchPoints;