forked from achillhasler/TFT_eTouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TFT_eTouch.h
132 lines (117 loc) · 3.88 KB
/
TFT_eTouch.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef TFT_E_TOUCH_H
#define TFT_E_TOUCH_H
//
// TFT_eTouch.h
//
// (C) Copyright Achill Hasler 2019.
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file at https://www.boost.org/LICENSE_1_0.txt
//
//
// See TFT_eTouch/docs/html/index.html for documentation.
//
#include <TFT_eTouchBase.h>
/**
* @brief touch support for tft
* @param T used display driver, must be Adafuit compatible
*/
template <class T>
class TFT_eTouch : public TFT_eTouchBase
{
public:
/**
* Create instance with defaults.
*
* Display and touch mostly use the same spi bus (SPI). This will by configured by the tft driver on tft.begin() and
* the touch driver use this configuration.
* When not you have to look that your used spi parameter get configured elsewhere bevor you call touch.begin().
* @brief constructor
* @param tft used display, must be Adafuit compatible
* @param cs_pin touch chip select line processor pin
* @param penirq_pin touch penirq line processor pin. 0xff disable touch interrupt
* @param spi used spi bus, configured by the tft driver
*/
TFT_eTouch(T& tft, uint8_t cs_pin, uint8_t penirq_pin = 0xff, SPIClass& spi = SPI);
/**
* Initialize the processor pins and initialize interrupt handling.
* @brief init touch
*/
void init();
/**
* Initialize the processor pins and initialize interrupt handling.
* @brief begin touch
*/
void begin();
/**
* Get Adafuit compatible display driver.
* @brief get display
* @return used display
*/
T& tft();
#ifdef TOUCH_USE_USER_CALIBRATION
/**
* Calculate the calibration values from 4 measures. User has to hit the blue target.
* If it is get red try it again til it is green and next target is shown.
* At the end a configuration string will be printed out to Serial.
* @brief get calibration from user
* @param data display coordinate of touch
* @param xy_off display coordinate of touch
* @return false on error otherwise data is set.
*/
bool getUserCalibration(Calibation& data, uint8_t xy_off);
#endif
/**
* Tranfom a raw touch measure into display position.
* The value tp is only set if the function returns true.
* @brief raw to display
* @param raw touch data
* @param tp display data
* @return true when raw data valid
*/
bool transform(const Measure& raw, TouchPoint& tp);
/**
* Get display position of touch.
* The values x and y are only set if the function returns true.
* @brief display position
* @param x display coordinate of touch
* @param y display coordinate of touch
* @return true when display is tuched
*/
bool getXY(int16_t& x, int16_t& y);
/**
* Get display position and touched area of touch.
* The value tp is only set if the function returns true.
* @brief touch display values
* @param tp touch
* @return true when display is tuched
*/
bool get(TouchPoint& tp);
#ifdef TOUCH_USE_PENIRQ_CODE
# ifdef ESP32
static void IRAM_ATTR cb_isr_touch_fnk();
# else
static void cb_isr_touch_fnk();
# endif
#endif // end TOUCH_USE_PENIRQ_CODE
private:
#ifdef TOUCH_USE_USER_CALIBRATION
/**
* Show one calibration target and get the raw touch values for that point.
* The Target get red when not accurate and function returns false.
* othewise the target get green and function returns true.
*
* If it is allways get red try a other configuration. see setAcurateDistance()
* @brief one calibration target
* @param point target, when the function returns true touch parameters are set.
* @return true when accurate
*/
bool handleTouchCalibrationTarget(CalibrationPoint& point);
#endif
T& tft_; ///< the given display driver
#ifdef TOUCH_USE_PENIRQ_CODE
static TFT_eTouch<T>* isr_instance_; ///< one instance used for interrupt handling
#endif // end TOUCH_USE_PENIRQ_CODE
};
#include <TFT_eTouch.inl>
#endif // TFT_E_TOUCH_H