Display_Lib_RPI 2.3.0
A C++ Library to connect electronic displays to Linux single board computers.
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Attributes | Private Attributes | Static Private Attributes | List of all members
XPT_2046_RDL Class Reference

Class to interface hardware of Touch point IC XPT2046. More...

#include <XPT2046_TS_TFT_LCD_RDL.hpp>

Classes

struct  Touch_Point_t
 Structure representing a touch point on the screen. This structure is used to define a touch area on the screen, x1andx2represent 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...
 

Public Member Functions

 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 Public Attributes

static constexpr auto MaxTouchPoints = 20
 
static constexpr uint8_t MAX_LEN_BUFFER = 3
 
static constexpr uint32_t DTMAX = 800000
 

Private Attributes

uint16_t tpc
 
uint16_t tpx
 
time_t lsec
 
suseconds_t lusec
 
Touch_Point_t tps [MaxTouchPoints]
 
bool _calibration
 
int16_t _min_xp
 
int16_t _min_yp
 
int16_t _max_xp
 
int16_t _max_yp
 
int16_t _min_xc
 
int16_t _min_yc
 
int16_t _max_xc
 
int16_t _max_yc
 
int _spiDev = 0
 
int _spiChan = 1
 
int _spiBaud = 50000
 
int _spiFlags = 0
 
int _spiHandle = 0
 
int _DeviceNumGpioChip = 0
 
int _GpioHandle = 0
 
uint8_t _RESET_PIN = 0
 
uint8_t _IRQ_PIN = 0
 
bool _resetXPTPinOn = false
 

Static Private Attributes

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
 

Detailed Description

Class to interface hardware of Touch point IC XPT2046.

Member Function Documentation

◆ 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
commandthe 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
xpthe X position
ypthe 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
x1The first x-coordinate to set.
y1The first y-coordinate to set.
x2The second x-coordinate to set.
y2The second y-coordinate to set.
idThe identifier for the touch point.

◆ XPTSPIend()

rdlib::Return_Codes_e XPT_2046_RDL::XPTSPIend ( void  )

◆ 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
deviceA SPI device, >= 0.
channelA SPI channel, >= 0.
speedThe speed of serial communication in bits per second.
flagsThe flags may be used to modify the default behaviour. Set to 0(mode 0) for this device.
gpioDevThe device number of a gpiochip.
IRQPinThe GPIO to use for interrupt eg T_IRQ on ili9341 PCB
resPinGPIO for reset pin MOSI only needed if SPI not already on by TFT set to -1 normally
Returns
Returns a rdlib::Return_Codes_e
  1. rdlib::Success
  2. rdlib::GpioChipDevice
  3. rdlib::GpioChipClaim
  4. rdlib::SPIOpenFailure

Member Data Documentation

◆ _calibration

bool XPT_2046_RDL::_calibration
private

Calibration flag

◆ _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

Maximum x coordinate

◆ _max_xp

int16_t XPT_2046_RDL::_max_xp
private

Maximum xp calibration

◆ _max_yc

int16_t XPT_2046_RDL::_max_yc
private

Maximum y coordinate

◆ _max_yp

int16_t XPT_2046_RDL::_max_yp
private

Maximum yp calibration

◆ _min_xc

int16_t XPT_2046_RDL::_min_xc
private

Minimum x coordinate

◆ _min_xp

int16_t XPT_2046_RDL::_min_xp
private

Minimum xp calibration

◆ _min_yc

int16_t XPT_2046_RDL::_min_yc
private

Minimum y coordinate

◆ _min_yp

int16_t XPT_2046_RDL::_min_yp
private

Minimum yp calibration

◆ _RESET_PIN

uint8_t XPT_2046_RDL::_RESET_PIN = 0
private

Reset pin for SPI

◆ _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

A SPI channel, >= 0.

◆ _spiDev

int XPT_2046_RDL::_spiDev = 0
private

A SPI device, >= 0.

◆ _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

Delay 800mS

◆ 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

Touch_Point_t XPT_2046_RDL::tps[MaxTouchPoints]
private

Array of touch points

◆ 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

Mode select 8 bit

◆ 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

Single-Ended Select bit

◆ 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: