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)

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Tue Nov 13 01:33:41 2018 +0000
Parent:
154:ad2450fc3dc3
Child:
156:4bdb2772128d
Commit message:
use eventThread for newer OS5 in place of callbacks.; touch-cal timeout increased to 30s from 15.

Changed in this revision

RA8875.cpp Show annotated file Show diff for this revision Revisions of this file
RA8875.h 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/RA8875.cpp	Fri Aug 17 01:29:06 2018 +0000
+++ b/RA8875.cpp	Tue Nov 13 01:33:41 2018 +0000
@@ -142,7 +142,10 @@
     // Interrupt
     m_irq->mode(PullUp);
     m_irq->enable_irq();
-    #if (MBED_MAJOR_VERSION >= 5) || (MBED_LIBRARY_VERSION > 128)   // Is this the right version?
+    #if MBED_VERSION >= MBED_ENCODE_VERSION(5,8,0)
+    eventThread.start(callback(&queue, &EventQueue::dispatch_forever));
+    m_irq->fall(queue.event(callback(this, &RA8875::TouchPanelISR)));
+    #elif (MBED_MAJOR_VERSION >= 5) || (MBED_LIBRARY_VERSION > 128)   // Is this the right version?
     m_irq->fall(callback(this, &RA8875::TouchPanelISR));
     #else
     m_irq->fall(this, &RA8875::TouchPanelISR);
--- a/RA8875.h	Fri Aug 17 01:29:06 2018 +0000
+++ b/RA8875.h	Tue Nov 13 01:33:41 2018 +0000
@@ -1006,10 +1006,10 @@
     ///             non-volatile memory to recover the calibration after a power fail.
     /// @param[in] maxwait_s is the maximum number of seconds to wait for a touch
     ///             calibration. If no touch panel installed, it then reports
-    ///             touch_cal_timeout.
+    ///             touch_cal_timeout. Default: 30 s.
     /// @returns success/failure code. See @ref RetCode_t.
     ///
-    RetCode_t TouchPanelCalibrate(const char * msg, tpMatrix_t * matrix = NULL, int maxwait_s = 15);
+    RetCode_t TouchPanelCalibrate(const char * msg, tpMatrix_t * matrix = NULL, int maxwait_s = 30);
 
 
     /// Set the calibration matrix for the touch panel.
@@ -2791,6 +2791,10 @@
 
     touchInfo_T touchInfo[5];   /// Contains the actual touch information in an array from 0 to n-1
 
+    #if MBED_VERSION >= MBED_ENCODE_VERSION(5,8,0)
+    Thread eventThread;
+    EventQueue queue;
+    #endif
     InterruptIn * m_irq;
     I2C * m_i2c;
     int m_addr;
