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:
123:2f45e80fec5f
Parent:
108:7415c405ee08
Child:
124:1690a7ae871c
--- a/RA8875_Touch.cpp	Tue May 17 22:33:06 2016 +0000
+++ b/RA8875_Touch.cpp	Mon Jul 25 10:55:58 2016 +0000
@@ -6,8 +6,6 @@
 #define NOTOUCH_TIMEOUT_uS 100000
 #define TOUCH_TICKER_uS      1000
 
-// ### Touch Panel support code additions begin here
-
 RetCode_t RA8875::TouchPanelInit(void)
 {
     //TPCR0: Set enable bit, default sample time, wakeup, and ADC clock
@@ -67,13 +65,11 @@
     // |                                                    |
     // +----------------------------------------------------+
 
-
 RetCode_t RA8875::TouchPanelCalibrate(tpMatrix_t * matrix)
 {
     return TouchPanelCalibrate(NULL, matrix);
 }
 
-
 RetCode_t RA8875::TouchPanelCalibrate(const char * msg, tpMatrix_t * matrix, int maxwait_s)
 {
     point_t pTest[3];
@@ -82,8 +78,14 @@
     Timer timeout;  // timeout guards for not-installed, stuck, user not present...
     
     timeout.start();
-    while (TouchPanelA2DFiltered(&x, &y) && timeout.read() < maxwait_s)
+    while (TouchPanelA2DFiltered(&x, &y) && timeout.read() < maxwait_s) {
         wait_ms(20);
+        if (idle_callback) {
+            if (external_abort == (*idle_callback)(touchcal_wait)) {
+                return external_abort;
+            }
+        }
+    }
     cls();
     if (msg)
         puts(msg);
@@ -97,17 +99,36 @@
         printf(" (%3d,%3d) => ", pTest[i].x, pTest[i].y);
         line(pTest[i].x-10, pTest[i].y, pTest[i].x+10, pTest[i].y, White);
         line(pTest[i].x, pTest[i].y-10, pTest[i].x, pTest[i].y+10, White);
-        while (!TouchPanelA2DFiltered(&x, &y) && timeout.read() < maxwait_s)
+        while (!TouchPanelA2DFiltered(&x, &y) && timeout.read() < maxwait_s) {
             wait_ms(20);
+            if (idle_callback) {
+                if (external_abort == (*idle_callback)(touchcal_wait)) {
+                    return external_abort;
+                }
+            }
+        }
         pSample[i].x = x;
         pSample[i].y = y;
         line(pTest[i].x-10, pTest[i].y, pTest[i].x+10, pTest[i].y, Black);
         line(pTest[i].x, pTest[i].y-10, pTest[i].x, pTest[i].y+10, Black);
         foreground(Blue);
         printf(" (%4d,%4d)\r\n", x,y);
-        while (TouchPanelA2DFiltered(&x, &y) && timeout.read() < maxwait_s)
+        while (TouchPanelA2DFiltered(&x, &y) && timeout.read() < maxwait_s) {
             wait_ms(20);
-        wait(2);
+            if (idle_callback) {
+                if (external_abort == (*idle_callback)(touchcal_wait)) {
+                    return external_abort;
+                }
+            }
+        }
+        for (int t=0; t<100; t++) {
+            wait_ms(20);
+            if (idle_callback) {
+                if (external_abort == (*idle_callback)(touchcal_wait)) {
+                    return external_abort;
+                }
+            }
+        }
     }
     if (timeout.read() >= maxwait_s)
         return touch_cal_timeout;
@@ -118,7 +139,7 @@
 
 /**********************************************************************
  *
- *     Function: getDisplayPoint()
+ *     Function: TouchPanelReadable()
  *
  *  Description: Given a valid set of calibration factors and a point
  *                value reported by the touch screen, this function
@@ -204,14 +225,24 @@
 
 TouchCode_t RA8875::TouchPanelGet(point_t * TouchPoint)
 {
-    TouchCode_t t;
+    TouchCode_t t = no_touch;
     
-    do {
+    while (true) {
         t = TouchPanelReadable(TouchPoint);
-    } while (t == no_touch);
+        if (t != no_touch)
+            break;
+        if (idle_callback) {
+            if (external_abort == (*idle_callback)(touch_wait)) {
+                return no_touch;
+            }
+        }
+    }
     return t;
 }
 
+// Below here are primarily "helper" functions. While many are accessible
+// to the user code, they usually don't need to be called.
+
 RetCode_t RA8875::TouchPanelSetMatrix(tpMatrix_t * matrixPtr)
 {
     if (matrixPtr == NULL || matrixPtr->Divider == 0)
@@ -221,7 +252,6 @@
     return noerror;
 }
 
-
 static void InsertionSort(int * buf, int bufsize)
 {
     int i, j;