refactor: k_work_queue API updates.

This commit is contained in:
Peter Johanson
2021-11-05 04:23:17 +00:00
committed by Pete Johanson
parent 79ab60dfe5
commit 2c5d5fde51
7 changed files with 23 additions and 20 deletions

View File

@@ -71,7 +71,7 @@ struct active_hold_tap {
int64_t timestamp;
enum status status;
const struct behavior_hold_tap_config *config;
struct k_delayed_work work;
struct k_work_delayable work;
bool work_is_cancelled;
// 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
// wait for the remaining time.
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;
}
@@ -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.
// 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)) {
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) {
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;
}
}

View File

@@ -44,7 +44,7 @@ struct active_sticky_key {
bool timer_started;
bool timer_cancelled;
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
uint8_t modified_key_usage_page;
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) {
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) {
// too late to cancel, we'll let the timer handler clear up.
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
int32_t ms_left = sticky_key->release_at - k_uptime_get();
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;
}
@@ -268,8 +268,8 @@ static int behavior_sticky_key_init(const struct device *dev) {
static bool init_first_run = true;
if (init_first_run) {
for (int i = 0; i < ZMK_BHV_STICKY_KEY_MAX_HELD; i++) {
k_delayed_work_init(&active_sticky_keys[i].release_timer,
behavior_sticky_key_timer_handler);
k_work_init_delayable(&active_sticky_keys[i].release_timer,
behavior_sticky_key_timer_handler);
active_sticky_keys[i].position = ZMK_BHV_STICKY_KEY_POSITION_FREE;
}
}