LCDGFX LCD display driver  1.2.0
Lightweight graphics library for SSD1306, SSD1325, SSD1327, SSD1331, SSD1351, SH1106, SH1107, IL9163, ST7735, ST7789, ILI9341, PCD8544 displays over I2C/SPI
LcdGfxXpt2046< SpiT > Class Template Reference

Driver for the XPT2046 resistive touch controller (also compatible with ADS7843 / TSC2046 silicon). More...

#include <xpt2046.h>

Public Member Functions

 LcdGfxXpt2046 (SpiT &spi)
 Constructs the driver around an SPI transport instance owned by the caller.
 
void begin ()
 Initialises the SPI transport. More...
 
void end ()
 Releases the SPI transport.
 
void setCalibration (const TouchCalibration &cal)
 Sets the calibration used by read(). More...
 
TouchCalibrationcalibration ()
 Returns the current calibration (mutable reference).
 
void setPressureThreshold (uint16_t threshold)
 Sets the minimum pressure (Z1 reading) considered an active touch. More...
 
bool readRaw (int16_t &rawX, int16_t &rawY, int16_t &rawZ)
 Reads raw 12-bit ADC samples from the controller without applying any calibration. More...
 
bool read (int16_t &x, int16_t &y)
 Reads calibrated screen-pixel coordinates. More...
 
bool read (int16_t &x, int16_t &y, int16_t &pressure)
 Reads calibrated coordinates plus raw pressure. More...
 

Detailed Description

template<typename SpiT>
class LcdGfxXpt2046< SpiT >

Driver for the XPT2046 resistive touch controller (also compatible with ADS7843 / TSC2046 silicon).

The driver is parameterized on a SPI transport type so it can be unit-tested with a mock and used on any platform without coupling to lcdgfx's display SPI configuration.

Template Parameters
SpiTSPI transport class. It must provide:
  • void begin();
  • void start(); // assert CS
  • void stop(); // de-assert CS
  • uint8_t transfer(uint8_t outByte); // full-duplex transfer of one byte
  • void end();

Definition at line 71 of file xpt2046.h.

Member Function Documentation

◆ begin()

template<typename SpiT>
void LcdGfxXpt2046< SpiT >::begin ( )
inline

Initialises the SPI transport.

The user is expected to have configured any platform-specific pins (CS, IRQ, MISO/MOSI/CLK) before calling.

Definition at line 86 of file xpt2046.h.

◆ read() [1/2]

template<typename SpiT>
bool LcdGfxXpt2046< SpiT >::read ( int16_t &  x,
int16_t &  y 
)
inline

Reads calibrated screen-pixel coordinates.

Returns true if a touch is detected (pressure above the threshold).

Definition at line 157 of file xpt2046.h.

◆ read() [2/2]

template<typename SpiT>
bool LcdGfxXpt2046< SpiT >::read ( int16_t &  x,
int16_t &  y,
int16_t &  pressure 
)
inline

Reads calibrated coordinates plus raw pressure.

Pressure is a dimensionless metric (higher = harder press) computed as Z1 + (4095-Z2).

Definition at line 173 of file xpt2046.h.

◆ readRaw()

template<typename SpiT>
bool LcdGfxXpt2046< SpiT >::readRaw ( int16_t &  rawX,
int16_t &  rawY,
int16_t &  rawZ 
)
inline

Reads raw 12-bit ADC samples from the controller without applying any calibration.

Returns true if pressure is above the threshold.

Three samples per axis are averaged with the smallest and largest discarded to suppress occasional spikes.

Definition at line 132 of file xpt2046.h.

◆ setCalibration()

template<typename SpiT>
void LcdGfxXpt2046< SpiT >::setCalibration ( const TouchCalibration cal)
inline

Sets the calibration used by read().

Defaults are reasonable for a typical 320x240 panel but most boards will need per-unit calibration.

Definition at line 103 of file xpt2046.h.

◆ setPressureThreshold()

template<typename SpiT>
void LcdGfxXpt2046< SpiT >::setPressureThreshold ( uint16_t  threshold)
inline

Sets the minimum pressure (Z1 reading) considered an active touch.

Default is 200; lower the threshold if your panel is less sensitive.

Definition at line 120 of file xpt2046.h.


The documentation for this class was generated from the following file: