2019-07-14 23:16:26 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 14:00:57 +00:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2019-07-14 23:16:26 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
// Relies on XPT2046-compatible mode of ADS7843,
|
|
|
|
// hence no Z1 / Z2 measurements are possible.
|
|
|
|
|
|
|
|
#define XPT2046_DFR_MODE 0x00
|
|
|
|
#define XPT2046_SER_MODE 0x04
|
|
|
|
#define XPT2046_CONTROL 0x80
|
|
|
|
|
|
|
|
enum XPTCoordinate : uint8_t {
|
2019-07-17 09:41:10 +00:00
|
|
|
XPT2046_X = 0x10,
|
|
|
|
XPT2046_Y = 0x50,
|
|
|
|
XPT2046_Z1 = 0x30,
|
|
|
|
XPT2046_Z2 = 0x40
|
2019-07-14 23:16:26 +00:00
|
|
|
};
|
|
|
|
|
2019-07-30 22:08:11 +00:00
|
|
|
#ifndef XPT2046_Z1_THRESHOLD
|
|
|
|
#define XPT2046_Z1_THRESHOLD 10
|
|
|
|
#endif
|
2019-07-17 09:41:10 +00:00
|
|
|
|
2019-07-14 23:16:26 +00:00
|
|
|
class XPT2046 {
|
|
|
|
public:
|
2019-09-17 01:31:08 +00:00
|
|
|
static void init();
|
2019-07-14 23:16:26 +00:00
|
|
|
static uint8_t read_buttons();
|
2019-09-04 22:32:20 +00:00
|
|
|
bool getTouchPoint(uint16_t &x, uint16_t &y);
|
2019-07-17 09:41:10 +00:00
|
|
|
static bool isTouched();
|
2019-09-17 01:31:08 +00:00
|
|
|
inline void waitForRelease() { while (isTouched()) { /* nada */ } }
|
2019-09-04 22:32:20 +00:00
|
|
|
inline void waitForTouch(uint16_t &x, uint16_t &y) { while (!getTouchPoint(x, y)) { /* nada */ } }
|
|
|
|
private:
|
2019-07-14 23:16:26 +00:00
|
|
|
static uint16_t getInTouch(const XPTCoordinate coordinate);
|
|
|
|
};
|
|
|
|
|
|
|
|
extern XPT2046 touch;
|