Skip to content

Commit 74f0ad5

Browse files
committed
Merge branch 'contrib/github_pr_15853' into 'master'
Fix for an infinite wait in spi-lcd-touch example (GitHub PR) Closes IDFGH-15181 See merge request espressif/esp-idf!38735
2 parents 38628f9 + 6b724b0 commit 74f0ad5

File tree

7 files changed

+43
-32
lines changed

7 files changed

+43
-32
lines changed

components/esp_lcd/test_apps/rgb_lcd/main/test_rgb_panel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ TEST_CASE("lcd_rgb_panel_bounce_buffer", "[lcd]")
166166
TaskHandle_t cur_task = xTaskGetCurrentTaskHandle();
167167

168168
printf("initialize RGB panel with non-stream mode\r\n");
169-
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);
169+
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);
170170
printf("flush random color block\r\n");
171171
for (int i = 0; i < 200; i++) {
172172
uint8_t color_byte = esp_random() & 0xFF;

examples/peripherals/lcd/i2c_oled/main/i2c_oled_example_main.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: CC0-1.0
55
*/
66

77
#include <stdio.h>
88
#include <unistd.h>
99
#include <sys/lock.h>
10+
#include <sys/param.h>
1011
#include "freertos/FreeRTOS.h"
1112
#include "freertos/task.h"
1213
#include "esp_timer.h"
@@ -52,6 +53,8 @@ static const char *TAG = "example";
5253
#define EXAMPLE_LVGL_TASK_STACK_SIZE (4 * 1024)
5354
#define EXAMPLE_LVGL_TASK_PRIORITY 2
5455
#define EXAMPLE_LVGL_PALETTE_SIZE 8
56+
#define EXAMPLE_LVGL_TASK_MAX_DELAY_MS 500
57+
#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1000 / CONFIG_FREERTOS_HZ
5558

5659
// To use LV_COLOR_FORMAT_I1, we need an extra buffer to hold the converted data
5760
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)
119122
_lock_acquire(&lvgl_api_lock);
120123
time_till_next_ms = lv_timer_handler();
121124
_lock_release(&lvgl_api_lock);
125+
// in case of triggering a task watch dog time out
126+
time_till_next_ms = MAX(time_till_next_ms, EXAMPLE_LVGL_TASK_MIN_DELAY_MS);
127+
// in case of lvgl display not ready yet
128+
time_till_next_ms = MIN(time_till_next_ms, EXAMPLE_LVGL_TASK_MAX_DELAY_MS);
122129
usleep(1000 * time_till_next_ms);
123130
}
124131
}

examples/peripherals/lcd/i80_controller/main/i80_controller_example_main.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: CC0-1.0
55
*/
66

77
#include <stdio.h>
88
#include <sys/lock.h>
9+
#include <sys/param.h>
910
#include "freertos/FreeRTOS.h"
1011
#include "freertos/task.h"
1112
#include "freertos/semphr.h"
@@ -69,7 +70,7 @@ static const char *TAG = "example";
6970

7071
#define EXAMPLE_LVGL_TICK_PERIOD_MS 2
7172
#define EXAMPLE_LVGL_TASK_MAX_DELAY_MS 500
72-
#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1
73+
#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1000 / CONFIG_FREERTOS_HZ
7374
#define EXAMPLE_LVGL_TASK_STACK_SIZE (4 * 1024)
7475
#define EXAMPLE_LVGL_TASK_PRIORITY 2
7576
#define EXAMPLE_LVGL_DRAW_BUF_LINES 100
@@ -116,11 +117,10 @@ static void example_lvgl_port_task(void *arg)
116117
_lock_acquire(&lvgl_api_lock);
117118
time_till_next_ms = lv_timer_handler();
118119
_lock_release(&lvgl_api_lock);
119-
if (time_till_next_ms > EXAMPLE_LVGL_TASK_MAX_DELAY_MS) {
120-
time_till_next_ms = EXAMPLE_LVGL_TASK_MAX_DELAY_MS;
121-
} else if (time_till_next_ms < EXAMPLE_LVGL_TASK_MIN_DELAY_MS) {
122-
time_till_next_ms = EXAMPLE_LVGL_TASK_MIN_DELAY_MS;
123-
}
120+
// in case of triggering a task watch dog time out
121+
time_till_next_ms = MAX(time_till_next_ms, EXAMPLE_LVGL_TASK_MIN_DELAY_MS);
122+
// in case of lvgl display not ready yet
123+
time_till_next_ms = MIN(time_till_next_ms, EXAMPLE_LVGL_TASK_MAX_DELAY_MS);
124124
vTaskDelay(pdMS_TO_TICKS(time_till_next_ms));
125125
}
126126
}

