LCD LIB

Dependents:   HagridOS5

Fork of RA8875 by David Smart

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Thu Jun 01 11:00:40 2017 +0000
Parent:
144:ba002c4b21b3
Parent:
145:5eb2492acdda
Child:
147:3494792458d9
Commit message:
Adopt new callback structure for ISRs,; Provide hooks for swMalloc for advanced memory usage tracking.

Changed in this revision

GraphicsDisplay.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
--- a/GraphicsDisplay.cpp	Sat May 06 20:14:48 2017 +0000
+++ b/GraphicsDisplay.cpp	Thu Jun 01 11:00:40 2017 +0000
@@ -9,6 +9,12 @@
 #include "Bitmap.h"
 #include "string.h"
 
+//#include "Utility.h"            // private memory manager
+#ifndef UTILITY_H
+#define swMalloc malloc         // use the standard
+#define swFree free
+#endif
+
 //#define DEBUG "GD  "
 // ...
 // INFO("Stuff to show %d", var); // new-line is automatically appended
@@ -313,7 +319,7 @@
         // Read the color palette
         colorCount = 1 << BMP_Info.biBitCount;
         paletteSize = sizeof(RGBQUAD) * colorCount;
-        colorPalette = (RGBQUAD *)malloc(paletteSize);
+        colorPalette = (RGBQUAD *)swMalloc(paletteSize);
         if (colorPalette == NULL) {
             fclose(Image);
             return(not_enough_ram);
@@ -324,17 +330,17 @@
 
     int lineBufSize = ((BPP_t * PixelWidth + 7)/8);
     INFO("BPP_t %d, PixelWidth %d, lineBufSize %d", BPP_t, PixelWidth, lineBufSize);
-    lineBuffer = (uint8_t *)malloc(lineBufSize);
+    lineBuffer = (uint8_t *)swMalloc(lineBufSize);
     if (lineBuffer == NULL) {
-        free(colorPalette);
+        swFree(colorPalette);
         fclose(Image);
         return(not_enough_ram);
     }
-    pixelBuffer = (color_t *)malloc(PixelWidth * sizeof(color_t));
+    pixelBuffer = (color_t *)swMalloc(PixelWidth * sizeof(color_t));
     if (pixelBuffer == NULL) {
-        free(lineBuffer);
+        swFree(lineBuffer);
         if (colorPalette)
-            free(colorPalette);
+            swFree(colorPalette);
         fclose(Image);
         return(not_enough_ram);
     }
@@ -384,10 +390,10 @@
     }
 //    _EndGraphicsStream();
     window(restore);
-    free(pixelBuffer);      // don't leak memory
-    free(lineBuffer);
+    swFree(pixelBuffer);      // don't leak memory
+    swFree(lineBuffer);
     if (colorPalette)
-        free(colorPalette);
+        swFree(colorPalette);
     return (noerror);
 }
 
@@ -407,7 +413,7 @@
 
 RetCode_t GraphicsDisplay::RenderJpegFile(loc_t x, loc_t y, const char *Name_JPG)
 {
-    #define JPEG_WORK_SPACE_SIZE 3100
+    #define JPEG_WORK_SPACE_SIZE 3100   // Worst case requirements for the decompression
     JDEC * jdec;
     uint16_t * work;
     RetCode_t r = noerror;  // start optimistic
@@ -415,12 +421,10 @@
     
     if (!fh)
         return(file_not_found);
-    
     //INFO("RenderJpegFile(%d,%d,%s)", x,y, Name_JPG);
-    work = (uint16_t *)malloc(JPEG_WORK_SPACE_SIZE);
-    
+    work = (uint16_t *)swMalloc(JPEG_WORK_SPACE_SIZE);
     if (work) {
-        jdec = (JDEC *)malloc(sizeof(JDEC));
+        jdec = (JDEC *)swMalloc(sizeof(JDEC));
         if (jdec) {
             memset(work, 0, JPEG_WORK_SPACE_SIZE/sizeof(uint16_t));
             memset(jdec, 0, sizeof(JDEC));
@@ -434,12 +438,12 @@
             } else {
                 r = not_supported_format;   // error("jd_prepare error:%d", r);
             }
-            free(jdec);
+            swFree(jdec);
         } else {
             WARN("checkpoint");
             r = not_enough_ram;
         }
-        free(work);
+        swFree(work);
     } else {
         WARN("checkpoint");
         r = not_enough_ram;
--- a/RA8875.cpp	Sat May 06 20:14:48 2017 +0000
+++ b/RA8875.cpp	Thu Jun 01 11:00:40 2017 +0000
@@ -13,6 +13,12 @@
 ///
 #include "RA8875.h"
 
+//#include "Utility.h"            // private memory manager
+#ifndef UTILITY_H
+#define swMalloc malloc         // use the standard
+#define swFree free
+#endif
+
 //#define DEBUG "RAIO"
 // ...
 // INFO("Stuff to show %d", var); // new-line is automatically appended
@@ -135,7 +141,7 @@
     // Interrupt
     m_irq->mode(PullUp);
     m_irq->enable_irq();
-    m_irq->fall(this, &RA8875::TouchPanelISR);
+    m_irq->fall(callback(this, &RA8875::TouchPanelISR));
     TouchPanelInit();
 }
 
@@ -2037,7 +2043,7 @@
 
         // Allocate the memory we need to proceed
         int lineBufSize = ((24 * w + 7)/8);
