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:
190:3132b7dfad82
Parent:
182:8832d03a2a29
Child:
198:9b6851107426
--- a/GraphicsDisplay.cpp	Thu Sep 19 21:45:18 2019 +0000
+++ b/GraphicsDisplay.cpp	Sat Sep 21 17:30:00 2019 +0000
@@ -22,14 +22,14 @@
 // INFO("Stuff to show %d", var); // new-line is automatically appended
 //
 #if (defined(DEBUG) && !defined(TARGET_LPC11U24))
-#define INFO(x, ...) std::printf("[INF %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
-#define WARN(x, ...) std::printf("[WRN %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
-#define ERR(x, ...)  std::printf("[ERR %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
+#define INFO(x, ...) std::printf("[INF %s %4d] " x "\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
+#define WARN(x, ...) std::printf("[WRN %s %4d] " x "\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
+#define ERR(x, ...)  std::printf("[ERR %s %4d] " x "\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
 static void HexDump(const char * title, const uint8_t * p, int count)
 {
     int i;
     char buf[100] = "0000: ";
-    
+
     if (*title)
         INFO("%s", title);
     for (i=0; i<count; ) {
@@ -87,7 +87,7 @@
 }
 
 
-GraphicsDisplay::GraphicsDisplay(const char *name) 
+GraphicsDisplay::GraphicsDisplay(const char *name)
     : TextDisplay(name)
 {
     font = NULL;
@@ -220,11 +220,11 @@
     uint16_t lastChar  = font[5] * 256 + font[4];
     dim_t charHeight = font[6];
     const unsigned char * charRecord;   // width, data, data, data, ...
-    
+
     INFO("first:%d, last:%d, c:%d", firstChar, lastChar, c);
     if (c < firstChar || c > lastChar)
         return NULL;       // advance zero pixels since it was unprintable...
-    
+
     // 8 bytes of preamble to the first level lookup table
     offsetToCharLookup = 8 + 4 * (c - firstChar);    // 4-bytes: width(pixels), 16-bit offset from table start, 0
     dim_t charWidth = font[offsetToCharLookup];
@@ -261,7 +261,7 @@
 color_t GraphicsDisplay::RGBQuadToRGB16(RGBQUAD * colorPalette, uint16_t i)
 {
     color_t c;
- 
+
     c  = ((colorPalette[i].rgbBlue  >> 3) <<  0);
     c |= ((colorPalette[i].rgbGreen >> 2) <<  5);
     c |= ((colorPalette[i].rgbRed   >> 3) << 11);
@@ -278,7 +278,7 @@
 RGBQUAD GraphicsDisplay::RGB16ToRGBQuad(color_t c)
 {
     RGBQUAD q;
-    
+
     memset(&q, 0, sizeof(q));
     //c = (c << 8) | (c >> 8);    // swap
     q.rgbBlue  = ((c & 0x001F) << 3) | (c & 0x07);          /* Blue value */
@@ -288,7 +288,7 @@
     return q;
 }
 
-RetCode_t GraphicsDisplay::_RenderBitmap(loc_t x, loc_t y, uint32_t fileOffset, FILE * Image)
+RetCode_t GraphicsDisplay::_RenderBitmap(loc_t x, loc_t y, uint32_t fileOffset, FILE * Image, rect_t * infoOnly)
 {
     BITMAPINFOHEADER BMP_Info;
     RGBQUAD * colorPalette = NULL;
@@ -319,8 +319,18 @@
     PixelHeight = BMP_Info.biHeight;
     PixelWidth = BMP_Info.biWidth;
     INFO("(%d,%d) (%d,%d) (%d,%d)", x,y, PixelWidth,PixelHeight, width(), height());
+    if (infoOnly) {
+        infoOnly->p1.x = x;
+        infoOnly->p1.y = y;
+        infoOnly->p2.x = x+PixelWidth;
+        infoOnly->p2.y = y+PixelHeight;
+        return (noerror);
+    }
+
     if (PixelHeight > height() + y || PixelWidth > width() + x) {
         fclose(Image);
+        ERR("too big: img: (%d,%d), xy: (%d,%d), screen: (%d,%d)\r\n",
+            PixelWidth, PixelHeight, x, y, width(), height());
         return(image_too_big);
     }
     if (BMP_Info.biBitCount <= 8) {
@@ -406,22 +416,61 @@
     return (noerror);
 }
 
-
-RetCode_t GraphicsDisplay::RenderImageFile(loc_t x, loc_t y, const char *FileName)
+rect_t GraphicsDisplay::GetImageRect(loc_t x, loc_t y, const char *Filename)
 {
+    rect_t r = { 0, 0, 0, 0};
+
+    RenderImageFile(x,y,Filename, &r);
+    return r;
+}
+
+RetCode_t GraphicsDisplay::RenderImageFile(loc_t x, loc_t y, const char * FileName, rect_t * getDim) {
     if (mystrnicmp(FileName + strlen(FileName) - 4, ".bmp", 4) == 0) {
-        return RenderBitmapFile(x,y,FileName);
+        return RenderBitmapFile(x, y, FileName, getDim);
     } else if (mystrnicmp(FileName + strlen(FileName) - 4, ".jpg", 4) == 0) {
-        return RenderJpegFile(x,y,FileName);
+        if (getDim)
+            return not_supported_format;
+        return RenderJpegFile(x, y, FileName);
     } else if (mystrnicmp(FileName + strlen(FileName) - 4, ".ico", 4) == 0) {
-        return RenderIconFile(x,y,FileName);
+        if (getDim)
+            return not_supported_format;
+        return RenderIconFile(x, y, FileName);
     } else if (mystrnicmp(FileName + strlen(FileName) - 4, ".gif", 4) == 0) {
-        return RenderGIFFile(x,y,FileName);
+        if (getDim)
+            return not_supported_format;
+        return RenderGIFFile(x, y, FileName);
     } else {
         return not_supported_format;
     }
 }
 
+RetCode_t GraphicsDisplay::RenderBitmapFile(loc_t x, loc_t y, const char *Name_BMP, rect_t * getDim)
+{
+    BITMAPFILEHEADER BMP_Header;
+
+    INFO("Opening {%s}", Name_BMP);
+    FILE *Image = fopen(Name_BMP, "rb");
+    if (!Image) {
+        return(file_not_found);
+    }
+
+    fread(&BMP_Header, 1, sizeof(BMP_Header), Image);      // get the BMP Header
+    INFO("bfType %04X, Header size: %d", BMP_Header.bfType, sizeof(BITMAPFILEHEADER));
+    HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header));
+    if (BMP_Header.bfType != BF_TYPE) {
+        fclose(Image);
+        return(not_bmp_format);
+    }
+    INFO("bfOffits %04X", BMP_Header.bfOffBits);
+    RetCode_t rt = _RenderBitmap(x, y, BMP_Header.bfOffBits, Image, getDim);
+    if (rt != noerror) {
+        return rt;
+    } else {
+        fclose(Image);
+        return (noerror);
+    }
+}
+
 RetCode_t GraphicsDisplay::RenderJpegFile(loc_t x, loc_t y, const char *Name_JPG)
 {
     #define JPEG_WORK_SPACE_SIZE 3100   // Worst case requirements for the decompression
@@ -429,7 +478,7 @@
     uint16_t * work;
     RetCode_t r = noerror;  // start optimistic
     FILE * fh = fopen(Name_JPG, "rb");
-    
+
     if (!fh)
         return(file_not_found);
     //INFO("RenderJpegFile(%d,%d,%s)", x,y, Name_JPG);
@@ -444,7 +493,7 @@
             memset(jdec, 0, sizeof(JDEC));
             r = (RetCode_t)jd_prepare(jdec, NULL, work, JPEG_WORK_SPACE_SIZE, fh);
             INFO("jd_prepare returned %d", r);
-            
+
             if (r == noerror) {
                 img_x = x;  // save the origin for the privOutput function
                 img_y = y;
@@ -466,33 +515,6 @@
     return r;   // error("jd_decomp error:%d", r);
 }
 
-RetCode_t GraphicsDisplay::RenderBitmapFile(loc_t x, loc_t y, const char *Name_BMP)
-{
-    BITMAPFILEHEADER BMP_Header;
-
-    INFO("Opening {%s}", Name_BMP);
-    FILE *Image = fopen(Name_BMP, "rb");
-    if (!Image) {
-        return(file_not_found);
-    }
-
-    fread(&BMP_Header, 1, sizeof(BMP_Header), Image);      // get the BMP Header
-    INFO("bfType %04X", BMP_Header.bfType);
-    HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header));
-    if (BMP_Header.bfType != BF_TYPE) {
-        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;
-    } else {
-        fclose(Image);
-        return (noerror);
-    }
-}
-
 RetCode_t GraphicsDisplay::RenderIconFile(loc_t x, loc_t y, const char *Name_ICO)
 {
     ICOFILEHEADER ICO_Header;