From 32e9c25c082f4d337b338bd28a0010e715272701 Mon Sep 17 00:00:00 2001 From: Vilem Zavodny Date: Fri, 24 Jan 2025 13:59:50 +0100 Subject: [PATCH] feat(lvgl_port): Changed queue to event group for speed up. --- components/esp_lvgl_port/CHANGELOG.md | 7 ++- components/esp_lvgl_port/idf_component.yml | 2 +- .../esp_lvgl_port/include/esp_lvgl_port.h | 10 ++-- .../esp_lvgl_port/src/lvgl9/esp_lvgl_port.c | 50 ++++++++++--------- .../src/lvgl9/esp_lvgl_port_disp.c | 6 ++- .../sdkconfig.bsp.m5stack_core_2 | 36 ++++++++----- 6 files changed, 66 insertions(+), 45 deletions(-) diff --git a/components/esp_lvgl_port/CHANGELOG.md b/components/esp_lvgl_port/CHANGELOG.md index 7ef303555..ed3d600bc 100644 --- a/components/esp_lvgl_port/CHANGELOG.md +++ b/components/esp_lvgl_port/CHANGELOG.md @@ -1,9 +1,14 @@ # Changelog -## [Unreleased] +## 2.4.4 + +### Features +- Changed queue to event group in main LVGL task for speed up https://github.com/espressif/esp-bsp/issues/492 +- Reworked handling encoder (knob) https://github.com/espressif/esp-bsp/pull/450 ### Fixes - Fixed a crash when esp_lvgl_port was initialized from high priority task https://github.com/espressif/esp-bsp/issues/455 +- Allow to swap bytes when used SW rotation https://github.com/espressif/esp-bsp/issues/497 ## 2.4.3 diff --git a/components/esp_lvgl_port/idf_component.yml b/components/esp_lvgl_port/idf_component.yml index fb7e76196..aed2f92d7 100644 --- a/components/esp_lvgl_port/idf_component.yml +++ b/components/esp_lvgl_port/idf_component.yml @@ -1,4 +1,4 @@ -version: "2.4.3" +version: "2.4.4" description: ESP LVGL port url: https://github.com/espressif/esp-bsp/tree/master/components/esp_lvgl_port dependencies: diff --git a/components/esp_lvgl_port/include/esp_lvgl_port.h b/components/esp_lvgl_port/include/esp_lvgl_port.h index 398a5c70e..63e0f0b58 100644 --- a/components/esp_lvgl_port/include/esp_lvgl_port.h +++ b/components/esp_lvgl_port/include/esp_lvgl_port.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -31,9 +31,9 @@ extern "C" { * @brief LVGL Port task event type */ typedef enum { - LVGL_PORT_EVENT_DISPLAY = 1, - LVGL_PORT_EVENT_TOUCH = 2, - LVGL_PORT_EVENT_USER = 99, + LVGL_PORT_EVENT_DISPLAY = 0x01, + LVGL_PORT_EVENT_TOUCH = 0x02, + LVGL_PORT_EVENT_USER = 0x80, } lvgl_port_event_type_t; /** @@ -144,7 +144,7 @@ esp_err_t lvgl_port_resume(void); * @note It is called from LVGL events and touch interrupts * * @param event event type - * @param param user param + * @param param parameter is not used, keep for backwards compatibility * @return * - ESP_OK on success * - ESP_ERR_NOT_SUPPORTED if it is not implemented diff --git a/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port.c b/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port.c index 1aeb872c7..24d9d70b3 100644 --- a/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port.c +++ b/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port.c @@ -14,6 +14,7 @@ #include "freertos/portmacro.h" #include "freertos/task.h" #include "freertos/semphr.h" +#include "freertos/event_groups.h" #include "esp_lvgl_port.h" #include "esp_lvgl_port_priv.h" #include "lvgl.h" @@ -30,7 +31,7 @@ typedef struct lvgl_port_ctx_s { TaskHandle_t lvgl_task; SemaphoreHandle_t lvgl_mux; SemaphoreHandle_t timer_mux; - QueueHandle_t lvgl_queue; + EventGroupHandle_t lvgl_events; SemaphoreHandle_t task_init_mux; esp_timer_handle_t tick_timer; bool running; @@ -79,8 +80,8 @@ esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg) 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_queue = xQueueCreate(100, sizeof(lvgl_port_event_t)); - ESP_GOTO_ON_FALSE(lvgl_port_ctx.lvgl_queue, ESP_ERR_NO_MEM, err, TAG, "Create LVGL queue fail!"); + 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!"); BaseType_t res; if (cfg->task_affinity < 0) { @@ -169,23 +170,30 @@ void lvgl_port_unlock(void) esp_err_t lvgl_port_task_wake(lvgl_port_event_type_t event, void *param) { - if (!lvgl_port_ctx.lvgl_queue) { + EventBits_t bits = 0; + if (!lvgl_port_ctx.lvgl_events) { return ESP_ERR_INVALID_STATE; } - lvgl_port_event_t ev = { - .type = event, - .param = param, - }; + /* Get unprocessed bits */ + if (xPortInIsrContext() == pdTRUE) { + bits = xEventGroupGetBitsFromISR(lvgl_port_ctx.lvgl_events); + } else { + bits = xEventGroupGetBits(lvgl_port_ctx.lvgl_events); + } + + /* Set event */ + bits |= event; + /* Save */ if (xPortInIsrContext() == pdTRUE) { BaseType_t xHigherPriorityTaskWoken = pdFALSE; - xQueueSendFromISR(lvgl_port_ctx.lvgl_queue, &ev, &xHigherPriorityTaskWoken); + xEventGroupSetBitsFromISR(lvgl_port_ctx.lvgl_events, bits, &xHigherPriorityTaskWoken); if (xHigherPriorityTaskWoken) { portYIELD_FROM_ISR( ); } } else { - xQueueSend(lvgl_port_ctx.lvgl_queue, &ev, 0); + xEventGroupSetBits(lvgl_port_ctx.lvgl_events, bits); } return ESP_OK; @@ -212,7 +220,7 @@ IRAM_ATTR bool lvgl_port_task_notify(uint32_t value) static void lvgl_port_task(void *arg) { TaskHandle_t task_to_notify = (TaskHandle_t)arg; - lvgl_port_event_t event; + EventBits_t events = 0; uint32_t task_delay_ms = 0; lv_indev_t *indev = NULL; @@ -235,21 +243,17 @@ static void lvgl_port_task(void *arg) while (lvgl_port_ctx.running) { /* Wait for queue or timeout (sleep task) */ TickType_t wait = (pdMS_TO_TICKS(task_delay_ms) >= 1 ? pdMS_TO_TICKS(task_delay_ms) : 1); - xQueueReceive(lvgl_port_ctx.lvgl_queue, &event, wait); + events = xEventGroupWaitBits(lvgl_port_ctx.lvgl_events, 0xFF, pdTRUE, pdFALSE, wait); if (lv_display_get_default() && lvgl_port_lock(0)) { /* Call read input devices */ - if (event.type == LVGL_PORT_EVENT_TOUCH) { + if (events & LVGL_PORT_EVENT_TOUCH) { xSemaphoreTake(lvgl_port_ctx.timer_mux, portMAX_DELAY); - if (event.param != NULL) { - lv_indev_read(event.param); - } else { - indev = lv_indev_get_next(NULL); - while (indev != NULL) { - lv_indev_read(indev); - indev = lv_indev_get_next(indev); - } + indev = lv_indev_get_next(NULL); + while (indev != NULL) { + lv_indev_read(indev); + indev = lv_indev_get_next(indev); } xSemaphoreGive(lvgl_port_ctx.timer_mux); } @@ -287,8 +291,8 @@ static void lvgl_port_task_deinit(void) if (lvgl_port_ctx.task_init_mux) { vSemaphoreDelete(lvgl_port_ctx.task_init_mux); } - if (lvgl_port_ctx.lvgl_queue) { - vQueueDelete(lvgl_port_ctx.lvgl_queue); + if (lvgl_port_ctx.lvgl_events) { + vEventGroupDelete(lvgl_port_ctx.lvgl_events); } memset(&lvgl_port_ctx, 0, sizeof(lvgl_port_ctx)); #if LV_ENABLE_GC || !LV_MEM_CUSTOM diff --git a/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_disp.c b/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_disp.c index 921954b99..9e8d65778 100644 --- a/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_disp.c +++ b/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_disp.c @@ -567,7 +567,7 @@ static void lvgl_port_flush_callback(lv_display_t *drv, const lv_area_t *area, u int offsety2 = area->y2; /* SW rotation enabled */ - if (disp_ctx->flags.sw_rotate && (disp_ctx->current_rotation > LV_DISPLAY_ROTATION_0 || disp_ctx->flags.swap_bytes)) { + if (disp_ctx->flags.sw_rotate && (disp_ctx->current_rotation > LV_DISPLAY_ROTATION_0)) { /* SW rotation */ if (disp_ctx->draw_buffs[2]) { 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 offsety1 = area->y1; offsety2 = area->y2; } - } else if (disp_ctx->flags.swap_bytes) { + } + + if (disp_ctx->flags.swap_bytes) { size_t len = lv_area_get_size(area); lv_draw_sw_rgb565_swap(color_map, len); } diff --git a/examples/display_audio_photo/sdkconfig.bsp.m5stack_core_2 b/examples/display_audio_photo/sdkconfig.bsp.m5stack_core_2 index b8e255c57..6c13864b7 100644 --- a/examples/display_audio_photo/sdkconfig.bsp.m5stack_core_2 +++ b/examples/display_audio_photo/sdkconfig.bsp.m5stack_core_2 @@ -3,25 +3,35 @@ # CONFIG_IDF_TARGET="esp32" CONFIG_BSP_PMU_AXP2101=y -CONFIG_ESPTOOLPY_FLASHFREQ_80M=y -CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_ESPTOOLPY_FLASHMODE_QIO=y +CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_SPIRAM=y CONFIG_SPIRAM_SPEED_80M=y -CONFIG_ESP_INT_WDT_TIMEOUT_MS=300 +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y +CONFIG_SPIFFS_PAGE_SIZE=1024 +CONFIG_LV_SPRINTF_CUSTOM=y +CONFIG_CODEC_I2C_BACKWARD_COMPATIBLE=n +# CONFIG_LV_BUILD_EXAMPLES is not set + +## LVGL8 ## +CONFIG_LV_USE_PERF_MONITOR=y +CONFIG_LV_COLOR_16_SWAP=y +CONFIG_LV_MEM_CUSTOM=y +CONFIG_LV_MEMCPY_MEMSET_STD=y + +## LVGL9 ## +CONFIG_LV_CONF_SKIP=y + +#CLIB default CONFIG_LV_USE_CLIB_MALLOC=y -CONFIG_LV_USE_CLIB_STRING=y CONFIG_LV_USE_CLIB_SPRINTF=y -CONFIG_LV_ATTRIBUTE_FAST_MEM_USE_IRAM=y -CONFIG_LV_FONT_MONTSERRAT_12=y -CONFIG_LV_FONT_MONTSERRAT_16=y +CONFIG_LV_USE_CLIB_STRING=y + +# Performance monitor CONFIG_LV_USE_OBSERVER=y CONFIG_LV_USE_SYSMON=y CONFIG_LV_USE_PERF_MONITOR=y -CONFIG_LV_BUILD_EXAMPLES=n -CONFIG_LV_USE_DEMO_WIDGETS=y -CONFIG_LV_USE_DEMO_STRESS=y -CONFIG_LV_USE_DEMO_MUSIC=y -CONFIG_LV_DEMO_MUSIC_ROUND=y -CONFIG_LV_DEMO_MUSIC_AUTO_PLAY=y + +