Skip to content

feat(touch): add spi xpt2046 #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion ESP_Panel_Board_Custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@
* - CST816S
* - FT5x06
* - GT911, GT1151
* - ST7123
* - TT21100
* - XPT2046
*/
#define ESP_PANEL_TOUCH_NAME TT21100

Expand All @@ -229,7 +231,7 @@
/**
* Touch panel bus type. Choose one of the following:
* - ESP_PANEL_BUS_TYPE_I2C
* - ESP_PANEL_BUS_TYPE_SPI (not ready)
* - ESP_PANEL_BUS_TYPE_SPI
*/
#define ESP_PANEL_TOUCH_BUS_TYPE (ESP_PANEL_BUS_TYPE_I2C)
/* Touch panel bus parameters */
Expand All @@ -246,6 +248,18 @@
#define ESP_PANEL_TOUCH_I2C_IO_SDA (8)
#endif

#elif ESP_PANEL_TOUCH_BUS_TYPE == ESP_PANEL_BUS_TYPE_SPI

#define ESP_PANEL_TOUCH_BUS_HOST_ID (1) // Typically set to 1
#define ESP_PANEL_TOUCH_SPI_IO_CS (5)
#if !ESP_PANEL_TOUCH_BUS_SKIP_INIT_HOST
#define ESP_PANEL_TOUCH_SPI_IO_SCK (7)
#define ESP_PANEL_TOUCH_SPI_IO_MOSI (6)
#define ESP_PANEL_TOUCH_SPI_IO_MISO (9)
#endif
#define ESP_PANEL_TOUCH_SPI_CLK_HZ (1 * 1000 * 1000)
// Should be an integer divisor of 80M, typically set to 1M

#else

#error "The function is not ready and will be implemented in the future."
Expand Down
33 changes: 33 additions & 0 deletions ESP_Panel_Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,36 @@

/* Maximum button number */
#define ESP_PANEL_TOUCH_MAX_BUTTONS (1)

/* Model configurations */
// XPT2046
#define ESP_PANEL_TOUCH_XPT2046_Z_THRESHOLD (400) // Minimum Z pressure threshold
/**
* Enable Interrupt (PENIRQ) output, also called Full Power Mode.
* Enable this to configure the XPT2046 to output low on the PENIRQ output if a touch is detected.
* This mode uses more power when enabled. Note that this signal goes low normally when a read is active.
*/
#define ESP_PANEL_TOUCH_XPT2046_INTERRUPT_MODE (0) // 0/1
/**
* Keep internal Vref enabled.
* Enable this to keep the internal Vref enabled between conversions. This uses slightly more power,
* but requires fewer transactions when reading the battery voltage, aux voltage and temperature.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_VREF_ON_MODE (0) // 0/1
/**
* Convert touch coordinates to screen coordinates.
* When this option is enabled the raw ADC values will be converted from 0-4096 to 0-{screen width} or 0-{screen height}.
* When this option is disabled the process_coordinates method will need to be used to convert the raw ADC values into a
* screen coordinate.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_CONVERT_ADC_TO_COORDS (1) // 0/1
/**
* Enable data structure locking.
* By enabling this option the XPT2046 driver will lock the touch position data structures when reading values from the
* XPT2046 and when reading position data via API.
* WARNING: enabling this option may result in unintended crashes.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_ENABLE_LOCKING (0) // 0/1
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ Below is a list of [supported touch controllers](src/touch/README.md):
| GOODiX | GT911, GT1151 |
| Sitronix | ST7123 |
| Parade | TT21100 |
| Xptek | XPT2046 |

## Dependencies and Versions

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

## How to Use

Expand Down Expand Up @@ -270,6 +271,7 @@ The following examples demonstrate how to develop different interface and model
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:

* [I2C](examples/Touch/I2C/)
* [SPI](examples/Touch/SPI/)

#### Panel

Expand Down
4 changes: 3 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ ESP32_Display_Panel 的功能框图如下所示,主要包含以下特性:
| GOODiX | GT911, GT1151 |
| Sitronix | ST7123 |
| Parade | TT21100 |
| Xptek | XPT2046 |

## 依赖项及版本

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

## 如何使用

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

* [I2C](examples/Touch/I2C/)
* [SPI](examples/Touch/SPI/)

#### Panel

Expand Down
1 change: 1 addition & 0 deletions check_copyright_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ DEFAULT:
# when setting this option in a section, you need to list all the allowed licenses
allowed_licenses:
- Apache-2.0
- MIT
license_for_new_files: Apache-2.0 # license to be used when inserting a new copyright notice
new_notice_c: | # notice for new C, CPP, H, HPP and LD files
/*
Expand Down
33 changes: 33 additions & 0 deletions examples/LCD/3wireSPI_RGB/ESP_Panel_Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,36 @@

/* Maximum button number */
#define ESP_PANEL_TOUCH_MAX_BUTTONS (1)

/* Model configurations */
// XPT2046
#define ESP_PANEL_TOUCH_XPT2046_Z_THRESHOLD (400) // Minimum Z pressure threshold
/**
* Enable Interrupt (PENIRQ) output, also called Full Power Mode.
* Enable this to configure the XPT2046 to output low on the PENIRQ output if a touch is detected.
* This mode uses more power when enabled. Note that this signal goes low normally when a read is active.
*/
#define ESP_PANEL_TOUCH_XPT2046_INTERRUPT_MODE (0) // 0/1
/**
* Keep internal Vref enabled.
* Enable this to keep the internal Vref enabled between conversions. This uses slightly more power,
* but requires fewer transactions when reading the battery voltage, aux voltage and temperature.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_VREF_ON_MODE (0) // 0/1
/**
* Convert touch coordinates to screen coordinates.
* When this option is enabled the raw ADC values will be converted from 0-4096 to 0-{screen width} or 0-{screen height}.
* When this option is disabled the process_coordinates method will need to be used to convert the raw ADC values into a
* screen coordinate.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_CONVERT_ADC_TO_COORDS (1) // 0/1
/**
* Enable data structure locking.
* By enabling this option the XPT2046 driver will lock the touch position data structures when reading values from the
* XPT2046 and when reading position data via API.
* WARNING: enabling this option may result in unintended crashes.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_ENABLE_LOCKING (0) // 0/1
33 changes: 33 additions & 0 deletions examples/LCD/QSPI/ESP_Panel_Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,36 @@

/* Maximum button number */
#define ESP_PANEL_TOUCH_MAX_BUTTONS (1)

/* Model configurations */
// XPT2046
#define ESP_PANEL_TOUCH_XPT2046_Z_THRESHOLD (400) // Minimum Z pressure threshold
/**
* Enable Interrupt (PENIRQ) output, also called Full Power Mode.
* Enable this to configure the XPT2046 to output low on the PENIRQ output if a touch is detected.
* This mode uses more power when enabled. Note that this signal goes low normally when a read is active.
*/
#define ESP_PANEL_TOUCH_XPT2046_INTERRUPT_MODE (0) // 0/1
/**
* Keep internal Vref enabled.
* Enable this to keep the internal Vref enabled between conversions. This uses slightly more power,
* but requires fewer transactions when reading the battery voltage, aux voltage and temperature.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_VREF_ON_MODE (0) // 0/1
/**
* Convert touch coordinates to screen coordinates.
* When this option is enabled the raw ADC values will be converted from 0-4096 to 0-{screen width} or 0-{screen height}.
* When this option is disabled the process_coordinates method will need to be used to convert the raw ADC values into a
* screen coordinate.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_CONVERT_ADC_TO_COORDS (1) // 0/1
/**
* Enable data structure locking.
* By enabling this option the XPT2046 driver will lock the touch position data structures when reading values from the
* XPT2046 and when reading position data via API.
* WARNING: enabling this option may result in unintended crashes.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_ENABLE_LOCKING (0) // 0/1
33 changes: 33 additions & 0 deletions examples/LCD/RGB/ESP_Panel_Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,36 @@

/* Maximum button number */
#define ESP_PANEL_TOUCH_MAX_BUTTONS (1)

