Browse Source

refactor: `k_work_queue` API updates.

xmkb
Peter Johanson 3 years ago committed by Pete Johanson
parent
commit
2c5d5fde51
  1. 8
      app/src/behaviors/behavior_hold_tap.c
  2. 8
      app/src/behaviors/behavior_sticky_key.c
  3. 2
      app/src/combo.c
  4. 4
      app/src/display/main.c
  5. 5
      app/src/hog.c
  6. 4
      app/src/split/bluetooth/central.c
  7. 6
      app/src/split/bluetooth/service.c

8
app/src/behaviors/behavior_hold_tap.c

@ -71,7 +71,7 @@ struct active_hold_tap { @@ -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, @@ -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, @@ -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) { @@ -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;
}
}

8
app/src/behaviors/behavior_sticky_key.c

@ -44,7 +44,7 @@ struct active_sticky_key { @@ -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 @@ -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, @@ -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,7 +268,7 @@ static int behavior_sticky_key_init(const struct device *dev) { @@ -268,7 +268,7 @@ 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,
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;
}

2
app/src/combo.c

@ -389,7 +389,7 @@ static void update_timeout_task() { @@ -389,7 +389,7 @@ static void update_timeout_task() {
k_work_cancel_delayable(&timeout_task);
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;
}
}

4
app/src/display/main.c

@ -95,9 +95,9 @@ int zmk_display_init() { @@ -95,9 +95,9 @@ int zmk_display_init() {
}
#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),
CONFIG_ZMK_DISPLAY_DEDICATED_THREAD_PRIORITY);
CONFIG_ZMK_DISPLAY_DEDICATED_THREAD_PRIORITY, NULL);
#endif
screen = zmk_display_status_screen();

5
app/src/hog.c

@ -262,8 +262,9 @@ int zmk_hog_send_consumer_report(struct zmk_hid_consumer_report_body *report) { @@ -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) {
k_work_q_start(&hog_work_q, hog_q_stack, K_THREAD_STACK_SIZEOF(hog_q_stack),
CONFIG_ZMK_BLE_THREAD_PRIORITY);
static const struct k_work_queue_config queue_config = {.name = "HID Over GATT Send Work"};
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;
}

4
app/src/split/bluetooth/central.c

@ -562,9 +562,9 @@ int zmk_split_bt_invoke_behavior(uint8_t source, struct zmk_behavior_binding *bi @@ -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) {
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),
CONFIG_ZMK_BLE_THREAD_PRIORITY);
CONFIG_ZMK_BLE_THREAD_PRIORITY, NULL);
bt_conn_cb_register(&conn_callbacks);
return start_scan();

6
app/src/split/bluetooth/service.c

@ -152,8 +152,10 @@ int zmk_split_bt_position_released(uint8_t position) { @@ -152,8 +152,10 @@ int zmk_split_bt_position_released(uint8_t position) {
}
int service_init(const struct device *_arg) {
k_work_q_start(&service_work_q, service_q_stack, K_THREAD_STACK_SIZEOF(service_q_stack),
CONFIG_ZMK_SPLIT_BLE_PERIPHERAL_PRIORITY);
static const struct k_work_queue_config queue_config = {
.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;
}

Loading…
Cancel
Save