Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mouse): Add mouse move and scroll support #2477

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if(CONFIG_ZMK_BEHAVIOR_LOCAL_IDS)
endif()

zephyr_syscall_header(${APPLICATION_SOURCE_DIR}/include/drivers/behavior.h)
zephyr_syscall_header(${APPLICATION_SOURCE_DIR}/include/drivers/input_processor.h)
zephyr_syscall_header(${APPLICATION_SOURCE_DIR}/include/drivers/ext_power.h)

# Add your source file to the "app" target. This must come after
Expand All @@ -37,15 +38,14 @@ target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_WAKEUP_TRIGGER app PRIVATE src/gpio_key
target_sources(app PRIVATE src/events/activity_state_changed.c)
target_sources(app PRIVATE src/events/position_state_changed.c)
target_sources(app PRIVATE src/events/sensor_event.c)
target_sources(app PRIVATE src/events/mouse_button_state_changed.c)
target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/events/wpm_state_changed.c)
target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/events/usb_conn_state_changed.c)
target_sources(app PRIVATE src/behaviors/behavior_reset.c)
target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/behaviors/behavior_ext_power.c)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_SOFT_OFF app PRIVATE src/behaviors/behavior_soft_off.c)
add_subdirectory_ifdef(CONFIG_ZMK_POINTING src/pointing/)
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.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)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_HOLD_TAP app PRIVATE src/behaviors/behavior_hold_tap.c)
Expand All @@ -65,6 +65,7 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_SENSOR_ROTATE_COMMON app PRIVATE src/behaviors/behavior_sensor_rotate_common.c)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_MOUSE_KEY_PRESS app PRIVATE src/behaviors/behavior_mouse_key_press.c)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_STUDIO_UNLOCK app PRIVATE src/behaviors/behavior_studio_unlock.c)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_INPUT_TWO_AXIS app PRIVATE src/behaviors/behavior_input_two_axis.c)
target_sources(app PRIVATE src/combo.c)
target_sources(app PRIVATE src/behaviors/behavior_tap_dance.c)
target_sources(app PRIVATE src/behavior_queue.c)
Expand Down
7 changes: 1 addition & 6 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,7 @@ endif # ZMK_BACKLIGHT

endmenu # Display/LED Options

menu "Mouse Options"

config ZMK_MOUSE
bool "Enable ZMK mouse emulation"

endmenu # Mouse Options
rsource "src/pointing/Kconfig"

menu "Power Management"

Expand Down
8 changes: 6 additions & 2 deletions app/Kconfig.behaviors
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ config ZMK_BEHAVIOR_KEY_TOGGLE
config ZMK_BEHAVIOR_MOUSE_KEY_PRESS
bool
default y
depends on DT_HAS_ZMK_BEHAVIOR_MOUSE_KEY_PRESS_ENABLED
imply ZMK_MOUSE
depends on DT_HAS_ZMK_BEHAVIOR_MOUSE_KEY_PRESS_ENABLED && ZMK_POINTING

config ZMK_BEHAVIOR_STICKY_KEY
bool
Expand All @@ -94,6 +93,11 @@ config ZMK_BEHAVIOR_SOFT_OFF
default y
depends on DT_HAS_ZMK_BEHAVIOR_SOFT_OFF_ENABLED && ZMK_PM_SOFT_OFF

config ZMK_BEHAVIOR_INPUT_TWO_AXIS
bool
default y
depends on DT_HAS_ZMK_BEHAVIOR_INPUT_TWO_AXIS_ENABLED && ZMK_POINTING

config ZMK_BEHAVIOR_SENSOR_ROTATE_COMMON
bool

Expand Down
2 changes: 1 addition & 1 deletion app/core-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ include:
nickname: "display"
- board: nice_nano_v2
shield: kyria_left
cmake-args: "-DCONFIG_ZMK_MOUSE=y"
cmake-args: "-DCONFIG_ZMK_POINTING=y"
nickname: "mouse"
- board: sparkfun_pro_micro_rp2040
shield: reviung41
Expand Down
8 changes: 7 additions & 1 deletion app/dts/behaviors.dtsi
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright (c) 2024 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

#include <behaviors/key_press.dtsi>
#include <behaviors/key_toggle.dtsi>
#include <behaviors/transparent.dtsi>
Expand All @@ -19,6 +25,6 @@
#include <behaviors/key_repeat.dtsi>
#include <behaviors/backlight.dtsi>
#include <behaviors/macros.dtsi>
#include <behaviors/mouse_key_press.dtsi>
#include <behaviors/soft_off.dtsi>
#include <behaviors/studio_unlock.dtsi>
#include <behaviors/mouse_keys.dtsi>
5 changes: 5 additions & 0 deletions app/dts/behaviors/mouse_key_press.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
#binding-cells = <1>;
};
};

mkp_input_listener: mkp_input_listener {
compatible = "zmk,input-listener";
device = <&mkp>;
};
};
9 changes: 9 additions & 0 deletions app/dts/behaviors/mouse_keys.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright (c) 2024 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

#include "mouse_key_press.dtsi"
#include "mouse_move.dtsi"
#include "mouse_scroll.dtsi"
25 changes: 25 additions & 0 deletions app/dts/behaviors/mouse_move.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2024 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