/* Model configurations */
// XPT2046
#define ESP_PANEL_TOUCH_XPT2046_Z_THRESHOLD (400) // Minimum Z pressure threshold
/**
* Enable Interrupt (PENIRQ) output, also called Full Power Mode.
* Enable this to configure the XPT2046 to output low on the PENIRQ output if a touch is detected.
* This mode uses more power when enabled. Note that this signal goes low normally when a read is active.
*/
#define ESP_PANEL_TOUCH_XPT2046_INTERRUPT_MODE (0) // 0/1
/**
* Keep internal Vref enabled.
* Enable this to keep the internal Vref enabled between conversions. This uses slightly more power,
* but requires fewer transactions when reading the battery voltage, aux voltage and temperature.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_VREF_ON_MODE (0) // 0/1
/**
* Convert touch coordinates to screen coordinates.
* When this option is enabled the raw ADC values will be converted from 0-4096 to 0-{screen width} or 0-{screen height}.
* When this option is disabled the process_coordinates method will need to be used to convert the raw ADC values into a
* screen coordinate.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_CONVERT_ADC_TO_COORDS (1) // 0/1
/**
* Enable data structure locking.
* By enabling this option the XPT2046 driver will lock the touch position data structures when reading values from the
* XPT2046 and when reading position data via API.
* WARNING: enabling this option may result in unintended crashes.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_ENABLE_LOCKING (0) // 0/1
33 changes: 33 additions & 0 deletions examples/LCD/SPI/ESP_Panel_Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,36 @@

/* Maximum button number */
#define ESP_PANEL_TOUCH_MAX_BUTTONS (1)

/* Model configurations */
// XPT2046
#define ESP_PANEL_TOUCH_XPT2046_Z_THRESHOLD (400) // Minimum Z pressure threshold
/**
* Enable Interrupt (PENIRQ) output, also called Full Power Mode.
* Enable this to configure the XPT2046 to output low on the PENIRQ output if a touch is detected.
* This mode uses more power when enabled. Note that this signal goes low normally when a read is active.
*/
#define ESP_PANEL_TOUCH_XPT2046_INTERRUPT_MODE (0) // 0/1
/**
* Keep internal Vref enabled.
* Enable this to keep the internal Vref enabled between conversions. This uses slightly more power,
* but requires fewer transactions when reading the battery voltage, aux voltage and temperature.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_VREF_ON_MODE (0) // 0/1
/**
* Convert touch coordinates to screen coordinates.
* When this option is enabled the raw ADC values will be converted from 0-4096 to 0-{screen width} or 0-{screen height}.
* When this option is disabled the process_coordinates method will need to be used to convert the raw ADC values into a
* screen coordinate.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_CONVERT_ADC_TO_COORDS (1) // 0/1
/**
* Enable data structure locking.
* By enabling this option the XPT2046 driver will lock the touch position data structures when reading values from the
* XPT2046 and when reading position data via API.
* WARNING: enabling this option may result in unintended crashes.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_ENABLE_LOCKING (0) // 0/1
16 changes: 15 additions & 1 deletion examples/LVGL/v8/Porting/ESP_Panel_Board_Custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@
* - CST816S
* - FT5x06
* - GT911, GT1151
* - ST7123
* - TT21100
* - XPT2046
*/
#define ESP_PANEL_TOUCH_NAME TT21100

Expand All @@ -229,7 +231,7 @@
/**
* Touch panel bus type. Choose one of the following:
* - ESP_PANEL_BUS_TYPE_I2C
* - ESP_PANEL_BUS_TYPE_SPI (not ready)
* - ESP_PANEL_BUS_TYPE_SPI
*/
#define ESP_PANEL_TOUCH_BUS_TYPE (ESP_PANEL_BUS_TYPE_I2C)
/* Touch panel bus parameters */
Expand All @@ -246,6 +248,18 @@
#define ESP_PANEL_TOUCH_I2C_IO_SDA (8)
#endif

#elif ESP_PANEL_TOUCH_BUS_TYPE == ESP_PANEL_BUS_TYPE_SPI

