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:
Wed Apr 27 01:29:55 2016 +0000
Parent:
111:efe436c43aba
Child:
113:843888f7785b
Child:
114:dbfb996bfbf3
Commit message:
Added support for monochrome BMP format.; Tiny optimization (simplified the code, no noticeable performance increase).

Changed in this revision

DisplayDefs.h Show annotated file Show diff for this revision Revisions of this file
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
--- a/DisplayDefs.h	Mon Apr 25 01:43:59 2016 +0000
+++ b/DisplayDefs.h	Wed Apr 27 01:29:55 2016 +0000
@@ -15,7 +15,7 @@
     file_not_found,         ///< specified file could not be found
     not_bmp_format,         ///< file is not a .bmp file
     not_ico_format,         ///< file is not a .ico file
-    not_supported_format,   ///< file format is not yet supported
+    not_supported_format,   ///< file format is not yet supported (e.g. bits per pixel, compression)
     image_too_big,          ///< image is too large for the screen
     not_enough_ram,         ///< could not allocate ram for scanline
     touch_cal_timeout,      ///< timeout while trying to calibrate touchscreen, perhaps it is not installed.
--- 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;
--- a/GraphicsDisplay.h	Mon Apr 25 01:43:59 2016 +0000
+++ b/GraphicsDisplay.h	Wed Apr 27 01:29:55 2016 +0000
@@ -286,9 +286,11 @@
     /// puts it on the screen.
     ///
     /// Supported formats:
-    /// \li 4-bit color format (16 colors)
-    /// \li 8-bit color format (256 colors)
+    /// \li 1-bit color format  (2 colors)
+    /// \li 4-bit color format  (16 colors)
+    /// \li 8-bit color format  (256 colors)
     /// \li 16-bit color format (65k colors)
+    /// \li 24-bit color format (16M colors)
     /// \li compression: no.
     ///
     /// @note This is a slow operation, typically due to the use of