-        lineBuffer = (uint8_t *)malloc(lineBufSize);
+        lineBuffer = (uint8_t *)swMalloc(lineBufSize);
         if (lineBuffer == NULL) {
             ERR("Not enough RAM for PrintScreen lineBuffer");
             return(not_enough_ram);
@@ -2050,21 +2056,21 @@
         // but is actually causing a failure later. 
         // This test helps determine if it is truly out of memory,
         // or if malloc is broken.
-        pixelBuffer = (color_t *)malloc(2 * w * sizeof(color_t));
+        pixelBuffer = (color_t *)swMalloc(2 * w * sizeof(color_t));
         pixelBuffer2 = pixelBuffer + (w * sizeof(color_t));
         #else
-        pixelBuffer = (color_t *)malloc(w * sizeof(color_t));
-        pixelBuffer2 = (color_t *)malloc(w * sizeof(color_t));
+        pixelBuffer = (color_t *)swMalloc(w * sizeof(color_t));
+        pixelBuffer2 = (color_t *)swMalloc(w * sizeof(color_t));
         #endif
         if (pixelBuffer == NULL || pixelBuffer2 == NULL) {
             ERR("Not enough RAM for pixelBuffer");
             #ifndef DOUBLEBUF
             if (pixelBuffer2)
-                free(pixelBuffer2);
+                swFree(pixelBuffer2);
             #endif
             if (pixelBuffer)
-                free(pixelBuffer);
-            free(lineBuffer);
+                swFree(pixelBuffer);
+            swFree(lineBuffer);
             return(not_enough_ram);
         }
 
@@ -2154,11 +2160,11 @@
         
         #ifndef DOUBLEBUF
         if (pixelBuffer2)
-            free(pixelBuffer2);
+            swFree(pixelBuffer2);
         #endif
         if (pixelBuffer)
-            free(pixelBuffer);
-        free(lineBuffer);
+            swFree(pixelBuffer);
+        swFree(lineBuffer);
         INFO("Image closed");
         return noerror;
     } else {
@@ -2200,7 +2206,7 @@
 
         // Allocate the memory we need to proceed
         int lineBufSize = ((24 * w + 7)/8);
-        lineBuffer = (uint8_t *)malloc(lineBufSize);
+        lineBuffer = (uint8_t *)swMalloc(lineBufSize);
         if (lineBuffer == NULL) {
             ERR("Not enough RAM for PrintScreen lineBuffer");
             return(not_enough_ram);
@@ -2213,21 +2219,21 @@
         // but is actually causing a failure later. 
         // This test helps determine if it is truly out of memory,
         // or if malloc is broken.
-        pixelBuffer = (color_t *)malloc(2 * w * sizeof(color_t));
+        pixelBuffer = (color_t *)swMalloc(2 * w * sizeof(color_t));
         pixelBuffer2 = pixelBuffer + (w * sizeof(color_t));
         #else
-        pixelBuffer = (color_t *)malloc(w * sizeof(color_t));
-        pixelBuffer2 = (color_t *)malloc(w * sizeof(color_t));
+        pixelBuffer = (color_t *)swMalloc(w * sizeof(color_t));
+        pixelBuffer2 = (color_t *)swMalloc(w * sizeof(color_t));
         #endif
         if (pixelBuffer == NULL || pixelBuffer2 == NULL) {
             ERR("Not enough RAM for pixelBuffer");
             #ifndef DOUBLEBUF
             if (pixelBuffer2)
-                free(pixelBuffer2);
+                swFree(pixelBuffer2);
             #endif
             if (pixelBuffer)
-                free(pixelBuffer);
-            free(lineBuffer);
+                swFree(pixelBuffer);
+            swFree(lineBuffer);
             return(not_enough_ram);
         }
 
@@ -2236,11 +2242,11 @@
             ERR("Can't open file for write");
             #ifndef DOUBLEBUF
             if (pixelBuffer2)
-                free(pixelBuffer2);
+                swFree(pixelBuffer2);
             #endif
             if (pixelBuffer)
-                free(pixelBuffer);
-            free(lineBuffer);
+                swFree(pixelBuffer);
+            swFree(lineBuffer);
             return(file_not_found);
         }
 
@@ -2322,11 +2328,11 @@
         fclose(Image);
         #ifndef DOUBLEBUF
         if (pixelBuffer2)
-            free(pixelBuffer2);
+            swFree(pixelBuffer2);
         #endif
         if (pixelBuffer)
-            free(pixelBuffer);
-        free(lineBuffer);
+            swFree(pixelBuffer);
+        swFree(lineBuffer);
         INFO("Image closed");
         return noerror;
     } else {
--- a/RA8875_Touch.cpp	Sat May 06 20:14:48 2017 +0000
+++ b/RA8875_Touch.cpp	Thu Jun 01 11:00:40 2017 +0000
@@ -35,7 +35,7 @@
         WriteCommand(INTC2, RA8875_INT_TP);                            // reg INTC2: Clear any TP interrupt flag
         touchSample = 0;
         touchState = no_cal;
-        touchTicker.attach_us(this, &RA8875::_TouchTicker, TOUCH_TICKER_uS);
+        touchTicker.attach_us(callback(this, &RA8875::_TouchTicker), TOUCH_TICKER_uS);
         touchTimer.start();
         touchTimer.reset();
     }
@@ -67,7 +67,7 @@
         touchSample = 0;
         touchState = no_cal;
         if (bTpEnable == TP_ENABLE) {
-            touchTicker.attach_us(this, &RA8875::_TouchTicker, TOUCH_TICKER_uS);
+            touchTicker.attach_us(callback(this, &RA8875::_TouchTicker), TOUCH_TICKER_uS);
             touchTimer.start();
             touchTimer.reset();
         } else {