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:
198:9b6851107426
Parent:
197:853d08e2fb53
Child:
202:a22cbc04f332
--- a/RA8875_Touch.cpp	Tue Feb 11 21:51:42 2020 +0000
+++ b/RA8875_Touch.cpp	Sat Mar 28 15:01:38 2020 +0000
@@ -87,7 +87,6 @@
 {
     if (useTouchPanel == TP_GSL1680) {
         INFO("TouchPanelInit: TP_GSL1680");
-        /// @todo Added support for TP_GSL1680
     } else if (useTouchPanel == TP_FT5206) {
         INFO("TouchPanelInit: TP_FT5206");
         TouchPanelInit();
@@ -241,99 +240,17 @@
  *
  *     Function: TouchPanelReadable()
  *
- *  Description: Given a valid set of calibration factors and a point
- *                value reported by the touch screen, this function
- *                calculates and returns the true (or closest to true)
- *                display point below the spot where the touch screen
- *                was touched.
- *
- *
- *
- *  Argument(s): displayPtr (output) - Pointer to the calculated
- *                                      (true) display point.
- *               screenPtr (input) - Pointer to the reported touch
- *                                    screen point.
- *               matrixPtr (input) - Pointer to calibration factors
- *                                    matrix previously calculated
- *                                    from a call to
- *                                    setCalibrationMatrix()
- *
- *
- *  The function simply solves for Xd and Yd by implementing the
- *   computations required by the translation matrix.
- *
- *                                              /-     -\
- *              /-    -\     /-            -\   |       |
- *              |      |     |              |   |   Xs  |
- *              |  Xd  |     | A    B    C  |   |       |
- *              |      |  =  |              | * |   Ys  |
- *              |  Yd  |     | D    E    F  |   |       |
- *              |      |     |              |   |   1   |
- *              \-    -/     \-            -/   |       |
- *                                              \-     -/
- *
- *  It must be kept brief to avoid consuming CPU cycles.
- *
- *       Return: OK - the display point was correctly calculated
- *                     and its value is in the output argument.
- *               NOT_OK - an error was detected and the function
- *                         failed to return a valid point.
- *
- *                 NOTE!    NOTE!    NOTE!
- *
- *  setCalibrationMatrix() and getDisplayPoint() will do fine
- *  for you as they are, provided that your digitizer
- *  resolution does not exceed 10 bits (1024 values).  Higher
- *  resolutions may cause the integer operations to overflow
- *  and return incorrect values.  If you wish to use these
- *  functions with digitizer resolutions of 12 bits (4096
- *  values) you will either have to a) use 64-bit signed
- *  integer variables and math, or b) judiciously modify the
- *  operations to scale results by a factor of 2 or even 4.
- *
  */
 TouchCode_t RA8875::TouchPanelReadable(point_t * TouchPoint)
 {
     TouchCode_t ts = no_touch;
 
     if (useTouchPanel == TP_FT5206) {
-        INFO("TP_FT5206");
+        //INFO("TP_FT5206");
     } else if (useTouchPanel == TP_GSL1680) {
-        INFO("TP_GSL1680");
+        //INFO("TP_GSL1680");
     } else if (useTouchPanel == TP_RES) {
-        int a2dX = 0;
-        int a2dY = 0;
-
-        touchInfo[0].touchID = 0;
-        ts = TouchPanelA2DFiltered(&a2dX, &a2dY);
-        #ifdef DEBUG
-        static TouchCode_t tsLast;
-        if (tsLast != ts)
-            INFO("ts: %d", ts);
-        tsLast = ts;
-        #endif
-        if (ts != no_touch) {
-            panelTouched = true;
-            numberOfTouchPoints = 1;
-
-            if (tpMatrix.Divider != 0) {
-                /* Operation order is important since we are doing integer */
-                /*  math. Make sure you add all terms together before      */
-                /*  dividing, so that the remainder is not rounded off     */
-                /*  prematurely.                                           */
-                touchInfo[0].coordinates.x = ( (tpMatrix.An * a2dX) +
-                                  (tpMatrix.Bn * a2dY) + tpMatrix.Cn
-                                ) / tpMatrix.Divider ;
-                touchInfo[0].coordinates.y = ( (tpMatrix.Dn * a2dX) +
-                                  (tpMatrix.En * a2dY) + tpMatrix.Fn
-                                ) / tpMatrix.Divider ;
-            } else {
-                ts = no_cal;
-            }
-        } else {
-            numberOfTouchPoints = 0;
-        }
-        touchInfo[0].touchCode = ts;
+        ReadResistive();
     }
     // For Resistive touch, panelTouched is computed above.
     // For Cap Sense, panelTouched is set in another process
@@ -399,27 +316,22 @@
 {
     point_t newPoint = rawPoint;
 
-    #if 1
     switch (screen_orientation) {
         default:
         case rotate_0:
+        case rotate_180:
             newPoint = rawPoint;
             break;
         case rotate_90:
             newPoint.x = rawPoint.y;
-            newPoint.y = height() - rawPoint.x;
-            break;
-        case rotate_180:
-            newPoint.x = width() - rawPoint.x;
-            newPoint.y = height() - rawPoint.y;
+            newPoint.y = rawPoint.x;
             break;
         case rotate_270:
-            newPoint.x = height() - rawPoint.y;
+            newPoint.x = width() - rawPoint.y;
             newPoint.y = rawPoint.x;
             break;
     }
     //INFO("Translate(%3d x %3d) => (%3d x %3d)", rawPoint.x, rawPoint.y, newPoint.x, newPoint.y);
-    #endif
     return newPoint;
 }
 
@@ -475,6 +387,86 @@
     }
 }
 
+
+//  Description: Given a valid set of calibration factors and a point
+//                value reported by the touch screen, this function
+//                calculates and returns the true (or closest to true)
+//                display point below the spot where the touch screen
+//                was touched.
+//
+//  Argument(s): displayPtr (output) - Pointer to the calculated
+//                                      (true) display point.
+//               screenPtr (input) - Pointer to the reported touch
+//                                    screen point.
+//               matrixPtr (input) - Pointer to calibration factors
+//                                    matrix previously calculated
+//                                    from a call to
+//                                    setCalibrationMatrix()
+//
+//  The function simply solves for Xd and Yd by implementing the
+//   computations required by the translation matrix.
+//
+//                                              /-     -\   //
+//              /-    -\     /-            -\   |       |   //
+//              |      |     |              |   |   Xs  |   //
+//              |  Xd  |     | A    B    C  |   |       |   //
+//              |      |  =  |              | * |   Ys  |   //
+//              |  Yd  |     | D    E    F  |   |       |   //
+//              |      |     |              |   |   1   |   //
+//              \-    -/     \-            -/   |       |   //
+//                                              \-     -/   //
+//
+//  It must be kept brief to avoid consuming CPU cycles.
+//
+//       Return: OK - the display point was correctly calculated
+//                     and its value is in the output argument.
+//               NOT_OK - an error was detected and the function
+//                         failed to return a valid point.
+//
+//                 NOTE!    NOTE!    NOTE!
+//
+//  setCalibrationMatrix() and getDisplayPoint() will do fine
+//  for you as they are, provided that your digitizer
+//  resolution does not exceed 10 bits (1024 values).  Higher
+//  resolutions may cause the integer operations to overflow
+//  and return incorrect values.  If you wish to use these
+//  functions with digitizer resolutions of 12 bits (4096
+//  values) you will either have to a) use 64-bit signed
+//  integer variables and math, or b) judiciously modify the
+//  operations to scale results by a factor of 2 or even 4.
+//
+void RA8875::ReadResistive() {
+    TouchCode_t ts = no_touch;
+    int a2dX = 0;
+    int a2dY = 0;
+
+    touchInfo[0].touchID = 0;
+    ts = TouchPanelA2DFiltered(&a2dX, &a2dY);
+    if (ts != no_touch) {
+        panelTouched = true;
+        numberOfTouchPoints = 1;
+
+        if (tpMatrix.Divider != 0) {
+            /* Operation order is important since we are doing integer */
+            /*  math. Make sure you add all terms together before      */
+            /*  dividing, so that the remainder is not rounded off     */
+            /*  prematurely.                                           */
+            touchInfo[0].coordinates.x = ((tpMatrix.An * a2dX) +
+                (tpMatrix.Bn * a2dY) + tpMatrix.Cn
+                ) / tpMatrix.Divider;
+            touchInfo[0].coordinates.y = ((tpMatrix.Dn * a2dX) +
+                (tpMatrix.En * a2dY) + tpMatrix.Fn
+                ) / tpMatrix.Divider;
+        } else {
+            ts = no_cal;
+        }
+    } else {
+        numberOfTouchPoints = 0;
+    }
+    touchInfo[0].touchCode = ts;
+}
+
+
 TouchCode_t RA8875::TouchPanelA2DRaw(int *x, int *y)
 {
     INFO("A2Raw");
@@ -852,13 +844,16 @@
 void RA8875::TouchPanelISR(void)
 {
     if (useTouchPanel == TP_FT5206) {
-        if (FT5206_TouchPositions())
+        if (FT5206_TouchPositions()) {
             panelTouched = true;
+            timeSinceTouch.reset();
+        }
     } else if (useTouchPanel == TP_GSL1680) {
-        if (GSL1680_TouchPositions())
+        if (GSL1680_TouchPositions()) {
             panelTouched = true;
+            timeSinceTouch.reset();
+        }
     }
 }
 
-
 // #### end of touch panel code additions