This is the David Smart RA8875 Library with mods for working with FRDM-K64F

Revision:
182:8832d03a2a29
Parent:
181:0032d1b8f5d4
Child:
183:808f272e481e
--- a/RA8875.cpp	Fri Aug 02 02:12:26 2019 +0000
+++ b/RA8875.cpp	Sat Aug 03 00:26:33 2019 +0000
@@ -193,21 +193,10 @@
     , res(reset)
 {
     INFO("RA8875");
+    InitAllMemberVars();
     touchInfo = (touchInfo_T *)malloc(RESISTIVE_TOUCH_POINTS * sizeof(touchInfo_T));
     if (touchInfo)
         useTouchPanel = TP_RES;
-    else
-        useTouchPanel = TP_NONE;    // unfortnately a silent failure, but unlikely
-    tpFQFN = NULL;
-    tpCalMessage = NULL;
-    m_irq = NULL;
-    m_i2c = NULL;
-    m_wake = NULL;
-    c_callback = NULL;
-    obj_callback = NULL;
-    method_callback = NULL;
-    idle_callback = NULL;
-    fontScaleX = fontScaleY = 1;
 }
 
 // Touch, based on FT5206 Controller Chip
@@ -220,8 +209,7 @@
     , res(reset)
 {
     INFO("RA8875");
-    tpFQFN = NULL;
-    tpCalMessage = NULL;
+    InitAllMemberVars();
     m_irq = new InterruptIn(irq);
     m_i2c = new I2C(sda, scl);
     INFO("m_i2c = %p", m_i2c);
@@ -230,18 +218,9 @@
     touchInfo = (touchInfo_T *)malloc(FT5206_TOUCH_POINTS * sizeof(touchInfo_T));
     if (touchInfo)
         useTouchPanel = TP_FT5206;
-    else
-        useTouchPanel = TP_NONE;    // unfortnately a silent failure, but unlikely
     m_addr = (FT5206_I2C_ADDRESS << 1);
     m_i2c->frequency(FT5206_I2C_FREQUENCY);
-    m_wake = NULL;      // not used for FT5206
     
-    c_callback = NULL;
-    obj_callback = NULL;
-    method_callback = NULL;
-    idle_callback = NULL;
-    fontScaleX = fontScaleY = 1;
-
     // Interrupt
     m_irq->mode(PullUp);
     #if MBED_VERSION >= MBED_ENCODE_VERSION(5,8,0)
@@ -268,8 +247,8 @@
     , res(reset)
 {
     INFO("RA8875");
-    tpFQFN = NULL;
-    tpCalMessage = NULL;
+    InitAllMemberVars();
+    
     m_irq = new InterruptIn(irq);
     m_i2c = new I2C(sda, scl);
 
@@ -277,18 +256,10 @@
     touchInfo = (touchInfo_T *)malloc(FT5206_TOUCH_POINTS * sizeof(touchInfo_T));
     if (touchInfo)
         useTouchPanel = TP_GSL1680;
-    else
-        useTouchPanel = TP_NONE;    // unfortnately a silent failure, but unlikely
     m_addr = (GSL1680_I2C_ADDRESS << 1);
     m_i2c->frequency(GSL1680_I2C_FREQUENCY);
     m_wake = new DigitalOut(wake);
 
-    c_callback = NULL;
-    obj_callback = NULL;
-    method_callback = NULL;
-    idle_callback = NULL;
-    fontScaleX = fontScaleY = 1;
-
     // Interrupt
     m_irq->mode(PullUp);
     m_irq->enable_irq();
@@ -309,6 +280,46 @@
 //{
 //}
 
+void RA8875::InitAllMemberVars() {
+    tpFQFN = NULL;
+    tpCalMessage = NULL;
+    c_callback = NULL;
+    obj_callback = NULL;
+    method_callback = NULL;
+    idle_callback = NULL;
+    fontScaleX = fontScaleY = 1;
+    m_addr = 0;
+    m_wake = NULL;      // not used for FT5206
+    m_irq = NULL;
+    m_i2c = NULL;
+    touchInfo = NULL;
+    useTouchPanel = TP_NONE;
+    touchState = no_touch;
+    numberOfTouchPoints = 0;
+    gesture = 0;
+    panelTouched = 0;
+    touchSample = 0;
+    memset(&tpMatrix, 0, sizeof(tpMatrix_t));
+    pKeyMap = NULL;
+    spiWriteSpeed = false;
+    spiwritefreq = 1000000;
+    spireadfreq = 1000000;
+    screenbpp = 16;
+    screenwidth = 0;
+    screenheight = 0;
+    memset(&windowrect, 0, sizeof(rect_t));
+    portraitmode = false;
+    font = NULL;
+    extFontHeight = 0;
+    extFontWidth = 0;
+    cursor_x = 0;
+    cursor_y = 0;
+    _printFH = NULL;
+    screen_orientation = normal;
+#ifdef PERF_METRICS
+    ClearPerformance();
+#endif
+}
 
 RetCode_t RA8875::init(int width, int height, int color_bpp, uint8_t poweron, bool keypadon, bool touchscreenon)
 {
@@ -2376,7 +2387,10 @@
         // This test helps determine if it is truly out of memory,
         // or if malloc is broken.
         pixelBuffer = (color_t *)swMalloc(2 * w * sizeof(color_t));
-        pixelBuffer2 = pixelBuffer + (w * sizeof(color_t));
+        if (pixelBuffer)
+            pixelBuffer2 = pixelBuffer + (w * sizeof(color_t));
+        else
+            pixelBuffer2 = NULL;
         #else
         pixelBuffer = (color_t *)swMalloc(w * sizeof(color_t));
         pixelBuffer2 = (color_t *)swMalloc(w * sizeof(color_t));
@@ -2434,7 +2448,7 @@
         // 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--) {
-            if (idle_callback) {
+            if (idle_callback && h >= 1) {
                 (*idle_callback)(progress, (h - 1 - j) * 100 / (h - 1));
             }
 
@@ -2587,7 +2601,10 @@
         // This test helps determine if it is truly out of memory,
         // or if malloc is broken.
         pixelBuffer = (color_t *)swMalloc(2 * w * sizeof(color_t));
-        pixelBuffer2 = pixelBuffer + (w * sizeof(color_t));
+        if (pixelBuffer)
+            pixelBuffer2 = pixelBuffer + (w * sizeof(color_t));
+        else
+            pixelBuffer2 = NULL;
         #else
         pixelBuffer = (color_t *)swMalloc(w * sizeof(color_t));
         pixelBuffer2 = (color_t *)swMalloc(w * sizeof(color_t));
@@ -2652,7 +2669,7 @@
         // 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--) {
-            if (idle_callback) {
+            if (idle_callback && h >= 1) {
                 (*idle_callback)(progress, (h - 1 - j) * 100 / (h - 1));
             }
 
@@ -2934,7 +2951,7 @@
     display.puts("RA8875 Backlight Test - Ramp up.");
     wait_ms(delay);
     for (int i=0; i <= 255; i++) {
-        snprintf(buf, sizeof(buf), "%3d, %4d", i, w);
+        snprintf(buf, sizeof(buf), "%3d, %4u", i, w);
         display.puts(100,100,buf);
         display.Backlight_u8(i);
         wait_ms(w);