Browse Source

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

pull/1/head
Tanguy Pruvot 5 years ago
committed by Scott Lahteine
parent
commit
9dfa5ba3a5
  1. 23
      Marlin/src/feature/touch/xpt2046.cpp
  2. 7
      Marlin/src/feature/touch/xpt2046.h
  3. 3
      Marlin/src/pins/pinsDebug_list.h

23
Marlin/src/feature/touch/xpt2046.cpp

@ -44,13 +44,16 @@ XPT2046 touch;
extern int8_t encoderDiff;
void XPT2046::init(void) {
SET_INPUT(TOUCH_INT_PIN); // Pendrive interrupt pin, used as polling in getInTouch
SET_INPUT(TOUCH_MISO_PIN);
SET_OUTPUT(TOUCH_MOSI_PIN);
OUT_WRITE(TOUCH_SCK_PIN, 0);
SET_OUTPUT(TOUCH_SCK_PIN);
OUT_WRITE(TOUCH_CS_PIN, 1);
#if PIN_EXISTS(TOUCH_INT)
// Optional Pendrive interrupt pin
SET_INPUT(TOUCH_INT_PIN);
#endif
// Read once to enable pendrive status pin
getInTouch(XPT2046_X);
}
@ -74,10 +77,10 @@ uint8_t XPT2046::read_buttons() {
// We rely on XPT2046 compatible mode to ADS7843, hence no Z1 and Z2 measurements possible.
if (READ(TOUCH_INT_PIN)) return 0; // If HIGH there are no screen presses.
if (!isTouched()) return 0;
const uint16_t x = uint16_t(((uint32_t(getInTouch(XPT2046_X))) * tsoffsets[0]) >> 16) + tsoffsets[1],
y = uint16_t(((uint32_t(getInTouch(XPT2046_Y))) * tsoffsets[2]) >> 16) + tsoffsets[3];
if (READ(TOUCH_INT_PIN)) return 0; // Fingers must still be on the TS for a valid read.
if (!isTouched()) return 0; // Fingers must still be on the TS for a valid read.
if (y < 185 || y > 224) return 0;
@ -88,6 +91,16 @@ uint8_t XPT2046::read_buttons() {
return 0;
}
bool XPT2046::isTouched() {
return (
#if PIN_EXISTS(TOUCH_INT)
READ(TOUCH_INT_PIN) != HIGH
#else
getInTouch(XPT2046_Z1) >= XPT2046_Z1_TRESHHOLD
#endif
);
}
uint16_t XPT2046::getInTouch(const XPTCoordinate coordinate) {
uint16_t data[3];

7
Marlin/src/feature/touch/xpt2046.h

@ -29,14 +29,19 @@
enum XPTCoordinate : uint8_t {
XPT2046_X = 0x10,
XPT2046_Y = 0x50
XPT2046_Y = 0x50,
XPT2046_Z1 = 0x30,
XPT2046_Z2 = 0x40
};
#define XPT2046_Z1_TRESHHOLD 10
class XPT2046 {
public:
static void init(void);
static uint8_t read_buttons();
private:
static bool isTouched();
static uint16_t getInTouch(const XPTCoordinate coordinate);
};

3
Marlin/src/pins/pinsDebug_list.h

@ -1172,3 +1172,6 @@
#if PIN_EXISTS(TOUCH_CS)
REPORT_NAME_DIGITAL(__LINE__, TOUCH_CS_PIN)
#endif
#if PIN_EXISTS(TOUCH_INT)
REPORT_NAME_DIGITAL(__LINE__, TOUCH_INT_PIN)
#endif

Loading…
Cancel
Save