atanisoft / esp_lcd_touch_xpt2046

MIT License
14 stars 3 forks source link

touch coords conversion #1

Open abusca opened 1 year ago

abusca commented 1 year ago

Hi, I'm using your component in a ESP32-2432S028 board. I'm running spi_lcd_touch example with ESP-IDF v5.0-rc1. I had to edit some lines at ESP_LCD_TOUCH_IO_SPI_XPT2046_CONFIG struct, but the touch component works fine! Thank you!

However, display buttons and touch coords do not match and I wonder what would be the best way to convert them applying some offsets. By now, I implemented data_convert function from esp_lcd_touch_stmpe610 component and looks good. But, would you do this conversion at app level? Maybe by implementing a process_coordinates callback function from esp_lcd_touch_config_t struct?

Thanks!

atanisoft commented 1 year ago

What edits did you need to make in ESP_LCD_TOUCH_IO_SPI_XPT2046_CONFIG? I haven't tested with IDF v5.0-rc1 (yet).

One downside of the current esp_lcd_touch API is that it doesn't provide for any touch config data (such as offsets). It also doesn't handle calibration which is needed for touch controllers like XPT2046. Perhaps it would make sense to add a few Kconfig.projbuild entries for creation of a bounding box for the coordinates and constrain them similar to the data_convert function is doing.

The usage of a process_coordinates method would likely still be needed for calibration adjustments though.

abusca commented 1 year ago

I had to delete .dc_as_cmd_phase line because does not exist on esp_lcd_panel_io_spi_config_t. Then I had to delete .dc_gpio_num line because I was getting the following error at runtime: E (560) lcd_panel.io.spi: esp_lcd_new_panel_io_spi(71): invalid DC mode I also had to replace #include "esp_lcd_panel_vendor.h" with #include "esp_lcd_touch.h"

atanisoft commented 1 year ago

I had to delete .dc_as_cmd_phase line because does not exist on esp_lcd_panel_io_spi_config_t.

Looks like they removed that between IDF v4.x and v5.x, let me add a version check and drop that field.

Then I had to delete .dc_gpio_num line because I was getting the following error at runtime: E (560) lcd_panel.io.spi: esp_lcd_new_panel_io_spi(71): invalid DC mode

Looks like they introduced a bug in the code that conflicts with the documentation. However, it is very likely that they will toggle GPIO 0 when trying to talk to the XPT2046 which is not ideal.

I also had to replace #include "esp_lcd_panel_vendor.h" with #include "esp_lcd_touch.h"

Oops, that is a leftover from copying the header from the ILI9488 component. It should be:

#include "esp_lcd_touch.h"
#include "esp_lcd_panel_io.h"

Let me get these changes pushed up to GitHub and do some further testing before releasing a new version. If you want to test the latest use the git override as described in the readme.

atanisoft commented 1 year ago

Then I had to delete .dc_gpio_num line because I was getting the following error at runtime: E (560) lcd_panel.io.spi: esp_lcd_new_panel_io_spi(71): invalid DC mode

Logged https://github.com/espressif/esp-idf/issues/10215 for this.

atanisoft commented 1 year ago

@abusca Can you try with v1.0.1? It will need one override in user code to set dc_gpio_num until https://github.com/espressif/esp-idf/issues/10215 has been fixed (should be soon).

I've added an option to return the raw ADC values instead of approximate screen coordinates, this can be used in the process_coordinates method to adjust for calibration or any necessary offsets.

abusca commented 1 year ago

Yes. v1.01 works as expected after I override dc_gpio_num with an unused gpio. I'll come back when I try enabling absolute ADC values option with process_coordinates method.

atanisoft commented 1 year ago

@abusca It appears that IDF v5.0 release now has the fix for dc_gpio_num. I haven't tested it yet but will in the very near future.