refactor: k_work_queue
API updates.
This commit is contained in:
parent
79ab60dfe5
commit
2c5d5fde51
7 changed files with 23 additions and 20 deletions
|
@ -71,7 +71,7 @@ struct active_hold_tap {
|
||||||
int64_t timestamp;
|
int64_t timestamp;
|
||||||
enum status status;
|
enum status status;
|
||||||
const struct behavior_hold_tap_config *config;
|
const struct behavior_hold_tap_config *config;
|
||||||
struct k_delayed_work work;
|
struct k_work_delayable work;
|
||||||
bool work_is_cancelled;
|
bool work_is_cancelled;
|
||||||
|
|
||||||
// initialized to -1, which is to be interpreted as "no other key has been pressed yet"
|
// initialized to -1, which is to be interpreted as "no other key has been pressed yet"
|
||||||
|
@ -522,7 +522,7 @@ static int on_hold_tap_binding_pressed(struct zmk_behavior_binding *binding,
|
||||||
// if this behavior was queued we have to adjust the timer to only
|
// if this behavior was queued we have to adjust the timer to only
|
||||||
// wait for the remaining time.
|
// wait for the remaining time.
|
||||||
int32_t tapping_term_ms_left = (hold_tap->timestamp + cfg->tapping_term_ms) - k_uptime_get();
|
int32_t tapping_term_ms_left = (hold_tap->timestamp + cfg->tapping_term_ms) - k_uptime_get();
|
||||||
k_delayed_work_submit(&hold_tap->work, K_MSEC(tapping_term_ms_left));
|
k_work_schedule(&hold_tap->work, K_MSEC(tapping_term_ms_left));
|
||||||
|
|
||||||
return ZMK_BEHAVIOR_OPAQUE;
|
return ZMK_BEHAVIOR_OPAQUE;
|
||||||
}
|
}
|
||||||
|
@ -537,7 +537,7 @@ static int on_hold_tap_binding_released(struct zmk_behavior_binding *binding,
|
||||||
|
|
||||||
// If these events were queued, the timer event may be queued too late or not at all.
|
// If these events were queued, the timer event may be queued too late or not at all.
|
||||||
// We insert a timer event before the TH_KEY_UP event to verify.
|
// We insert a timer event before the TH_KEY_UP event to verify.
|
||||||
int work_cancel_result = k_delayed_work_cancel(&hold_tap->work);
|
int work_cancel_result = k_work_cancel_delayable(&hold_tap->work);
|
||||||
if (event.timestamp > (hold_tap->timestamp + hold_tap->config->tapping_term_ms)) {
|
if (event.timestamp > (hold_tap->timestamp + hold_tap->config->tapping_term_ms)) {
|
||||||
decide_hold_tap(hold_tap, HT_TIMER_EVENT);
|
decide_hold_tap(hold_tap, HT_TIMER_EVENT);
|
||||||
}
|
}
|
||||||
|
@ -666,7 +666,7 @@ static int behavior_hold_tap_init(const struct device *dev) {
|
||||||
|
|
||||||
if (init_first_run) {
|
if (init_first_run) {
|
||||||
for (int i = 0; i < ZMK_BHV_HOLD_TAP_MAX_HELD; i++) {
|
for (int i = 0; i < ZMK_BHV_HOLD_TAP_MAX_HELD; i++) {
|
||||||
k_delayed_work_init(&active_hold_taps[i].work, behavior_hold_tap_timer_work_handler);
|
k_work_init_delayable(&active_hold_taps[i].work, behavior_hold_tap_timer_work_handler);
|
||||||
active_hold_taps[i].position = ZMK_BHV_HOLD_TAP_POSITION_NOT_USED;
|
active_hold_taps[i].position = ZMK_BHV_HOLD_TAP_POSITION_NOT_USED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ struct active_sticky_key {
|
||||||
bool timer_started;
|
bool timer_started;
|
||||||
bool timer_cancelled;
|
bool timer_cancelled;
|
||||||
int64_t release_at;
|
int64_t release_at;
|
||||||
struct k_delayed_work release_timer;
|
struct k_work_delayable release_timer;
|
||||||
// usage page and keycode for the key that is being modified by this sticky key
|
// usage page and keycode for the key that is being modified by this sticky key
|
||||||
uint8_t modified_key_usage_page;
|
uint8_t modified_key_usage_page;
|
||||||
uint32_t modified_key_keycode;
|
uint32_t modified_key_keycode;
|
||||||
|
@ -119,7 +119,7 @@ static inline int release_sticky_key_behavior(struct active_sticky_key *sticky_k
|
||||||
}
|
}
|
||||||
|
|
||||||
static int stop_timer(struct active_sticky_key *sticky_key) {
|
static int stop_timer(struct active_sticky_key *sticky_key) {
|
||||||
int timer_cancel_result = k_delayed_work_cancel(&sticky_key->release_timer);
|
int timer_cancel_result = k_work_cancel_delayable(&sticky_key->release_timer);
|
||||||
if (timer_cancel_result == -EINPROGRESS) {
|
if (timer_cancel_result == -EINPROGRESS) {
|
||||||
// too late to cancel, we'll let the timer handler clear up.
|
// too late to cancel, we'll let the timer handler clear up.
|
||||||
sticky_key->timer_cancelled = true;
|
sticky_key->timer_cancelled = true;
|
||||||
|
@ -168,7 +168,7 @@ static int on_sticky_key_binding_released(struct zmk_behavior_binding *binding,
|
||||||
// adjust timer in case this behavior was queued by a hold-tap
|
// adjust timer in case this behavior was queued by a hold-tap
|
||||||
int32_t ms_left = sticky_key->release_at - k_uptime_get();
|
int32_t ms_left = sticky_key->release_at - k_uptime_get();
|
||||||
if (ms_left > 0) {
|
if (ms_left > 0) {
|
||||||
k_delayed_work_submit(&sticky_key->release_timer, K_MSEC(ms_left));
|
k_work_schedule(&sticky_key->release_timer, K_MSEC(ms_left));
|
||||||
}
|
}
|
||||||
return ZMK_BEHAVIOR_OPAQUE;
|
return ZMK_BEHAVIOR_OPAQUE;
|
||||||
}
|
}
|
||||||
|
@ -268,8 +268,8 @@ static int behavior_sticky_key_init(const struct device *dev) {
|
||||||
static bool init_first_run = true;
|
static bool init_first_run = true;
|
||||||
if (init_first_run) {
|
if (init_first_run) {
|
||||||
for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) {
|
for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) {
|
||||||
k_delayed_work_init(&active_sticky_keys[i].release_timer,
|
k_work_init_delayable(&active_sticky_keys[i].release_timer,
|
||||||
behavior_sticky_key_timer_handler);
|
behavior_sticky_key_timer_handler);
|
||||||
active_sticky_keys[i].position = ZMK_BHV_STICKY_KEY_POSITION_FREE;
|
active_sticky_keys[i].position = ZMK_BHV_STICKY_KEY_POSITION_FREE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -389,7 +389,7 @@ static void update_timeout_task() {
|
||||||
k_work_cancel_delayable(&timeout_task);
|
k_work_cancel_delayable(&timeout_task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (k_work_schedule(&timeout_task, K_MSEC(first_timeout - k_uptime_get())) == 0) {
|
if (k_work_schedule(&timeout_task, K_MSEC(first_timeout - k_uptime_get())) >= 0) {
|
||||||
timeout_task_timeout_at = first_timeout;
|
timeout_task_timeout_at = first_timeout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,9 +95,9 @@ int zmk_display_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if IS_ENABLED(CONFIG_ZMK_DISPLAY_WORK_QUEUE_DEDICATED)
|
#if IS_ENABLED(CONFIG_ZMK_DISPLAY_WORK_QUEUE_DEDICATED)
|
||||||
k_work_q_start(&display_work_q, display_work_stack_area,
|
k_work_queue_start(&display_work_q, display_work_stack_area,
|
||||||
K_THREAD_STACK_SIZEOF(display_work_stack_area),
|
K_THREAD_STACK_SIZEOF(display_work_stack_area),
|
||||||
CONFIG_ZMK_DISPLAY_DEDICATED_THREAD_PRIORITY);
|
CONFIG_ZMK_DISPLAY_DEDICATED_THREAD_PRIORITY, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
screen = zmk_display_status_screen();
|
screen = zmk_display_status_screen();
|
||||||
|
|
|
@ -262,8 +262,9 @@ int zmk_hog_send_consumer_report(struct zmk_hid_consumer_report_body *report) {
|
||||||
};
|
};
|
||||||
|
|
||||||
int zmk_hog_init(const struct device *_arg) {
|
int zmk_hog_init(const struct device *_arg) {
|
||||||
k_work_q_start(&hog_work_q, hog_q_stack, K_THREAD_STACK_SIZEOF(hog_q_stack),
|
static const struct k_work_queue_config queue_config = {.name = "HID Over GATT Send Work"};
|
||||||
CONFIG_ZMK_BLE_THREAD_PRIORITY);
|
k_work_queue_start(&hog_work_q, hog_q_stack, K_THREAD_STACK_SIZEOF(hog_q_stack),
|
||||||
|
CONFIG_ZMK_BLE_THREAD_PRIORITY, &queue_config);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -562,9 +562,9 @@ int zmk_split_bt_invoke_behavior(uint8_t source, struct zmk_behavior_binding *bi
|
||||||
}
|
}
|
||||||
|
|
||||||
int zmk_split_bt_central_init(const struct device *_arg) {
|
int zmk_split_bt_central_init(const struct device *_arg) {
|
||||||
k_work_q_start(&split_central_split_run_q, split_central_split_run_q_stack,
|
k_work_queue_start(&split_central_split_run_q, split_central_split_run_q_stack,
|
||||||
K_THREAD_STACK_SIZEOF(split_central_split_run_q_stack),
|
K_THREAD_STACK_SIZEOF(split_central_split_run_q_stack),
|
||||||
CONFIG_ZMK_BLE_THREAD_PRIORITY);
|
CONFIG_ZMK_BLE_THREAD_PRIORITY, NULL);
|
||||||
bt_conn_cb_register(&conn_callbacks);
|
bt_conn_cb_register(&conn_callbacks);
|
||||||
|
|
||||||
return start_scan();
|
return start_scan();
|
||||||
|
|
|
@ -152,8 +152,10 @@ int zmk_split_bt_position_released(uint8_t position) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int service_init(const struct device *_arg) {
|
int service_init(const struct device *_arg) {
|
||||||
k_work_q_start(&service_work_q, service_q_stack, K_THREAD_STACK_SIZEOF(service_q_stack),
|
static const struct k_work_queue_config queue_config = {
|
||||||
CONFIG_ZMK_SPLIT_BLE_PERIPHERAL_PRIORITY);
|
.name = "Split Peripheral Notification Queue"};
|
||||||
|
k_work_queue_start(&service_work_q, service_q_stack, K_THREAD_STACK_SIZEOF(service_q_stack),
|
||||||
|
CONFIG_ZMK_SPLIT_BLE_PERIPHERAL_PRIORITY, &queue_config);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue