Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rzeldent committed Mar 5, 2024
1 parent 450bb4d commit bb278c0
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 53 deletions.
6 changes: 0 additions & 6 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ build_flags =
'-D ESP_LCD_GC9A01_VER_MINOR=2'
'-D ESP_LCD_GC9A01_VER_PATCH=0'

# Defined in boards
# "'-D CONFIG_ESP_LCD_TOUCH_MAX_POINTS=1'"
# "'-D CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS=0'"
# "'-D GT911_IO_I2C_CONFIG_DEV_ADDRESS=0x5D"
# "'-D XPT2046_Z_THRESHOLD=600'"

lib_deps =
lvgl/lvgl@^8.3.9
# The platformio.test_dir contains the test_main.cpp just to have an setup() and loop() function
Expand Down
12 changes: 6 additions & 6 deletions src/esp_lcd_touch_cst816s.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extern "C"

esp_err_t cst816s_reset(esp_lcd_touch_handle_t th)
{
log_v("cst816s_reset. th:0x%08x", th);
log_v("th:0x%08x", th);

esp_err_t res;

Expand Down Expand Up @@ -103,7 +103,7 @@ extern "C"

esp_err_t cst816s_read_info(esp_lcd_touch_handle_t th)
{
log_v("cst816s_read_info. th:0x%08x", th);
log_v("th:0x%08x", th);

esp_err_t res;

Expand All @@ -123,7 +123,7 @@ extern "C"

esp_err_t cst816s_read_data(esp_lcd_touch_handle_t th)
{
log_v("cst816s_read_data. th:0x%08x", th);
log_v("th:0x%08x", th);

esp_err_t res;
cst816s_touch_event buffer;
Expand All @@ -150,7 +150,7 @@ extern "C"

bool cst816s_get_xy(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("cst816s_get_xy. 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);
log_v("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);
*point_num = th->data.points > max_point_num ? max_point_num : th->data.points;
Expand All @@ -170,7 +170,7 @@ extern "C"

esp_err_t cst816s_del(esp_lcd_touch_handle_t th)
{
log_v("cst816s_del. th:0x%08x", th);
log_v("th:0x%08x", th);

portENTER_CRITICAL(&th->data.lock);

Expand All @@ -194,7 +194,7 @@ extern "C"

esp_err_t esp_lcd_touch_new_i2c_gt911(const esp_lcd_panel_io_handle_t io, const esp_lcd_touch_config_t *config, esp_lcd_touch_handle_t *handle)
{
log_v("esp_lcd_touch_new_spi_gt911. 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);
Expand Down
66 changes: 34 additions & 32 deletions src/esp_lcd_touch_gt911.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ extern "C"

esp_err_t gt911_reset(esp_lcd_touch_handle_t th)
{
log_v("gt911_reset. th:0x%08x", th);
log_v("th:0x%08x", th);

esp_err_t res;

Expand Down Expand Up @@ -99,7 +99,7 @@ extern "C"
// 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);
log_v("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;
Expand All @@ -110,15 +110,15 @@ extern "C"
// 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);
log_d("Processed coordinates: (%d,%d), area:%d", x[i], y[i], strength[i]);
}

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);
log_v("th:0x%08x", th);

esp_err_t res;

Expand All @@ -129,37 +129,40 @@ extern "C"
th->config.user_data = NULL;
}

gt911_info *info = heap_caps_calloc(1, sizeof(gt911_info), MALLOC_CAP_DEFAULT);
if (info == NULL)
gt911_info info;
uint8_t config;
if ((res = esp_lcd_panel_io_rx_param(th->io, GT911_PRODUCT_ID_REG, &info, sizeof(info))) != ESP_OK ||
(res = esp_lcd_panel_io_rx_param(th->io, GT911_CONFIG_REG, &config, sizeof(config))) != ESP_OK)
{
log_e("No memory available for gt911_info");
return ESP_ERR_NO_MEM;
}

if ((res = esp_lcd_panel_io_rx_param(th->io, GT911_PRODUCT_ID_REG, info, sizeof(gt911_info))) != ESP_OK)
{
free(info);
log_e("Unable to read GT911 info");
return res;
}

if (strcmp((char *)&info->productId, "911") != 0)
if (strcmp((char *)&info.productId, "911") != 0)
{
free(info);
log_e("GT911 chip not found");
return ESP_FAIL;
}

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
log_d("GT911 productId: %s", info.productId); // 0x8140 - 0x8143
log_d("GT911 fwId: 0x%04x", info.fwId); // 0x8144 - 0x8145
log_d("GT911 xResolution/yResolution: (%d, %d)", info.xResolution, info.yResolution); // 0x8146 - 0x8147 // 0x8148 - 0x8149
log_d("GT911 vendorId: 0x%02x", info.vendorId); // 0x814A
log_d("GT911 config reg: 0x%02x", config); // 0x8047

gt911_info *gt911_info = heap_caps_calloc(1, sizeof(gt911_info), MALLOC_CAP_DEFAULT);
if (gt911_info == NULL)
{
log_e("No memory available for gt911_info");
return ESP_ERR_NO_MEM;
}

th->config.user_data = info;
memcpy(gt911_info, &info, sizeof(info));
th->config.user_data = gt911_info;

if (info->xResolution > 0 && info->yResolution > 0 && (info->xResolution != th->config.x_max || info->yResolution != th->config.y_max))
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);
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;
}

Expand All @@ -168,7 +171,7 @@ extern "C"

esp_err_t gt911_enter_sleep(esp_lcd_touch_handle_t th)
{
log_v("gt911_enter_sleep. th:0x%08x", th);
log_v("th:0x%08x", th);

esp_err_t res;
const uint8_t data[] = {0x05}; // Sleep
Expand All @@ -180,7 +183,7 @@ extern "C"

esp_err_t gt911_exit_sleep(esp_lcd_touch_handle_t th)
{
log_v("gt911_exit_sleep. th:0x%08x", th);
log_v("th:0x%08x", th);

esp_err_t res;
if (th->config.int_gpio_num == GPIO_NUM_NC)
Expand Down Expand Up @@ -212,7 +215,7 @@ extern "C"

esp_err_t gt911_read_data(esp_lcd_touch_handle_t th)
{
log_v("gt911_read_data. th:0x%08x", th);
log_v("th:0x%08x", th);

esp_err_t res;
gt911_touch_data buffer;
Expand Down Expand Up @@ -262,7 +265,7 @@ extern "C"
portENTER_CRITICAL(&th->data.lock);
for (uint8_t i = 0; i < points_available; i++)
{
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);
log_d("Point: #%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;
Expand All @@ -286,7 +289,7 @@ extern "C"

bool gt911_get_xy(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_get_xy. 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);
log_v("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);
*point_num = th->data.points > max_point_num ? max_point_num : th->data.points;
Expand All @@ -297,7 +300,7 @@ extern "C"
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);
log_d("touch data: x:%d, y:%d, area:%d", x[i], y[i], strength != NULL ? strength[i] : 0);
}

th->data.points = 0;
Expand All @@ -309,7 +312,7 @@ extern "C"
#if (CONFIG_ESP_LCD_TOUCH_MAX_BUTTONS > 0)
esp_err_t gt911_get_button_state(esp_lcd_touch_handle_t th, uint8_t n, uint8_t *state)
{
log_v("gt911_get_xy. th:0x%08x, n:%d, state:0x%08x", th, n, state);
log_v("th:0x%08x, n:%d, state:0x%08x", th, n, state);

if (n > th->data.buttons)
{
Expand All @@ -327,7 +330,7 @@ extern "C"

esp_err_t gt911_del(esp_lcd_touch_handle_t th)
{
log_v("gt911_del. th:0x%08x", th);
log_v("th:0x%08x", th);

portENTER_CRITICAL(&th->data.lock);
// Remove gt911_info
Expand All @@ -354,7 +357,7 @@ extern "C"

esp_err_t esp_lcd_touch_new_i2c_gt911(const esp_lcd_panel_io_handle_t io, const esp_lcd_touch_config_t *config, esp_lcd_touch_handle_t *handle)
{
log_v("esp_lcd_touch_new_spi_gt911. 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);
Expand Down Expand Up @@ -449,7 +452,6 @@ extern "C"
return res;
}

// TODO: creates an invalid instruction when reading
// Read type and resolution
// if ((res = gt911_read_info(th)) != ESP_OK)
// {
Expand Down
18 changes: 9 additions & 9 deletions src/esp_lcd_touch_xpt2046.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern "C"

esp_err_t xpt2046_enter_sleep(esp_lcd_touch_handle_t th)
{
log_v("xpt2046_enter_sleep. th:0x%08x", th);
log_v("th:0x%08x", th);

esp_err_t res;
uint16_t discard;
Expand All @@ -49,7 +49,7 @@ extern "C"

esp_err_t xpt2046_exit_sleep(esp_lcd_touch_handle_t th)
{
log_v("xpt2046_exit_sleep. th:0x%08x", th);
log_v("th:0x%08x", th);

esp_err_t res;
uint16_t discard;
Expand All @@ -64,7 +64,7 @@ extern "C"

esp_err_t xpt2046_read_data(esp_lcd_touch_handle_t th)
{
log_v("xpt2046_read_data. th:0x%08x", th);
log_v("th:0x%08x", th);

esp_err_t res;
uint32_t x = 0, y = 0;
Expand Down Expand Up @@ -125,7 +125,7 @@ extern "C"

bool xpt2046_get_xy(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("xpt2046_get_xy. 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);
log_v("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);
*point_num = th->data.points > max_point_num ? max_point_num : th->data.points;
Expand Down Expand Up @@ -154,7 +154,7 @@ extern "C"

esp_err_t xpt2046_del(esp_lcd_touch_handle_t th)
{
log_v("xpt2046_del. th:0x%08x", th);
log_v("th:0x%08x", th);

portENTER_CRITICAL(&th->data.lock);
// Remove interrupts and reset INT
Expand All @@ -173,7 +173,7 @@ extern "C"

esp_err_t esp_lcd_touch_new_spi_xpt2046(const esp_lcd_panel_io_handle_t io, const esp_lcd_touch_config_t *config, esp_lcd_touch_handle_t *handle)
{
log_v("esp_lcd_touch_new_spi_xpt2046. 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);
Expand Down Expand Up @@ -237,9 +237,9 @@ extern "C"
return ESP_OK;
}

esp_err_t esp_lcd_touch_xpt2046_read_battery_level(const esp_lcd_touch_handle_t th, float *outhut)
esp_err_t esp_lcd_touch_xpt2046_read_battery_level(const esp_lcd_touch_handle_t th, float *output)
{
log_v("esp_lcd_touch_xpt2046_read_battery_level. th:0x%08x, outhut:0x%08x", th, outhut);
log_v("th:0x%08x, output:0x%08x", th, output);

assert(th != NULL);
assert(outhut != NULL);
Expand All @@ -256,7 +256,7 @@ extern "C"
// battery voltage is reported as 1/4 the actual voltage due to logic in the chip, then
// adjust for internal vref of 2.5v and finally
// adjust for ADC bit count
*outhut = level * 4 * 2.5f / XPT2046_ADC_LIMIT;
*output = level * 4 * 2.5f / XPT2046_ADC_LIMIT;

return ESP_OK;
}
Expand Down

0 comments on commit bb278c0

Please sign in to comment.