lvgl_esp32_drivers icon indicating copy to clipboard operation
lvgl_esp32_drivers copied to clipboard

XPT2046 from time to time does not work

Open Silvesterrr opened this issue 2 years ago • 0 comments

I've seen some weid problem with XPT2046. Im using esp32-s3 with ILI9486 driver and XPT2046 driver + SD card on the same SPI bus. Everything works fine but from time to time the touch stops working. The command line does not show any difference to proper working run. The "Solution" is to unplug the SPI connector plug it back in and reboot. Than it works without any problem. Here is my initialization:

static void guiTask(void *pvParameter)
{
    esp_err_t rc;

    xGuiSemaphore = xSemaphoreCreateMutex();

    lv_init();

    lvgl_driver_init();
    lv_color_t *buf1 = heap_caps_malloc(DISP_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA);
    assert(buf1 != NULL);

    lv_color_t *buf2 = heap_caps_malloc(DISP_BUF_SIZE * sizeof(lv_color_t), MALLOC_CAP_DMA);
    assert(buf2 != NULL);

    static lv_disp_draw_buf_t disp_buf;

    uint32_t size_in_px = DISP_BUF_SIZE;

    lv_disp_draw_buf_init(&disp_buf, buf1, buf2, size_in_px);

    lv_disp_drv_t disp_drv;
    lv_disp_drv_init(&disp_drv);
    disp_drv.flush_cb = disp_driver_flush;
    disp_drv.draw_buf = &disp_buf;
    disp_drv.ver_res = 320;
    disp_drv.hor_res = 480;
    lv_disp_drv_register(&disp_drv);

    lv_indev_drv_t indev_drv;
    lv_indev_drv_init(&indev_drv);
    indev_drv.read_cb = touch_driver_read;
    indev_drv.type = LV_INDEV_TYPE_POINTER;
    lv_indev_drv_register(&indev_drv);

    const esp_timer_create_args_t periodic_timer_args = {
        .callback = &lv_tick_task,
        .name = "periodic_gui"};
    esp_timer_handle_t periodic_timer;
    esp_timer_create(&periodic_timer_args, &periodic_timer);
    esp_timer_start_periodic(periodic_timer, LV_TICK_PERIOD_MS * 1000);

    keypad_lvgl_port_init();

    main_tabview();

    sd_card_lvgl_port_init();


    lv_timer_create(memory_monitor, 3000, NULL); // to delete

    while (1)
    {
        vTaskDelay(pdMS_TO_TICKS(100));
        if (pdTRUE == xSemaphoreTake(xGuiSemaphore, portMAX_DELAY))
        {
            lv_task_handler();

            xSemaphoreGive(xGuiSemaphore);
        }
    }
}

static void lv_tick_task(void *arg)
{
    (void)arg;
    lv_tick_inc(LV_TICK_PERIOD_MS);
}

Waiting for any response :)

Silvesterrr avatar Sep 23 '22 10:09 Silvesterrr