Skip to content

Commit 32e9c25

Browse files
committed
feat(lvgl_port): Changed queue to event group for speed up.
1 parent 75464fd commit 32e9c25

File tree

6 files changed

+66
-45
lines changed

6 files changed

+66
-45
lines changed

components/esp_lvgl_port/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# Changelog
22

3-
## [Unreleased]
3+
## 2.4.4
4+
5+
### Features
6+
- Changed queue to event group in main LVGL task for speed up https://github.com/espressif/esp-bsp/issues/492
7+
- Reworked handling encoder (knob) https://github.com/espressif/esp-bsp/pull/450
48

59
### Fixes
610
- Fixed a crash when esp_lvgl_port was initialized from high priority task https://github.com/espressif/esp-bsp/issues/455
11+
- Allow to swap bytes when used SW rotation https://github.com/espressif/esp-bsp/issues/497
712

813
## 2.4.3
914

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.4.3"
1+
version: "2.4.4"
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/include/esp_lvgl_port.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -31,9 +31,9 @@ extern "C" {
3131
* @brief LVGL Port task event type
3232
*/
3333
typedef enum {
34-
LVGL_PORT_EVENT_DISPLAY = 1,
35-
LVGL_PORT_EVENT_TOUCH = 2,
36-
LVGL_PORT_EVENT_USER = 99,
34+
LVGL_PORT_EVENT_DISPLAY = 0x01,
35+
LVGL_PORT_EVENT_TOUCH = 0x02,
36+
LVGL_PORT_EVENT_USER = 0x80,
3737
} lvgl_port_event_type_t;
3838

3939
/**
@@ -144,7 +144,7 @@ esp_err_t lvgl_port_resume(void);
144144
* @note It is called from LVGL events and touch interrupts
145145
*
146146
* @param event event type
147-
* @param param user param
147+
* @param param parameter is not used, keep for backwards compatibility
148148
* @return
149149
* - ESP_OK on success
150150
* - ESP_ERR_NOT_SUPPORTED if it is not implemented

components/esp_lvgl_port/src/lvgl9/esp_lvgl_port.c

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "freertos/portmacro.h"
1515
#include "freertos/task.h"
1616
#include "freertos/semphr.h"
17+
#include "freertos/event_groups.h"
1718
#include "esp_lvgl_port.h"
1819
#include "esp_lvgl_port_priv.h"
1920
#include "lvgl.h"
@@ -30,7 +31,7 @@ typedef struct lvgl_port_ctx_s {
3031
TaskHandle_t lvgl_task;
3132
SemaphoreHandle_t lvgl_mux;
3233
SemaphoreHandle_t timer_mux;
33-
QueueHandle_t lvgl_queue;
34+
EventGroupHandle_t lvgl_events;
3435
SemaphoreHandle_t task_init_mux;
3536
esp_timer_handle_t tick_timer;
3637
bool running;
@@ -79,8 +80,8 @@ esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg)
7980
lvgl_port_ctx.task_init_mux = xSemaphoreCreateMutex();
8081
ESP_GOTO_ON_FALSE(lvgl_port_ctx.task_init_mux, ESP_ERR_NO_MEM, err, TAG, "Create LVGL task sem fail!");
8182
/* Task queue */
82-
lvgl_port_ctx.lvgl_queue = xQueueCreate(100, sizeof(lvgl_port_event_t));
83-
ESP_GOTO_ON_FALSE(lvgl_port_ctx.lvgl_queue, ESP_ERR_NO_MEM, err, TAG, "Create LVGL queue fail!");
83+
lvgl_port_ctx.lvgl_events = xEventGroupCreate();
84+
ESP_GOTO_ON_FALSE(lvgl_port_ctx.lvgl_events, ESP_ERR_NO_MEM, err, TAG, "Create LVGL Event Group fail!");
8485

8586
BaseType_t res;
8687
if (cfg->task_affinity < 0) {
@@ -169,23 +170,30 @@ void lvgl_port_unlock(void)
169170

170171
esp_err_t lvgl_port_task_wake(lvgl_port_event_type_t event, void *param)
171172
{
172-
if (!lvgl_port_ctx.lvgl_queue) {
173+
EventBits_t bits = 0;
174+
if (!lvgl_port_ctx.lvgl_events) {
173175
return ESP_ERR_INVALID_STATE;
174176
}
175177

176-
lvgl_port_event_t ev = {
177-
.type = event,
178-
.param = param,
179-
};
178+
/* Get unprocessed bits */
179+
if (xPortInIsrContext() == pdTRUE) {
180+
bits = xEventGroupGetBitsFromISR(lvgl_port_ctx.lvgl_events);
181+
} else {
182+
bits = xEventGroupGetBits(lvgl_port_ctx.lvgl_events);
183+
}
184+
185+
/* Set event */
186+
bits |= event;
180187

188+
/* Save */
181189
if (xPortInIsrContext() == pdTRUE) {
182190
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
183-
xQueueSendFromISR(lvgl_port_ctx.lvgl_queue, &ev, &xHigherPriorityTaskWoken);
191+
xEventGroupSetBitsFromISR(lvgl_port_ctx.lvgl_events, bits, &xHigherPriorityTaskWoken);
184192
if (xHigherPriorityTaskWoken) {
185193
portYIELD_FROM_ISR( );
186194
}
187195
} else {
188-
xQueueSend(lvgl_port_ctx.lvgl_queue, &ev, 0);
196+
xEventGroupSetBits(lvgl_port_ctx.lvgl_events, bits);
189197
}
190198

191199
return ESP_OK;
@@ -212,7 +220,7 @@ IRAM_ATTR bool lvgl_port_task_notify(uint32_t value)
212220
static void lvgl_port_task(void *arg)
213221
{
214222
TaskHandle_t task_to_notify = (TaskHandle_t)arg;
215-
lvgl_port_event_t event;
223+
EventBits_t events = 0;
216224
uint32_t task_delay_ms = 0;
217225
lv_indev_t *indev = NULL;
218226

@@ -235,21 +243,17 @@ static void lvgl_port_task(void *arg)
235243
while (lvgl_port_ctx.running) {
236244
/* Wait for queue or timeout (sleep task) */
237245
TickType_t wait = (pdMS_TO_TICKS(task_delay_ms) >= 1 ? pdMS_TO_TICKS(task_delay_ms) : 1);
238-
xQueueReceive(lvgl_port_ctx.lvgl_queue, &event, wait);
246+
events = xEventGroupWaitBits(lvgl_port_ctx.lvgl_events, 0xFF, pdTRUE, pdFALSE, wait);
239247

240248
if (lv_display_get_default() && lvgl_port_lock(0)) {
241249

242250
/* Call read input devices */
243-
if (event.type == LVGL_PORT_EVENT_TOUCH) {
251+
if (events & LVGL_PORT_EVENT_TOUCH) {
244252
xSemaphoreTake(lvgl_port_ctx.timer_mux, portMAX_DELAY);
245-
if (event.param != NULL) {
246-
lv_indev_read(event.param);
247-
} else {
248-
indev = lv_indev_get_next(NULL);
249-
while (indev != NULL) {
250-
lv_indev_read(indev);
251-
indev = lv_indev_get_next(indev);
252-
}
253+
indev = lv_indev_get_next(NULL);
254+
while (indev != NULL) {
255+
lv_indev_read(indev);
256+
indev = lv_indev_get_next(indev);
253257
}
254258
xSemaphoreGive(lvgl_port_ctx.timer_mux);
255259
}
@@ -287,8 +291,8 @@ static void lvgl_port_task_deinit(void)
287291
if (lvgl_port_ctx.task_init_mux) {
288292
vSemaphoreDelete(lvgl_port_ctx.task_init_mux);
289293
}
290-
if (lvgl_port_ctx.lvgl_queue) {
291-
vQueueDelete(lvgl_port_ctx.lvgl_queue);
294+
if (lvgl_port_ctx.lvgl_events) {
295+
vEventGroupDelete(lvgl_port_ctx.lvgl_events);
292296
}
293297
memset(&lvgl_port_ctx, 0, sizeof(lvgl_port_ctx));
294298
#if LV_ENABLE_GC || !LV_MEM_CUSTOM

components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_disp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ static void lvgl_port_flush_callback(lv_display_t *drv, const lv_area_t *area, u
567567
int offsety2 = area->y2;
568568

569569
/* SW rotation enabled */
570-
if (disp_ctx->flags.sw_rotate && (disp_ctx->current_rotation > LV_DISPLAY_ROTATION_0 || disp_ctx->flags.swap_bytes)) {
570+
if (disp_ctx->flags.sw_rotate && (disp_ctx->current_rotation > LV_DISPLAY_ROTATION_0)) {
571571
/* SW rotation */
572572
if (disp_ctx->draw_buffs[2]) {
573573
int32_t ww = lv_area_get_width(area);
@@ -589,7 +589,9 @@ static void lvgl_port_flush_callback(lv_display_t *drv, const lv_area_t *area, u
589589
offsety1 = area->y1;
590590
offsety2 = area->y2;
591591
}
592-
} else if (disp_ctx->flags.swap_bytes) {
592+
}
593+
594+
if (disp_ctx->flags.swap_bytes) {
593595
size_t len = lv_area_get_size(area);
594596
lv_draw_sw_rgb565_swap(color_map, len);
595597
}

examples/display_audio_photo/sdkconfig.bsp.m5stack_core_2

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,35 @@
33
#
44
CONFIG_IDF_TARGET="esp32"
55
CONFIG_BSP_PMU_AXP2101=y
6-
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
7-
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
6+
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
7+
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
88
CONFIG_PARTITION_TABLE_CUSTOM=y
99
CONFIG_SPIRAM=y
1010
CONFIG_SPIRAM_SPEED_80M=y
11-
CONFIG_ESP_INT_WDT_TIMEOUT_MS=300
11+
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
12+
CONFIG_SPIFFS_PAGE_SIZE=1024
13+
CONFIG_LV_SPRINTF_CUSTOM=y
14+
CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n
15+
# CONFIG_LV_BUILD_EXAMPLES is not set
16+
17+
## LVGL8 ##
18+
CONFIG_LV_USE_PERF_MONITOR=y
19+
CONFIG_LV_COLOR_16_SWAP=y
20+
CONFIG_LV_MEM_CUSTOM=y
21+
CONFIG_LV_MEMCPY_MEMSET_STD=y
22+
23+
## LVGL9 ##
24+
CONFIG_LV_CONF_SKIP=y
25+
26+
#CLIB default
1227
CONFIG_LV_USE_CLIB_MALLOC=y
13-
CONFIG_LV_USE_CLIB_STRING=y
1428
CONFIG_LV_USE_CLIB_SPRINTF=y
15-
CONFIG_LV_ATTRIBUTE_FAST_MEM_USE_IRAM=y
16-
CONFIG_LV_FONT_MONTSERRAT_12=y
17-
CONFIG_LV_FONT_MONTSERRAT_16=y
29+
CONFIG_LV_USE_CLIB_STRING=y
30+
31+
# Performance monitor
1832
CONFIG_LV_USE_OBSERVER=y
1933
CONFIG_LV_USE_SYSMON=y
2034
CONFIG_LV_USE_PERF_MONITOR=y
21-
CONFIG_LV_BUILD_EXAMPLES=n
22-
CONFIG_LV_USE_DEMO_WIDGETS=y
23-
CONFIG_LV_USE_DEMO_STRESS=y
24-
CONFIG_LV_USE_DEMO_MUSIC=y
25-
CONFIG_LV_DEMO_MUSIC_ROUND=y
26-
CONFIG_LV_DEMO_MUSIC_AUTO_PLAY=y
35+
36+
2737

0 commit comments

Comments
 (0)