espressif / esp-bsp

Board support components for Espressif development boards
Other
202 stars 102 forks source link

CST816 Touch driver support (IDFGH-10255) (BSP-328) #178

Closed krupis closed 1 year ago

krupis commented 1 year ago

Is your feature request related to a problem?

I have been using ST7789 display from the lilygo and it works flawlesly.

The only issue is that I believe the esp-idf does not currently support the touch driver (CST816) for this display.

image

https://www.lilygo.cc/products/t-display-s3

I think adding support for this touch driver would be very useful for developers such as myself.

Describe the solution you'd like.

Working touch display driver for CST816 and example project on how to get it going.

Describe alternatives you've considered.

Using different displays.

Additional context.

No response

davidthings commented 1 month ago

Did you try checking the interrupt level before running the I2C operation.  If no interrupt, don’t poll the chip?  This is working for me.On Sep 22, 2024, at 10:27 AM, FrankBJensen @.***> wrote: Hi there. I have a problem, that seems somewhat similar to this. I am using esp_lvgl_port and the esp_led_touch_cs816s driver for that. I have installed both as components, and it kind of work. Problem is the wakeup and sleep of the CST816. This function fails esp_lcd_touch_new_i2c_cst816s(tp_io_handle, &tp_cfg, &touch_handle); due to no communication from adr. 0x15, due to the CST816 sleeping. So I need to wake up the CST816 in order to be able to register the interupt callback. But I can only communicate with the CST816 in a timewindow following the interupt. Its like the hen and the egg....... I can not wakeup the CST816 by toggling the reset. Right now my only workaround is to continously tap the display during boot, to keep it alive, until I get a CST816 init OK. Then all works. This way the esp_lcd_touch_new_i2c_cst816s do not fail, and callback is registred correctly. But that is not a usable solution. Any suggestions?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

FrankBJensen commented 1 month ago

Can you communicate with the chip, before the first interupt? My problem is, that LVGL wants to initialize it, before any interupts, meaning the chip is sleeping.

I call this function, in order to register it, but it fails, cause it tries to write to the chip, when its sleeping.

` touch_mux = xSemaphoreCreateBinary();

esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG();

esp_lcd_touch_config_t tp_cfg = {
    .x_max = EXAMPLE_LCD_H_RES,
    .y_max = EXAMPLE_LCD_V_RES,
    .rst_gpio_num = TOUCH_GPIO_RST, // GPIO_NUM_39
    .int_gpio_num = TOUCH_GPIO_INT,
    .levels = {
        .reset = 0,
        .interrupt = 0,
    },
    .flags = {
        .swap_xy = 0,
        .mirror_x = 0,
        .mirror_y = 0,
    }
};

esp_lcd_panel_io_handle_t tp_io_handle = NULL;

ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)EXAMPLE_TOUCH_I2C_NUM, &tp_io_config, &tp_io_handle), TAG, "");
return esp_lcd_touch_new_i2c_cst816s(tp_io_handle, &tp_cfg, &touch_handle);

`

FrankBJensen commented 1 month ago

My solution for this problem. Catch the first interupt, and init the touch there, including disable autosleep. Only catch is, that first touch after reboot is ignored.

void IRAM_ATTR gpio_isr_handler(void* arg) {
    // Handle the interrupt, e.g., toggle a flag or send data to a queue
    int gpio_num = (int) arg;
    ESP_EARLY_LOGI(TAG, "Interrupt on GPIO %d", gpio_num);
    gpio_isr_handler_remove(gpio_num);
    xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
}

And handle this interupt in my main loop, to add the touch handler to LVGL.

if (xQueueReceive(gpio_evt_queue, &gpio_num, portMAX_DELAY)) {
  ESP_LOGI(TAG, "Handling GPIO %d initialization in task", gpio_num);
  app_touch_init();
  ESP_LOGI(TAG, "Initialization done for GPIO %d", gpio_num);
  esp_err_t result = i2c_master_write_byte1(0x15, 0xFE, 0xFF); // Disable autosleep
}