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 Nov 16 02:48:45 2016 +0000
Parent:
135:af519fe4ba91
Child:
137:9e09f6081ef1
Commit message:
JPG Rendering can now write to display in 8-bit color format, not just 16-bit color format.

Changed in this revision

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
GraphicsDisplayJPEG.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 Nov 13 02:06:30 2016 +0000
+++ b/GraphicsDisplay.cpp	Wed Nov 16 02:48:45 2016 +0000
@@ -336,8 +336,8 @@
     // 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();
+//    SetGraphicsCursor(x, y);
+//    _StartGraphicsStream();
 
     //start_data = BMP_Info.bfOffBits;
     //HexDump("Raw Data", (uint8_t *)&start_data, 32);
@@ -353,8 +353,7 @@
                 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);                
+                pixelBuffer[i] = RGBQuadToRGB16(colorPalette, bit);
             } else if (BPP_t == 4) {
                 uint8_t dPix = lineBuffer[i/2];
                 if ((i & 1) == 0)
@@ -373,7 +372,7 @@
         }
         pixelStream(pixelBuffer, PixelWidth, x, y++);
     }
-    _EndGraphicsStream();
+//    _EndGraphicsStream();
     window(restore);
     free(pixelBuffer);      // don't leak memory
     free(lineBuffer);
@@ -419,7 +418,8 @@
             INFO("jd_prepare returned %d", r);
             
             if (r == noerror) {
-                SetGraphicsCursor(x,y);
+                img_x = x;  // save the origin for the privOutput function
+                img_y = y;
                 r = (RetCode_t)jd_decomp(jdec, NULL, 0);
             } else {
                 r = not_supported_format;   // error("jd_prepare error:%d", r);
--- a/GraphicsDisplay.h	Sun Nov 13 02:06:30 2016 +0000
+++ b/GraphicsDisplay.h	Wed Nov 16 02:48:45 2016 +0000
@@ -105,6 +105,21 @@
     ///
     virtual RetCode_t SetGraphicsCursor(loc_t x, loc_t y) = 0;
     
+    
+    /// Prepare the controller to write binary data to the screen by positioning
+    /// the memory cursor.
+    ///
+    /// @param[in] p is the point representing the cursor position to set
+    /// @returns success/failure code. See @ref RetCode_t.
+    ///
+    virtual RetCode_t SetGraphicsCursor(point_t p) = 0;
+    
+    /// Read the current graphics cursor position as a point.
+    ///
+    /// @returns the graphics cursor as a point.
+    ///
+    virtual point_t GetGraphicsCursor(void) = 0;
+
     /// Prepare the controller to read binary data from the screen by positioning
     /// the memory read cursor.
     ///
@@ -465,6 +480,9 @@
 
 private:
 
+    loc_t img_x;    /// x position of a rendered jpg
+    loc_t img_y;    /// y position of a rendered jpg
+
     /// Analyze the jpeg data in preparation for decompression.
     ///
     JRESULT jd_prepare(JDEC * jd, uint16_t(* infunc)(JDEC * jd, uint8_t * buffer, uint16_t bufsize), void * pool, uint16_t poolsize, void * filehandle);
--- a/GraphicsDisplayJPEG.cpp	Sun Nov 13 02:06:30 2016 +0000
+++ b/GraphicsDisplayJPEG.cpp	Wed Nov 16 02:48:45 2016 +0000
@@ -839,14 +839,10 @@
         return privInFunc(jd, buff, ndata);
 }
 
