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:
165:695c24cc5197
Child:
166:53fd4a876dac
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RA8875_Touch_FT5206.cpp	Sun Feb 24 00:40:00 2019 +0000
@@ -0,0 +1,149 @@
+
+
+#include "RA8875.h"
+
+//#define DEBUG "RAFT" // RA8875 FT5206
+// ...
+// INFO("Stuff to show %d", var); // new-line is automatically appended
+//
+#if (defined(DEBUG) && !defined(TARGET_LPC11U24))
+#define INFO(x, ...) std::printf("[INF %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
+#define WARN(x, ...) std::printf("[WRN %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
+#define ERR(x, ...)  std::printf("[ERR %s %4d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
+static void HexDump(const char * title, const uint8_t * p, int count)
+{
+    int i;
+    char buf[100] = "0000: ";
+
+    if (*title)
+        INFO("%s", title);
+    for (i=0; i<count; ) {
+        sprintf(buf + strlen(buf), "%02X ", *(p+i));
+        if ((++i & 0x0F) == 0x00) {
+            INFO("%s", buf);
+            if (i < count)
+                sprintf(buf, "%04X: ", i);
+            else
+                buf[0] = '\0';
+        }
+    }
+    if (strlen(buf))
+        INFO("%s", buf);
+}
+#else
+#define INFO(x, ...)
+#define WARN(x, ...)
+#define ERR(x, ...)
+#define HexDump(a, b, c)
+#endif
+
+
+
+// Translate from FT5206 Event Flag to Touch Code to API-match the
+// alternate resistive touch screen driver common in the RA8875
+// displays.
+static const TouchCode_t FT5206_EventFlagToTouchCode[4] = {
+    touch,      // 00b Put Down
+    release,    // 01b Put Up
+    held,       // 10b Contact
+    no_touch    // 11b Reserved
+};
+
+
+RetCode_t RA8875::FT5206_Init() {
+    char data[2] = {FT5206_DEVICE_MODE, 0};
+
+    m_i2c->write(m_addr, data, 2);
+    return noerror;
+}
+
+uint8_t RA8875::FT5206_TouchPositions(void) {
+    uint8_t valXH;
+    uint8_t valYH;
+
+    //INFO("FT5206_TouchPositions()");
+    numberOfTouchPoints = FT5206_ReadRegU8(FT5206_TD_STATUS) & 0xF;
+    //INFO("  numOfTouchPoints %d", numberOfTouchPoints);
+    gesture = FT5206_ReadRegU8(FT5206_GEST_ID);
+    //INFO("  gesture %d", gesture);
+    
+    // If the switch statement was based only on numberOfTouchPoints, it would not
+    // be able to generate notification for 'release' events (as it is no longer touched).
+    // Therefore, forcing a 5, and it intentionally falls through each lower case.
+    switch (5) {    // numberOfTouchPoints
+        case 5:
+            valXH  = FT5206_ReadRegU8(FT5206_TOUCH5_XH);
+            valYH  = FT5206_ReadRegU8(FT5206_TOUCH5_YH);
+            touchInfo[4].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
+            touchInfo[4].touchID   = (valYH >> 4);
+            touchInfo[4].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH5_XL);
+            touchInfo[4].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH5_YL);
+            if (touchInfo[4].touchCode)
+            INFO("  Touch[%d] code %d, id %2d, (%4d,%4d)",
+                5, 
+                touchInfo[4].touchCode, 
+                touchInfo[4].touchID,
+                touchInfo[4].coordinates.x, 
+                touchInfo[4].coordinates.y);
+        case 4:
+            valXH  = FT5206_ReadRegU8(FT5206_TOUCH4_XH);
+            valYH  = FT5206_ReadRegU8(FT5206_TOUCH4_YH);
+            touchInfo[3].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
+            touchInfo[3].touchID   = (valYH >> 4);
+            touchInfo[3].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH4_XL);
+            touchInfo[3].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH4_YL);
+            if (touchInfo[3].touchCode)
+            INFO("  Touch[%d] code %d, id %2d, (%4d,%4d)",
+                4, 
+                touchInfo[3].touchCode, 
+                touchInfo[3].touchID,
+                touchInfo[3].coordinates.x, 
+                touchInfo[3].coordinates.y);
+        case 3:
+            valXH  = FT5206_ReadRegU8(FT5206_TOUCH3_XH);
+            valYH  = FT5206_ReadRegU8(FT5206_TOUCH3_YH);
+            touchInfo[2].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
+            touchInfo[2].touchID   = (valYH >> 4);
+            touchInfo[2].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH3_XL);
+            touchInfo[2].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH3_YL);
+            if (touchInfo[2].touchCode)
+            INFO("  Touch[%d] code %d, id %2d, (%4d,%4d)",
+                3, 
+                touchInfo[2].touchCode, 
+                touchInfo[2].touchID,
+                touchInfo[2].coordinates.x, 
+                touchInfo[2].coordinates.y);
+        case 2:
+            valXH  = FT5206_ReadRegU8(FT5206_TOUCH2_XH);
+            valYH  = FT5206_ReadRegU8(FT5206_TOUCH2_YH);
+            touchInfo[1].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
+            touchInfo[1].touchID   = (valYH >> 4);
+            touchInfo[1].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH2_XL);
+            touchInfo[1].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH2_YL);
+            if (touchInfo[1].touchCode)
+            INFO("  Touch[%d] code %d, id %2d, (%4d,%4d)",
+                2, 
+                touchInfo[1].touchCode, 
+                touchInfo[1].touchID,
+                touchInfo[1].coordinates.x, 
+                touchInfo[1].coordinates.y);
+        case 1:
+            valXH  = FT5206_ReadRegU8(FT5206_TOUCH1_XH);
+            valYH  = FT5206_ReadRegU8(FT5206_TOUCH1_YH);
+            touchInfo[0].touchCode = FT5206_EventFlagToTouchCode[valXH >> 6];
+            touchInfo[0].touchID   = (valYH >> 4);
+            touchInfo[0].coordinates.x = (valXH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH1_XL);
+            touchInfo[0].coordinates.y = (valYH & 0x0f)*256 + FT5206_ReadRegU8(FT5206_TOUCH1_YL);
+            if (touchInfo[0].touchCode)
+            INFO("  Touch[%d] code %d, id %2d, (%4d,%4d)",
+                1, 
+                touchInfo[0].touchCode, 
+                touchInfo[0].touchID,
+                touchInfo[0].coordinates.x, 
+                touchInfo[0].coordinates.y);
+            break;
+        default:
+            break;
+    }
+    return numberOfTouchPoints;
+}