Class to interface hardware of Touch point IC XPT2046.
More...
#include <XPT2046_TS_TFT_LCD_RDL.hpp>
|
struct | Touch_Point_t |
| Structure representing a touch point on the screen. This structure is used to define a touch area on the screen, x1and x2represent the horizontal boundaries of the touch region. y1 and y2 represent the vertical boundaries of the touch region. The id field is used to uniquely identify the touch point. More...
|
|
|
| XPT_2046_RDL () |
| Constructor for class XPT2046_RDL.
|
|
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.
|
|
bool | XPTIRQIsPressed () |
| Poll the IRQ pin.
|
|
rdlib::Return_Codes_e | XPTSPIend (void) |
| Stop the SPI interface.
|
|
int | XPTReadSensor (int command) |
| Read the touch screen sensor Data.
|
|
void | XPTReadXY (int *xp, int *yp) |
| Get the X Y position data.
|
|
void | XPTInitValues () |
| init values
|
|
void | XPTPrintValues () |
| print the touch point values if debug enabled
|
|
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.
|
|
int | XPTGetPoint () |
| Gets the touch point ID based on the current touch coordinates.
|
|
|
static constexpr uint8_t | XPT_START = 0x80 |
|
static constexpr uint8_t | XPT_XPOS = 0x50 |
|
static constexpr uint8_t | XPT_YPOS = 0x10 |
|
static constexpr uint8_t | XPT_8BIT = 0x08 |
|
static constexpr uint8_t | XPT_SER = 0x04 |
|
static constexpr uint8_t | XPT_DEF = 0x03 |
|
Class to interface hardware of Touch point IC XPT2046.
◆ XPTGetPoint()
int XPT_2046_RDL::XPTGetPoint |
( |
| ) |
|
Gets the touch point ID based on the current touch coordinates.
This function reads the X and Y touch coordinates, performs a range check, and then scales the coordinates based on predefined minimum and maximum values for both the touch screen and the display. It ensures no double-touch is registered by checking the time between touch events, and returns the ID of the touch point if it lies within the specified touch areas.
- Returns
- The ID of the touch point if it lies within a valid region, or -1 if no valid touch is detected or double-touch is detected.
◆ XPTIRQIsPressed()
bool XPT_2046_RDL::XPTIRQIsPressed |
( |
| ) |
|
Poll the IRQ pin.
- Returns
- true for touchpen down false for pen up
◆ XPTReadSensor()
int XPT_2046_RDL::XPTReadSensor |
( |
int |
command | ) |
|
Read the touch screen sensor Data.
- Parameters
-
command | the x or y position |
- Returns
- The readbuffer data
◆ XPTReadXY()
void XPT_2046_RDL::XPTReadXY |
( |
int * |
xp, |
|
|
int * |
yp |
|
) |
| |
Get the X Y position data.
- Parameters
-
xp | the X position |
yp | the Y position |
◆ XPTSetPoint()
void XPT_2046_RDL::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.
This function updates the touch point coordinates (x1
, y1
, x2
, y2
) and touch point ID (id
) for the touch controller. It ensures the coordinates are correctly ordered, swapping values if necessary (i.e., making sure that x1 <= x2
and y1 <= y2
). The function then stores the updated values into the tps
array at the current tpc
index, and increments tpc
to move to the next index.
- Parameters
-
x1 | The first x-coordinate to set. |
y1 | The first y-coordinate to set. |
x2 | The second x-coordinate to set. |
y2 | The second y-coordinate to set. |
id | The identifier for the touch point. |
◆ XPTSPIend()
◆ XPTSPIInit()
rdlib::Return_Codes_e XPT_2046_RDL::XPTSPIInit |
( |
int |
device, |
|
|
int |
channel, |
|
|
int |
speed, |
|
|
int |
flags, |
|
|
int |
gpioDev, |
|
|
uint8_t |
IRQPin, |
|
|
int8_t |
resPin |
|
) |
| |
Initialise the SPI interface.
- Parameters
-
device | A SPI device, >= 0. |
channel | A SPI channel, >= 0. |
speed | The speed of serial communication in bits per second. |
flags | The flags may be used to modify the default behaviour. Set to 0(mode 0) for this device. |
gpioDev | The device number of a gpiochip.
|
IRQPin | The GPIO to use for interrupt eg T_IRQ on ili9341 PCB |
resPin | GPIO for reset pin MOSI only needed if SPI not already on by TFT set to -1 normally |
- Returns
- Returns a rdlib::Return_Codes_e
- rdlib::Success
- rdlib::GpioChipDevice
- rdlib::GpioChipClaim
- rdlib::SPIOpenFailure
◆ _calibration
bool XPT_2046_RDL::_calibration |
|
private |
◆ _DeviceNumGpioChip
int XPT_2046_RDL::_DeviceNumGpioChip = 0 |
|
private |
The device number of a gpiochip ls /dev/gpio
◆ _GpioHandle
int XPT_2046_RDL::_GpioHandle = 0 |
|
private |
This holds a handle to a gpiochip device opened by lgGpiochipOpen
◆ _IRQ_PIN
uint8_t XPT_2046_RDL::_IRQ_PIN = 0 |
|
private |
Interrupt request GPIO pin
◆ _max_xc
int16_t XPT_2046_RDL::_max_xc |
|
private |
◆ _max_xp
int16_t XPT_2046_RDL::_max_xp |
|
private |
◆ _max_yc
int16_t XPT_2046_RDL::_max_yc |
|
private |
◆ _max_yp
int16_t XPT_2046_RDL::_max_yp |
|
private |
◆ _min_xc
int16_t XPT_2046_RDL::_min_xc |
|
private |
◆ _min_xp
int16_t XPT_2046_RDL::_min_xp |
|
private |
◆ _min_yc
int16_t XPT_2046_RDL::_min_yc |
|
private |
◆ _min_yp
int16_t XPT_2046_RDL::_min_yp |
|
private |
◆ _RESET_PIN
uint8_t XPT_2046_RDL::_RESET_PIN = 0 |
|
private |
◆ _resetXPTPinOn
bool XPT_2046_RDL::_resetXPTPinOn = false |
|
private |
Defines if reset pin is bring used
◆ _spiBaud
int XPT_2046_RDL::_spiBaud = 50000 |
|
private |
The speed of serial communication in bits per second.
◆ _spiChan
int XPT_2046_RDL::_spiChan = 1 |
|
private |
◆ _spiDev
int XPT_2046_RDL::_spiDev = 0 |
|
private |
◆ _spiFlags
int XPT_2046_RDL::_spiFlags = 0 |
|
private |
The flags 2 LSB defines SPI mode
◆ _spiHandle
int XPT_2046_RDL::_spiHandle = 0 |
|
private |
Hold a handle for the SPI device on the channel.
◆ DTMAX
constexpr uint32_t XPT_2046_RDL::DTMAX = 800000 |
|
staticconstexpr |
◆ lsec
time_t XPT_2046_RDL::lsec |
|
private |
Last recorded second for touch event timestamp
◆ lusec
suseconds_t XPT_2046_RDL::lusec |
|
private |
Last recorded microsecond for touch event timestamp
◆ MAX_LEN_BUFFER
constexpr uint8_t XPT_2046_RDL::MAX_LEN_BUFFER = 3 |
|
staticconstexpr |
Maximum length of RX and TX buffer
◆ MaxTouchPoints
constexpr auto XPT_2046_RDL::MaxTouchPoints = 20 |
|
staticconstexpr |
Maximum Number of Touch point's to record
◆ tpc
uint16_t XPT_2046_RDL::tpc |
|
private |
Number of touch points stored
◆ tps
◆ tpx
uint16_t XPT_2046_RDL::tpx |
|
private |
Maximum number of touch points
◆ XPT_8BIT
constexpr uint8_t XPT_2046_RDL::XPT_8BIT = 0x08 |
|
staticconstexprprivate |
◆ XPT_DEF
constexpr uint8_t XPT_2046_RDL::XPT_DEF = 0x03 |
|
staticconstexprprivate |
Differential Reference Select bit
◆ XPT_SER
constexpr uint8_t XPT_2046_RDL::XPT_SER = 0x04 |
|
staticconstexprprivate |
◆ XPT_START
constexpr uint8_t XPT_2046_RDL::XPT_START = 0x80 |
|
staticconstexprprivate |
Start bit Control Register
◆ XPT_XPOS
constexpr uint8_t XPT_2046_RDL::XPT_XPOS = 0x50 |
|
staticconstexprprivate |
A2-A0 Channel select bits for XPOS
◆ XPT_YPOS
constexpr uint8_t XPT_2046_RDL::XPT_YPOS = 0x10 |
|
staticconstexprprivate |
A2-A0 Channel select bits for YPOS
The documentation for this class was generated from the following files: