Skip to content

Commit

Permalink
Disabled reading info from gt911. Seems to cause problems
Browse files Browse the repository at this point in the history
  • Loading branch information
rzeldent committed Mar 5, 2024
1 parent 5ce2c69 commit 450bb4d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 46 deletions.
93 changes: 54 additions & 39 deletions src/esp_lcd_touch_gt911.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -125,24 +145,24 @@ 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
log_d("GT911 vendorId: %02x", info->vendorId); // 0x814A

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;
}

Expand Down Expand Up @@ -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)
Expand All @@ -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");
Expand All @@ -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)
{
Expand All @@ -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);
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/lvgl_cst816s_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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));

Expand All @@ -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));

Expand Down
6 changes: 3 additions & 3 deletions src/lvgl_gt911_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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));

Expand All @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion src/lvgl_xpt2046_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit 450bb4d

Please sign in to comment.