Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/esp_lvgl_port/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 2.6.3

### Fixes
- Improved and fixed deinit function (remove semaphor) - https://github.com/espressif/esp-bsp/issues/673

## 2.6.2

- Changed minimum IDF version to IDF5.1
Expand Down
2 changes: 1 addition & 1 deletion components/esp_lvgl_port/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "2.6.2"
version: "2.6.3"
description: ESP LVGL port
url: https://github.com/espressif/esp-bsp/tree/master/components/esp_lvgl_port
dependencies:
Expand Down
44 changes: 10 additions & 34 deletions components/esp_lvgl_port/src/lvgl8/esp_lvgl_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,13 @@

static const char *TAG = "LVGL";

#define ESP_LVGL_PORT_TASK_MUX_DELAY_MS 10000

/*******************************************************************************
* Types definitions
*******************************************************************************/

typedef struct lvgl_port_ctx_s {
TaskHandle_t lvgl_task;
SemaphoreHandle_t lvgl_mux;
SemaphoreHandle_t task_mux;
esp_timer_handle_t tick_timer;
bool running;
int task_max_sleep_ms;
Expand Down Expand Up @@ -73,9 +70,6 @@ esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg)
/* LVGL semaphore */
lvgl_port_ctx.lvgl_mux = xSemaphoreCreateRecursiveMutex();
ESP_GOTO_ON_FALSE(lvgl_port_ctx.lvgl_mux, ESP_ERR_NO_MEM, err, TAG, "Create LVGL mutex fail!");
/* Task semaphore */
lvgl_port_ctx.task_mux = xSemaphoreCreateMutex();
ESP_GOTO_ON_FALSE(lvgl_port_ctx.task_mux, ESP_ERR_NO_MEM, err, TAG, "Create LVGL task sem fail!");

BaseType_t res;
const uint32_t caps = cfg->task_stack_caps ? cfg->task_stack_caps : MALLOC_CAP_INTERNAL | MALLOC_CAP_DEFAULT; // caps cannot be zero
Expand Down Expand Up @@ -120,27 +114,11 @@ esp_err_t lvgl_port_stop(void)

esp_err_t lvgl_port_deinit(void)
{
/* Stop and delete timer */
if (lvgl_port_ctx.tick_timer != NULL) {
esp_timer_stop(lvgl_port_ctx.tick_timer);
esp_timer_delete(lvgl_port_ctx.tick_timer);
lvgl_port_ctx.tick_timer = NULL;
}

/* Stop running task */
if (lvgl_port_ctx.running) {
lvgl_port_ctx.running = false;
}

/* Wait for stop task */
if (xSemaphoreTake(lvgl_port_ctx.task_mux, pdMS_TO_TICKS(ESP_LVGL_PORT_TASK_MUX_DELAY_MS)) != pdTRUE) {
ESP_LOGE(TAG, "Failed to stop LVGL task");
return ESP_ERR_TIMEOUT;
}
ESP_LOGI(TAG, "Stopped LVGL task");

lvgl_port_task_deinit();

return ESP_OK;
}

Expand Down Expand Up @@ -186,13 +164,6 @@ static void lvgl_port_task(void *arg)
{
uint32_t task_delay_ms = lvgl_port_ctx.task_max_sleep_ms;

/* Take the task semaphore */
if (xSemaphoreTake(lvgl_port_ctx.task_mux, 0) != pdTRUE) {
ESP_LOGE(TAG, "Failed to take LVGL task sem");
lvgl_port_task_deinit();
vTaskDelete( NULL );
}

ESP_LOGI(TAG, "Starting LVGL task");
lvgl_port_ctx.running = true;
while (lvgl_port_ctx.running) {
Expand All @@ -208,21 +179,26 @@ static void lvgl_port_task(void *arg)
vTaskDelay(pdMS_TO_TICKS(task_delay_ms));
}

/* Give semaphore back */
xSemaphoreGive(lvgl_port_ctx.task_mux);
ESP_LOGI(TAG, "Stopped LVGL task");

lvgl_port_task_deinit();

/* Close task */
vTaskDelete( NULL );
}

