diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index fb0a34618bd0..6f62597dbbcb 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -22,7 +22,6 @@ target_sources(app PRIVATE src/activity.c) target_sources(app PRIVATE src/behavior.c) target_sources(app PRIVATE src/kscan.c) target_sources(app PRIVATE src/matrix_transform.c) -target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/mouse/main.c) target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/mouse/input_config.c) target_sources(app PRIVATE src/sensors.c) target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/wpm.c) @@ -37,7 +36,6 @@ target_sources(app PRIVATE src/behaviors/behavior_reset.c) target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/behaviors/behavior_ext_power.c) if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL) target_sources(app PRIVATE src/hid.c) - target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/mouse/main.c) target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/mouse/hid_input_listener.c) target_sources(app PRIVATE src/behaviors/behavior_key_press.c) target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_KEY_TOGGLE app PRIVATE src/behaviors/behavior_key_toggle.c) diff --git a/app/dts/bindings/behaviors/zmk,behavior-input-two-axis.yaml b/app/dts/bindings/behaviors/zmk,behavior-input-two-axis.yaml index 820ee7035b8a..0c138e039299 100644 --- a/app/dts/bindings/behaviors/zmk,behavior-input-two-axis.yaml +++ b/app/dts/bindings/behaviors/zmk,behavior-input-two-axis.yaml @@ -11,6 +11,10 @@ properties: y-input-code: type: int required: true + trigger-period-ms: + type: int + default: 16 + description: The time (in ms) between generated inputs when an input has non-zero speed. delay-ms: type: int time-to-max-speed-ms: diff --git a/app/include/zmk/mouse.h b/app/include/zmk/mouse.h index 28dab60d1433..c898f0010980 100644 --- a/app/include/zmk/mouse.h +++ b/app/include/zmk/mouse.h @@ -10,5 +10,3 @@ typedef uint8_t zmk_mouse_button_flags_t; typedef uint16_t zmk_mouse_button_t; - -int zmk_mouse_init(void); diff --git a/app/src/behaviors/behavior_input_two_axis.c b/app/src/behaviors/behavior_input_two_axis.c index 5a6afe63384a..0146df868ef2 100644 --- a/app/src/behaviors/behavior_input_two_axis.c +++ b/app/src/behaviors/behavior_input_two_axis.c @@ -43,12 +43,13 @@ struct behavior_input_two_axis_data { struct behavior_input_two_axis_config { int16_t x_code; int16_t y_code; - int delay_ms; - int time_to_max_speed_ms; + uint16_t delay_ms; + uint16_t time_to_max_speed_ms; + uint8_t trigger_period_ms; // acceleration exponent 0: uniform speed // acceleration exponent 1: uniform acceleration // acceleration exponent 2: uniform jerk - int acceleration_exponent; + uint8_t acceleration_exponent; }; #if CONFIG_MINIMAL_LIBC @@ -107,10 +108,9 @@ static float update_movement_1d(const struct behavior_input_two_axis_config *con } int64_t move_duration = ms_since_start(state->start_time, now, config->delay_ms); - move = - (move_duration > 0) - ? (speed(config, state->speed, move_duration) * CONFIG_ZMK_MOUSE_TICK_DURATION / 1000) - : 0; + move = (move_duration > 0) + ? (speed(config, state->speed, move_duration) * config->trigger_period_ms / 1000) + : 0; track_remainder(&(move), &(state->remainder)); @@ -165,7 +165,7 @@ static void tick_work_cb(struct k_work *work) { } if (should_be_working(data)) { - k_work_schedule(&data->tick_work, K_MSEC(CONFIG_ZMK_MOUSE_TICK_DURATION)); + k_work_schedule(&data->tick_work, K_MSEC(cfg->trigger_period_ms)); } } @@ -183,11 +183,12 @@ static void set_start_times_for_activity(struct movement_state_2d *state) { static void update_work_scheduling(const struct device *dev) { struct behavior_input_two_axis_data *data = dev->data; + const struct behavior_input_two_axis_config *cfg = dev->config; set_start_times_for_activity(&data->state); if (should_be_working(data)) { - k_work_schedule(&data->tick_work, K_MSEC(CONFIG_ZMK_MOUSE_TICK_DURATION)); + k_work_schedule(&data->tick_work, K_MSEC(cfg->trigger_period_ms)); } else { k_work_cancel_delayable(&data->tick_work); } @@ -260,6 +261,7 @@ static const struct behavior_driver_api behavior_input_two_axis_driver_api = { static struct behavior_input_two_axis_config behavior_input_two_axis_config_##n = { \ .x_code = DT_INST_PROP(n, x_input_code), \ .y_code = DT_INST_PROP(n, y_input_code), \ + .trigger_period_ms = DT_INST_PROP(n, trigger_period_ms), \ .delay_ms = DT_INST_PROP_OR(n, delay_ms, 0), \ .time_to_max_speed_ms = DT_INST_PROP(n, time_to_max_speed_ms), \ .acceleration_exponent = DT_INST_PROP_OR(n, acceleration_exponent, 1), \ diff --git a/app/src/main.c b/app/src/main.c index b5276c1a00fd..acaf3b649cab 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -32,8 +32,5 @@ int main(void) { zmk_display_init(); #endif /* CONFIG_ZMK_DISPLAY */ -#ifdef CONFIG_ZMK_MOUSE - zmk_mouse_init(); -#endif /* CONFIG_ZMK_MOUSE */ return 0; } diff --git a/app/src/mouse/Kconfig b/app/src/mouse/Kconfig index 8eb64f4cc847..398cabb1420a 100644 --- a/app/src/mouse/Kconfig +++ b/app/src/mouse/Kconfig @@ -7,34 +7,3 @@ config ZMK_MOUSE select INPUT select INPUT_THREAD_PRIORITY_OVERRIDE -config ZMK_MOUSE_TICK_DURATION - int "Mouse tick duration in ms" - default 16 - -if ZMK_MOUSE - -choice ZMK_MOUSE_WORK_QUEUE - prompt "Work queue selection for mouse events" - default ZMK_MOUSE_WORK_QUEUE_DEDICATED - -config ZMK_MOUSE_WORK_QUEUE_SYSTEM - bool "Use default system work queue for mouse events" - -config ZMK_MOUSE_WORK_QUEUE_DEDICATED - bool "Use dedicated work queue for mouse events" - -endchoice - -if ZMK_MOUSE_WORK_QUEUE_DEDICATED - -config ZMK_MOUSE_DEDICATED_THREAD_STACK_SIZE - int "Stack size for dedicated mouse thread/queue" - default 2048 - -config ZMK_MOUSE_DEDICATED_THREAD_PRIORITY - int "Thread priority for dedicated mouse thread/queue" - default 3 - -endif # ZMK_MOUSE_WORK_QUEUE_DEDICATED - -endif diff --git a/app/src/mouse/main.c b/app/src/mouse/main.c deleted file mode 100644 index e1227425ea58..000000000000 --- a/app/src/mouse/main.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2020 The ZMK Contributors - * - * SPDX-License-Identifier: MIT - */ - -#include -#include - -#if IS_ENABLED(CONFIG_ZMK_MOUSE_WORK_QUEUE_DEDICATED) -K_THREAD_STACK_DEFINE(mouse_work_stack_area, CONFIG_ZMK_MOUSE_DEDICATED_THREAD_STACK_SIZE); -static struct k_work_q mouse_work_q; -#endif - -struct k_work_q *zmk_mouse_work_q() { -#if IS_ENABLED(CONFIG_ZMK_MOUSE_WORK_QUEUE_DEDICATED) - return &mouse_work_q; -#else - return &k_sys_work_q; -#endif -} - -int zmk_mouse_init(void) { -#if IS_ENABLED(CONFIG_ZMK_MOUSE_WORK_QUEUE_DEDICATED) - k_work_queue_start(&mouse_work_q, mouse_work_stack_area, - K_THREAD_STACK_SIZEOF(mouse_work_stack_area), - CONFIG_ZMK_MOUSE_DEDICATED_THREAD_PRIORITY, NULL); -#endif - return 0; -} \ No newline at end of file