Selaa lähdekoodia

XPT2046: Handle MKS touchscreen w/out PenIRQ pin (#14640)

Tanguy Pruvot 5 vuotta sitten
vanhempi
commit
9dfa5ba3a5

+ 18
- 5
Marlin/src/feature/touch/xpt2046.cpp Näytä tiedosto

@@ -44,13 +44,16 @@ XPT2046 touch;
44 44
 extern int8_t encoderDiff;
45 45
 
46 46
 void XPT2046::init(void) {
47
-  SET_INPUT(TOUCH_INT_PIN); // Pendrive interrupt pin, used as polling in getInTouch
48 47
   SET_INPUT(TOUCH_MISO_PIN);
49 48
   SET_OUTPUT(TOUCH_MOSI_PIN);
50
-
51
-  OUT_WRITE(TOUCH_SCK_PIN, 0);
49
+  SET_OUTPUT(TOUCH_SCK_PIN);
52 50
   OUT_WRITE(TOUCH_CS_PIN, 1);
53 51
 
52
+  #if PIN_EXISTS(TOUCH_INT)
53
+    // Optional Pendrive interrupt pin
54
+    SET_INPUT(TOUCH_INT_PIN);
55
+  #endif
56
+
54 57
   // Read once to enable pendrive status pin
55 58
   getInTouch(XPT2046_X);
56 59
 }
@@ -74,10 +77,10 @@ uint8_t XPT2046::read_buttons() {
74 77
 
75 78
   // We rely on XPT2046 compatible mode to ADS7843, hence no Z1 and Z2 measurements possible.
76 79
 
77
-  if (READ(TOUCH_INT_PIN)) return 0; // If HIGH there are no screen presses.
80
+  if (!isTouched()) return 0;
78 81
   const uint16_t x = uint16_t(((uint32_t(getInTouch(XPT2046_X))) * tsoffsets[0]) >> 16) + tsoffsets[1],
79 82
                  y = uint16_t(((uint32_t(getInTouch(XPT2046_Y))) * tsoffsets[2]) >> 16) + tsoffsets[3];
80
-  if (READ(TOUCH_INT_PIN)) return 0; // Fingers must still be on the TS for a valid read.
83
+  if (!isTouched()) return 0; // Fingers must still be on the TS for a valid read.
81 84
 
82 85
   if (y < 185 || y > 224) return 0;
83 86
 
@@ -88,6 +91,16 @@ uint8_t XPT2046::read_buttons() {
88 91
   return 0;
89 92
 }
90 93
 
94
+bool XPT2046::isTouched() {
95
+  return (
96
+    #if PIN_EXISTS(TOUCH_INT)
97
+      READ(TOUCH_INT_PIN) != HIGH
98
+    #else
99
+      getInTouch(XPT2046_Z1) >= XPT2046_Z1_TRESHHOLD
100
+    #endif
101
+  );
102
+}
103
+
91 104
 uint16_t XPT2046::getInTouch(const XPTCoordinate coordinate) {
92 105
   uint16_t data[3];
93 106
 

+ 7
- 2
Marlin/src/feature/touch/xpt2046.h Näytä tiedosto

@@ -28,15 +28,20 @@
28 28
 #define XPT2046_CONTROL  0x80
29 29
 
30 30
 enum XPTCoordinate : uint8_t {
31
-  XPT2046_X = 0x10,
32
-  XPT2046_Y = 0x50
31
+  XPT2046_X  = 0x10,
32
+  XPT2046_Y  = 0x50,
33
+  XPT2046_Z1 = 0x30,
34
+  XPT2046_Z2 = 0x40
33 35
 };
34 36
 
37
+#define XPT2046_Z1_TRESHHOLD 10
38
+
35 39
 class XPT2046 {
36 40
 public:
37 41
   static void init(void);
38 42
   static uint8_t read_buttons();
39 43
 private:
44
+  static bool isTouched();
40 45
   static uint16_t getInTouch(const XPTCoordinate coordinate);
41 46
 };
42 47
 

+ 3
- 0
Marlin/src/pins/pinsDebug_list.h Näytä tiedosto

@@ -1172,3 +1172,6 @@
1172 1172
 #if PIN_EXISTS(TOUCH_CS)
1173 1173
   REPORT_NAME_DIGITAL(__LINE__, TOUCH_CS_PIN)
1174 1174
 #endif
1175
+#if PIN_EXISTS(TOUCH_INT)
1176
+  REPORT_NAME_DIGITAL(__LINE__, TOUCH_INT_PIN)
1177
+#endif

Loading…
Peruuta
Tallenna