Skip to content

Commit 21c6cd0

Browse files
authored
Merge pull request #675 from espressif/fix/lvgl_port_deinit_fix
fix(lvgl_port): Improved and fixed deinit function (remove semaphore)
2 parents 7245bf2 + b1c0156 commit 21c6cd0

File tree

6 files changed

+63
-83
lines changed

6 files changed

+63
-83
lines changed

components/esp_lvgl_port/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 2.6.3
4+
5+
### Fixes
6+
- Improved and fixed deinit function (remove semaphor) - https://github.com/espressif/esp-bsp/issues/673
7+
38
## 2.6.2
49

510
- Changed minimum IDF version to IDF5.1

components/esp_lvgl_port/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "2.6.2"
1+
version: "2.6.3"
22
description: ESP LVGL port
33
url: https://github.com/espressif/esp-bsp/tree/master/components/esp_lvgl_port
44
dependencies:

components/esp_lvgl_port/src/lvgl8/esp_lvgl_port.c

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@
2020

2121
static const char *TAG = "LVGL";
2222

23-
#define ESP_LVGL_PORT_TASK_MUX_DELAY_MS 10000
24-
2523
/*******************************************************************************
2624
* Types definitions
2725
*******************************************************************************/
2826

2927
typedef struct lvgl_port_ctx_s {
3028
TaskHandle_t lvgl_task;
3129
SemaphoreHandle_t lvgl_mux;
32-
SemaphoreHandle_t task_mux;
3330
esp_timer_handle_t tick_timer;
3431
bool running;
3532
int task_max_sleep_ms;
@@ -73,9 +70,6 @@ esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg)
7370
/* LVGL semaphore */
7471
lvgl_port_ctx.lvgl_mux = xSemaphoreCreateRecursiveMutex();
7572
ESP_GOTO_ON_FALSE(lvgl_port_ctx.lvgl_mux, ESP_ERR_NO_MEM, err, TAG, "Create LVGL mutex fail!");
76-
/* Task semaphore */
77-
lvgl_port_ctx.task_mux = xSemaphoreCreateMutex();
78-
ESP_GOTO_ON_FALSE(lvgl_port_ctx.task_mux, ESP_ERR_NO_MEM, err, TAG, "Create LVGL task sem fail!");
7973

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

121115
esp_err_t lvgl_port_deinit(void)
122116
{
123-
/* Stop and delete timer */
124-
if (lvgl_port_ctx.tick_timer != NULL) {
125-
esp_timer_stop(lvgl_port_ctx.tick_timer);
126-
esp_timer_delete(lvgl_port_ctx.tick_timer);
127-
lvgl_port_ctx.tick_timer = NULL;
128-
}
129-
130117
/* Stop running task */
131118
if (lvgl_port_ctx.running) {
132119
lvgl_port_ctx.running = false;
133120
}
134121

135-
/* Wait for stop task */
136-
if (xSemaphoreTake(lvgl_port_ctx.task_mux, pdMS_TO_TICKS(ESP_LVGL_PORT_TASK_MUX_DELAY_MS)) != pdTRUE) {
137-
ESP_LOGE(TAG, "Failed to stop LVGL task");
138-
return ESP_ERR_TIMEOUT;
139-
}
140-
ESP_LOGI(TAG, "Stopped LVGL task");
141-
142-
lvgl_port_task_deinit();
143-
144122
return ESP_OK;
145123
}
146124

@@ -186,13 +164,6 @@ static void lvgl_port_task(void *arg)
186164
{
187165
uint32_t task_delay_ms = lvgl_port_ctx.task_max_sleep_ms;
188166

189-
/* Take the task semaphore */
190-
if (xSemaphoreTake(lvgl_port_ctx.task_mux, 0) != pdTRUE) {
191-
ESP_LOGE(TAG, "Failed to take LVGL task sem");
192-
lvgl_port_task_deinit();
193-
vTaskDelete( NULL );
194-
}
195-
196167
ESP_LOGI(TAG, "Starting LVGL task");
197168
lvgl_port_ctx.running = true;
198169
while (lvgl_port_ctx.running) {
@@ -208,21 +179,26 @@ static void lvgl_port_task(void *arg)
208179
vTaskDelay(pdMS_TO_TICKS(task_delay_ms));
209180
}
210181

211-
/* Give semaphore back */
212-
xSemaphoreGive(lvgl_port_ctx.task_mux);
182+
ESP_LOGI(TAG, "Stopped LVGL task");
183+
184+
lvgl_port_task_deinit();
213185

214186
/* Close task */
215187
vTaskDelete( NULL );
216188
}
217189

