From 80dc8af6ed5d62b148e7046350d0e18f3d5064d4 Mon Sep 17 00:00:00 2001 From: Decstar77 <34284628+Decstar77@users.noreply.github.com> Date: Thu, 24 Apr 2025 21:37:37 +0200 Subject: [PATCH 1/3] fix(spi-lcd-touch-example): Fix for an infinite wait caused by UINT32_MAX --- .../spi_lcd_touch/main/spi_lcd_touch_example_main.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/peripherals/lcd/spi_lcd_touch/main/spi_lcd_touch_example_main.c b/examples/peripherals/lcd/spi_lcd_touch/main/spi_lcd_touch_example_main.c index ad5d8b1bfb..32ce7c152b 100644 --- a/examples/peripherals/lcd/spi_lcd_touch/main/spi_lcd_touch_example_main.c +++ b/examples/peripherals/lcd/spi_lcd_touch/main/spi_lcd_touch_example_main.c @@ -164,9 +164,15 @@ static void example_lvgl_port_task(void *arg) _lock_acquire(&lvgl_api_lock); time_till_next_ms = lv_timer_handler(); _lock_release(&lvgl_api_lock); - // in case of triggering a task watch dog time out - time_till_next_ms = MAX(time_till_next_ms, time_threshold_ms); - usleep(1000 * time_till_next_ms); + if ( time_till_next_ms == LV_NO_TIMER_READY ) { + //most probably lvgl display not ready yet + usleep( 1000 * 1000 ); + } + else { + // in case of triggering a task watch dog time out + time_till_next_ms = MAX(time_till_next_ms, time_threshold_ms); + usleep(1000 * time_till_next_ms); + } } } From ca88289e625f7ab6b38fb9b7662d9dfc0284f646 Mon Sep 17 00:00:00 2001 From: Chen Jichang Date: Fri, 25 Apr 2025 18:32:58 +0800 Subject: [PATCH 2/3] fix(lcd): fix the infinite wait when lvgl timer is no ready Merges https://github.com/espressif/esp-idf/pull/15853 --- .../lcd/i2c_oled/main/i2c_oled_example_main.c | 9 ++++++++- .../main/i80_controller_example_main.c | 14 +++++++------- .../mipi_dsi/main/mipi_dsi_lcd_example_main.c | 14 ++++++++------ .../main/parlio_simulate_example_main.c | 14 +++++++------- .../lcd/rgb_panel/main/rgb_lcd_example_main.c | 15 ++++++++------- .../main/spi_lcd_touch_example_main.c | 17 ++++++----------- 6 files changed, 44 insertions(+), 39 deletions(-) diff --git a/examples/peripherals/lcd/i2c_oled/main/i2c_oled_example_main.c b/examples/peripherals/lcd/i2c_oled/main/i2c_oled_example_main.c index 2a11223047..46a8d0c514 100644 --- a/examples/peripherals/lcd/i2c_oled/main/i2c_oled_example_main.c +++ b/examples/peripherals/lcd/i2c_oled/main/i2c_oled_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -7,6 +7,7 @@ #include #include #include +#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_timer.h" @@ -52,6 +53,8 @@ static const char *TAG = "example"; #define EXAMPLE_LVGL_TASK_STACK_SIZE (4 * 1024) #define EXAMPLE_LVGL_TASK_PRIORITY 2 #define EXAMPLE_LVGL_PALETTE_SIZE 8 +#define EXAMPLE_LVGL_TASK_MAX_DELAY_MS 500 +#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1000 / CONFIG_FREERTOS_HZ // To use LV_COLOR_FORMAT_I1, we need an extra buffer to hold the converted data static uint8_t oled_buffer[EXAMPLE_LCD_H_RES * EXAMPLE_LCD_V_RES / 8]; @@ -119,6 +122,10 @@ static void example_lvgl_port_task(void *arg) _lock_acquire(&lvgl_api_lock); time_till_next_ms = lv_timer_handler(); _lock_release(&lvgl_api_lock); + // in case of triggering a task watch dog time out + time_till_next_ms = MAX(time_till_next_ms, EXAMPLE_LVGL_TASK_MIN_DELAY_MS); + // in case of lvgl display not ready yet + time_till_next_ms = MIN(time_till_next_ms, EXAMPLE_LVGL_TASK_MAX_DELAY_MS); usleep(1000 * time_till_next_ms); } } diff --git a/examples/peripherals/lcd/i80_controller/main/i80_controller_example_main.c b/examples/peripherals/lcd/i80_controller/main/i80_controller_example_main.c index 6f65912e30..c17de48158 100644 --- a/examples/peripherals/lcd/i80_controller/main/i80_controller_example_main.c +++ b/examples/peripherals/lcd/i80_controller/main/i80_controller_example_main.c @@ -1,11 +1,12 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ #include #include +#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" @@ -69,7 +70,7 @@ static const char *TAG = "example"; #define EXAMPLE_LVGL_TICK_PERIOD_MS 2 #define EXAMPLE_LVGL_TASK_MAX_DELAY_MS 500 -#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1 +#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1000 / CONFIG_FREERTOS_HZ #define EXAMPLE_LVGL_TASK_STACK_SIZE (4 * 1024) #define EXAMPLE_LVGL_TASK_PRIORITY 2 #define EXAMPLE_LVGL_DRAW_BUF_LINES 100 @@ -116,11 +117,10 @@ static void example_lvgl_port_task(void *arg) _lock_acquire(&lvgl_api_lock); time_till_next_ms = lv_timer_handler(); _lock_release(&lvgl_api_lock); - if (time_till_next_ms > EXAMPLE_LVGL_TASK_MAX_DELAY_MS) { - time_till_next_ms = EXAMPLE_LVGL_TASK_MAX_DELAY_MS; - } else if (time_till_next_ms < EXAMPLE_LVGL_TASK_MIN_DELAY_MS) { - time_till_next_ms = EXAMPLE_LVGL_TASK_MIN_DELAY_MS; - } + // in case of triggering a task watch dog time out + time_till_next_ms = MAX(time_till_next_ms, EXAMPLE_LVGL_TASK_MIN_DELAY_MS); + // in case of lvgl display not ready yet + time_till_next_ms = MIN(time_till_next_ms, EXAMPLE_LVGL_TASK_MAX_DELAY_MS); vTaskDelay(pdMS_TO_TICKS(time_till_next_ms)); } } diff --git a/examples/peripherals/lcd/mipi_dsi/main/mipi_dsi_lcd_example_main.c b/examples/peripherals/lcd/mipi_dsi/main/mipi_dsi_lcd_example_main.c index 80f8e08f81..a51828a783 100644 --- a/examples/peripherals/lcd/mipi_dsi/main/mipi_dsi_lcd_example_main.c +++ b/examples/peripherals/lcd/mipi_dsi/main/mipi_dsi_lcd_example_main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ @@ -7,6 +7,7 @@ #include #include #include +#include #include "sdkconfig.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -79,6 +80,8 @@ static const char *TAG = "example"; #define EXAMPLE_LVGL_TICK_PERIOD_MS 2 #define EXAMPLE_LVGL_TASK_STACK_SIZE (4 * 1024) #define EXAMPLE_LVGL_TASK_PRIORITY 2 +#define EXAMPLE_LVGL_TASK_MAX_DELAY_MS 500 +#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1000 / CONFIG_FREERTOS_HZ // LVGL library is not thread-safe, this example will call LVGL APIs from different tasks, so use a mutex to protect it static _lock_t lvgl_api_lock; @@ -110,11 +113,10 @@ static void example_lvgl_port_task(void *arg) _lock_acquire(&lvgl_api_lock); time_till_next_ms = lv_timer_handler(); _lock_release(&lvgl_api_lock); - - // in case of task watch dog timeout, set the minimal delay to 10ms - if (time_till_next_ms < 10) { - time_till_next_ms = 10; - } + // in case of triggering a task watch dog time out + time_till_next_ms = MAX(time_till_next_ms, EXAMPLE_LVGL_TASK_MIN_DELAY_MS); + // in case of lvgl display not ready yet + time_till_next_ms = MIN(time_till_next_ms, EXAMPLE_LVGL_TASK_MAX_DELAY_MS); usleep(1000 * time_till_next_ms); } } diff --git a/examples/peripherals/lcd/parlio_simulate/main/parlio_simulate_example_main.c b/examples/peripherals/lcd/parlio_simulate/main/parlio_simulate_example_main.c index e3309cdb32..cb4f3f90c1 100644 --- a/examples/peripherals/lcd/parlio_simulate/main/parlio_simulate_example_main.c +++ b/examples/peripherals/lcd/parlio_simulate/main/parlio_simulate_example_main.c @@ -1,11 +1,12 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: CC0-1.0 */ #include #include +#include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" @@ -50,7 +51,7 @@ static const char *TAG = "example"; #define EXAMPLE_LVGL_TICK_PERIOD_MS 2 #define EXAMPLE_LVGL_TASK_MAX_DELAY_MS 500 -#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1 +#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1000 / CONFIG_FREERTOS_HZ #define EXAMPLE_LVGL_TASK_STACK_SIZE (4 * 1024) #define EXAMPLE_LVGL_TASK_PRIORITY 2 #define EXAMPLE_LVGL_DRAW_BUF_LINES 100 @@ -97,11 +98,10 @@ static void example_lvgl_port_task(void *arg) _lock_acquire(&lvgl_api_lock); time_till_next_ms = lv_timer_handler(); _lock_release(&lvgl_api_lock); - if (time_till_next_ms > EXAMPLE_LVGL_TASK_MAX_DELAY_MS) { - time_till_next_ms = EXAMPLE_LVGL_TASK_MAX_DELAY_MS; - } else if (time_till_next_ms < EXAMPLE_LVGL_TASK_MIN_DELAY_MS) { - time_till_next_ms = EXAMPLE_LVGL_TASK_MIN_DELAY_MS; - } + // in case of triggering a task watch dog time out + time_till_next_ms = MAX(time_till_next_ms, EXAMPLE_LVGL_TASK_MIN_DELAY_MS); + // in case of lvgl display not ready yet + time_till_next_ms = MIN(time_till_next_ms, EXAMPLE_LVGL_TASK_MAX_DELAY_MS); vTaskDelay(pdMS_TO_TICKS(time_till_next_ms)); } } diff --git a/examples/peripherals/lcd/rgb_panel/main/rgb_lcd_example_main.c b/examples/peripherals/lcd/rgb_panel/main/rgb_lcd_example_main.c index d9b983617d..0b0366158b 100644 --- a/examples/peripherals/lcd/rgb_panel/main/rgb_lcd_example_main.c +++ b/examples/peripherals/lcd/rgb_panel/main/rgb_lcd_example_main.c @@ -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: CC0-1.0 */ @@ -7,6 +7,7 @@ #include #include #include +#include #include "sdkconfig.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -95,6 +96,8 @@ static const char *TAG = "example"; #define EXAMPLE_LVGL_TICK_PERIOD_MS 2 #define EXAMPLE_LVGL_TASK_STACK_SIZE (5 * 1024) #define EXAMPLE_LVGL_TASK_PRIORITY 2 +#define EXAMPLE_LVGL_TASK_MAX_DELAY_MS 500 +#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1000 / CONFIG_FREERTOS_HZ // LVGL library is not thread-safe, this example will call LVGL APIs from different tasks, so use a mutex to protect it static _lock_t lvgl_api_lock; @@ -133,12 +136,10 @@ static void example_lvgl_port_task(void *arg) _lock_acquire(&lvgl_api_lock); time_till_next_ms = lv_timer_handler(); _lock_release(&lvgl_api_lock); - - // in case of task watch dog timeout, set the minimal delay to 10ms - if (time_till_next_ms < 10) { - time_till_next_ms = 10; - } - + // in case of task watch dog timeout + time_till_next_ms = MAX(time_till_next_ms, EXAMPLE_LVGL_TASK_MIN_DELAY_MS); + // in case of lvgl display not ready yet + time_till_next_ms = MIN(time_till_next_ms, EXAMPLE_LVGL_TASK_MAX_DELAY_MS); usleep(1000 * time_till_next_ms); } } diff --git a/examples/peripherals/lcd/spi_lcd_touch/main/spi_lcd_touch_example_main.c b/examples/peripherals/lcd/spi_lcd_touch/main/spi_lcd_touch_example_main.c index 32ce7c152b..66a181fd2a 100644 --- a/examples/peripherals/lcd/spi_lcd_touch/main/spi_lcd_touch_example_main.c +++ b/examples/peripherals/lcd/spi_lcd_touch/main/spi_lcd_touch_example_main.c @@ -67,7 +67,7 @@ static const char *TAG = "example"; #define EXAMPLE_LVGL_DRAW_BUF_LINES 20 // number of display lines in each draw buffer #define EXAMPLE_LVGL_TICK_PERIOD_MS 2 #define EXAMPLE_LVGL_TASK_MAX_DELAY_MS 500 -#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1 +#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1000 / CONFIG_FREERTOS_HZ #define EXAMPLE_LVGL_TASK_STACK_SIZE (4 * 1024) #define EXAMPLE_LVGL_TASK_PRIORITY 2 @@ -159,20 +159,15 @@ static void example_lvgl_port_task(void *arg) { ESP_LOGI(TAG, "Starting LVGL task"); uint32_t time_till_next_ms = 0; - uint32_t time_threshold_ms = 1000 / CONFIG_FREERTOS_HZ; while (1) { _lock_acquire(&lvgl_api_lock); time_till_next_ms = lv_timer_handler(); _lock_release(&lvgl_api_lock); - if ( time_till_next_ms == LV_NO_TIMER_READY ) { - //most probably lvgl display not ready yet - usleep( 1000 * 1000 ); - } - else { - // in case of triggering a task watch dog time out - time_till_next_ms = MAX(time_till_next_ms, time_threshold_ms); - usleep(1000 * time_till_next_ms); - } + // in case of triggering a task watch dog time out + time_till_next_ms = MAX(time_till_next_ms, EXAMPLE_LVGL_TASK_MIN_DELAY_MS); + // in case of lvgl display not ready yet + time_till_next_ms = MIN(time_till_next_ms, EXAMPLE_LVGL_TASK_MAX_DELAY_MS); + usleep(1000 * time_till_next_ms); } } From 6b724b0fc14f3cb20bb61fa9746f17b7dd2e9280 Mon Sep 17 00:00:00 2001 From: Chen Jichang Date: Sun, 27 Apr 2025 14:22:02 +0800 Subject: [PATCH 3/3] fix(lcd): fix test failure regression --- components/esp_lcd/test_apps/rgb_lcd/main/test_rgb_panel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_lcd/test_apps/rgb_lcd/main/test_rgb_panel.c b/components/esp_lcd/test_apps/rgb_lcd/main/test_rgb_panel.c index 0de40e884c..61877901bd 100644 --- a/components/esp_lcd/test_apps/rgb_lcd/main/test_rgb_panel.c +++ b/components/esp_lcd/test_apps/rgb_lcd/main/test_rgb_panel.c @@ -166,7 +166,7 @@ TEST_CASE("lcd_rgb_panel_bounce_buffer", "[lcd]") TaskHandle_t cur_task = xTaskGetCurrentTaskHandle(); printf("initialize RGB panel with non-stream mode\r\n"); - esp_lcd_panel_handle_t panel_handle = test_rgb_panel_initialization(16, 16, 10 * TEST_LCD_H_RES, false, test_rgb_panel_trans_done, cur_task); + esp_lcd_panel_handle_t panel_handle = test_rgb_panel_initialization(16, 16, 20 * TEST_LCD_H_RES, false, test_rgb_panel_trans_done, cur_task); printf("flush random color block\r\n"); for (int i = 0; i < 200; i++) { uint8_t color_byte = esp_random() & 0xFF;