static void lvgl_port_task_deinit(void)
{
/* Stop and delete timer */
if (lvgl_port_ctx.tick_timer != NULL) {
esp_timer_stop(lvgl_port_ctx.tick_timer);
esp_timer_delete(lvgl_port_ctx.tick_timer);
lvgl_port_ctx.tick_timer = NULL;
}

if (lvgl_port_ctx.lvgl_mux) {
vSemaphoreDelete(lvgl_port_ctx.lvgl_mux);
}
if (lvgl_port_ctx.task_mux) {
vSemaphoreDelete(lvgl_port_ctx.task_mux);
}
memset(&lvgl_port_ctx, 0, sizeof(lvgl_port_ctx));
#if LV_ENABLE_GC || !LV_MEM_CUSTOM
/* Deinitialize LVGL */
Expand Down
45 changes: 11 additions & 34 deletions components/esp_lvgl_port/src/lvgl9/esp_lvgl_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

static const char *TAG = "LVGL";

#define ESP_LVGL_PORT_TASK_MUX_DELAY_MS 10000

/*******************************************************************************
* Types definitions
*******************************************************************************/
Expand All @@ -33,7 +31,6 @@ typedef struct lvgl_port_ctx_s {
SemaphoreHandle_t lvgl_mux;
SemaphoreHandle_t timer_mux;
EventGroupHandle_t lvgl_events;
SemaphoreHandle_t task_init_mux;
esp_timer_handle_t tick_timer;
bool running;
int task_max_sleep_ms;
Expand Down Expand Up @@ -77,9 +74,6 @@ esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg)
/* LVGL semaphore */
lvgl_port_ctx.lvgl_mux = xSemaphoreCreateRecursiveMutex();
ESP_GOTO_ON_FALSE(lvgl_port_ctx.lvgl_mux, ESP_ERR_NO_MEM, err, TAG, "Create LVGL mutex fail!");
/* Task init semaphore */
lvgl_port_ctx.task_init_mux = xSemaphoreCreateMutex();
ESP_GOTO_ON_FALSE(lvgl_port_ctx.task_init_mux, ESP_ERR_NO_MEM, err, TAG, "Create LVGL task sem fail!");
/* Task queue */
lvgl_port_ctx.lvgl_events = xEventGroupCreate();
ESP_GOTO_ON_FALSE(lvgl_port_ctx.lvgl_events, ESP_ERR_NO_MEM, err, TAG, "Create LVGL Event Group fail!");
Expand Down Expand Up @@ -132,27 +126,11 @@ esp_err_t lvgl_port_stop(void)

esp_err_t lvgl_port_deinit(void)
{
/* Stop and delete timer */
if (lvgl_port_ctx.tick_timer != NULL) {
esp_timer_stop(lvgl_port_ctx.tick_timer);
esp_timer_delete(lvgl_port_ctx.tick_timer);
lvgl_port_ctx.tick_timer = NULL;
}

/* Stop running task */
if (lvgl_port_ctx.running) {
lvgl_port_ctx.running = false;
}

/* Wait for stop task */
if (xSemaphoreTake(lvgl_port_ctx.task_init_mux, pdMS_TO_TICKS(ESP_LVGL_PORT_TASK_MUX_DELAY_MS)) != pdTRUE) {
ESP_LOGE(TAG, "Failed to stop LVGL task");
return ESP_ERR_TIMEOUT;
}
ESP_LOGI(TAG, "Stopped LVGL task");

lvgl_port_task_deinit();

return ESP_OK;
}

Expand Down Expand Up @@ -226,13 +204,6 @@ static void lvgl_port_task(void *arg)
uint32_t task_delay_ms = 0;
lv_indev_t *indev = NULL;

/* Take the task semaphore */
if (xSemaphoreTake(lvgl_port_ctx.task_init_mux, 0) != pdTRUE) {
ESP_LOGE(TAG, "Failed to take LVGL task sem");
lvgl_port_task_deinit();
vTaskDelete( NULL );
}

/* LVGL init */
lv_init();
/* LVGL is initialized, notify lvgl_port_init() function about it */
Expand Down Expand Up @@ -275,24 +246,30 @@ static void lvgl_port_task(void *arg)
vTaskDelay(1);
}

