Skip to content

Commit

Permalink
Merge pull request #493 from espressif/feat/lvgl_port_events
Browse files Browse the repository at this point in the history
feat(lvgl_port): Changed queue to event group for speed up.
  • Loading branch information
espzav authored Jan 28, 2025
2 parents 75464fd + 32e9c25 commit dddc990
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 45 deletions.
7 changes: 6 additions & 1 deletion components/esp_lvgl_port/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

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.4.3"
version: "2.4.4"
description: ESP LVGL port
url: https://github.com/espressif/esp-bsp/tree/master/components/esp_lvgl_port
dependencies:
Expand Down
10 changes: 5 additions & 5 deletions components/esp_lvgl_port/include/esp_lvgl_port.h
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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
Expand Down
50 changes: 27 additions & 23 deletions components/esp_lvgl_port/src/lvgl9/esp_lvgl_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_disp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down
36 changes: 23 additions & 13 deletions examples/display_audio_photo/sdkconfig.bsp.m5stack_core_2
Original file line number Diff line number Diff line change
Expand Up @@ -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



0 comments on commit dddc990

Please sign in to comment.