--- a/RA8875_Touch.cpp	Fri Aug 17 01:29:06 2018 +0000
+++ b/RA8875_Touch.cpp	Tue Nov 13 01:33:41 2018 +0000
@@ -60,8 +60,10 @@
     panelTouched = false;
     if (useTouchPanel == TP_CAP) {
         // Set to normal mode
+        INFO("TouchPanelInit: TP_CAP");
         writeRegister8(FT5206_DEVICE_MODE, 0);
     } else {
+        INFO("TouchPanelInit: TP_RES");
         //TPCR0: Set enable bit, default sample time, wakeup, and ADC clock
         WriteCommand(TPCR0, TP_ENABLE | TP_ADC_SAMPLE_DEFAULT_CLKS | TP_ADC_CLKDIV_DEFAULT);
         // TPCR1: Set auto/manual, Ref voltage, debounce, manual mode params
@@ -87,8 +89,10 @@
 RetCode_t RA8875::TouchPanelInit(uint8_t bTpEnable, uint8_t bTpAutoManual, uint8_t bTpDebounce, uint8_t bTpManualMode, uint8_t bTpAdcClkDiv, uint8_t bTpAdcSampleTime)
 {
     if (useTouchPanel == TP_CAP) {
+        INFO("TouchPanelInit: TP_CAP");
         TouchPanelInit();
     } else {
+        INFO("TouchPanelInit: TP_RES");
         // Parameter bounds check
         if( \
                 !(bTpEnable == TP_ENABLE || bTpEnable == TP_ENABLE) || \
@@ -320,6 +324,8 @@
         if (TouchPoint) {
             *TouchPoint = touchInfo[0].coordinates;
             ts = touchInfo[0].touchCode;
+            INFO("Touch[0] %2d (%4d,%4d)", touchInfo[0].touchCode,
+                touchInfo[0].coordinates.x, touchInfo[0].coordinates.y);
         } else {
             ts = touch;
         }
@@ -376,6 +382,7 @@
 
 void RA8875::_TouchTicker(void)
 {
+    INFO("_TouchTicker()");
     if (touchTimer.read_us() > NOTOUCH_TIMEOUT_uS) {
         touchSample = 0;
         if (touchState == held)
@@ -694,7 +701,9 @@
 uint8_t RA8875::readRegister8(uint8_t reg) {
     char val;
     
+    //INFO("readRegister8(%02X) @ %X", reg, m_i2c);
     m_i2c->write(m_addr, (const char *)&reg, 1);
+    //INFO("  write(%X, ...)", m_addr);
     m_i2c->read(m_addr, &val, 1);
     return (uint8_t)val;
 }
@@ -711,16 +720,21 @@
 // Interrupt for touch detection
 void RA8875::TouchPanelISR(void)
 {
-    getTouchPositions();
-    panelTouched = true;
+    //INFO("TouchPanelISR()");
+    if (getTouchPositions())
+        panelTouched = true;
+    //INFO("   return");
 }
 
 uint8_t RA8875::getTouchPositions(void) {
     uint8_t valXH;
     uint8_t valYH;
 
+    //INFO("getTouchPositions()");
     numberOfTouchPoints = readRegister8(FT5206_TD_STATUS) & 0xF;
+    //INFO("  numOfTouchPoints %d", numberOfTouchPoints);
     gesture = readRegister8(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).
@@ -733,34 +747,69 @@
             touchInfo[4].touchID   = (valYH >> 4);
             touchInfo[4].coordinates.x = (valXH & 0x0f)*256 + readRegister8(FT5206_TOUCH5_XL);
             touchInfo[4].coordinates.y = (valYH & 0x0f)*256 + readRegister8(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  = readRegister8(FT5206_TOUCH4_XH);
             valYH  = readRegister8(FT5206_TOUCH4_YH);
             touchInfo[3].touchCode = EventFlagToTouchCode[valXH >> 6];
             touchInfo[3].touchID   = (valYH >> 4);
-            touchInfo[3].coordinates.x = (readRegister8(FT5206_TOUCH4_XH) & 0x0f)*256 + readRegister8(FT5206_TOUCH4_XL);
+            touchInfo[3].coordinates.x = (valXH & 0x0f)*256 + readRegister8(FT5206_TOUCH4_XL);
             touchInfo[3].coordinates.y = (valYH & 0x0f)*256 + readRegister8(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  = readRegister8(FT5206_TOUCH3_XH);
             valYH  = readRegister8(FT5206_TOUCH3_YH);
             touchInfo[2].touchCode = EventFlagToTouchCode[valXH >> 6];
             touchInfo[2].touchID   = (valYH >> 4);
-            touchInfo[2].coordinates.x = (readRegister8(FT5206_TOUCH3_XH) & 0x0f)*256 + readRegister8(FT5206_TOUCH3_XL);
+            touchInfo[2].coordinates.x = (valXH & 0x0f)*256 + readRegister8(FT5206_TOUCH3_XL);
             touchInfo[2].coordinates.y = (valYH & 0x0f)*256 + readRegister8(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  = readRegister8(FT5206_TOUCH2_XH);
             valYH  = readRegister8(FT5206_TOUCH2_YH);
             touchInfo[1].touchCode = EventFlagToTouchCode[valXH >> 6];
             touchInfo[1].touchID   = (valYH >> 4);
-            touchInfo[1].coordinates.x  = (readRegister8(FT5206_TOUCH2_XH) & 0x0f)*256 + readRegister8(FT5206_TOUCH2_XL);
-            touchInfo[1].coordinates.y  = (valYH & 0x0f)*256 + readRegister8(FT5206_TOUCH2_YL);
+            touchInfo[1].coordinates.x = (valXH & 0x0f)*256 + readRegister8(FT5206_TOUCH2_XL);
+            touchInfo[1].coordinates.y = (valYH & 0x0f)*256 + readRegister8(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  = readRegister8(FT5206_TOUCH1_XH);
             valYH  = readRegister8(FT5206_TOUCH1_YH);
             touchInfo[0].touchCode = EventFlagToTouchCode[valXH >> 6];
             touchInfo[0].touchID   = (valYH >> 4);
-            touchInfo[0].coordinates.x = (readRegister8(FT5206_TOUCH1_XH) & 0x0f)*256 + readRegister8(FT5206_TOUCH1_XL);
+            touchInfo[0].coordinates.x = (valXH & 0x0f)*256 + readRegister8(FT5206_TOUCH1_XL);
             touchInfo[0].coordinates.y = (valYH & 0x0f)*256 + readRegister8(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;