witnessmenow / ESP32-Cheap-Yellow-Display

Building a community around a cheap ESP32 Display with a touch screen
MIT License
1.5k stars 148 forks source link

Examples/ESP-IDF/LVGL9 touch pad does not working #237

Closed aliaktas closed 1 month ago

aliaktas commented 1 month ago

Hi,

I have been trying to build a simple touch screen project with esp-idf 5.2 and 2432s028 board.

I have intended to use Examples/ESP-IDF/LVGL9 project as starting point however the touch panel does not fire a touch event.

1) I tested the touch pad with LCD_Touch example and it is working 2) hardware.h seems to be correct for pin mapping 3) tp object is not NULL, 4) compiler does not give an error 5) changing some configuration from the menuconfig for XPT2046 but no luck

Does anybody have a chance to test with similar configuration ?


void ui_event_Screen(lv_event_t *e)
{
     LV_LOG_USER("Event");
static uint8_t cnt=1;

    lv_event_code_t event_code = lv_event_get_code(e);
    lv_obj_t *btn = (lv_obj_t *)lv_event_get_user_data(e);

    if (event_code == LV_EVENT_CLICKED)
    {   
        LV_LOG_USER("Click Event");
        cnt++;
        if (cnt > 9) cnt=1;
        /*Get the first child of the button which is the label and change its text*/
        lv_obj_t * label = lv_obj_get_child(btn, 0);
        lv_label_set_text_fmt(label, "Button: %d", cnt);
    }
}

static esp_err_t app_lvgl_main(void)
{
    lv_obj_t *scr = lv_scr_act();
    lvgl_port_lock(0);
               //--other display objects---//
    // Touch action managements
    lv_obj_t *btn_counter = lv_button_create(scr);
    lv_obj_set_size(btn_counter, 100, 40);
    lv_obj_align(btn_counter, LV_ALIGN_BOTTOM_MID, 0, -10);
    lv_obj_add_event_cb(btn_counter, ui_event_Screen, LV_EVENT_ALL, NULL);

    lv_obj_t * label = lv_label_create(btn_counter);    
    lv_label_set_text(label, "Button");                     
    lv_obj_center(label);

    lvgl_port_unlock();
}
aliaktas commented 1 month ago

Hi,

I have solved the issue. At hardware.h file change line:42 to #define TOUCH_IRQ (gpio_num_t) GPIO_NUM_NC // GPIO_NUM_36. For some reason setting irq pin does prevent touchpad from fire touch event.

Any solution with using IRQ pin is welcome, i think that using IRQ pin for detecting touch events is more feasible.

Moreoever, if you test above code just changelv_obj_add_event_cb(btn_counter, ui_event_Screen, LV_EVENT_ALL, NULL); to lv_obj_add_event_cb(btn_counter, ui_event_Screen, LV_EVENT_ALL, btn_counter);