Display_Lib_RPI 2.3.0
A C++ Library to connect electronic displays to Linux single board computers.
Loading...
Searching...
No Matches
XPT2046_TS_TFT_LCD_RDL.hpp
Go to the documentation of this file.
1
9#include <sys/time.h> // gettimeofday
10#include <cstdio> // for printf
11#include <cstdint>
12#include <cstdbool>
13#include <ctime> // for localtime etc
14#include <lgpio.h>
15#include "common_data_RDL.hpp"
16
17
22{
23
24public:
25
27 ~XPT_2046_RDL(){};
28
29 // SPI functions
30 rdlib::Return_Codes_e XPTSPIInit(int device, int channel, int speed, int flags, int gpioDev, uint8_t IRQPin ,int8_t resPin);
31 bool XPTIRQIsPressed();
33
34 // Read functions
35 int XPTReadSensor(int command);
36 void XPTReadXY( int *xp, int *yp);
37
38 // Calibration & debug Functions
39 void XPTInitValues();
40 void XPTPrintValues();
41 void XPTSetPoint(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t id);
42 int XPTGetPoint();
51 {
52 uint32_t x1;
53 uint32_t x2;
54 uint32_t y1;
55 uint32_t y2;
56 uint32_t id;
57 };
58
59 static constexpr auto MaxTouchPoints = 20;
60 static constexpr uint8_t MAX_LEN_BUFFER = 3;
61 static constexpr uint32_t DTMAX = 800000;
63private:
64 // Control Register
65 static constexpr uint8_t XPT_START = 0x80;
66 static constexpr uint8_t XPT_XPOS = 0x50;
67 static constexpr uint8_t XPT_YPOS = 0x10;
68 static constexpr uint8_t XPT_8BIT = 0x08;
69 static constexpr uint8_t XPT_SER = 0x04;
70 static constexpr uint8_t XPT_DEF = 0x03;
72 uint16_t tpc;
73 uint16_t tpx;
74 time_t lsec;
75 suseconds_t lusec;
79 int16_t _min_xp;
80 int16_t _min_yp;
81 int16_t _max_xp;
82 int16_t _max_yp;
83 int16_t _min_xc;
84 int16_t _min_yc;
85 int16_t _max_xc;
86 int16_t _max_yc;
89 // SPI related
90 int _spiDev = 0;
91 int _spiChan = 1;
92 int _spiBaud = 50000;
93 int _spiFlags = 0;
94 int _spiHandle = 0;
95 // GPIO
97 int _GpioHandle = 0;
98 uint8_t _RESET_PIN = 0;
99 uint8_t _IRQ_PIN = 0;
100 bool _resetXPTPinOn = false;
101};
Class to interface hardware of Touch point IC XPT2046.
Definition XPT2046_TS_TFT_LCD_RDL.hpp:22
int16_t _max_xc
Definition XPT2046_TS_TFT_LCD_RDL.hpp:85
static constexpr uint8_t XPT_DEF
Definition XPT2046_TS_TFT_LCD_RDL.hpp:70
static constexpr uint8_t XPT_XPOS
Definition XPT2046_TS_TFT_LCD_RDL.hpp:66
uint8_t _RESET_PIN
Definition XPT2046_TS_TFT_LCD_RDL.hpp:98
int _spiFlags
Definition XPT2046_TS_TFT_LCD_RDL.hpp:93
int16_t _min_yc
Definition XPT2046_TS_TFT_LCD_RDL.hpp:84
int _DeviceNumGpioChip
Definition XPT2046_TS_TFT_LCD_RDL.hpp:96
rdlib::Return_Codes_e XPTSPIInit(int device, int channel, int speed, int flags, int gpioDev, uint8_t IRQPin, int8_t resPin)
Initialise the SPI interface.
Definition XPT2046_TS_TFT_LCD_RDL.cpp:32
int _spiHandle
Definition XPT2046_TS_TFT_LCD_RDL.hpp:94
bool XPTIRQIsPressed()
Poll the IRQ pin.
Definition XPT2046_TS_TFT_LCD_RDL.cpp:152
static constexpr uint8_t XPT_YPOS
Definition XPT2046_TS_TFT_LCD_RDL.hpp:67
void XPTSetPoint(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t id)
Sets the touch points for the XPT_2046 touch controller.
Definition XPT2046_TS_TFT_LCD_RDL.cpp:245
static constexpr uint8_t XPT_START
Definition XPT2046_TS_TFT_LCD_RDL.hpp:65
int16_t _min_xc
Definition XPT2046_TS_TFT_LCD_RDL.hpp:83
time_t lsec
Definition XPT2046_TS_TFT_LCD_RDL.hpp:74
int XPTReadSensor(int command)
Read the touch screen sensor Data.
Definition XPT2046_TS_TFT_LCD_RDL.cpp:173
static constexpr uint8_t MAX_LEN_BUFFER
Definition XPT2046_TS_TFT_LCD_RDL.hpp:60
int _spiDev
Definition XPT2046_TS_TFT_LCD_RDL.hpp:90
int16_t _min_xp
Definition XPT2046_TS_TFT_LCD_RDL.hpp:79
static constexpr uint32_t DTMAX
Definition XPT2046_TS_TFT_LCD_RDL.hpp:61
int _GpioHandle
Definition XPT2046_TS_TFT_LCD_RDL.hpp:97
int16_t _min_yp
Definition XPT2046_TS_TFT_LCD_RDL.hpp:80
void XPTPrintValues()
print the touch point values if debug enabled
Definition XPT2046_TS_TFT_LCD_RDL.cpp:218
suseconds_t lusec
Definition XPT2046_TS_TFT_LCD_RDL.hpp:75
Touch_Point_t tps[MaxTouchPoints]
Definition XPT2046_TS_TFT_LCD_RDL.hpp:76
XPT_2046_RDL()
Constructor for class XPT2046_RDL.
Definition XPT2046_TS_TFT_LCD_RDL.cpp:13
int _spiBaud
Definition XPT2046_TS_TFT_LCD_RDL.hpp:92
int16_t _max_xp
Definition XPT2046_TS_TFT_LCD_RDL.hpp:81
static constexpr uint8_t XPT_8BIT
Definition XPT2046_TS_TFT_LCD_RDL.hpp:68
int _spiChan
Definition XPT2046_TS_TFT_LCD_RDL.hpp:91
rdlib::Return_Codes_e XPTSPIend(void)
Stop the SPI interface.
Definition XPT2046_TS_TFT_LCD_RDL.cpp:93
uint16_t tpx
Definition XPT2046_TS_TFT_LCD_RDL.hpp:73
void XPTReadXY(int *xp, int *yp)
Get the X Y position data.
Definition XPT2046_TS_TFT_LCD_RDL.cpp:199
static constexpr uint8_t XPT_SER
Definition XPT2046_TS_TFT_LCD_RDL.hpp:69
int16_t _max_yp
Definition XPT2046_TS_TFT_LCD_RDL.hpp:82
void XPTInitValues()
init values
Definition XPT2046_TS_TFT_LCD_RDL.cpp:208
bool _calibration
Definition XPT2046_TS_TFT_LCD_RDL.hpp:77
static constexpr auto MaxTouchPoints
Definition XPT2046_TS_TFT_LCD_RDL.hpp:59
int16_t _max_yc
Definition XPT2046_TS_TFT_LCD_RDL.hpp:86
uint8_t _IRQ_PIN
Definition XPT2046_TS_TFT_LCD_RDL.hpp:99
uint16_t tpc
Definition XPT2046_TS_TFT_LCD_RDL.hpp:72
bool _resetXPTPinOn
Definition XPT2046_TS_TFT_LCD_RDL.hpp:100
int XPTGetPoint()
Gets the touch point ID based on the current touch coordinates.
Definition XPT2046_TS_TFT_LCD_RDL.cpp:277
file to hold common data and functions used by many Displays Project Name: Display_Lib_RPI
Return_Codes_e
Definition common_data_RDL.hpp:22
Structure representing a touch point on the screen. This structure is used to define a touch area on ...
Definition XPT2046_TS_TFT_LCD_RDL.hpp:51
uint32_t y2
Definition XPT2046_TS_TFT_LCD_RDL.hpp:55
uint32_t x1
Definition XPT2046_TS_TFT_LCD_RDL.hpp:52
uint32_t x2
Definition XPT2046_TS_TFT_LCD_RDL.hpp:53
uint32_t y1
Definition XPT2046_TS_TFT_LCD_RDL.hpp:54
uint32_t id
Definition XPT2046_TS_TFT_LCD_RDL.hpp:56