218190
static void lvgl_port_task_deinit(void)
219191
{
192+
/* Stop and delete timer */
193+
if (lvgl_port_ctx.tick_timer != NULL) {
194+
esp_timer_stop(lvgl_port_ctx.tick_timer);
195+
esp_timer_delete(lvgl_port_ctx.tick_timer);
196+
lvgl_port_ctx.tick_timer = NULL;
197+
}
198+
220199
if (lvgl_port_ctx.lvgl_mux) {
221200
vSemaphoreDelete(lvgl_port_ctx.lvgl_mux);
222201
}
223-
if (lvgl_port_ctx.task_mux) {
224-
vSemaphoreDelete(lvgl_port_ctx.task_mux);
225-
}
226202
memset(&lvgl_port_ctx, 0, sizeof(lvgl_port_ctx));
227203
#if LV_ENABLE_GC || !LV_MEM_CUSTOM
228204
/* Deinitialize LVGL */

components/esp_lvgl_port/src/lvgl9/esp_lvgl_port.c

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
static const char *TAG = "LVGL";
2424

25-
#define ESP_LVGL_PORT_TASK_MUX_DELAY_MS 10000
26-
2725
/*******************************************************************************
2826
* Types definitions
2927
*******************************************************************************/
@@ -33,7 +31,6 @@ typedef struct lvgl_port_ctx_s {
3331
SemaphoreHandle_t lvgl_mux;
3432
SemaphoreHandle_t timer_mux;
3533
EventGroupHandle_t lvgl_events;
36-
SemaphoreHandle_t task_init_mux;
3734
esp_timer_handle_t tick_timer;
3835
bool running;
3936
int task_max_sleep_ms;
@@ -77,9 +74,6 @@ esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg)
7774
/* LVGL semaphore */
7875
lvgl_port_ctx.lvgl_mux = xSemaphoreCreateRecursiveMutex();
7976
ESP_GOTO_ON_FALSE(lvgl_port_ctx.lvgl_mux, ESP_ERR_NO_MEM, err, TAG, "Create LVGL mutex fail!");
80-
/* Task init semaphore */
81-
lvgl_port_ctx.task_init_mux = xSemaphoreCreateMutex();
82-
ESP_GOTO_ON_FALSE(lvgl_port_ctx.task_init_mux, ESP_ERR_NO_MEM, err, TAG, "Create LVGL task sem fail!");
8377
/* Task queue */
8478
lvgl_port_ctx.lvgl_events = xEventGroupCreate();
8579
ESP_GOTO_ON_FALSE(lvgl_port_ctx.lvgl_events, ESP_ERR_NO_MEM, err, TAG, "Create LVGL Event Group fail!");
@@ -132,27 +126,11 @@ esp_err_t lvgl_port_stop(void)
132126

133127
esp_err_t lvgl_port_deinit(void)
134128
{
135-
/* Stop and delete timer */
136-
if (lvgl_port_ctx.tick_timer != NULL) {
137-
esp_timer_stop(lvgl_port_ctx.tick_timer);
138-
esp_timer_delete(lvgl_port_ctx.tick_timer);
139-
lvgl_port_ctx.tick_timer = NULL;
140-
}
141-
142129
/* Stop running task */
143130
if (lvgl_port_ctx.running) {
144131
lvgl_port_ctx.running = false;
145132
}
146133

147-
/* Wait for stop task */
148-
if (xSemaphoreTake(lvgl_port_ctx.task_init_mux, pdMS_TO_TICKS(ESP_LVGL_PORT_TASK_MUX_DELAY_MS)) != pdTRUE) {
149-
ESP_LOGE(TAG, "Failed to stop LVGL task");
150-
return ESP_ERR_TIMEOUT;
151-
}
152-
ESP_LOGI(TAG, "Stopped LVGL task");
153-
154-
lvgl_port_task_deinit();
155-
156134
return ESP_OK;
157135
}
158136

@@ -226,13 +204,6 @@ static void lvgl_port_task(void *arg)
226204
uint32_t task_delay_ms = 0;
227205
lv_indev_t *indev = NULL;
228206

229-
/* Take the task semaphore */
230-
if (xSemaphoreTake(lvgl_port_ctx.task_init_mux, 0) != pdTRUE) {
231-
ESP_LOGE(TAG, "Failed to take LVGL task sem");
232-
lvgl_port_task_deinit();
233-
vTaskDelete( NULL );
234-
}
235-
236207
/* LVGL init */
237208
lv_init();
238209
/* LVGL is initialized, notify lvgl_port_init() function about it */
@@ -275,24 +246,30 @@ static void lvgl_port_task(void *arg)
275246
vTaskDelay(1);
276247
}
277248