#define ESP_PANEL_TOUCH_BUS_HOST_ID (1) // Typically set to 1
#define ESP_PANEL_TOUCH_SPI_IO_CS (5)
#if !ESP_PANEL_TOUCH_BUS_SKIP_INIT_HOST
#define ESP_PANEL_TOUCH_SPI_IO_SCK (7)
#define ESP_PANEL_TOUCH_SPI_IO_MOSI (6)
#define ESP_PANEL_TOUCH_SPI_IO_MISO (9)
#endif
#define ESP_PANEL_TOUCH_SPI_CLK_HZ (1 * 1000 * 1000)
// Should be an integer divisor of 80M, typically set to 1M

#else

#error "The function is not ready and will be implemented in the future."
Expand Down
33 changes: 33 additions & 0 deletions examples/LVGL/v8/Porting/ESP_Panel_Conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,36 @@

/* Maximum button number */
#define ESP_PANEL_TOUCH_MAX_BUTTONS (1)

/* Model configurations */
// XPT2046
#define ESP_PANEL_TOUCH_XPT2046_Z_THRESHOLD (400) // Minimum Z pressure threshold
/**
* Enable Interrupt (PENIRQ) output, also called Full Power Mode.
* Enable this to configure the XPT2046 to output low on the PENIRQ output if a touch is detected.
* This mode uses more power when enabled. Note that this signal goes low normally when a read is active.
*/
#define ESP_PANEL_TOUCH_XPT2046_INTERRUPT_MODE (0) // 0/1
/**
* Keep internal Vref enabled.
* Enable this to keep the internal Vref enabled between conversions. This uses slightly more power,
* but requires fewer transactions when reading the battery voltage, aux voltage and temperature.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_VREF_ON_MODE (0) // 0/1
/**
* Convert touch coordinates to screen coordinates.
* When this option is enabled the raw ADC values will be converted from 0-4096 to 0-{screen width} or 0-{screen height}.
* When this option is disabled the process_coordinates method will need to be used to convert the raw ADC values into a
* screen coordinate.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_CONVERT_ADC_TO_COORDS (1) // 0/1
/**
* Enable data structure locking.
* By enabling this option the XPT2046 driver will lock the touch position data structures when reading values from the
* XPT2046 and when reading position data via API.
* WARNING: enabling this option may result in unintended crashes.
*
*/
#define ESP_PANEL_TOUCH_XPT2046_ENABLE_LOCKING (0) // 0/1
16 changes: 15 additions & 1 deletion examples/LVGL/v8/Rotation/ESP_Panel_Board_Custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@
* - CST816S
* - FT5x06
* - GT911, GT1151
* - ST7123
* - TT21100
* - XPT2046
*/
#define ESP_PANEL_TOUCH_NAME TT21100

Expand All @@ -229,7 +231,7 @@
/**
* Touch panel bus type. Choose one of the following:
* - ESP_PANEL_BUS_TYPE_I2C
* - ESP_PANEL_BUS_TYPE_SPI (not ready)
* - ESP_PANEL_BUS_TYPE_SPI
*/
#define ESP_PANEL_TOUCH_BUS_TYPE (ESP_PANEL_BUS_TYPE_I2C)
/* Touch panel bus parameters */
Expand All @@ -246,6 +248,18 @@
#define ESP_PANEL_TOUCH_I2C_IO_SDA (8)
#endif

#elif ESP_PANEL_TOUCH_BUS_TYPE == ESP_PANEL_BUS_TYPE_SPI

#define ESP_PANEL_TOUCH_BUS_HOST_ID (1) // Typically set to 1
#define ESP_PANEL_TOUCH_SPI_IO_CS (5)
#if !ESP_PANEL_TOUCH_BUS_SKIP_INIT_HOST
#define ESP_PANEL_TOUCH_SPI_IO_SCK (7)
#define ESP_PANEL_TOUCH_SPI_IO_MOSI (6)
#define ESP_PANEL_TOUCH_SPI_IO_MISO (9)
#endif
#define ESP_PANEL_TOUCH_SPI_CLK_HZ (1 * 1000 * 1000)
// Should be an integer divisor of 80M, typically set to 1M

#else

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