/* Give semaphore back */
xSemaphoreGive(lvgl_port_ctx.task_init_mux);
ESP_LOGI(TAG, "Stopped LVGL task");

/* Deinit LVGL */
lvgl_port_task_deinit();

/* Close task */
vTaskDelete( NULL );
}

static void lvgl_port_task_deinit(void)
{
/* Stop and delete timer */
if (lvgl_port_ctx.tick_timer != NULL) {
esp_timer_stop(lvgl_port_ctx.tick_timer);
esp_timer_delete(lvgl_port_ctx.tick_timer);
lvgl_port_ctx.tick_timer = NULL;
}

if (lvgl_port_ctx.timer_mux) {
vSemaphoreDelete(lvgl_port_ctx.timer_mux);
}
if (lvgl_port_ctx.lvgl_mux) {
vSemaphoreDelete(lvgl_port_ctx.lvgl_mux);
}
if (lvgl_port_ctx.task_init_mux) {
vSemaphoreDelete(lvgl_port_ctx.task_init_mux);
}
if (lvgl_port_ctx.lvgl_events) {
vEventGroupDelete(lvgl_port_ctx.lvgl_events);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## IDF Component Manager Manifest File
dependencies:
idf: ">=4.4"
esp_lcd_touch_tt21100:
esp_lcd_ili9341: "^2.0.1"
esp_lcd_touch_gt911:
version: "^1"
override_path: "../../../../lcd_touch/esp_lcd_touch_tt21100/"
override_path: "../../../../lcd_touch/esp_lcd_touch_gt911/"
esp_lvgl_port:
version: "*"
override_path: "../../../"
45 changes: 33 additions & 12 deletions components/esp_lvgl_port/test_apps/lvgl_port/main/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
#include "esp_lcd_panel_vendor.h"
#include "esp_lcd_panel_ops.h"
#include "esp_lvgl_port.h"
#include "esp_lcd_ili9341.h"

#include "esp_lcd_touch_tt21100.h"
#include "esp_lcd_touch_gt911.h"

#include "unity.h"

Expand All @@ -40,7 +41,7 @@
#define EXAMPLE_LCD_GPIO_RST (GPIO_NUM_48)
#define EXAMPLE_LCD_GPIO_DC (GPIO_NUM_4)
#define EXAMPLE_LCD_GPIO_CS (GPIO_NUM_5)
#define EXAMPLE_LCD_GPIO_BL (GPIO_NUM_45)
#define EXAMPLE_LCD_GPIO_BL (GPIO_NUM_47)

/* Touch settings */
#define EXAMPLE_TOUCH_I2C_NUM (0)
Expand All @@ -64,6 +65,26 @@ static lv_display_t *lvgl_disp = NULL;
static lv_indev_t *lvgl_touch_indev = NULL;
static i2c_master_bus_handle_t i2c_handle = NULL;

static const ili9341_lcd_init_cmd_t vendor_specific_init[] = {
{0xC8, (uint8_t []){0xFF, 0x93, 0x42}, 3, 0},
{0xC0, (uint8_t []){0x0E, 0x0E}, 2, 0},
{0xC5, (uint8_t []){0xD0}, 1, 0},
{0xC1, (uint8_t []){0x02}, 1, 0},
{0xB4, (uint8_t []){0x02}, 1, 0},
{0xE0, (uint8_t []){0x00, 0x03, 0x08, 0x06, 0x13, 0x09, 0x39, 0x39, 0x48, 0x02, 0x0a, 0x08, 0x17, 0x17, 0x0F}, 15, 0},
{0xE1, (uint8_t []){0x00, 0x28, 0x29, 0x01, 0x0d, 0x03, 0x3f, 0x33, 0x52, 0x04, 0x0f, 0x0e, 0x37, 0x38, 0x0F}, 15, 0},

{0xB1, (uint8_t []){00, 0x1B}, 2, 0},
{0x36, (uint8_t []){0x08}, 1, 0},
{0x3A, (uint8_t []){0x55}, 1, 0},
{0xB7, (uint8_t []){0x06}, 1, 0},

{0x11, (uint8_t []){0}, 0x80, 0},
{0x29, (uint8_t []){0}, 0x80, 0},

{0, (uint8_t []){0}, 0xff, 0},
};

static esp_err_t app_lcd_init(void)
{
esp_err_t ret = ESP_OK;
Expand Down Expand Up @@ -100,16 +121,22 @@ static esp_err_t app_lcd_init(void)
ESP_GOTO_ON_ERROR(esp_lcd_new_panel_io_spi((esp_lcd_spi_bus_handle_t)EXAMPLE_LCD_SPI_NUM, &io_config, &lcd_io), err, TAG, "New panel IO failed");

ESP_LOGD(TAG, "Install LCD driver");
const ili9341_vendor_config_t vendor_config = {
.init_cmds = &vendor_specific_init[0],
.init_cmds_size = sizeof(vendor_specific_init) / sizeof(ili9341_lcd_init_cmd_t),
};
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = EXAMPLE_LCD_GPIO_RST,
.flags.reset_active_high = 1,
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(6, 0, 0)
.rgb_endian = LCD_RGB_ENDIAN_BGR,
#else
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_BGR,
#endif
.bits_per_pixel = EXAMPLE_LCD_BITS_PER_PIXEL,
.vendor_config = (void *) &vendor_config,
};
ESP_GOTO_ON_ERROR(esp_lcd_new_panel_st7789(lcd_io, &panel_config, &lcd_panel), err, TAG, "New panel failed");
ESP_GOTO_ON_ERROR(esp_lcd_new_panel_ili9341(lcd_io, &panel_config, &lcd_panel), err, TAG, "New panel failed");

esp_lcd_panel_reset(lcd_panel);
esp_lcd_panel_init(lcd_panel);
Expand Down Expand Up @@ -168,10 +195,10 @@ static esp_err_t app_touch_init(void)
.mirror_y = 0,
},
};
esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_TT21100_CONFIG();
esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG();
tp_io_config.scl_speed_hz = EXAMPLE_TOUCH_I2C_CLK_HZ;
ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c(i2c_handle, &tp_io_config, &tp_io_handle), TAG, "");
return esp_lcd_touch_new_i2c_tt21100(tp_io_handle, &tp_cfg, &touch_handle);
return esp_lcd_touch_new_i2c_gt911(tp_io_handle, &tp_cfg, &touch_handle);
}

static esp_err_t app_touch_deinit(void)
Expand All @@ -185,13 +212,7 @@ static esp_err_t app_touch_deinit(void)
static esp_err_t app_lvgl_init(void)
{
/* Initialize LVGL */
const lvgl_port_cfg_t lvgl_cfg = {
.task_priority = 4, /* LVGL task priority */
.task_stack = 4096, /* LVGL task stack size */
.task_affinity = -1, /* LVGL task pinned to core (-1 is no affinity) */
.task_max_sleep_ms = 500, /* Maximum sleep in LVGL task */
.timer_period_ms = 5 /* LVGL timer tick period in ms */
};
const lvgl_port_cfg_t lvgl_cfg = ESP_LVGL_PORT_INIT_CONFIG();
ESP_RETURN_ON_ERROR(lvgl_port_init(&lvgl_cfg), TAG, "LVGL port initialization failed");

/* Add LCD screen */
Expand Down
Loading