Skip to content

Commit 403f51a

Browse files
committed
feat(touch): add spi xpt2046
Closes #18
1 parent be924cc commit 403f51a

40 files changed

+1524
-38
lines changed

ESP_Panel_Board_Custom.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@
212212
* - CST816S
213213
* - FT5x06
214214
* - GT911, GT1151
215+
* - ST7123
215216
* - TT21100
217+
* - XPT2046
216218
*/
217219
#define ESP_PANEL_TOUCH_NAME TT21100
218220

@@ -229,7 +231,7 @@
229231
/**
230232
* Touch panel bus type. Choose one of the following:
231233
* - ESP_PANEL_BUS_TYPE_I2C
232-
* - ESP_PANEL_BUS_TYPE_SPI (not ready)
234+
* - ESP_PANEL_BUS_TYPE_SPI
233235
*/
234236
#define ESP_PANEL_TOUCH_BUS_TYPE (ESP_PANEL_BUS_TYPE_I2C)
235237
/* Touch panel bus parameters */
@@ -246,6 +248,18 @@
246248
#define ESP_PANEL_TOUCH_I2C_IO_SDA (8)
247249
#endif
248250

251+
#elif ESP_PANEL_TOUCH_BUS_TYPE == ESP_PANEL_BUS_TYPE_SPI
252+
253+
#define ESP_PANEL_TOUCH_BUS_HOST_ID (1) // Typically set to 1
254+
#define ESP_PANEL_TOUCH_SPI_IO_CS (5)
255+
#if !ESP_PANEL_TOUCH_BUS_SKIP_INIT_HOST
256+
#define ESP_PANEL_TOUCH_SPI_IO_SCK (7)
257+
#define ESP_PANEL_TOUCH_SPI_IO_MOSI (6)
258+
#define ESP_PANEL_TOUCH_SPI_IO_MISO (9)
259+
#endif
260+
#define ESP_PANEL_TOUCH_SPI_CLK_HZ (1 * 1000 * 1000)
261+
// Should be an integer divisor of 80M, typically set to 1M
262+
249263
#else
250264

251265
#error "The function is not ready and will be implemented in the future."

ESP_Panel_Conf.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,36 @@
2525

2626
/* Maximum button number */
2727
#define ESP_PANEL_TOUCH_MAX_BUTTONS (1)
28+
29+
/* Model configurations */
30+
// XPT2046
31+
#define ESP_PANEL_TOUCH_XPT2046_Z_THRESHOLD (400) // Minimum Z pressure threshold
32+
/**
33+
* Enable Interrupt (PENIRQ) output, also called Full Power Mode.
34+
* Enable this to configure the XPT2046 to output low on the PENIRQ output if a touch is detected.
35+
* This mode uses more power when enabled. Note that this signal goes low normally when a read is active.
36+
*/
37+
#define ESP_PANEL_TOUCH_XPT2046_INTERRUPT_MODE (0) // 0/1
38+
/**
39+
* Keep internal Vref enabled.
40+
* Enable this to keep the internal Vref enabled between conversions. This uses slightly more power,
41+
* but requires fewer transactions when reading the battery voltage, aux voltage and temperature.
42+
*
43+
*/
44+
#define ESP_PANEL_TOUCH_XPT2046_VREF_ON_MODE (0) // 0/1
45+
/**
46+
* Convert touch coordinates to screen coordinates.
47+
* When this option is enabled the raw ADC values will be converted from 0-4096 to 0-{screen width} or 0-{screen height}.
48+
* When this option is disabled the process_coordinates method will need to be used to convert the raw ADC values into a
49+
* screen coordinate.
50+
*
51+
*/
52+
#define ESP_PANEL_TOUCH_XPT2046_CONVERT_ADC_TO_COORDS (1) // 0/1
53+
/**
54+
* Enable data structure locking.
55+
* By enabling this option the XPT2046 driver will lock the touch position data structures when reading values from the
56+
* XPT2046 and when reading position data via API.
57+
* WARNING: enabling this option may result in unintended crashes.
58+
*
59+
*/
60+
#define ESP_PANEL_TOUCH_XPT2046_ENABLE_LOCKING (0) // 0/1

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,14 @@ Below is a list of [supported touch controllers](src/touch/README.md):
8686
| GOODiX | GT911, GT1151 |
8787
| Sitronix | ST7123 |
8888
| Parade | TT21100 |
89+
| Xptek | XPT2046 |
8990