examples/peripherals/lcd/mipi_dsi/main/mipi_dsi_lcd_example_main.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: CC0-1.0
55
*/
66

77
#include <stdio.h>
88
#include <unistd.h>
99
#include <sys/lock.h>
10+
#include <sys/param.h>
1011
#include "sdkconfig.h"
1112
#include "freertos/FreeRTOS.h"
1213
#include "freertos/task.h"
@@ -79,6 +80,8 @@ static const char *TAG = "example";
7980
#define EXAMPLE_LVGL_TICK_PERIOD_MS 2
8081
#define EXAMPLE_LVGL_TASK_STACK_SIZE (4 * 1024)
8182
#define EXAMPLE_LVGL_TASK_PRIORITY 2
83+
#define EXAMPLE_LVGL_TASK_MAX_DELAY_MS 500
84+
#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1000 / CONFIG_FREERTOS_HZ
8285

8386
// LVGL library is not thread-safe, this example will call LVGL APIs from different tasks, so use a mutex to protect it
8487
static _lock_t lvgl_api_lock;
@@ -110,11 +113,10 @@ static void example_lvgl_port_task(void *arg)
110113
_lock_acquire(&lvgl_api_lock);
111114
time_till_next_ms = lv_timer_handler();
112115
_lock_release(&lvgl_api_lock);
113-
114-
// in case of task watch dog timeout, set the minimal delay to 10ms
115-
if (time_till_next_ms < 10) {
116-
time_till_next_ms = 10;
117-
}
116+
// in case of triggering a task watch dog time out
117+
time_till_next_ms = MAX(time_till_next_ms, EXAMPLE_LVGL_TASK_MIN_DELAY_MS);
118+
// in case of lvgl display not ready yet
119+
time_till_next_ms = MIN(time_till_next_ms, EXAMPLE_LVGL_TASK_MAX_DELAY_MS);
118120
usleep(1000 * time_till_next_ms);
119121
}
120122
}

examples/peripherals/lcd/parlio_simulate/main/parlio_simulate_example_main.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: CC0-1.0
55
*/
66

77
#include <stdio.h>
88
#include <sys/lock.h>
9+
#include <sys/param.h>
910
#include "freertos/FreeRTOS.h"
1011
#include "freertos/task.h"
1112
#include "freertos/semphr.h"
@@ -50,7 +51,7 @@ static const char *TAG = "example";
5051

5152
#define EXAMPLE_LVGL_TICK_PERIOD_MS 2
5253
#define EXAMPLE_LVGL_TASK_MAX_DELAY_MS 500
53-
#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1
54+
#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1000 / CONFIG_FREERTOS_HZ
5455
#define EXAMPLE_LVGL_TASK_STACK_SIZE (4 * 1024)
5556
#define EXAMPLE_LVGL_TASK_PRIORITY 2
5657
#define EXAMPLE_LVGL_DRAW_BUF_LINES 100
@@ -97,11 +98,10 @@ static void example_lvgl_port_task(void *arg)
9798
_lock_acquire(&lvgl_api_lock);
9899
time_till_next_ms = lv_timer_handler();
99100
_lock_release(&lvgl_api_lock);
100-
if (time_till_next_ms > EXAMPLE_LVGL_TASK_MAX_DELAY_MS) {
101-
time_till_next_ms = EXAMPLE_LVGL_TASK_MAX_DELAY_MS;
102-
} else if (time_till_next_ms < EXAMPLE_LVGL_TASK_MIN_DELAY_MS) {
103-
time_till_next_ms = EXAMPLE_LVGL_TASK_MIN_DELAY_MS;
104-
}
101+
// in case of triggering a task watch dog time out
102+
time_till_next_ms = MAX(time_till_next_ms, EXAMPLE_LVGL_TASK_MIN_DELAY_MS);
103+
// in case of lvgl display not ready yet
104+
time_till_next_ms = MIN(time_till_next_ms, EXAMPLE_LVGL_TASK_MAX_DELAY_MS);
105105
vTaskDelay(pdMS_TO_TICKS(time_till_next_ms));
106106
}
107107
}

