KSM edits to RA8875

Dependents:   Liz_Test_Code

Revision:
155:b3f225ae572c
Parent:
154:ad2450fc3dc3
Child:
157:1565f38ca44b
--- 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;