|
@@ -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
|
|