Skip to content

Commit

Permalink
Merge pull request espressif#125 from espressif/lvgl_port_add_max_sle…
Browse files Browse the repository at this point in the history
…ep_time

esp_lvgl_port: Add maximum time in ms for sleep LVGL task.
  • Loading branch information
espzav authored Feb 8, 2023
2 parents 805faec + 96b030f commit ee83eb4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
11 changes: 8 additions & 3 deletions components/esp_lvgl_port/esp_lvgl_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef struct lvgl_port_ctx_s {
SemaphoreHandle_t lvgl_mux;
esp_timer_handle_t tick_timer;
bool running;
int task_max_sleep_ms;
} lvgl_port_ctx_t;

typedef struct {
Expand Down Expand Up @@ -97,6 +98,10 @@ esp_err_t lvgl_port_init(const lvgl_port_cfg_t *cfg)
lvgl_port_timer_period_ms = cfg->timer_period_ms;
ESP_RETURN_ON_ERROR(lvgl_port_tick_init(), TAG, "");
/* Create task */
lvgl_port_ctx.task_max_sleep_ms = cfg->task_max_sleep_ms;
if (lvgl_port_ctx.task_max_sleep_ms == 0) {
lvgl_port_ctx.task_max_sleep_ms = 500;
}
lvgl_port_ctx.lvgl_mux = xSemaphoreCreateRecursiveMutex();
ESP_GOTO_ON_FALSE(lvgl_port_ctx.lvgl_mux, ESP_ERR_NO_MEM, err, TAG, "Create LVGL mutex fail!");

Expand Down Expand Up @@ -321,7 +326,7 @@ void lvgl_port_flush_ready(lv_disp_t *disp)

static void lvgl_port_task(void *arg)
{
uint32_t task_delay_ms = 500;
uint32_t task_delay_ms = lvgl_port_ctx.task_max_sleep_ms;

ESP_LOGI(TAG, "Starting LVGL task");
lvgl_port_ctx.running = true;
Expand All @@ -330,8 +335,8 @@ static void lvgl_port_task(void *arg)
task_delay_ms = lv_timer_handler();
lvgl_port_unlock();
}
if (task_delay_ms > 500) {
task_delay_ms = 500;
if (task_delay_ms > lvgl_port_ctx.task_max_sleep_ms) {
task_delay_ms = lvgl_port_ctx.task_max_sleep_ms;
} else if (task_delay_ms < 1) {
task_delay_ms = 1;
}
Expand Down
2 changes: 1 addition & 1 deletion components/esp_lvgl_port/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.0.3"
version: "1.0.4"
description: ESP LVGL port
url: https://github.com/espressif/esp-bsp/tree/master/components/esp_lvgl_port
dependencies:
Expand Down
12 changes: 7 additions & 5 deletions components/esp_lvgl_port/include/esp_lvgl_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ extern "C" {
typedef struct {
int task_priority; /*!< LVGL task priority */
int task_stack; /*!< LVGL task stack size */
int task_affinity; /*!< LVGL task pinned to core (-1 is no affinity) */
int task_affinity; /*!< LVGL task pinned to core (-1 is no affinity) */
int task_max_sleep_ms; /*!< Maximum sleep in LVGL task */
int timer_period_ms; /*!< LVGL timer tick period in ms */
} lvgl_port_cfg_t;

Expand Down Expand Up @@ -78,10 +79,11 @@ typedef struct {
*/
#define ESP_LVGL_PORT_INIT_CONFIG() \
{ \
.task_priority = 4, \
.task_stack = 4096, \
.task_affinity = -1, \
.timer_period_ms = 5, \
.task_priority = 4, \
.task_stack = 4096, \
.task_affinity = -1, \
.task_max_sleep_ms = 500, \
.timer_period_ms = 5, \
}

/**
Expand Down

0 comments on commit ee83eb4

Please sign in to comment.