28 #ifndef _LCDGFX_TOUCH_XPT2046_H_ 29 #define _LCDGFX_TOUCH_XPT2046_H_ 113 return m_calibration;
122 m_pressureThreshold = threshold;
132 bool readRaw(int16_t &rawX, int16_t &rawY, int16_t &rawZ)
137 rawZ = (int16_t)(z1 + (4095 - z2));
141 for (
int i = 0; i < 3; i++ )
148 rawX = (int16_t)median3(xs[0], xs[1], xs[2]);
149 rawY = (int16_t)median3(ys[0], ys[1], ys[2]);
150 return z1 > m_pressureThreshold;
157 bool read(int16_t &x, int16_t &y)
159 int16_t rawX, rawY, rawZ;
160 bool pressed = readRaw(rawX, rawY, rawZ);
165 m_calibration.apply(rawX, rawY, x, y);
173 bool read(int16_t &x, int16_t &y, int16_t &pressure)
176 bool pressed = readRaw(rawX, rawY, pressure);
181 m_calibration.apply(rawX, rawY, x, y);
188 uint16_t m_pressureThreshold = 200;
190 uint16_t sampleChannel(uint8_t cmd)
193 uint8_t hi = m_spi.transfer(0x00);
194 uint8_t lo = m_spi.transfer(0x00);
197 return (uint16_t)(((uint16_t)hi << 5) | (lo >> 3)) & 0x0FFF;
200 static uint16_t median3(uint16_t a, uint16_t b, uint16_t c)
LcdGfxXpt2046(SpiT &spi)
Constructs the driver around an SPI transport instance owned by the caller.
bool read(int16_t &x, int16_t &y)
Reads calibrated screen-pixel coordinates.
XPT2046 control byte definitions.
Driver for the XPT2046 resistive touch controller (also compatible with ADS7843 / TSC2046 silicon)...
constexpr uint8_t CMD_X
1 101 0 0 11 - read X (differential, 12-bit)
Generic touch driver interfaces and calibration helpers.
constexpr uint8_t CMD_Z1
1 011 0 0 11 - read Z1
void setPressureThreshold(uint16_t threshold)
Sets the minimum pressure (Z1 reading) considered an active touch.
void setCalibration(const TouchCalibration &cal)
Sets the calibration used by read().
void end()
Releases the SPI transport.
Linear calibration mapping raw ADC counts from a resistive touch panel into screen pixel coordinates...
bool read(int16_t &x, int16_t &y, int16_t &pressure)
Reads calibrated coordinates plus raw pressure.
constexpr uint8_t CMD_Z2
1 100 0 0 11 - read Z2
bool readRaw(int16_t &rawX, int16_t &rawY, int16_t &rawZ)
Reads raw 12-bit ADC samples from the controller without applying any calibration.
TouchCalibration & calibration()
Returns the current calibration (mutable reference).
void begin()
Initialises the SPI transport.
constexpr uint8_t CMD_Y
1 001 0 0 11 - read Y