Skip to content

Commit

Permalink
refactor(mouse): Remove mouse work queue, Kconfig
Browse files Browse the repository at this point in the history
* Remove now-unused mouse work queue and related mouse main file.
* Move ticks config into a DTS property on the two axis input behavior.
  • Loading branch information
petejohanson committed Dec 12, 2023
1 parent 7e466ee commit 089113f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 77 deletions.
2 changes: 0 additions & 2 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions app/dts/bindings/behaviors/zmk,behavior-input-two-axis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions app/include/zmk/mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@

typedef uint8_t zmk_mouse_button_flags_t;
typedef uint16_t zmk_mouse_button_t;

int zmk_mouse_init(void);
20 changes: 11 additions & 9 deletions app/src/behaviors/behavior_input_two_axis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -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));
}
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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), \
Expand Down
3 changes: 0 additions & 3 deletions app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
31 changes: 0 additions & 31 deletions app/src/mouse/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 0 additions & 30 deletions app/src/mouse/main.c

This file was deleted.

0 comments on commit 089113f

Please sign in to comment.