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:
72:ecffe56af969
Parent:
71:dcac8efd842d
Child:
73:f22a18707b5e
--- a/RA8875.cpp	Sat Oct 04 17:45:50 2014 +0000
+++ b/RA8875.cpp	Sat Oct 11 17:24:29 2014 +0000
@@ -87,9 +87,8 @@
     } else if (layer > 1) {
         return bad_parameter;
     } else { // layer == 0 ro 1
-        WriteCommand(0x41, mwcr1 | layer);
+        return WriteCommand(0x41, mwcr1 | layer);
     }
-    return noerror;
 }
 
 
@@ -1424,6 +1423,113 @@
     return noerror;
 }
 
+RetCode_t RA8875::PrintScreen(uint16_t layer, loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP)
+{
+    uint16_t curLayer = GetDrawingLayer();
+    RetCode_t ret = SelectDrawingLayer(layer);
+    if (ret == noerror) {
+        ret = PrintScreen(x, y, w, h, Name_BMP);
+    }
+    SelectDrawingLayer(curLayer);
+    return ret;
+}
+
+RetCode_t RA8875::PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP)
+{
+    BITMAPFILEHEADER BMP_Header;
+    BITMAPINFOHEADER BMP_Info;
+    
+    INFO("(%d,%d) - (%d,%d) %s", x,y,w,h,Name_BMP);
+    if (x >= 0 && x < width()
+    && y >= 0 && y < height()
+    && w > 0 && x + w <= width()
+    && h > 0 && y + h <= height()) {
+
+        BMP_Header.bfType = BF_TYPE;
+        BMP_Header.bfSize = (w * h * sizeof(RGBQUAD)) + sizeof(BMP_Header) + sizeof(BMP_Header);
+        BMP_Header.bfReserved1 = 0;
+        BMP_Header.bfReserved2 = 0;
+        BMP_Header.bfOffBits = sizeof(BMP_Header) + sizeof(BMP_Header);
+        
+        BMP_Info.biSize = sizeof(BMP_Info);
+        BMP_Info.biWidth = w;
+        BMP_Info.biHeight = h;
+        BMP_Info.biPlanes = 1;
+        BMP_Info.biBitCount = 24;
+        BMP_Info.biCompression = BI_RGB;
+        BMP_Info.biSizeImage = 0;
+        BMP_Info.biXPelsPerMeter = 0;
+        BMP_Info.biYPelsPerMeter = 0;
+        BMP_Info.biClrUsed = 0;
+        BMP_Info.biClrImportant = 0;
+
+        INFO("Writing {%s}", Name_BMP);
+        FILE *Image = fopen(Name_BMP, "wb");
+        if (!Image) {
+            ERR("File not found");
+            return(file_not_found);
+        }
+
+        // Be optimistic - don't check for errors.
+        //HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header));
+        fwrite(&BMP_Header, sizeof(char), sizeof(BMP_Header), Image);
+        //INFO("fwrite returned %d", r);
+        
+        //HexDump("BMP_Info", (uint8_t *)&BMP_Info, sizeof(BMP_Info));
+        fwrite(&BMP_Info, sizeof(char), sizeof(BMP_Info), Image);
+        //INFO("fwrite returned %d", r);
+        
+        int lineBufSize = ((24 * w + 7)/8);
+        uint8_t * lineBuffer = (uint8_t *)malloc(lineBufSize);
+        if (lineBuffer == NULL) {
+            fclose(Image);
+            ERR("Not enough RAM for lineBuffer");
+            return(not_enough_ram);
+        }
+        color_t * pixelBuffer = (color_t *)malloc(w * sizeof(color_t));
+        if (pixelBuffer == NULL) {
+            fclose(Image);
+            free(lineBuffer);
+            ERR("Not enough RAM for pixelBuffer");
+            return(not_enough_ram);
+        }
+        
+        // Read the display from the last line toward the top
+        // so we can write the file in one pass.
+        for (int j = h - 1; j >= 0; j--) {
+            // Read one line of pixels to a local buffer
+            if (getPixelStream(pixelBuffer, w, x,y+j) != noerror) {
+                ERR("getPixelStream error, and no recovery handler...");
+            }
+            // Convert the local buffer to RGBQUAD format
+            int lb = 0;
+            for (int i=0; i<w; i++) {
+                color_t pixel = pixelBuffer[x+i];
+                // Scale to 24-bits
+                RGBQUAD q = RGB16ToRGBQuad(pixel);
+                lineBuffer[lb++] = q.rgbBlue;
+                lineBuffer[lb++] = q.rgbGreen;
+                lineBuffer[lb++] = q.rgbRed;
+            }
+            // Write to disk
+            //HexDump("Line", lineBuffer, lineBufSize);
+            fwrite(lineBuffer, sizeof(char), lb, Image);
+        }
+        fclose(Image);
+        free(pixelBuffer);  // don't leak memory.
+        free(lineBuffer);
+        INFO("Image closed"); 
+        return noerror;
+    } else {
+        return bad_parameter;
+    }
+}
+
+
+// ##########################################################################
+// ##########################################################################
+// ##########################################################################
+
 #ifdef TESTENABLE
 
 #include "Arial12x12.h"