From b9df0934115972ba49db02477865366130cf1452 Mon Sep 17 00:00:00 2001 From: Rene Zeldenthuis Date: Wed, 6 Mar 2024 00:30:37 +0100 Subject: [PATCH] Fixes --- src/esp_lcd_gc9a01.c | 42 +++++++++++++++++++------------------ src/esp_lcd_touch_cst816s.c | 26 +++++++++++++++++------ src/esp_lcd_touch_gt911.c | 4 ++-- src/esp_lcd_touch_xpt2046.c | 2 +- src/lvgl_gc9a01_spi.c | 9 ++++++-- 5 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/esp_lcd_gc9a01.c b/src/esp_lcd_gc9a01.c index 17af2ec..a540401 100644 --- a/src/esp_lcd_gc9a01.c +++ b/src/esp_lcd_gc9a01.c @@ -70,10 +70,10 @@ const lcd_init_cmd_t vendor_specific_init_default[] = { esp_err_t gc9a01_reset(esp_lcd_panel_t *panel) { - gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; - log_v("gc9a01_reset. ph:0x%08x", ph); + log_v("panel:0x%08x", panel); assert(panel != NULL); + gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; if (ph->config.reset_gpio_num != GPIO_NUM_NC) { @@ -100,10 +100,10 @@ esp_err_t gc9a01_reset(esp_lcd_panel_t *panel) esp_err_t gc9a01_init(esp_lcd_panel_t *panel) { - gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; - log_v("gc9a01_init. ph:0x%08x", ph); + log_v("panel:0x%08x", panel); assert(panel != NULL); + gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; esp_err_t res; if ((res = esp_lcd_panel_io_tx_param(ph->io, LCD_CMD_SLPOUT, NULL, 0)) != ESP_OK) @@ -160,8 +160,10 @@ esp_err_t gc9a01_init(esp_lcd_panel_t *panel) esp_err_t gc9a01_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, int x_end, int y_end, const void *color_data) { + log_v("gc9a01_draw_bitmap. panel:0x%08x, x_start:%d, y_start:%d, x_end:%d, y_end:%d, color_data:0x%08x", panel, x_start, y_start, x_end, y_end, color_data); + + assert(panel != NULL); gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; - log_v("gc9a01_draw_bitmap. ph:0x%08x, x_start:%d, y_start:%d, x_end:%d, y_end:%d, color_data:0x%08x", ph, x_start, y_start, x_end, y_end, color_data); assert(panel != NULL); assert(color_data != NULL); @@ -207,11 +209,11 @@ esp_err_t gc9a01_draw_bitmap(esp_lcd_panel_t *panel, int x_start, int y_start, i esp_err_t gc9a01_invert_color(esp_lcd_panel_t *panel, bool invert) { - gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; - log_v("gc9a01_invert_color. ph:0x%08x, invert:%d", ph, invert); + log_v("panel:0x%08x, invert:%d", panel, invert); assert(panel != NULL); - + gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; + esp_err_t res; if ((res = esp_lcd_panel_io_tx_param(ph->io, invert ? LCD_CMD_INVON : LCD_CMD_INVOFF, NULL, 0)) != ESP_OK) { @@ -237,10 +239,10 @@ esp_err_t gc9a01_update_madctl(gc9a01_panel_t *ph) esp_err_t gc9a01_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y) { - gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; - log_v("gc9a01_mirror. ph:0x%08x, mirror_x:%d, mirror_y:%d", ph, mirror_x, mirror_y); + log_v("panel:0x%08x, mirror_x:%d, mirror_y:%d", panel, mirror_x, mirror_y); assert(panel != NULL); + gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; if (mirror_x) ph->madctl |= LCD_CMD_MX_BIT; @@ -257,10 +259,10 @@ esp_err_t gc9a01_mirror(esp_lcd_panel_t *panel, bool mirror_x, bool mirror_y) esp_err_t gc9a01_swap_xy(esp_lcd_panel_t *panel, bool swap_xy) { - gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; - log_v("gc9a01_swap_xy. ph:0x%08x, swap_xy:%d", ph, swap_xy); + log_v("panel:0x%08x, swap_xy:%d", panel, swap_xy); assert(panel != NULL); + gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; if (swap_xy) ph->madctl |= LCD_CMD_MV_BIT; @@ -272,10 +274,10 @@ esp_err_t gc9a01_swap_xy(esp_lcd_panel_t *panel, bool swap_xy) esp_err_t gc9a01_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap) { - gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; - log_v("gc9a01_set_gap. ph:0x%08x, x_gap:%d, y_gap:%d", ph, x_gap, y_gap); + log_v("panel:0x%08x, x_gap:%d, y_gap:%d", panel, x_gap, y_gap); assert(panel != NULL); + gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; ph->x_gap = x_gap; ph->y_gap = y_gap; @@ -285,10 +287,10 @@ esp_err_t gc9a01_set_gap(esp_lcd_panel_t *panel, int x_gap, int y_gap) esp_err_t gc9a01_disp_off(esp_lcd_panel_t *panel, bool off) { - gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; - log_v("gc9a01_disp_off. ph:0x%08x, off:%d", ph, off); + log_v("panel:0x%08x, off:%d", panel, off); assert(panel != NULL); + gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; esp_err_t res; if ((res = esp_lcd_panel_io_tx_param(ph->io, off ? LCD_CMD_DISPOFF : LCD_CMD_DISPON, NULL, 0)) != ESP_OK) @@ -302,10 +304,10 @@ esp_err_t gc9a01_disp_off(esp_lcd_panel_t *panel, bool off) esp_err_t gc9a01_del(esp_lcd_panel_t *panel) { - gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; - log_v("gc9a01_del. ph:0x%08x", ph); + log_v("panel:0x%08x", panel); assert(panel != NULL); + gc9a01_panel_t *ph = (gc9a01_panel_t *)panel; // Reset RESET if (ph->config.reset_gpio_num != GPIO_NUM_NC) @@ -318,7 +320,7 @@ esp_err_t gc9a01_del(esp_lcd_panel_t *panel) esp_err_t esp_lcd_new_panel_gc9a01(const esp_lcd_panel_io_handle_t io, const esp_lcd_panel_dev_config_t *config, esp_lcd_panel_handle_t *handle) { - log_v("esp_lcd_new_panel_gc9a01. io:0x%08x, config:0x%08x, handle:0x%08x", io, config, handle); + log_v("io:0x%08x, config:0x%08x, handle:0x%08x", io, config, handle); assert(io != NULL); assert(config != NULL); @@ -357,7 +359,7 @@ esp_err_t esp_lcd_new_panel_gc9a01(const esp_lcd_panel_io_handle_t io, const esp } } - gc9a01_panel_t *ph = heap_caps_aligned_alloc(1, sizeof(gc9a01_panel_t), MALLOC_CAP_DEFAULT); + gc9a01_panel_t *ph = heap_caps_calloc(1, sizeof(gc9a01_panel_t), MALLOC_CAP_DEFAULT); if (ph == NULL) { log_e("No memory available for gc9a01_panel_t"); diff --git a/src/esp_lcd_touch_cst816s.c b/src/esp_lcd_touch_cst816s.c index 5b430a6..cb5e7e1 100644 --- a/src/esp_lcd_touch_cst816s.c +++ b/src/esp_lcd_touch_cst816s.c @@ -18,6 +18,7 @@ const uint8_t CST816S_BC0L_REG = 0xB1; const uint8_t CST816S_BC1H_REG = 0xB2; const uint8_t CST816S_BC1L_REG = 0xB3; +const uint8_t CST816S_SLEEP_REG = 0xA5; const uint8_t CST816S_CHIPID_REG = 0xA7; const uint8_t CST816S_PROJID_REG = 0xA8; const uint8_t CST816S_FWVERSION_REG = 0xA9; @@ -44,10 +45,10 @@ const uint8_t CST816S_AUTOSLEEP_REG = 0xFE; // Touch events const uint8_t CST816S_TOUCH_EVENT_NONE = 0x0; -const uint8_t CST816S_TOUCH_EVENT_ON_SLIPPERY = 0x1; -const uint8_t CST816S_TOUCH_EVENT_DECLINE = 0x2; -const uint8_t CST816S_TOUCH_EVENT_LEFT_SLIDE = 0x3; -const uint8_t CST816S_TOUCH_EVENT_RIGHT_SLIDE = 0x4; +const uint8_t CST816S_TOUCH_EVENT_SLIDE_DOWN = 0x1; +const uint8_t CST816S_TOUCH_EVENT_SLIDE_UP = 0x2; +const uint8_t CST816S_TOUCH_EVENT_SLIDE_LEFT = 0x3; +const uint8_t CST816S_TOUCH_EVENT_SLIDE_RIGHT = 0x4; const uint8_t CST816S_TOUCH_EVENT_CLICK = 0x5; const uint8_t CST816S_TOUCH_EVENT_DOUBLE_CLICK = 0xB; const uint8_t CST816S_TOUCH_EVENT_PRESS = 0xC; @@ -99,8 +100,8 @@ extern "C" return res; } - // Wait at least 5ms - vTaskDelay(pdMS_TO_TICKS(5)); + // Wait at least 50ms + vTaskDelay(pdMS_TO_TICKS(50)); return ESP_OK; } @@ -124,6 +125,18 @@ extern "C" return ESP_OK; } + esp_err_t cst816s_enter_sleep(esp_lcd_touch_handle_t th) + { + log_v("th:0x%08x", th); + + esp_err_t res; + const uint8_t data[] = {0x03}; // Sleep + if ((res = esp_lcd_panel_io_tx_param(th->io, CST816S_SLEEP_REG, data, sizeof(data))) != ESP_OK) + log_e("Unable to write GT911_CONTROL_REG"); + + return res; + } + esp_err_t cst816s_read_data(esp_lcd_touch_handle_t th) { log_v("th:0x%08x", th); @@ -224,6 +237,7 @@ extern "C" } th->io = io; + th->enter_sleep = cst816s_enter_sleep; th->read_data = cst816s_read_data; th->get_xy = cst816s_get_xy; #if (CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0) diff --git a/src/esp_lcd_touch_gt911.c b/src/esp_lcd_touch_gt911.c index e35ba68..35b37a9 100644 --- a/src/esp_lcd_touch_gt911.c +++ b/src/esp_lcd_touch_gt911.c @@ -103,8 +103,8 @@ extern "C" return res; } - // Wait at least 5ms - vTaskDelay(pdMS_TO_TICKS(5)); + // Wait at least 50ms + vTaskDelay(pdMS_TO_TICKS(50)); return ESP_OK; } diff --git a/src/esp_lcd_touch_xpt2046.c b/src/esp_lcd_touch_xpt2046.c index 63fe53c..9596f11 100644 --- a/src/esp_lcd_touch_xpt2046.c +++ b/src/esp_lcd_touch_xpt2046.c @@ -235,7 +235,7 @@ extern "C" log_v("th:0x%08x, output:0x%08x", th, output); assert(th != NULL); - assert(outhut != NULL); + assert(output != NULL); esp_err_t res; uint16_t level; diff --git a/src/lvgl_gc9a01_spi.c b/src/lvgl_gc9a01_spi.c index 54df0ac..f0c62d3 100644 --- a/src/lvgl_gc9a01_spi.c +++ b/src/lvgl_gc9a01_spi.c @@ -8,8 +8,10 @@ #include "esp_lcd_gc9a01.h" -bool gc9a01_color_trans_done(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx) +bool gc9a01_color_trans_done(esp_lcd_panel_io_handle_t io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx) { + log_v("io:0x%08x, edata:%0x%08x, user_ctx:0x%08x", io, edata, user_ctx); + lv_disp_drv_t *disp_driver = user_ctx; lv_disp_flush_ready(disp_driver); return false; @@ -17,6 +19,8 @@ bool gc9a01_color_trans_done(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_i void gc9a01_lv_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color16_t *color_map) { + log_v("drv:0x%08x, area:%0x%08x, color_map:0x%08x", drv, area, color_map); + esp_lcd_panel_handle_t panel_handle = drv->user_data; #if LV_COLOR_16_SWAP != 1 #warning "LV_COLOR_16_SWAP should be 1 for max performance" @@ -30,7 +34,8 @@ void gc9a01_lv_flush(lv_disp_drv_t *drv, const lv_area_t *area, lv_color16_t *co void lvgl_lcd_init(lv_disp_drv_t *drv) { - log_d("lvgl_lcd_init"); + log_v("drv:0x%08x", drv); + // Hardware rotation is supported drv->sw_rotate = 0; drv->rotated = LV_DISP_ROT_NONE;