1 # Touch input (XPT2046)
3 `lcdgfx` v1.3.0 ships a templated XPT2046 resistive-touch driver in
4 `src/touch/xpt2046.h`. The driver is transport-agnostic: any class
5 exposing `begin()`, `end()`, and `transfer(uint8_t)` works.
9 | XPT2046 | MCU pin (typical) |
10 |---------|-------------------|
12 | `T_DIN` | SPI MOSI |
15 | `T_IRQ` | any GPIO (optional, falling-edge) |
17 `T_CS` may safely be the same physical CS as a non-XPT slave on the
18 same bus as long as you select only one device at a time. The driver
19 uses 2.5 MHz SPI mode 0.
24 #include "lcdgfx_xpt2046.h" // pulled in by lcdgfx_gui.h
26 LcdGfxXpt2046<SPI> touch(/*cs*/ 8, /*irq*/ 9);
30 touch.setCalibration({ /*ax*/ 0.072f, /*bx*/ -16.0f,
31 /*ay*/ 0.085f, /*by*/ -12.0f,
32 /*swap*/ false, /*invert_x*/ false,
34 /*w*/ 240, /*h*/ 320 });
38 if (touch.isPressed()) {
40 if (touch.read(x, y)) menu.onTouch(x, y);
45 `TouchCalibration` performs a per-axis affine transform (`x' =
46 ax * raw + bx`) followed by optional axis swap, axis invert, and
47 output clamping. A 3-point or 5-point calibration helper is *not*
48 shipped — pick three on-screen targets, record the raw samples, and
51 See `examples/gui/touch_demo` for a full sketch.