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:
112:325ca91bc03d
Parent:
111:efe436c43aba
Child:
113:843888f7785b
Child:
114:dbfb996bfbf3
--- a/GraphicsDisplay.cpp	Mon Apr 25 01:43:59 2016 +0000
+++ b/GraphicsDisplay.cpp	Wed Apr 27 01:29:55 2016 +0000
@@ -270,7 +270,7 @@
     unsigned int    i, offset;
     int padd,j;
     #ifdef DEBUG
-    uint32_t start_data;
+    //uint32_t start_data;
     #endif
 
     // Now, Read the bitmap info header
@@ -278,11 +278,14 @@
     HexDump("BMP_Info", (uint8_t *)&BMP_Info, sizeof(BMP_Info));
     BPP_t = BMP_Info.biBitCount;
     INFO("biBitCount %04X", BPP_t);
-    if (BPP_t != 4 && BPP_t != 8 && BPP_t != 16 && BPP_t != 24) { // Support 4, 8, 16, 24-bits per pixel
+    if (BPP_t != 1 && BPP_t != 4 && BPP_t != 8 && BPP_t != 16 && BPP_t != 24) { // Support 4, 8, 16, 24-bits per pixel
         fclose(Image);
         return(not_supported_format);
     }
-
+    if (BMP_Info.biCompression != 0) {  // Only the "no comporession" option is supported.
+        fclose(Image);
+        return(not_supported_format);
+    }
     PixelHeight = BMP_Info.biHeight;
     PixelWidth = BMP_Info.biWidth;
     INFO("(%d,%d) (%d,%d) (%d,%d)", x,y, PixelWidth,PixelHeight, width(), height());
@@ -321,38 +324,33 @@
         return(not_enough_ram);
     }
 
-    // the Raw Data records are padded to a multiple of 4 bytes
-    int recordSize = 2;
-    if (BPP_t == 4) {
-        recordSize = 1;
-    } else if (BPP_t == 8) {
-        recordSize = 1;
-    } else if (BPP_t == 16) {
-        recordSize = 2;
-    } else if (BPP_t == 24) {
-        recordSize = 3;
-    }
-    padd = -1;
-    do {
-        padd++;
-    } while ((PixelWidth * recordSize + padd) % 4 != 0);
+    padd = (lineBufSize % 4);
+    if (padd)
+        padd = 4 - padd;
 
     // Define window for top to bottom and left to right so writing auto-wraps
     rect_t restore = windowrect;
     window(x,y, PixelWidth,PixelHeight);
     SetGraphicsCursor(x, y);
     _StartGraphicsStream();
-    
-    //start_data = BMP_Header.bfOffBits;
-    HexDump("Raw Data", (uint8_t *)&start_data, 32);
+
+    //start_data = BMP_Info.bfOffBits;
+    //HexDump("Raw Data", (uint8_t *)&start_data, 32);
     INFO("(%d,%d) (%d,%d), [%d,%d]", x,y, PixelWidth,PixelHeight, lineBufSize, padd);
     for (j = PixelHeight - 1; j >= 0; j--) {                //Lines bottom up
         offset = fileOffset + j * (lineBufSize + padd);     // start of line
         fseek(Image, offset, SEEK_SET);
         fread(lineBuffer, 1, lineBufSize, Image);           // read a line - slow !
         //INFO("offset: %6X", offset);
+        //HexDump("Line", lineBuffer, lineBufSize);
         for (i = 0; i < PixelWidth; i++) {                  // copy pixel data to TFT
-            if (BPP_t == 4) {
+            if (BPP_t == 1) {
+                uint8_t dPix = lineBuffer[i/8];
+                uint8_t bMask = 0x80 >> (i % 8);
+                uint8_t bit = (bMask & dPix) ? 0 : 1;
+                //INFO("%02X & %02X ? => %02X", dPix, bMask, bit);
+                pixelBuffer[i] = RGBQuadToRGB16(colorPalette, bit);                
+            } else if (BPP_t == 4) {
                 uint8_t dPix = lineBuffer[i/2];
                 if ((i & 1) == 0)
                     dPix >>= 4;
@@ -408,6 +406,7 @@
         fclose(Image);
         return(not_bmp_format);
     }
+    INFO("bfOffits %04X", BMP_Header.bfOffBits);
     RetCode_t rt = _RenderBitmap(x, y, BMP_Header.bfOffBits, Image);
     if (rt != noerror) {
         return rt;