#include <zephyr/dt-bindings/input/input-event-codes.h>

/ {
behaviors {
/omit-if-no-ref/ mmv: mouse_move {
compatible = "zmk,behavior-input-two-axis";
#binding-cells = <1>;
x-input-code = <INPUT_REL_X>;
y-input-code = <INPUT_REL_Y>;
time-to-max-speed-ms = <300>;
acceleration-exponent = <1>;
};
};

mmv_input_listener: mmv_input_listener {
compatible = "zmk,input-listener";
device = <&mmv>;
};
};
26 changes: 26 additions & 0 deletions app/dts/behaviors/mouse_scroll.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

/*
* Copyright (c) 2024 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

#include <zephyr/dt-bindings/input/input-event-codes.h>

/ {
behaviors {
/omit-if-no-ref/ msc: mouse_scroll {
compatible = "zmk,behavior-input-two-axis";
#binding-cells = <1>;
x-input-code = <INPUT_REL_HWHEEL>;
y-input-code = <INPUT_REL_WHEEL>;
time-to-max-speed-ms = <300>;
acceleration-exponent = <0>;
};
};

msc_input_listener: msc_input_listener {
compatible = "zmk,input-listener";
device = <&msc>;
};
};
28 changes: 28 additions & 0 deletions app/dts/bindings/behaviors/zmk,behavior-input-two-axis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright (c) 2024 The ZMK Contributors
# SPDX-License-Identifier: MIT

description: Two axis input behavior

compatible: "zmk,behavior-input-two-axis"

include: one_param.yaml

properties:
x-input-code:
type: int
required: true
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:
type: int
required: true
acceleration-exponent:
type: int
default: 1
6 changes: 6 additions & 0 deletions app/dts/bindings/input_processors/ip_common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2024 The ZMK Contributors
# SPDX-License-Identifier: MIT

properties:
track-remainders:
type: boolean
13 changes: 13 additions & 0 deletions app/dts/bindings/input_processors/ip_one_param.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2024 The ZMK Contributors
# SPDX-License-Identifier: MIT

include: ip_common.yaml

properties:
"#input-processor-cells":
type: int
required: true
const: 1

input-processor-cells:
- param1
14 changes: 14 additions & 0 deletions app/dts/bindings/input_processors/ip_two_param.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2024 The ZMK Contributors
# SPDX-License-Identifier: MIT

include: ip_common.yaml

properties:
"#input-processor-cells":
type: int
required: true
const: 2

input-processor-cells:
- param1
- param2
10 changes: 10 additions & 0 deletions app/dts/bindings/input_processors/ip_zero_param.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2024 The ZMK Contributors
# SPDX-License-Identifier: MIT

include: ip_common.yaml

properties:
"#input-processor-cells":
type: int
required: true
const: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2024, The ZMK Contributors
# SPDX-License-Identifier: MIT

description: Input Processor for remapping certain input codes to other codes

compatible: "zmk,input-processor-code-mapper"

include: ip_zero_param.yaml

properties:
type:
type: int
required: true
map:
type: array
required: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2024, The ZMK Contributors
# SPDX-License-Identifier: MIT

description: Input Processor for scaling values

compatible: "zmk,input-processor-scaler"

include: ip_two_param.yaml

properties:
type:
type: int
required: true
codes:
type: array
required: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) 2024, The ZMK Contributors
# SPDX-License-Identifier: MIT

description: Input Processor for temporarily enabling a layer after input events

compatible: "zmk,input-processor-temp-layer"

include: ip_two_param.yaml

properties:
require-prior-idle-ms:
type: int
required: false
default: 0
description: Time in milliseconds that must pass after the last keystroke before the layer can be toggled

excluded-positions:
type: array
required: false
default: []
description: Array of key positions that will NOT trigger layer deactivation when pressed
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2024, The ZMK Contributors
# SPDX-License-Identifier: MIT

description: Input Processor for transforming values in various ways

compatible: "zmk,input-processor-transform"

include: ip_one_param.yaml

properties:
type:
type: int
x-codes:
type: array
required: true
y-codes:
type: array
required: true
26 changes: 26 additions & 0 deletions app/dts/bindings/zmk,input-listener.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright (c) 2024 The ZMK Contributors
# SPDX-License-Identifier: MIT

description: |
Listener to subscribe to input events and send HID updates after processing
compatible: "zmk,input-listener"

properties:
device:
type: phandle
required: true
input-processors:
type: phandle-array

child-binding:
description: "Listener overrides for certain layers"

properties:
layers:
type: array
required: true
process-next:
type: boolean
input-processors:
type: phandle-array
18 changes: 18 additions & 0 deletions app/dts/bindings/zmk,input-split.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2024 The ZMK Contributors
# SPDX-License-Identifier: MIT

include: [base.yaml]

compatible: "zmk,input-split"

description: Device to wire up an input device for split use.

properties:
reg:
required: true

device:
type: phandle

input-processors:
type: phandle-array
10 changes: 10 additions & 0 deletions app/dts/input/processors.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright (c) 2024 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

#include <input/processors/scaler.dtsi>
#include <input/processors/code_mapper.dtsi>
#include <input/processors/transform.dtsi>
#include <input/processors/temp_layer.dtsi>
Loading
Loading