Browse Source

feat(display): Optional dedicated work queue.

* Add new Kconfig settingsx to allow selecting system or dedicated
  work queue for performing UI updates.
* Allow UI updates to not block other system tasks when display is
  updating, especially important for e-ink displays.
xmkb
Peter Johanson 3 years ago committed by Pete Johanson
parent
commit
063d98e3df
  1. 2
      app/include/zmk/display.h
  2. 23
      app/src/display/Kconfig
  3. 35
      app/src/display/main.c

2
app/include/zmk/display.h

@ -6,4 +6,6 @@ @@ -6,4 +6,6 @@
#pragma once
struct k_work_q *zmk_display_work_q();
int zmk_display_init();

23
app/src/display/Kconfig

@ -29,6 +29,29 @@ config ZMK_DISPLAY_STATUS_SCREEN_CUSTOM @@ -29,6 +29,29 @@ config ZMK_DISPLAY_STATUS_SCREEN_CUSTOM
endchoice
choice ZMK_DISPLAY_WORK_QUEUE
prompt "Work queue selection for UI updates"
config ZMK_DISPLAY_WORK_QUEUE_SYSTEM
bool "Use default system work queue for UI updates"
config ZMK_DISPLAY_WORK_QUEUE_DEDICATED
bool "Use dedicated work queue for UI updates"
endchoice
if ZMK_DISPLAY_WORK_QUEUE_DEDICATED
config ZMK_DISPLAY_DEDICATED_THREAD_STACK_SIZE
int "Stack size for dedicated UI thread/queue"
default 2048
config ZMK_DISPLAY_DEDICATED_THREAD_PRIORITY
int "Thread priority for dedicated UI thread/queue"
default 5
endif # ZMK_DISPLAY_WORK_QUEUE_DEDICATED
rsource "widgets/Kconfig"
endif

35
app/src/display/main.c

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
* SPDX-License-Identifier: MIT
*/
#include <kernel.h>
#include <init.h>
#include <device.h>
#include <devicetree.h>
@ -32,19 +33,41 @@ void display_tick_cb(struct k_work *work) { lv_task_handler(); } @@ -32,19 +33,41 @@ void display_tick_cb(struct k_work *work) { lv_task_handler(); }
K_WORK_DEFINE(display_tick_work, display_tick_cb);
#if IS_ENABLED(CONFIG_ZMK_DISPLAY_WORK_QUEUE_DEDICATED)
K_THREAD_STACK_DEFINE(display_work_stack_area, CONFIG_ZMK_DISPLAY_DEDICATED_THREAD_STACK_SIZE);
static struct k_work_q display_work_q;
#endif
struct k_work_q *zmk_display_work_q() {
#if IS_ENABLED(CONFIG_ZMK_DISPLAY_WORK_QUEUE_DEDICATED)
return &display_work_q;
#else
return &k_sys_work_q;
#endif
}
void display_timer_cb() {
lv_tick_inc(TICK_MS);
k_work_submit(&display_tick_work);
k_work_submit_to_queue(zmk_display_work_q(), &display_tick_work);
}
void blank_display_cb(struct k_work *work) { display_blanking_on(display); }
void unblank_display_cb(struct k_work *work) { display_blanking_off(display); }
K_TIMER_DEFINE(display_timer, display_timer_cb, NULL);
K_WORK_DEFINE(blank_display_work, blank_display_cb);
K_WORK_DEFINE(unblank_display_work, unblank_display_cb);
static void start_display_updates() {
if (display == NULL) {
return;
}
display_blanking_off(display);
k_work_submit_to_queue(zmk_display_work_q(), &unblank_display_work);
k_timer_start(&display_timer, K_MSEC(TICK_MS), K_MSEC(TICK_MS));
}
@ -54,7 +77,7 @@ static void stop_display_updates() { @@ -54,7 +77,7 @@ static void stop_display_updates() {
return;
}
display_blanking_on(display);
k_work_submit_to_queue(zmk_display_work_q(), &blank_display_work);
k_timer_stop(&display_timer);
}
@ -68,6 +91,12 @@ int zmk_display_init() { @@ -68,6 +91,12 @@ int zmk_display_init() {
return -EINVAL;
}
#if IS_ENABLED(CONFIG_ZMK_DISPLAY_WORK_QUEUE_DEDICATED)
k_work_q_start(&display_work_q, display_work_stack_area,
K_THREAD_STACK_SIZEOF(display_work_stack_area),
CONFIG_ZMK_DISPLAY_DEDICATED_THREAD_PRIORITY);
#endif
screen = zmk_display_status_screen();
if (screen == NULL) {

Loading…
Cancel
Save