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 24, 2025
1 parent 1b4fa5e commit b7a62c9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bsp/esp-box-3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ESP32-S3-BOX-3 also uses a Type-C USB connector that provides 5 V of power input
| 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 |
| 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:| | |
Expand Down
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
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 queue 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

0 comments on commit b7a62c9

Please sign in to comment.