LCD LIB

Dependents:   HagridOS5

Fork of RA8875 by David Smart

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Sat May 06 20:27:44 2017 +0000
Parent:
141:2ec78a50dc98
Child:
146:373d59f08357
Commit message:
hook the memory allocation to use a special instrumented allocation

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
RA8875_Touch.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/GraphicsDisplay.cpp	Thu Dec 29 20:06:00 2016 +0000
+++ b/GraphicsDisplay.cpp	Sat May 06 20:27:44 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
@@ -303,7 +309,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);
@@ -314,17 +320,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);
     }
@@ -374,10 +380,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);
 }
 
@@ -397,7 +403,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
@@ -405,12 +411,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));
@@ -424,12 +428,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	Thu Dec 29 20:06:00 2016 +0000
+++ b/RA8875.cpp	Sat May 06 20:27:44 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();
 }
 
@@ -2009,7 +2015,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);
@@ -2022,21 +2028,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);
         }
 
@@ -2126,11 +2132,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 {
@@ -2172,7 +2178,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);
@@ -2185,21 +2191,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);
         }
 
@@ -2208,11 +2214,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);
         }
 
@@ -2294,11 +2300,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	Thu Dec 29 20:06:00 2016 +0000
+++ b/RA8875_Touch.cpp	Sat May 06 20:27:44 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 {