mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
fix(lcd): fix the infinite wait when lvgl timer is no ready
Merges https://github.com/espressif/esp-idf/pull/15853
This commit is contained in:
@ -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 <stdio.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/param.h>
|
||||
#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));
|
||||
}
|
||||
}
|
||||
|
@ -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 <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/param.h>
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
@ -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 <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/param.h>
|
||||
#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);
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,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
|
||||
|
||||
@ -157,22 +157,17 @@ 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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
|
Reference in New Issue
Block a user