From 59988ae57b8ea9cb98751bfdc704c47e0a0cbe5f Mon Sep 17 00:00:00 2001 From: Maldus512 Date: Tue, 7 Oct 2025 12:40:09 +0200 Subject: [PATCH 1/2] Add configuration option to circumvent internal task creation --- components/esp_lvgl_port/Kconfig | 7 ++++ .../esp_lvgl_port/src/lvgl8/esp_lvgl_port.c | 30 +++++++++++++++- .../esp_lvgl_port/src/lvgl9/esp_lvgl_port.c | 35 +++++++++++++++++-- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/components/esp_lvgl_port/Kconfig b/components/esp_lvgl_port/Kconfig index b54886bd1..2e10afb3b 100644 --- a/components/esp_lvgl_port/Kconfig +++ b/components/esp_lvgl_port/Kconfig @@ -7,4 +7,11 @@ menu "ESP LVGL PORT" help Enables using PPA for screen rotation. + config LVGL_PORT_INTERNAL_TASK + depends on SOC_PPA_SUPPORTED + bool "Use an internal task for LVGL management" + default y + help + If true, creates an internal task to handle LVGL management. If false the developer is responsible for initializing the stack and calling functions like `lv_timer_handle` and `lv_tick_inc`. + endmenu diff --git a/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port.c b/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port.c index bb0fa309b..48c5787b8 100644 --- a/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port.c +++ b/components/esp_lvgl_port/src/lvgl8/esp_lvgl_port.c @@ -39,6 +39,7 @@ typedef struct lvgl_port_ctx_s { /******************************************************************************* * Local variables *******************************************************************************/ +#if CONFIG_LVGL_PORT_INTERNAL_TASK static lvgl_port_ctx_t lvgl_port_ctx; /******************************************************************************* @@ -47,6 +48,7 @@ static lvgl_port_ctx_t lvgl_port_ctx; static void lvgl_port_task(void *arg); static esp_err_t lvgl_port_tick_init(void); static void lvgl_port_task_deinit(void); +#endif /******************************************************************************* * Public API functions @@ -54,6 +56,7 @@ static void lvgl_port_task_deinit(void); esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg) { +#if CONFIG_LVGL_PORT_INTERNAL_TASK esp_err_t ret = ESP_OK; ESP_GOTO_ON_FALSE(cfg, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument"); ESP_GOTO_ON_FALSE(cfg->task_affinity < (configNUM_CORES), ESP_ERR_INVALID_ARG, err, TAG, "Bad core number for task! Maximum core number is %d", (configNUM_CORES - 1)); @@ -92,10 +95,14 @@ esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg) } return ret; +#else + return ESP_OK; +#endif } esp_err_t lvgl_port_resume(void) { +#if CONFIG_LVGL_PORT_INTERNAL_TASK esp_err_t ret = ESP_ERR_INVALID_STATE; if (lvgl_port_ctx.tick_timer != NULL) { @@ -104,10 +111,14 @@ esp_err_t lvgl_port_resume(void) } return ret; +#else + return ESP_OK; +#endif } esp_err_t lvgl_port_stop(void) { +#if CONFIG_LVGL_PORT_INTERNAL_TASK esp_err_t ret = ESP_ERR_INVALID_STATE; if (lvgl_port_ctx.tick_timer != NULL) { @@ -116,10 +127,14 @@ esp_err_t lvgl_port_stop(void) } return ret; +#else + return ESP_OK; +#endif } esp_err_t lvgl_port_deinit(void) { +#if CONFIG_LVGL_PORT_INTERNAL_TASK /* Stop and delete timer */ if (lvgl_port_ctx.tick_timer != NULL) { esp_timer_stop(lvgl_port_ctx.tick_timer); @@ -140,22 +155,29 @@ esp_err_t lvgl_port_deinit(void) ESP_LOGI(TAG, "Stopped LVGL task"); lvgl_port_task_deinit(); - +#endif return ESP_OK; } bool lvgl_port_lock(uint32_t timeout_ms) { +#if CONFIG_LVGL_PORT_INTERNAL_TASK assert(lvgl_port_ctx.lvgl_mux && "lvgl_port_init must be called first"); const TickType_t timeout_ticks = (timeout_ms == 0) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms); return xSemaphoreTakeRecursive(lvgl_port_ctx.lvgl_mux, timeout_ticks) == pdTRUE; +#else + (void)timeout_ms; + return true; +#endif } void lvgl_port_unlock(void) { +#if CONFIG_LVGL_PORT_INTERNAL_TASK assert(lvgl_port_ctx.lvgl_mux && "lvgl_port_init must be called first"); xSemaphoreGiveRecursive(lvgl_port_ctx.lvgl_mux); +#endif } esp_err_t lvgl_port_task_wake(lvgl_port_event_type_t event, void *param) @@ -166,6 +188,7 @@ esp_err_t lvgl_port_task_wake(lvgl_port_event_type_t event, void *param) IRAM_ATTR bool lvgl_port_task_notify(uint32_t value) { +#if CONFIG_LVGL_PORT_INTERNAL_TASK BaseType_t need_yield = pdFALSE; // Notify LVGL task @@ -176,12 +199,16 @@ IRAM_ATTR bool lvgl_port_task_notify(uint32_t value) } return (need_yield == pdTRUE); +#else + return false; +#endif } /******************************************************************************* * Private functions *******************************************************************************/ +#if CONFIG_LVGL_PORT_INTERNAL_TASK static void lvgl_port_task(void *arg) { uint32_t task_delay_ms = lvgl_port_ctx.task_max_sleep_ms; @@ -246,3 +273,4 @@ static esp_err_t lvgl_port_tick_init(void) ESP_RETURN_ON_ERROR(esp_timer_create(&lvgl_tick_timer_args, &lvgl_port_ctx.tick_timer), TAG, "Creating LVGL timer filed!"); return esp_timer_start_periodic(lvgl_port_ctx.tick_timer, lvgl_port_ctx.timer_period_ms * 1000); } +#endif 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 79b7e1f3d..ca712acd9 100644 --- a/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port.c +++ b/components/esp_lvgl_port/src/lvgl9/esp_lvgl_port.c @@ -43,6 +43,7 @@ typedef struct lvgl_port_ctx_s { /******************************************************************************* * Local variables *******************************************************************************/ +#if CONFIG_LVGL_PORT_INTERNAL_TASK static lvgl_port_ctx_t lvgl_port_ctx; /******************************************************************************* @@ -51,6 +52,7 @@ static lvgl_port_ctx_t lvgl_port_ctx; static void lvgl_port_task(void *arg); static esp_err_t lvgl_port_tick_init(void); static void lvgl_port_task_deinit(void); +#endif /******************************************************************************* * Public API functions @@ -58,6 +60,7 @@ static void lvgl_port_task_deinit(void); esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg) { +#if CONFIG_LVGL_PORT_INTERNAL_TASK esp_err_t ret = ESP_OK; ESP_GOTO_ON_FALSE(cfg, ESP_ERR_INVALID_ARG, err, TAG, "invalid argument"); ESP_GOTO_ON_FALSE(cfg->task_affinity < (configNUM_CORES), ESP_ERR_INVALID_ARG, err, TAG, "Bad core number for task! Maximum core number is %d", (configNUM_CORES - 1)); @@ -104,10 +107,14 @@ esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg) } return ret; +#else + return ESP_OK; +#endif } esp_err_t lvgl_port_resume(void) { +#if CONFIG_LVGL_PORT_INTERNAL_TASK esp_err_t ret = ESP_ERR_INVALID_STATE; if (lvgl_port_ctx.tick_timer != NULL) { @@ -116,10 +123,14 @@ esp_err_t lvgl_port_resume(void) } return ret; +#else + return ESP_OK; +#endif } esp_err_t lvgl_port_stop(void) { +#if CONFIG_LVGL_PORT_INTERNAL_TASK esp_err_t ret = ESP_ERR_INVALID_STATE; if (lvgl_port_ctx.tick_timer != NULL) { @@ -128,10 +139,14 @@ esp_err_t lvgl_port_stop(void) } return ret; +#else + return ESP_OK; +#endif } esp_err_t lvgl_port_deinit(void) { +#if CONFIG_LVGL_PORT_INTERNAL_TASK /* Stop and delete timer */ if (lvgl_port_ctx.tick_timer != NULL) { esp_timer_stop(lvgl_port_ctx.tick_timer); @@ -153,25 +168,34 @@ esp_err_t lvgl_port_deinit(void) lvgl_port_task_deinit(); +#endif return ESP_OK; } bool lvgl_port_lock(uint32_t timeout_ms) { +#if CONFIG_LVGL_PORT_INTERNAL_TASK assert(lvgl_port_ctx.lvgl_mux && "lvgl_port_init must be called first"); const TickType_t timeout_ticks = (timeout_ms == 0) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms); return xSemaphoreTakeRecursive(lvgl_port_ctx.lvgl_mux, timeout_ticks) == pdTRUE; +#else + (void)timeout_ms; + return true; +#endif } void lvgl_port_unlock(void) { +#if CONFIG_LVGL_PORT_INTERNAL_TASK assert(lvgl_port_ctx.lvgl_mux && "lvgl_port_init must be called first"); xSemaphoreGiveRecursive(lvgl_port_ctx.lvgl_mux); +#endif } esp_err_t lvgl_port_task_wake(lvgl_port_event_type_t event, void *param) { +#if CONFIG_LVGL_PORT_INTERNAL_TASK EventBits_t bits = 0; if (!lvgl_port_ctx.lvgl_events) { return ESP_ERR_INVALID_STATE; @@ -197,12 +221,13 @@ esp_err_t lvgl_port_task_wake(lvgl_port_event_type_t event, void *param) } else { xEventGroupSetBits(lvgl_port_ctx.lvgl_events, bits); } - +#endif return ESP_OK; } IRAM_ATTR bool lvgl_port_task_notify(uint32_t value) { +#if CONFIG_LVGL_PORT_INTERNAL_TASK BaseType_t need_yield = pdFALSE; // Notify LVGL task @@ -213,12 +238,16 @@ IRAM_ATTR bool lvgl_port_task_notify(uint32_t value) } return (need_yield == pdTRUE); +#else + return false; +#endif } /******************************************************************************* * Private functions *******************************************************************************/ +#if CONFIG_LVGL_PORT_INTERNAL_TASK static void lvgl_port_task(void *arg) { TaskHandle_t task_to_notify = (TaskHandle_t)arg; @@ -240,7 +269,7 @@ static void lvgl_port_task(void *arg) /* Tick init */ lvgl_port_tick_init(); - ESP_LOGI(TAG, "Starting LVGL task"); + ESP_LOGI(TAG, "Starting LVGL task (custom)"); lvgl_port_ctx.running = true; while (lvgl_port_ctx.running) { /* Wait for queue or timeout (sleep task) */ @@ -321,3 +350,5 @@ static esp_err_t lvgl_port_tick_init(void) ESP_RETURN_ON_ERROR(esp_timer_create(&lvgl_tick_timer_args, &lvgl_port_ctx.tick_timer), TAG, "Creating LVGL timer filed!"); return esp_timer_start_periodic(lvgl_port_ctx.tick_timer, lvgl_port_ctx.timer_period_ms * 1000); } + +#endif From f011770832f6804f10a98e8152f404da939be8be Mon Sep 17 00:00:00 2001 From: Maldus512 Date: Tue, 7 Oct 2025 12:47:57 +0200 Subject: [PATCH 2/2] Removed unneded config dependency --- components/esp_lvgl_port/Kconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/components/esp_lvgl_port/Kconfig b/components/esp_lvgl_port/Kconfig index 2e10afb3b..6dfa91c9b 100644 --- a/components/esp_lvgl_port/Kconfig +++ b/components/esp_lvgl_port/Kconfig @@ -8,7 +8,6 @@ menu "ESP LVGL PORT" Enables using PPA for screen rotation. config LVGL_PORT_INTERNAL_TASK - depends on SOC_PPA_SUPPORTED bool "Use an internal task for LVGL management" default y help