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 f1b8ece commit b9df093
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 31 deletions.
42 changes: 22 additions & 20 deletions src/esp_lcd_gc9a01.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
26 changes: 20 additions & 6 deletions src/esp_lcd_touch_cst816s.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/esp_lcd_touch_gt911.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/esp_lcd_touch_xpt2046.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions src/lvgl_gc9a01_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@

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

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

0 comments on commit b9df093

Please sign in to comment.