examples/peripherals/lcd/rgb_panel/main/rgb_lcd_example_main.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: CC0-1.0
55
*/
66

77
#include <stdio.h>
88
#include <unistd.h>
99
#include <sys/lock.h>
10+
#include <sys/param.h>
1011
#include "sdkconfig.h"
1112
#include "freertos/FreeRTOS.h"
1213
#include "freertos/task.h"
@@ -95,6 +96,8 @@ static const char *TAG = "example";
9596
#define EXAMPLE_LVGL_TICK_PERIOD_MS 2
9697
#define EXAMPLE_LVGL_TASK_STACK_SIZE (5 * 1024)
9798
#define EXAMPLE_LVGL_TASK_PRIORITY 2
99+
#define EXAMPLE_LVGL_TASK_MAX_DELAY_MS 500
100+
#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1000 / CONFIG_FREERTOS_HZ
98101

99102
// LVGL library is not thread-safe, this example will call LVGL APIs from different tasks, so use a mutex to protect it
100103
static _lock_t lvgl_api_lock;
@@ -133,12 +136,10 @@ static void example_lvgl_port_task(void *arg)
133136
_lock_acquire(&lvgl_api_lock);
134137
time_till_next_ms = lv_timer_handler();
135138
_lock_release(&lvgl_api_lock);
136-
137-
// in case of task watch dog timeout, set the minimal delay to 10ms
138-
if (time_till_next_ms < 10) {
139-
time_till_next_ms = 10;
140-
}
141-
139+
// in case of task watch dog timeout
140+
time_till_next_ms = MAX(time_till_next_ms, EXAMPLE_LVGL_TASK_MIN_DELAY_MS);
141+
// in case of lvgl display not ready yet
142+
time_till_next_ms = MIN(time_till_next_ms, EXAMPLE_LVGL_TASK_MAX_DELAY_MS);
142143
usleep(1000 * time_till_next_ms);
143144
}
144145
}

examples/peripherals/lcd/spi_lcd_touch/main/spi_lcd_touch_example_main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static const char *TAG = "example";
6767
#define EXAMPLE_LVGL_DRAW_BUF_LINES 20 // number of display lines in each draw buffer
6868
#define EXAMPLE_LVGL_TICK_PERIOD_MS 2
6969
#define EXAMPLE_LVGL_TASK_MAX_DELAY_MS 500
70-
#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1
70+
#define EXAMPLE_LVGL_TASK_MIN_DELAY_MS 1000 / CONFIG_FREERTOS_HZ
7171
#define EXAMPLE_LVGL_TASK_STACK_SIZE (4 * 1024)
7272
#define EXAMPLE_LVGL_TASK_PRIORITY 2
7373

@@ -159,13 +159,14 @@ static void example_lvgl_port_task(void *arg)
159159
{
160160
ESP_LOGI(TAG, "Starting LVGL task");
161161
uint32_t time_till_next_ms = 0;
162-
uint32_t time_threshold_ms = 1000 / CONFIG_FREERTOS_HZ;
163162
while (1) {
164163
_lock_acquire(&lvgl_api_lock);
165164
time_till_next_ms = lv_timer_handler();
166165
_lock_release(&lvgl_api_lock);
167166
// in case of triggering a task watch dog time out
168-
time_till_next_ms = MAX(time_till_next_ms, time_threshold_ms);
167+
time_till_next_ms = MAX(time_till_next_ms, EXAMPLE_LVGL_TASK_MIN_DELAY_MS);
168+
// in case of lvgl display not ready yet
169+
time_till_next_ms = MIN(time_till_next_ms, EXAMPLE_LVGL_TASK_MAX_DELAY_MS);
169170
usleep(1000 * time_till_next_ms);
170171
}
171172
}

0 commit comments

Comments
 (0)