-
+// RGB565 if JD_FORMAT == 1
+// RGB888 if JD_FORMAT == 0
 uint16_t GraphicsDisplay::privOutFunc(JDEC * jd, void * bitmap, JRECT * rect)
 {
-    #if JD_FORMAT == 1
-    uint16_t *src = (uint16_t *)bitmap;
-    #else
-    uint8_t *src = (uint8_t *)bitmap;
-    #endif
     int x0 = rect->left;
     int x1 = rect->right;
     int y0 = rect->top;
@@ -854,15 +850,34 @@
  
     INFO("privOutFunc: (%d,%d)-(%d,%d) : (%d,%d)", x0,y0, x1,y1, width(), height());
     if (y0 >= height() || x0 >= width())
-        return 1;
- 
-    if (x1 > width()-1) x1 = width() - 1;
-    if (y1 > height()-1) y1 = height() - 1;
- 
-    INFO("checkpoint");
+        return 1;                               // off the right || bottom of screen
+    if (x1 > width()-1) x1 = width() - 1;       // clip to width
+    if (y1 > height()-1) y1 = height() - 1;     // clip to height
+
     int w = x1 - x0 + 1;
+
+#if 1
+    uint32_t pixelCount = (1 + (y1-y0)) * (1+x1-x0);
+    #if JD_FORMAT == 0
+    uint8_t *s = (uint8_t *)bitmap;
+    uint16_t rgb565, *d = (uint16_t *)s;
+    uint32_t pCount = pixelCount;
+    
+    do {
+        rgb565 = (*s++ & 0xF8) << 8;     /* RRRRR----------- */
+        rgb565 |= (*s++ & 0xFC) << 3;    /* -----GGGGGG----- */
+        rgb565 |= *s++ >> 3;             /* -----------BBBBB */
+        *d++ = rgb565;
+    } while (--pCount);
+    #endif
+    //
+    window(x0+img_x, y0+img_y, w, y1 - y0 + 2);
+    uint16_t *src = (uint16_t *)bitmap;     // pointer to RGB565 format
+    pixelStream(src, pixelCount, x0+img_x, y0+img_y);
+    window();
+#else
     for (int y= y0; y <= y1; y++) {
-        SetGraphicsCursor(x0, y);
+        SetGraphicsCursor(x0+img_x, y+img_y);
         _StartGraphicsStream();
         #if JD_FORMAT == 1
         uint16_t *p = src + w * (y - y0);
@@ -879,6 +894,7 @@
         }
         _EndGraphicsStream();
     }
+#endif
     return 1;
 }
 
@@ -1188,6 +1204,5 @@
             if (rc != JDR_OK) return rc;
         }
     }
-
     return rc;
 }
--- a/RA8875.cpp	Sun Nov 13 02:06:30 2016 +0000
+++ b/RA8875.cpp	Wed Nov 16 02:48:45 2016 +0000
@@ -584,6 +584,11 @@
     return ReadData();
 }
 
+uint16_t RA8875::ReadCommandW(unsigned char command)
+{
+    WriteCommand(command);
+    return ReadDataW();
+}
 
 unsigned char RA8875::ReadData(void)
 {
@@ -1121,6 +1126,19 @@
     return noerror;
 }
 
+RetCode_t RA8875::SetGraphicsCursor(point_t p)
+{
+    return SetGraphicsCursor(p.x, p.y);
+}
+
+point_t RA8875::GetGraphicsCursor(void)
+{
+    point_t p;
+    
+    p.x = ReadCommandW(0x46);
+    p.y = ReadCommandW(0x48);
+    return p;
+}
 
 RetCode_t RA8875::SetGraphicsCursorRead(loc_t x, loc_t y)
 {
--- a/RA8875.h	Sun Nov 13 02:06:30 2016 +0000
+++ b/RA8875.h	Wed Nov 16 02:48:45 2016 +0000
@@ -1210,8 +1210,16 @@
     /// @returns the value read from the register.
     ///
     unsigned char ReadCommand(unsigned char command);
+
+
+    /// Read a word from a command register
+    ///
+    /// @param[in] command is the command register to read.
+    /// @returns the value read from the register.
+    ///
+    uint16_t ReadCommandW(unsigned char command);
     
-
+    
     /// Read a data byte from the display
     ///
     /// This is a high level command, and may invoke several primitives.
@@ -1547,6 +1555,20 @@
     ///
     virtual RetCode_t SetGraphicsCursor(loc_t x, loc_t y);
 
+    /// Prepare the controller to write binary data to the screen by positioning
+    /// the memory cursor.
+    ///
+    /// @param[in] p is the point representing the cursor position to set
+    /// @returns success/failure code. See @ref RetCode_t.
+    ///
+    virtual RetCode_t SetGraphicsCursor(point_t p);
+    
+    /// Read the current graphics cursor position as a point.
+    ///
+    /// @returns the graphics cursor as a point.
+    ///
+    virtual point_t GetGraphicsCursor(void);
+
     
     /// Prepare the controller to read binary data from the screen by positioning
     /// the memory read cursor.
@@ -1748,7 +1770,7 @@
     virtual color_t getPixel(loc_t x, loc_t y);
     
     
-    /// Write a stream of pixels to the display.
+    /// Write an RGB565 stream of pixels to the display.
     ///
     /// @param[in] p is a pointer to a color_t array to write.
     /// @param[in] count is the number of pixels to write.