From 450bb4d7f9cd158c579a3149fc1328616ab2b88c Mon Sep 17 00:00:00 2001 From: Rene Zeldenthuis Date: Tue, 5 Mar 2024 01:41:35 +0100 Subject: [PATCH] Disabled reading info from gt911. Seems to cause problems --- src/esp_lcd_touch_gt911.c | 93 +++++++++++++++++++++++---------------- src/lvgl_cst816s_i2c.c | 6 +-- src/lvgl_gt911_i2c.c | 6 +-- src/lvgl_xpt2046_spi.c | 2 +- 4 files changed, 61 insertions(+), 46 deletions(-) diff --git a/src/esp_lcd_touch_gt911.c b/src/esp_lcd_touch_gt911.c index f5bfbfa..949b0a0 100644 --- a/src/esp_lcd_touch_gt911.c +++ b/src/esp_lcd_touch_gt911.c @@ -96,6 +96,26 @@ extern "C" return ESP_OK; } + // This function is called if the coordinates do not match the returned coordinates. This is the case for display having another form factor, e.g. 472x320 + void gt911_process_coordinates(esp_lcd_touch_handle_t th, uint16_t *x, uint16_t *y, uint16_t *strength, uint8_t *point_num, uint8_t max_point_num) + { + log_v("gt911_process_coordinates. th:0x%08x, x:0x%08x, y:0x%08x, strength:0x%08x, point_num:0x%08x, max_point_num:%d", th, x, y, strength, point_num, max_point_num); + + portENTER_CRITICAL(&th->data.lock); + gt911_info *info = th->config.user_data; + assert(info); + uint8_t points_available = *point_num > max_point_num ? max_point_num : *point_num; + for (uint8_t i = 0; i < points_available; i++) + { + // Correct the points for the info obtained from the GT911 and configured resolution + x[i] = (x[i] * th->config.x_max) / info->xResolution; + y[i] = (y[i] * th->config.y_max) / info->yResolution; + log_d("processed coordinates: x:%d, y:%d, area:%d", th->data.coords[i].x, th->data.coords[i].y, th->data.coords[i].strength); + } + + portEXIT_CRITICAL(&th->data.lock); + } + esp_err_t gt911_read_info(esp_lcd_touch_handle_t th) { log_v("gt911_read_info. th:0x%08x", th); @@ -125,17 +145,11 @@ extern "C" if (strcmp((char *)&info->productId, "911") != 0) { + free(info); log_e("GT911 chip not found"); return ESP_FAIL; } - if (info->xResolution == 0 || info->yResolution == 0) - { - log_w("Invalid resolution obtained from GT911. Using supplied resolution (%d,%d)", th->config.x_max, th->config.y_max); - info->xResolution = th->config.x_max; - info->yResolution = th->config.y_max; - } - log_d("GT911 productId: %s", info->productId); // 0x8140 - 0x8143 log_d("GT911 fwId: %04x", info->fwId); // 0x8144 - 0x8145 log_d("GT911 xResolution/yResolution: (%d, %d)", info->xResolution, info->yResolution); // 0x8146 - 0x8147 // 0x8148 - 0x8149 @@ -143,6 +157,12 @@ extern "C" th->config.user_data = info; + if (info->xResolution > 0 && info->yResolution > 0 && (info->xResolution != th->config.x_max || info->yResolution != th->config.y_max)) + { + log_w("Resolution obtained from GT911 (%d,%d) does not match supplied resolution (%d,%d)", info->xResolution, info->yResolution, th->config.x_max, th->config.y_max); + th->config.process_coordinates = gt911_process_coordinates; + } + return ESP_OK; } @@ -196,7 +216,6 @@ extern "C" esp_err_t res; gt911_touch_data buffer; - uint8_t i; // Read only the XY register if ((res = esp_lcd_panel_io_rx_param(th->io, GT911_READ_XY_REG, &buffer.flags, sizeof(buffer.flags))) != ESP_OK) @@ -210,7 +229,7 @@ extern "C" #if (CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0) if ((buffer.flags & FLAGS_HAVE_KEY) > 0) { - log_v("buttons available"); + log_v("Buttons available"); if ((res = esp_lcd_panel_io_rx_param(th->io, GT911_READ_KEY_REG, &buffer.data.buttons, CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS)) != ESP_OK) { log_e("Unable to read GT911_READ_KEY_REG"); @@ -229,7 +248,7 @@ extern "C" // Check if data is present if (points_available > 0) { - log_v("points_available: %d", points_available); + log_v("Points_available: %d", points_available); // Read the number of touches if (points_available <= GT911_TOUCH_MAX_POINTS) { @@ -240,23 +259,16 @@ extern "C" return res; } -#if ARDUHAL_LOG_LEVEL > ARDUHAL_LOG_LEVEL_NONE - for (uint8_t i = 0; i < points_available; i++) - log_v("event:%d, x:%d, y:%d, area:%d", buffer.data.points[i].event, buffer.data.points[i].x, buffer.data.points[i].y, buffer.data.points[i].area); -#endif - portENTER_CRITICAL(&th->data.lock); - gt911_info *info = th->config.user_data; - assert(info); - th->data.points = points_available; - for (i = 0; i < points_available; i++) + for (uint8_t i = 0; i < points_available; i++) { - // Correct the points for the info returned from the GT911 and configured resolution - th->data.coords[i].x = (double)buffer.data.points[i].x * th->config.x_max / info->xResolution; - th->data.coords[i].y = (double)buffer.data.points[i].y * th->config.y_max / info->yResolution; + log_d("Touch: #%d, event:%d, x:%d, y:%d, area:%d", i, buffer.data.points[i].event, buffer.data.points[i].x, buffer.data.points[i].y, buffer.data.points[i].area); + th->data.coords[i].x = buffer.data.points[i].x; + th->data.coords[i].y = buffer.data.points[i].y; th->data.coords[i].strength = buffer.data.points[i].area; } + th->data.points = points_available; portEXIT_CRITICAL(&th->data.lock); } } @@ -280,10 +292,12 @@ extern "C" *point_num = th->data.points > max_point_num ? max_point_num : th->data.points; for (uint8_t i = 0; i < *point_num; i++) { - x[i] = th->data.coords[i].y; - y[i] = th->data.coords[i].x; + x[i] = th->data.coords[i].x; + y[i] = th->data.coords[i].y; if (strength != NULL) strength[i] = th->data.coords[i].strength; + + log_d("Touch: x:%d, y:%d, area:%d", x[i], y[i], strength != NULL ? strength[i] : 0); } th->data.points = 0; @@ -425,24 +439,25 @@ extern "C" return res; } } + } - // Reset controller - if ((res = gt911_reset(th)) != ESP_OK) - { - log_e("GT911 reset failed"); - gt911_del(th); - return res; - } - - // Read type and resolution - if ((res = gt911_read_info(th)) != ESP_OK) - { - log_e("GT911 read info failed"); - gt911_del(th); - return res; - } + // Reset controller + if ((res = gt911_reset(th)) != ESP_OK) + { + log_e("GT911 reset failed"); + gt911_del(th); + return res; } + // TODO: creates an invalid instruction when reading + // Read type and resolution + // if ((res = gt911_read_info(th)) != ESP_OK) + // { + // log_e("GT911 read info failed"); + // gt911_del(th); + // return res; + // } + *handle = th; return ESP_OK; diff --git a/src/lvgl_cst816s_i2c.c b/src/lvgl_cst816s_i2c.c index e63ffc5..7705b85 100644 --- a/src/lvgl_cst816s_i2c.c +++ b/src/lvgl_cst816s_i2c.c @@ -42,7 +42,7 @@ void lvgl_touch_init(lv_indev_drv_t *drv) .master = { .clk_speed = CST816S_I2C_CONFIG_MASTER_CLK_SPEED}, .clk_flags = CST816S_I2C_CONFIG_CLK_FLAGS}; - log_v("i2c_config: mode:%d, sda_io_num:%d, scl_io_num:%d, sda_pullup_en:%d, scl_pullup_en:%d, master.clk_speed:%d, clk_flags:%d", i2c_config.mode, i2c_config.sda_io_num, i2c_config.scl_io_num, i2c_config.sda_pullup_en, i2c_config.scl_pullup_en, i2c_config.master.clk_speed, i2c_config.clk_flags); + log_d("i2c_config: mode:%d, sda_io_num:%d, scl_io_num:%d, sda_pullup_en:%d, scl_pullup_en:%d, master.clk_speed:%d, clk_flags:%d", i2c_config.mode, i2c_config.sda_io_num, i2c_config.scl_io_num, i2c_config.sda_pullup_en, i2c_config.scl_pullup_en, i2c_config.master.clk_speed, i2c_config.clk_flags); ESP_ERROR_CHECK(i2c_param_config(CST816S_I2C_HOST, &i2c_config)); ESP_ERROR_CHECK(i2c_driver_install(CST816S_I2C_HOST, i2c_config.mode, 0, 0, 0)); @@ -57,7 +57,7 @@ void lvgl_touch_init(lv_indev_drv_t *drv) .flags = { .dc_low_on_data = CST816S_IO_I2C_CONFIG_FLAGS_DC_LOW_ON_DATA, .disable_control_phase = CST816S_IO_I2C_CONFIG_FLAGS_DISABLE_CONTROL_PHASE}}; - log_v("io_i2c_config: dev_addr:0x%02x, control_phase_bytes:%d, user_ctx:0x%08x, dc_bit_offset:%d, lcd_cmd_bits:%d, lcd_param_bits:%d, flags.dc_low_on_data:%d, flags.disable_control_phase:%d", io_i2c_config.dev_addr, io_i2c_config.control_phase_bytes, io_i2c_config.user_ctx, io_i2c_config.dc_bit_offset, io_i2c_config.lcd_cmd_bits, io_i2c_config.lcd_param_bits, io_i2c_config.flags.dc_low_on_data, io_i2c_config.flags.disable_control_phase); + log_d("io_i2c_config: dev_addr:0x%02x, control_phase_bytes:%d, user_ctx:0x%08x, dc_bit_offset:%d, lcd_cmd_bits:%d, lcd_param_bits:%d, flags.dc_low_on_data:%d, flags.disable_control_phase:%d", io_i2c_config.dev_addr, io_i2c_config.control_phase_bytes, io_i2c_config.user_ctx, io_i2c_config.dc_bit_offset, io_i2c_config.lcd_cmd_bits, io_i2c_config.lcd_param_bits, io_i2c_config.flags.dc_low_on_data, io_i2c_config.flags.disable_control_phase); esp_lcd_panel_io_handle_t io_handle; ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)CST816S_I2C_HOST, &io_i2c_config, &io_handle)); @@ -73,7 +73,7 @@ void lvgl_touch_init(lv_indev_drv_t *drv) // Unfortunately not supported //.flags = {.swap_xy = CST816S_TOUCH_CONFIG_FLAGS_SWAP_XY, .mirror_x = CST816S_TOUCH_CONFIG_FLAGS_MIRROR_X, .mirror_y = CST816S_TOUCH_CONFIG_FLAGS_MIRROR_Y}, .user_data = io_handle}; - log_v("touch_config: x_max:%d, y_max:%d, rst_gpio_num:%d, int_gpio_num:%d, levels.reset:%d, levels.interrupt:%d, flags.swap_xy:%d, flags.mirror_x:%d, flags.mirror_y:%d, user_data:0x%08x", touch_config.x_max, touch_config.y_max, touch_config.rst_gpio_num, touch_config.int_gpio_num, touch_config.levels.reset, touch_config.levels.interrupt, touch_config.flags.swap_xy, touch_config.flags.mirror_x, touch_config.flags.mirror_y, touch_config.user_data); + log_d("touch_config: x_max:%d, y_max:%d, rst_gpio_num:%d, int_gpio_num:%d, levels.reset:%d, levels.interrupt:%d, flags.swap_xy:%d, flags.mirror_x:%d, flags.mirror_y:%d, user_data:0x%08x", touch_config.x_max, touch_config.y_max, touch_config.rst_gpio_num, touch_config.int_gpio_num, touch_config.levels.reset, touch_config.levels.interrupt, touch_config.flags.swap_xy, touch_config.flags.mirror_x, touch_config.flags.mirror_y, touch_config.user_data); esp_lcd_touch_handle_t touch_handle; ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_cst816s(io_handle, &touch_config, &touch_handle)); diff --git a/src/lvgl_gt911_i2c.c b/src/lvgl_gt911_i2c.c index 60fbcbc..6a45095 100644 --- a/src/lvgl_gt911_i2c.c +++ b/src/lvgl_gt911_i2c.c @@ -41,7 +41,7 @@ void lvgl_touch_init(lv_indev_drv_t *drv) .master = { .clk_speed = GT911_I2C_CONFIG_MASTER_CLK_SPEED}, .clk_flags = GT911_I2C_CONFIG_CLK_FLAGS}; - log_v("i2c_config: mode:%d, sda_io_num:%d, scl_io_num:%d, sda_pullup_en:%d, scl_pullup_en:%d, master.clk_speed:%d, clk_flags:%d", i2c_config.mode, i2c_config.sda_io_num, i2c_config.scl_io_num, i2c_config.sda_pullup_en, i2c_config.scl_pullup_en, i2c_config.master.clk_speed, i2c_config.clk_flags); + log_d("i2c_config: mode:%d, sda_io_num:%d, scl_io_num:%d, sda_pullup_en:%d, scl_pullup_en:%d, master.clk_speed:%d, clk_flags:%d", i2c_config.mode, i2c_config.sda_io_num, i2c_config.scl_io_num, i2c_config.sda_pullup_en, i2c_config.scl_pullup_en, i2c_config.master.clk_speed, i2c_config.clk_flags); ESP_ERROR_CHECK(i2c_param_config(GT911_I2C_HOST, &i2c_config)); ESP_ERROR_CHECK(i2c_driver_install(GT911_I2C_HOST, i2c_config.mode, 0, 0, 0)); @@ -56,7 +56,7 @@ void lvgl_touch_init(lv_indev_drv_t *drv) .flags = { .dc_low_on_data = GT911_IO_I2C_CONFIG_FLAGS_DC_LOW_ON_DATA, .disable_control_phase = GT911_IO_I2C_CONFIG_FLAGS_DISABLE_CONTROL_PHASE}}; - log_v("io_i2c_config: dev_addr:0x%02x, control_phase_bytes:%d, user_ctx:0x%08x, dc_bit_offset:%d, lcd_cmd_bits:%d, lcd_param_bits:%d, flags.dc_low_on_data:%d, flags.disable_control_phase:%d", io_i2c_config.dev_addr, io_i2c_config.control_phase_bytes, io_i2c_config.user_ctx, io_i2c_config.dc_bit_offset, io_i2c_config.lcd_cmd_bits, io_i2c_config.lcd_param_bits, io_i2c_config.flags.dc_low_on_data, io_i2c_config.flags.disable_control_phase); + log_d("io_i2c_config: dev_addr:0x%02x, control_phase_bytes:%d, user_ctx:0x%08x, dc_bit_offset:%d, lcd_cmd_bits:%d, lcd_param_bits:%d, flags.dc_low_on_data:%d, flags.disable_control_phase:%d", io_i2c_config.dev_addr, io_i2c_config.control_phase_bytes, io_i2c_config.user_ctx, io_i2c_config.dc_bit_offset, io_i2c_config.lcd_cmd_bits, io_i2c_config.lcd_param_bits, io_i2c_config.flags.dc_low_on_data, io_i2c_config.flags.disable_control_phase); esp_lcd_panel_io_handle_t io_handle; ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)GT911_I2C_HOST, &io_i2c_config, &io_handle)); @@ -71,7 +71,7 @@ void lvgl_touch_init(lv_indev_drv_t *drv) .interrupt = GT911_TOUCH_CONFIG_LEVELS_INTERRUPT}, //.flags = {.swap_xy = LCD_SWAP_XY, .mirror_x = LCD_MIRROR_X, .mirror_y = LCD_MIRROR_Y}, .user_data = io_handle}; - log_v("touch_config: x_max:%d, y_max:%d, rst_gpio_num:%d, int_gpio_num:%d, levels.reset:%d, levels.interrupt:%d, flags.swap_xy:%d, flags.mirror_x:%d, flags.mirror_y:%d, user_data:0x%08x", touch_config.x_max, touch_config.y_max, touch_config.rst_gpio_num, touch_config.int_gpio_num, touch_config.levels.reset, touch_config.levels.interrupt, touch_config.flags.swap_xy, touch_config.flags.mirror_x, touch_config.flags.mirror_y, touch_config.user_data); + log_d("touch_config: x_max:%d, y_max:%d, rst_gpio_num:%d, int_gpio_num:%d, levels.reset:%d, levels.interrupt:%d, flags.swap_xy:%d, flags.mirror_x:%d, flags.mirror_y:%d, user_data:0x%08x", touch_config.x_max, touch_config.y_max, touch_config.rst_gpio_num, touch_config.int_gpio_num, touch_config.levels.reset, touch_config.levels.interrupt, touch_config.flags.swap_xy, touch_config.flags.mirror_x, touch_config.flags.mirror_y, touch_config.user_data); esp_lcd_touch_handle_t touch_handle; ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_gt911(io_handle, &touch_config, &touch_handle)); diff --git a/src/lvgl_xpt2046_spi.c b/src/lvgl_xpt2046_spi.c index 5774b49..b24fee1 100644 --- a/src/lvgl_xpt2046_spi.c +++ b/src/lvgl_xpt2046_spi.c @@ -69,7 +69,7 @@ void lvgl_touch_init(lv_indev_drv_t *drv) .interrupt = XPT2046_TOUCH_CONFIG_LEVELS_INTERRUPT}, //.flags = {.swap_xy = LCD_SWAP_XY, .mirror_x = LCD_MIRROR_X, .mirror_y = LCD_MIRROR_Y}, .user_data = io_handle}; - log_v("touch_config: x_max:%d, y_max:%d, rst_gpio_num:%d, int_gpio_num:%d, levels.reset:%d, levels.interrupt:%d, flags.swap_xy:%d, flags.mirror_x:%d, flags.mirror_y:%d, user_data:0x%08x", touch_config.x_max, touch_config.y_max, touch_config.rst_gpio_num, touch_config.int_gpio_num, touch_config.levels.reset, touch_config.levels.interrupt, touch_config.flags.swap_xy, touch_config.flags.mirror_x, touch_config.flags.mirror_y, touch_config.user_data); + log_d("touch_config: x_max:%d, y_max:%d, rst_gpio_num:%d, int_gpio_num:%d, levels.reset:%d, levels.interrupt:%d, flags.swap_xy:%d, flags.mirror_x:%d, flags.mirror_y:%d, user_data:0x%08x", touch_config.x_max, touch_config.y_max, touch_config.rst_gpio_num, touch_config.int_gpio_num, touch_config.levels.reset, touch_config.levels.interrupt, touch_config.flags.swap_xy, touch_config.flags.mirror_x, touch_config.flags.mirror_y, touch_config.user_data); esp_lcd_touch_handle_t touch_handle; ESP_ERROR_CHECK(esp_lcd_touch_new_spi_xpt2046(io_handle, &touch_config, &touch_handle));