9091
## Dependencies and Versions
9192

9293
| **Dependency** | **Version** |
9394
| -------------- | ----------- |
9495
| [arduino-esp32](https://github.com/espressif/arduino-esp32) | >= v3.0.3 |
95-
| [ESP32_IO_Expander](https://github.com/esp-arduino-libs/ESP32_IO_Expander) | >= v0.0.1 |
96+
| [ESP32_IO_Expander](https://github.com/esp-arduino-libs/ESP32_IO_Expander) | >= 0.0.1 && < 0.1.0 |
9697

9798
## How to Use
9899

@@ -270,6 +271,7 @@ The following examples demonstrate how to develop different interface and model
270271
The following example demonstrates how to develop touch screens of different interfaces and models using standalone drivers and test them by printing touch point coordinates:
271272

272273
* [I2C](examples/Touch/I2C/)
274+
* [SPI](examples/Touch/SPI/)
273275

274276
#### Panel
275277

README_CN.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,14 @@ ESP32_Display_Panel 的功能框图如下所示,主要包含以下特性:
8686
| GOODiX | GT911, GT1151 |
8787
| Sitronix | ST7123 |
8888
| Parade | TT21100 |
89+
| Xptek | XPT2046 |
8990

9091
## 依赖项及版本
9192

9293
| **依赖项** | **版本** |
9394
| ---------- | -------- |
9495
| [arduino-esp32](https://github.com/espressif/arduino-esp32) | >= v3.0.3 |
95-
| [ESP32_IO_Expander](https://github.com/esp-arduino-libs/ESP32_IO_Expander) | >= v0.0.1 |
96+
| [ESP32_IO_Expander](https://github.com/esp-arduino-libs/ESP32_IO_Expander) | >= 0.0.1 && < 0.1.0 |
9697

9798
## 如何使用
9899

@@ -270,6 +271,7 @@ ESP32_Display_Panel 会根据 [ESP_Panel_Board_Custom.h](./ESP_Panel_Board_Custo
270271
以下示例演示了如何使用独立的驱动开发不同接口和不同型号的触摸屏,并通过打印触摸点坐标进行测试:
271272

272273
* [I2C](examples/Touch/I2C/)
274+
* [SPI](examples/Touch/SPI/)
273275

274276
#### Panel
275277

check_copyright_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ DEFAULT:
77
# when setting this option in a section, you need to list all the allowed licenses
88
allowed_licenses:
99
- Apache-2.0
10+
- MIT
1011
license_for_new_files: Apache-2.0 # license to be used when inserting a new copyright notice
1112
new_notice_c: | # notice for new C, CPP, H, HPP and LD files
1213
/*

examples/LCD/3wireSPI_RGB/ESP_Panel_Conf.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,36 @@
2525

2626
/* Maximum button number */
2727
#define ESP_PANEL_TOUCH_MAX_BUTTONS (1)
28+
29+
/* Model configurations */
30+
// XPT2046
31+
#define ESP_PANEL_TOUCH_XPT2046_Z_THRESHOLD (400) // Minimum Z pressure threshold
32+
/**
33+
* Enable Interrupt (PENIRQ) output, also called Full Power Mode.
34+
* Enable this to configure the XPT2046 to output low on the PENIRQ output if a touch is detected.
35+
* This mode uses more power when enabled. Note that this signal goes low normally when a read is active.
36+
*/
37+
#define ESP_PANEL_TOUCH_XPT2046_INTERRUPT_MODE (0) // 0/1
38+
/**
39+
* Keep internal Vref enabled.
40+
* Enable this to keep the internal Vref enabled between conversions. This uses slightly more power,
41+
* but requires fewer transactions when reading the battery voltage, aux voltage and temperature.
42+
*
43+
*/
44+
#define ESP_PANEL_TOUCH_XPT2046_VREF_ON_MODE (0) // 0/1
45+
/**
46+
* Convert touch coordinates to screen coordinates.
47+
* When this option is enabled the raw ADC values will be converted from 0-4096 to 0-{screen width} or 0-{screen height}.
48+
* When this option is disabled the process_coordinates method will need to be used to convert the raw ADC values into a
49+
* screen coordinate.
50+
*
51+
*/
52+
#define ESP_PANEL_TOUCH_XPT2046_CONVERT_ADC_TO_COORDS (1) // 0/1
53+
/**
54+
* Enable data structure locking.
55+
* By enabling this option the XPT2046 driver will lock the touch position data structures when reading values from the
56+
* XPT2046 and when reading position data via API.
57+
* WARNING: enabling this option may result in unintended crashes.
58+
*
59+
*/
60+
#define ESP_PANEL_TOUCH_XPT2046_ENABLE_LOCKING (0) // 0/1

examples/LCD/QSPI/ESP_Panel_Conf.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,36 @@
2525

2626
/* Maximum button number */
2727
#define ESP_PANEL_TOUCH_MAX_BUTTONS (1)
28+
29+
/* Model configurations */
30+
// XPT2046
31+
#define ESP_PANEL_TOUCH_XPT2046_Z_THRESHOLD (400) // Minimum Z pressure threshold
32+
/**
33+
* Enable Interrupt (PENIRQ) output, also called Full Power Mode.
34+
* Enable this to configure the XPT2046 to output low on the PENIRQ output if a touch is detected.
35+
* This mode uses more power when enabled. Note that this signal goes low normally when a read is active.
36+
*/
37+
#define ESP_PANEL_TOUCH_XPT2046_INTERRUPT_MODE (0) // 0/1
38+
/**
39+
* Keep internal Vref enabled.
40+
* Enable this to keep the internal Vref enabled between conversions. This uses slightly more power,
41+
* but requires fewer transactions when reading the battery voltage, aux voltage and temperature.
42+
*
43+
*/
44+
#define ESP_PANEL_TOUCH_XPT2046_VREF_ON_MODE (0) // 0/1
45+
/**
46+
* Convert touch coordinates to screen coordinates.
47+
* When this option is enabled the raw ADC values will be converted from 0-4096 to 0-{screen width} or 0-{screen height}.
48+
* When this option is disabled the process_coordinates method will need to be used to convert the raw ADC values into a
49+
* screen coordinate.
50+
*
51+
*/
52+
#define ESP_PANEL_TOUCH_XPT2046_CONVERT_ADC_TO_COORDS (1) // 0/1
53+
/**
54+
* Enable data structure locking.
55+
* By enabling this option the XPT2046 driver will lock the touch position data structures when reading values from the
56+
* XPT2046 and when reading position data via API.
57+
* WARNING: enabling this option may result in unintended crashes.
58+
*
59+
*/
60+
#define ESP_PANEL_TOUCH_XPT2046_ENABLE_LOCKING (0) // 0/1

examples/LCD/RGB/ESP_Panel_Conf.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,36 @@
2525

2626
/* Maximum button number */
2727
#define ESP_PANEL_TOUCH_MAX_BUTTONS (1)
28+
29+
/* Model configurations */
30+
// XPT2046
31+
#define ESP_PANEL_TOUCH_XPT2046_Z_THRESHOLD (400) // Minimum Z pressure threshold
32+
/**
33+
* Enable Interrupt (PENIRQ) output, also called Full Power Mode.
34+
* Enable this to configure the XPT2046 to output low on the PENIRQ output if a touch is detected.
35+
* This mode uses more power when enabled. Note that this signal goes low normally when a read is active.
36+
*/
37+
#define ESP_PANEL_TOUCH_XPT2046_INTERRUPT_MODE (0) // 0/1
38+
/**
39+
* Keep internal Vref enabled.
40+
* Enable this to keep the internal Vref enabled between conversions. This uses slightly more power,
41+
* but requires fewer transactions when reading the battery voltage, aux voltage and temperature.
42+
*
43+
*/
44+
#define ESP_PANEL_TOUCH_XPT2046_VREF_ON_MODE (0) // 0/1
45+
/**
46+
* Convert touch coordinates to screen coordinates.
47+
* When this option is enabled the raw ADC values will be converted from 0-4096 to 0-{screen width} or 0-{screen height}.
48+
* When this option is disabled the process_coordinates method will need to be used to convert the raw ADC values into a
49+
* screen coordinate.
50+
*
51+
*/
52+
#define ESP_PANEL_TOUCH_XPT2046_CONVERT_ADC_TO_COORDS (1) // 0/1
53+
/**
54+
* Enable data structure locking.
55+
* By enabling this option the XPT2046 driver will lock the touch position data structures when reading values from the
56+
* XPT2046 and when reading position data via API.
57+
* WARNING: enabling this option may result in unintended crashes.
58+
*
59+
*/
60+
#define ESP_PANEL_TOUCH_XPT2046_ENABLE_LOCKING (0) // 0/1

examples/LCD/SPI/ESP_Panel_Conf.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,36 @@
2525

2626
/* Maximum button number */
2727
#define ESP_PANEL_TOUCH_MAX_BUTTONS (1)
28+
29+
/* Model configurations */
30+
// XPT2046
31+
#define ESP_PANEL_TOUCH_XPT2046_Z_THRESHOLD (400) // Minimum Z pressure threshold
32+
/**
33+
* Enable Interrupt (PENIRQ) output, also called Full Power Mode.
34+
* Enable this to configure the XPT2046 to output low on the PENIRQ output if a touch is detected.
35+
* This mode uses more power when enabled. Note that this signal goes low normally when a read is active.
36+
*/
37+
#define ESP_PANEL_TOUCH_XPT2046_INTERRUPT_MODE (0) // 0/1
38+
/**
39+
* Keep internal Vref enabled.
40+
* Enable this to keep the internal Vref enabled between conversions. This uses slightly more power,
41+
* but requires fewer transactions when reading the battery voltage, aux voltage and temperature.
42+
*
43+
*/
44+
#define ESP_PANEL_TOUCH_XPT2046_VREF_ON_MODE (0) // 0/1
45+
/**
46+
* Convert touch coordinates to screen coordinates.
47+
* When this option is enabled the raw ADC values will be converted from 0-4096 to 0-{screen width} or 0-{screen height}.
48+
* When this option is disabled the process_coordinates method will need to be used to convert the raw ADC values into a
49+
* screen coordinate.
50+
*
51+
*/
52+
#define ESP_PANEL_TOUCH_XPT2046_CONVERT_ADC_TO_COORDS (1) // 0/1
53+
/**
54+
* Enable data structure locking.
55+
* By enabling this option the XPT2046 driver will lock the touch position data structures when reading values from the
56+
* XPT2046 and when reading position data via API.
57+
* WARNING: enabling this option may result in unintended crashes.
58+
*
59+
*/
60+
#define ESP_PANEL_TOUCH_XPT2046_ENABLE_LOCKING (0) // 0/1

examples/LVGL/v8/Porting/ESP_Panel_Board_Custom.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@
212212
* - CST816S
213213
* - FT5x06
214214
* - GT911, GT1151
215+
* - ST7123
215216
* - TT21100
217+
* - XPT2046
216218
*/
217219
#define ESP_PANEL_TOUCH_NAME TT21100
218220

@@ -229,7 +231,7 @@
229231
/**
230232
* Touch panel bus type. Choose one of the following:
231233
* - ESP_PANEL_BUS_TYPE_I2C
232-
* - ESP_PANEL_BUS_TYPE_SPI (not ready)
234+
* - ESP_PANEL_BUS_TYPE_SPI
233235
*/
234236
#define ESP_PANEL_TOUCH_BUS_TYPE (ESP_PANEL_BUS_TYPE_I2C)
235237
/* Touch panel bus parameters */
@@ -246,6 +248,18 @@
246248
#define ESP_PANEL_TOUCH_I2C_IO_SDA (8)
247249
#endif
248250

251+
#elif ESP_PANEL_TOUCH_BUS_TYPE == ESP_PANEL_BUS_TYPE_SPI
252+
253+
#define ESP_PANEL_TOUCH_BUS_HOST_ID (1) // Typically set to 1
254+
#define ESP_PANEL_TOUCH_SPI_IO_CS (5)
255+
#if !ESP_PANEL_TOUCH_BUS_SKIP_INIT_HOST
256+
#define ESP_PANEL_TOUCH_SPI_IO_SCK (7)
257+
#define ESP_PANEL_TOUCH_SPI_IO_MOSI (6)
258+
#define ESP_PANEL_TOUCH_SPI_IO_MISO (9)
259+
#endif
260+
#define ESP_PANEL_TOUCH_SPI_CLK_HZ (1 * 1000 * 1000)
261+
// Should be an integer divisor of 80M, typically set to 1M
262+
249263
#else
250264

251265
#error "The function is not ready and will be implemented in the future."

examples/LVGL/v8/Porting/ESP_Panel_Conf.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,36 @@
2525

2626
/* Maximum button number */
2727
#define ESP_PANEL_TOUCH_MAX_BUTTONS (1)
28+
29+
/* Model configurations */
30+
// XPT2046
31+
#define ESP_PANEL_TOUCH_XPT2046_Z_THRESHOLD (400) // Minimum Z pressure threshold
32+
/**
33+
* Enable Interrupt (PENIRQ) output, also called Full Power Mode.
34+
* Enable this to configure the XPT2046 to output low on the PENIRQ output if a touch is detected.
35+
* This mode uses more power when enabled. Note that this signal goes low normally when a read is active.
36+
*/
37+
#define ESP_PANEL_TOUCH_XPT2046_INTERRUPT_MODE (0) // 0/1
38+
/**
39+
* Keep internal Vref enabled.
40+
* Enable this to keep the internal Vref enabled between conversions. This uses slightly more power,
41+
* but requires fewer transactions when reading the battery voltage, aux voltage and temperature.
42+
*
43+
*/
44+
#define ESP_PANEL_TOUCH_XPT2046_VREF_ON_MODE (0) // 0/1
45+
/**
46+
* Convert touch coordinates to screen coordinates.
47+
* When this option is enabled the raw ADC values will be converted from 0-4096 to 0-{screen width} or 0-{screen height}.
48+
* When this option is disabled the process_coordinates method will need to be used to convert the raw ADC values into a
49+
* screen coordinate.
50+
*
51+
*/
52+
#define ESP_PANEL_TOUCH_XPT2046_CONVERT_ADC_TO_COORDS (1) // 0/1
53+
/**
54+
* Enable data structure locking.
55+
* By enabling this option the XPT2046 driver will lock the touch position data structures when reading values from the
56+
* XPT2046 and when reading position data via API.
57+
* WARNING: enabling this option may result in unintended crashes.
58+
*
59+
*/
60+
#define ESP_PANEL_TOUCH_XPT2046_ENABLE_LOCKING (0) // 0/1

examples/LVGL/v8/Rotation/ESP_Panel_Board_Custom.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@
212212
* - CST816S
213213
* - FT5x06
214214
* - GT911, GT1151
215+
* - ST7123
215216
* - TT21100
217+
* - XPT2046
216218
*/
217219
#define ESP_PANEL_TOUCH_NAME TT21100
218220

@@ -229,7 +231,7 @@
229231
/**
230232
* Touch panel bus type. Choose one of the following:
231233
* - ESP_PANEL_BUS_TYPE_I2C
232-
* - ESP_PANEL_BUS_TYPE_SPI (not ready)
234+
* - ESP_PANEL_BUS_TYPE_SPI
233235
*/
234236
#define ESP_PANEL_TOUCH_BUS_TYPE (ESP_PANEL_BUS_TYPE_I2C)
235237
/* Touch panel bus parameters */
@@ -246,6 +248,18 @@
246248
#define ESP_PANEL_TOUCH_I2C_IO_SDA (8)
247249
#endif
248250

251+
#elif ESP_PANEL_TOUCH_BUS_TYPE == ESP_PANEL_BUS_TYPE_SPI
252+
253+
#define ESP_PANEL_TOUCH_BUS_HOST_ID (1) // Typically set to 1
254+
#define ESP_PANEL_TOUCH_SPI_IO_CS (5)
255+
#if !ESP_PANEL_TOUCH_BUS_SKIP_INIT_HOST
256+
#define ESP_PANEL_TOUCH_SPI_IO_SCK (7)
257+
#define ESP_PANEL_TOUCH_SPI_IO_MOSI (6)
258+
#define ESP_PANEL_TOUCH_SPI_IO_MISO (9)
259+
#endif
260+
#define ESP_PANEL_TOUCH_SPI_CLK_HZ (1 * 1000 * 1000)
261+
// Should be an integer divisor of 80M, typically set to 1M
262+
249263
#else
250264

251265
#error "The function is not ready and will be implemented in the future."

0 commit comments

Comments
 (0)