atanisoft / esp_lcd_touch_xpt2046

MIT License
14 stars 4 forks source link

enable pin interrupt without a callback #7

Closed julr closed 3 months ago

julr commented 3 months ago

I'm currently using this xpt2046 driver together with the esp_lvgl_port component which makes lvgl integration a lot easier. For example it provides all the callbacks and boilerplate code. This means that the callback for the touch device is set in a separate step after the esp_lcd_touch_handle_t struct has been initialized by esp_lcd_touch_new_spi_xpt2046(). However the actual interrupt functionality of the pin is only activated when a callback is set which is not known at that stage so the interrupt_callback field inside the esp_lcd_touch_config_t struct instance is initialized to NULL. The check is implemented here esp_lcd_touch_xpt2046.c, line 108

As a workaround I added

gpio_set_intr_type(touchConfig.int_gpio_num, GPIO_INTR_NEGEDGE);
gpio_intr_enable(touchConfig.int_gpio_num);

between the calls to esp_lcd_touch_new_spi_xpt2046() and lvgl_port_add_touch() otherwise no touch events would be registered.

A possible fix would be to remove the if condition mentioned above. However, this is my first time working with an ESP32 and the ESP-IDF so I don't know what would happen if a pin interrupt triggers without a registered callback routine.

atanisoft commented 3 months ago

This shouldn't be necessary, the configuration of the interrupt should be handled by this line automatically.

A couple questions:

  1. Which version of LVGL?
  2. Are you using esp32_port_lvgl?
  3. Which version of ESP-IDF?
julr commented 3 months ago

Thanks for the quick reply. You are absolutely correct. My touch device seems to be a bit unstable using the interrupt mode which caused me to believe that this might be a problem. I will investigate this further and possibly just switch to polling mode (which works fine).

atanisoft commented 3 months ago

Sounds good, if you need help feel free to reach out and I'll do what I can. FWIW, I've mostly used polling mode and have found it to be reasonably fast. I do know there are some adjustments in this area for LVGL 9.x but I haven't upgraded beyond LVGL 8.4.x yet.