Prusa MINI Firmware overview
xpt2046.h
Go to the documentation of this file.
1 /**
2  * Marlin 3D Printer Firmware
3  * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  */
19 #pragma once
20 
21 #include <stdint.h>
22 
23 // Relies on XPT2046-compatible mode of ADS7843,
24 // hence no Z1 / Z2 measurements are possible.
25 
26 #define XPT2046_DFR_MODE 0x00
27 #define XPT2046_SER_MODE 0x04
28 #define XPT2046_CONTROL 0x80
29 
31  XPT2046_X = 0x10,
32  XPT2046_Y = 0x50,
33  XPT2046_Z1 = 0x30,
34  XPT2046_Z2 = 0x40
35 };
36 
37 #ifndef XPT2046_Z1_THRESHOLD
38  #define XPT2046_Z1_THRESHOLD 10
39 #endif
40 
41 class XPT2046 {
42 public:
43  static void init();
44  static uint8_t read_buttons();
45  bool getTouchPoint(uint16_t &x, uint16_t &y);
46  static bool isTouched();
47  inline void waitForRelease() { while (isTouched()) { /* nada */ } }
48  inline void waitForTouch(uint16_t &x, uint16_t &y) { while (!getTouchPoint(x, y)) { /* nada */ } }
49 private:
50  static uint16_t getInTouch(const XPTCoordinate coordinate);
51 };
52 
53 extern XPT2046 touch;
XPT2046_CONTROL
#define XPT2046_CONTROL
Definition: xpt2046.h:28
WITHIN
#define WITHIN(N, L, H)
Definition: macros.h:195
XPT2046::init
static void init()
OUT_WRITE
#define OUT_WRITE(IO, V)
Definition: fastio.h:108
XPT2046::isTouched
static bool isTouched()
XPTCoordinate
XPTCoordinate
Definition: xpt2046.h:30
touch
XPT2046 touch
LOW
#define LOW
Definition: wiring_constants.h:70
XPT2046_X
Definition: xpt2046.h:31
_MAX
#define _MAX(V...)
Definition: macros.h:346
data
uint8_t data[8]
Definition: masstorage.h:49
i
uint8_t i
Definition: screen_test_graph.c:72
_MIN
#define _MIN(V...)
Definition: macros.h:333
XPT2046::waitForTouch
void waitForTouch(uint16_t &x, uint16_t &y)
Definition: xpt2046.h:48
SET_OUTPUT
#define SET_OUTPUT(IO)
Definition: fastio.h:101
xpt2046.h
XPT2046_Z1
Definition: xpt2046.h:33
XPT2046_DFR_MODE
#define XPT2046_DFR_MODE
Definition: xpt2046.h:26
SET_INPUT
#define SET_INPUT(IO)
Definition: fastio.h:99
XPT2046::getTouchPoint
bool getTouchPoint(uint16_t &x, uint16_t &y)
XPT2046
Definition: xpt2046.h:41
WRITE
#define WRITE(IO, V)
Definition: fastio.h:96
PIN_EXISTS
#define PIN_EXISTS(V...)
Definition: macros.h:188
XPT2046_Z2
Definition: xpt2046.h:34
uint8_t
const uint8_t[]
Definition: 404_html.c:3
XPT2046_Y
Definition: xpt2046.h:32
XPT2046::read_buttons
static uint8_t read_buttons()
HIGH
#define HIGH
Definition: wiring_constants.h:71
XPT2046_Z1_THRESHOLD
#define XPT2046_Z1_THRESHOLD
Definition: xpt2046.h:38
READ
#define READ(IO)
Definition: fastio.h:95
XPT2046::waitForRelease
void waitForRelease()
Definition: xpt2046.h:47