Display_Lib_RPI 2.4.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#pragma once
18
23{
24
25public:
26
28 ~XPT_2046_RDL(){};
29
30 // SPI functions
31 rdlib::Return_Codes_e XPTSPIInit(int device, int channel, int speed, int flags, int gpioDev, uint8_t IRQPin ,int8_t resPin);
32 bool XPTIRQIsPressed();
34
35 // Read functions
36 int XPTReadSensor(int command);
37 void XPTReadXY( int *xp, int *yp);
38
39 // Calibration & debug Functions
40 void XPTInitValues();
41 void XPTPrintValues();
42 void XPTSetPoint(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t id);
43 int XPTGetPoint();
52 {
53 uint32_t x1;
54 uint32_t x2;
55 uint32_t y1;
56 uint32_t y2;
57 uint32_t id;
58 };
59
60 static constexpr auto MaxTouchPoints = 20;
61 static constexpr uint8_t MAX_LEN_BUFFER = 3;
62 static constexpr uint32_t DTMAX = 800000;
64private:
65 // Control Register
66 static constexpr uint8_t XPT_START = 0x80;
67 static constexpr uint8_t XPT_XPOS = 0x50;
68 static constexpr uint8_t XPT_YPOS = 0x10;
69 static constexpr uint8_t XPT_8BIT = 0x08;
70 static constexpr uint8_t XPT_SER = 0x04;
71 static constexpr uint8_t XPT_DEF = 0x03;
73 uint16_t tpc;
74 uint16_t tpx;
75 time_t lsec;
76 suseconds_t lusec;
80 int16_t _min_xp;
81 int16_t _min_yp;
82 int16_t _max_xp;
83 int16_t _max_yp;
84 int16_t _min_xc;
85 int16_t _min_yc;
86 int16_t _max_xc;
87 int16_t _max_yc;
90 // SPI related
91 int _spiDev = 0;
92 int _spiChan = 1;
93 int _spiBaud = 50000;
94 int _spiFlags = 0;
95 int _spiHandle = 0;
96 // GPIO
98 int _GpioHandle = 0;
99 uint8_t _RESET_PIN = 0;
100 uint8_t _IRQ_PIN = 0;
101 bool _resetXPTPinOn = false;
102};
Class to interface hardware of Touch point IC XPT2046.
Definition XPT2046_TS_TFT_LCD_RDL.hpp:23
int16_t _max_xc
Definition XPT2046_TS_TFT_LCD_RDL.hpp:86
static constexpr uint8_t XPT_DEF
Definition XPT2046_TS_TFT_LCD_RDL.hpp:71
static constexpr uint8_t XPT_XPOS
Definition XPT2046_TS_TFT_LCD_RDL.hpp:67
uint8_t _RESET_PIN
Definition XPT2046_TS_TFT_LCD_RDL.hpp:99
int _spiFlags
Definition XPT2046_TS_TFT_LCD_RDL.hpp:94
int16_t _min_yc
Definition XPT2046_TS_TFT_LCD_RDL.hpp:85
int _DeviceNumGpioChip
Definition XPT2046_TS_TFT_LCD_RDL.hpp:97
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:95
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:68
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:66
int16_t _min_xc
Definition XPT2046_TS_TFT_LCD_RDL.hpp:84
time_t lsec
Definition XPT2046_TS_TFT_LCD_RDL.hpp:75
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:61
int _spiDev
Definition XPT2046_TS_TFT_LCD_RDL.hpp:91
int16_t _min_xp
Definition XPT2046_TS_TFT_LCD_RDL.hpp:80
static constexpr uint32_t DTMAX
Definition XPT2046_TS_TFT_LCD_RDL.hpp:62
int _GpioHandle
Definition XPT2046_TS_TFT_LCD_RDL.hpp:98
int16_t _min_yp
Definition XPT2046_TS_TFT_LCD_RDL.hpp:81
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:76
Touch_Point_t tps[MaxTouchPoints]
Definition XPT2046_TS_TFT_LCD_RDL.hpp:77
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:93
int16_t _max_xp
Definition XPT2046_TS_TFT_LCD_RDL.hpp:82
static constexpr uint8_t XPT_8BIT
Definition XPT2046_TS_TFT_LCD_RDL.hpp:69
int _spiChan
Definition XPT2046_TS_TFT_LCD_RDL.hpp:92
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:74
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:70
int16_t _max_yp
Definition XPT2046_TS_TFT_LCD_RDL.hpp:83
void XPTInitValues()
init values
Definition XPT2046_TS_TFT_LCD_RDL.cpp:208
bool _calibration
Definition XPT2046_TS_TFT_LCD_RDL.hpp:78
static constexpr auto MaxTouchPoints
Definition XPT2046_TS_TFT_LCD_RDL.hpp:60
int16_t _max_yc
Definition XPT2046_TS_TFT_LCD_RDL.hpp:87
uint8_t _IRQ_PIN
Definition XPT2046_TS_TFT_LCD_RDL.hpp:100
uint16_t tpc
Definition XPT2046_TS_TFT_LCD_RDL.hpp:73
bool _resetXPTPinOn
Definition XPT2046_TS_TFT_LCD_RDL.hpp:101
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:52
uint32_t y2
Definition XPT2046_TS_TFT_LCD_RDL.hpp:56
uint32_t x1
Definition XPT2046_TS_TFT_LCD_RDL.hpp:53
uint32_t x2
Definition XPT2046_TS_TFT_LCD_RDL.hpp:54
uint32_t y1
Definition XPT2046_TS_TFT_LCD_RDL.hpp:55
uint32_t id
Definition XPT2046_TS_TFT_LCD_RDL.hpp:57