278-
/* Give semaphore back */
279-
xSemaphoreGive(lvgl_port_ctx.task_init_mux);
249+
ESP_LOGI(TAG, "Stopped LVGL task");
250+
251+
/* Deinit LVGL */
252+
lvgl_port_task_deinit();
280253

281254
/* Close task */
282255
vTaskDelete( NULL );
283256
}
284257

285258
static void lvgl_port_task_deinit(void)
286259
{
260+
/* Stop and delete timer */
261+
if (lvgl_port_ctx.tick_timer != NULL) {
262+
esp_timer_stop(lvgl_port_ctx.tick_timer);
263+
esp_timer_delete(lvgl_port_ctx.tick_timer);
264+
lvgl_port_ctx.tick_timer = NULL;
265+
}
266+
287267
if (lvgl_port_ctx.timer_mux) {
288268
vSemaphoreDelete(lvgl_port_ctx.timer_mux);
289269
}
290270
if (lvgl_port_ctx.lvgl_mux) {
291271
vSemaphoreDelete(lvgl_port_ctx.lvgl_mux);
292272
}
293-
if (lvgl_port_ctx.task_init_mux) {
294-
vSemaphoreDelete(lvgl_port_ctx.task_init_mux);
295-
}
296273
if (lvgl_port_ctx.lvgl_events) {
297274
vEventGroupDelete(lvgl_port_ctx.lvgl_events);
298275
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
## IDF Component Manager Manifest File
22
dependencies:
33
idf: ">=4.4"
4-
esp_lcd_touch_tt21100:
4+
esp_lcd_ili9341: "^2.0.1"
5+
esp_lcd_touch_gt911:
56
version: "^1"
6-
override_path: "../../../../lcd_touch/esp_lcd_touch_tt21100/"
7+
override_path: "../../../../lcd_touch/esp_lcd_touch_gt911/"
78
esp_lvgl_port:
89
version: "*"
910
override_path: "../../../"

components/esp_lvgl_port/test_apps/lvgl_port/main/test.c

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
#include "esp_lcd_panel_vendor.h"
1616
#include "esp_lcd_panel_ops.h"
1717
#include "esp_lvgl_port.h"
18+
#include "esp_lcd_ili9341.h"
1819

19-
#include "esp_lcd_touch_tt21100.h"
20+
#include "esp_lcd_touch_gt911.h"
2021

2122
#include "unity.h"
2223

@@ -40,7 +41,7 @@
4041
#define EXAMPLE_LCD_GPIO_RST (GPIO_NUM_48)
4142
#define EXAMPLE_LCD_GPIO_DC (GPIO_NUM_4)
4243
#define EXAMPLE_LCD_GPIO_CS (GPIO_NUM_5)
43-
#define EXAMPLE_LCD_GPIO_BL (GPIO_NUM_45)
44+
#define EXAMPLE_LCD_GPIO_BL (GPIO_NUM_47)
4445

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

68+
static const ili9341_lcd_init_cmd_t vendor_specific_init[] = {
69+
{0xC8, (uint8_t []){0xFF, 0x93, 0x42}, 3, 0},
70+
{0xC0, (uint8_t []){0x0E, 0x0E}, 2, 0},
71+
{0xC5, (uint8_t []){0xD0}, 1, 0},
72+
{0xC1, (uint8_t []){0x02}, 1, 0},
73+
{0xB4, (uint8_t []){0x02}, 1, 0},
74+
{0xE0, (uint8_t []){0x00, 0x03, 0x08, 0x06, 0x13, 0x09, 0x39, 0x39, 0x48, 0x02, 0x0a, 0x08, 0x17, 0x17, 0x0F}, 15, 0},
75+
{0xE1, (uint8_t []){0x00, 0x28, 0x29, 0x01, 0x0d, 0x03, 0x3f, 0x33, 0x52, 0x04, 0x0f, 0x0e, 0x37, 0x38, 0x0F}, 15, 0},
76+
77+
{0xB1, (uint8_t []){00, 0x1B}, 2, 0},
78+
{0x36, (uint8_t []){0x08}, 1, 0},
79+
{0x3A, (uint8_t []){0x55}, 1, 0},
80+
{0xB7, (uint8_t []){0x06}, 1, 0},
81+
82+
{0x11, (uint8_t []){0}, 0x80, 0},
83+
{0x29, (uint8_t []){0}, 0x80, 0},
84+
85+
{0, (uint8_t []){0}, 0xff, 0},
86+
};
87+
6788
static esp_err_t app_lcd_init(void)
6889
{
6990
esp_err_t ret = ESP_OK;
@@ -100,16 +121,22 @@ static esp_err_t app_lcd_init(void)
100121
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");
101122

102123
ESP_LOGD(TAG, "Install LCD driver");
124+
const ili9341_vendor_config_t vendor_config = {
125+
.init_cmds = &vendor_specific_init[0],
126+
.init_cmds_size = sizeof(vendor_specific_init) / sizeof(ili9341_lcd_init_cmd_t),
127+
};
103128
const esp_lcd_panel_dev_config_t panel_config = {
104129
.reset_gpio_num = EXAMPLE_LCD_GPIO_RST,
130+
.flags.reset_active_high = 1,
105131
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(6, 0, 0)
106132
.rgb_endian = LCD_RGB_ENDIAN_BGR,
107133
#else
108134
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_BGR,
109135
#endif
110136
.bits_per_pixel = EXAMPLE_LCD_BITS_PER_PIXEL,
137+
.vendor_config = (void *) &vendor_config,
111138
};
112-
ESP_GOTO_ON_ERROR(esp_lcd_new_panel_st7789(lcd_io, &panel_config, &lcd_panel), err, TAG, "New panel failed");
139+
ESP_GOTO_ON_ERROR(esp_lcd_new_panel_ili9341(lcd_io, &panel_config, &lcd_panel), err, TAG, "New panel failed");
113140

114141
esp_lcd_panel_reset(lcd_panel);
115142
esp_lcd_panel_init(lcd_panel);
@@ -168,10 +195,10 @@ static esp_err_t app_touch_init(void)
168195
.mirror_y = 0,
169196
},
170197
};
171-
esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_TT21100_CONFIG();
198+
esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG();
172199
tp_io_config.scl_speed_hz = EXAMPLE_TOUCH_I2C_CLK_HZ;
173200
ESP_RETURN_ON_ERROR(esp_lcd_new_panel_io_i2c(i2c_handle, &tp_io_config, &tp_io_handle), TAG, "");
174-
return esp_lcd_touch_new_i2c_tt21100(tp_io_handle, &tp_cfg, &touch_handle);
201+
return esp_lcd_touch_new_i2c_gt911(tp_io_handle, &tp_cfg, &touch_handle);
175202
}
176203

177204
static esp_err_t app_touch_deinit(void)
@@ -185,13 +212,7 @@ static esp_err_t app_touch_deinit(void)
185212
static esp_err_t app_lvgl_init(void)
186213
{
187214
/* Initialize LVGL */
188-
const lvgl_port_cfg_t lvgl_cfg = {
189-
.task_priority = 4, /* LVGL task priority */
190-
.task_stack = 4096, /* LVGL task stack size */
191-
.task_affinity = -1, /* LVGL task pinned to core (-1 is no affinity) */
192-
.task_max_sleep_ms = 500, /* Maximum sleep in LVGL task */
193-
.timer_period_ms = 5 /* LVGL timer tick period in ms */
194-
};
215+
const lvgl_port_cfg_t lvgl_cfg = ESP_LVGL_PORT_INIT_CONFIG();
195216
ESP_RETURN_ON_ERROR(lvgl_port_init(&lvgl_cfg), TAG, "LVGL port initialization failed");
196217

197218
/* Add LCD screen */

0 commit comments

Comments
 (0)