Skip to content

Commit

Permalink
feat(lvgl_port): Changed queue to event group for speed up.
Browse files Browse the repository at this point in the history
  • Loading branch information
espzav committed Jan 28, 2025
1 parent 1b4fa5e commit b0a1a84
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repos:
name: Update BSP README with dependencies section
entry: .github/ci/update_readme_dependencies.py
language: python
files: 'bsp\/.*\/include\/.*\.h|bsp\/\w*\/idf_component\.yml|bsp\/\w*\/README\.md' # All idf_component.yml, README.md and .h files in bsp directory
files: 'bsp\/.*\/include\/.*\.h|bsp\/.*\/idf_component\.yml|bsp\/.*\/README\.md' # All idf_component.yml, README.md and .h files in bsp directory
additional_dependencies:
- idf_component_manager==1.4.2
- py-markdown-table
Expand Down
22 changes: 11 additions & 11 deletions bsp/esp-box-3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ ESP32-S3-BOX-3 also uses a Type-C USB connector that provides 5 V of power input

<!-- Autogenerated start: Dependencies -->
### Capabilities and dependencies
| Capability | Available | Component |Version|
|-------------|------------------|----------------------------------------------------------------------------------------------------------|-------|
| DISPLAY |:heavy_check_mark:| [espressif/esp_lcd_ili9341](https://components.espressif.com/components/espressif/esp_lcd_ili9341) | ^1 |
| LVGL_PORT |:heavy_check_mark:| [espressif/esp_lvgl_port](https://components.espressif.com/components/espressif/esp_lvgl_port) | ^2 |
| TOUCH |:heavy_check_mark:|[espressif/esp_lcd_touch_gt911](https://components.espressif.com/components/espressif/esp_lcd_touch_gt911)| ^1 |
| BUTTONS |:heavy_check_mark:| [espressif/button](https://components.espressif.com/components/espressif/button) | >=2.5 |
| AUDIO |:heavy_check_mark:| [espressif/esp_codec_dev](https://components.espressif.com/components/espressif/esp_codec_dev) | ~1.3.1|
|AUDIO_SPEAKER|:heavy_check_mark:| | |
| AUDIO_MIC |:heavy_check_mark:| | |
| SDCARD |:heavy_check_mark:| idf | >=5.3 |
| IMU |:heavy_check_mark:| [espressif/icm42670](https://components.espressif.com/components/espressif/icm42670) | ^2.0.1|
| Capability | Available | Component | Version |
|-------------|------------------|----------------------------------------------------------------------------------------------------------|----------|
| DISPLAY |:heavy_check_mark:| [espressif/esp_lcd_ili9341](https://components.espressif.com/components/espressif/esp_lcd_ili9341) | ^1 |
| LVGL_PORT |:heavy_check_mark:| [espressif/esp_lvgl_port](https://components.espressif.com/components/espressif/esp_lvgl_port) | ^2 |
| TOUCH |:heavy_check_mark:|[espressif/esp_lcd_touch_gt911](https://components.espressif.com/components/espressif/esp_lcd_touch_gt911)| ^1 |
| BUTTONS |:heavy_check_mark:| [espressif/button](https://components.espressif.com/components/espressif/button) |>=2.5,<4.0|
| AUDIO |:heavy_check_mark:| [espressif/esp_codec_dev](https://components.espressif.com/components/espressif/esp_codec_dev) | ~1.3.1 |
|AUDIO_SPEAKER|:heavy_check_mark:| | |
| AUDIO_MIC |:heavy_check_mark:| | |
| SDCARD |:heavy_check_mark:| idf | >=5.3 |
| IMU |:heavy_check_mark:| [espressif/icm42670](https://components.espressif.com/components/espressif/icm42670) | ^2.0.1 |
<!-- Autogenerated end: Dependencies -->
2 changes: 1 addition & 1 deletion bsp/esp-box-3/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies:
public: true

button:
version: ">=2.5"
version: ">=2.5,<4.0"
public: true

icm42670:
Expand Down
6 changes: 5 additions & 1 deletion components/esp_lvgl_port/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# 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

### 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
8 changes: 4 additions & 4 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
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
4 changes: 3 additions & 1 deletion components/esp_lvgl_port/src/lvgl9/esp_lvgl_port_disp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 b0a1a84

Please sign in to comment.