Skip to content

Commit 6b40bfd

Browse files
petejohansoncaksoylarkrikun98urobftc
authored
feat(mouse): Add mouse move and scroll support (#2477)
* feat(mouse): Add mouse move and scroll support * Use Zephyr input subsystem for all pointers. * Input processors for modifying events, e.g. scaling, swapping codes, temporary (mouse) layers, etc. * Mouse move/scroll behaviors. * Infrastructure in place for physical pointer input devices. * feat: Add input split support. * docs: Add initial pointer docs. --------- Co-authored-by: Cem Aksoylar <caksoylar@users.noreply.github.com> Co-authored-by: Alexander Krikun <krikun98@gmail.com> Co-authored-by: Robert U <urob@users.noreply.github.com> Co-authored-by: Shawn Meier <ftc@users.noreply.github.com> Co-authored-by: Chris Andreae <chris@andreae.gen.nz> Co-authored-by: Anant Thazhemadam <47104651+thazhemadam@users.noreply.github.com> Co-authored-by: Erik Tollerud <erik.tollerud@gmail.com> Co-authored-by: Nicolas Munnich <98408764+Nick-Munnich@users.noreply.github.com>
1 parent 7e8c542 commit 6b40bfd

File tree

119 files changed

+4226
-232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+4226
-232
lines changed

app/CMakeLists.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if(CONFIG_ZMK_BEHAVIOR_LOCAL_IDS)
1717
endif()
1818

1919
zephyr_syscall_header(${APPLICATION_SOURCE_DIR}/include/drivers/behavior.h)
20+
zephyr_syscall_header(${APPLICATION_SOURCE_DIR}/include/drivers/input_processor.h)
2021
zephyr_syscall_header(${APPLICATION_SOURCE_DIR}/include/drivers/ext_power.h)
2122

2223
# Add your source file to the "app" target. This must come after
@@ -37,15 +38,14 @@ target_sources_ifdef(CONFIG_ZMK_GPIO_KEY_WAKEUP_TRIGGER app PRIVATE src/gpio_key
3738
target_sources(app PRIVATE src/events/activity_state_changed.c)
3839
target_sources(app PRIVATE src/events/position_state_changed.c)
3940
target_sources(app PRIVATE src/events/sensor_event.c)
40-
target_sources(app PRIVATE src/events/mouse_button_state_changed.c)
4141
target_sources_ifdef(CONFIG_ZMK_WPM app PRIVATE src/events/wpm_state_changed.c)
4242
target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/events/usb_conn_state_changed.c)
4343
target_sources(app PRIVATE src/behaviors/behavior_reset.c)
4444
target_sources_ifdef(CONFIG_ZMK_EXT_POWER app PRIVATE src/behaviors/behavior_ext_power.c)
4545
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_SOFT_OFF app PRIVATE src/behaviors/behavior_soft_off.c)
46+
add_subdirectory_ifdef(CONFIG_ZMK_POINTING src/pointing/)
4647
if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
4748
target_sources(app PRIVATE src/hid.c)
48-
target_sources_ifdef(CONFIG_ZMK_MOUSE app PRIVATE src/mouse.c)
4949
target_sources(app PRIVATE src/behaviors/behavior_key_press.c)
5050
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_KEY_TOGGLE app PRIVATE src/behaviors/behavior_key_toggle.c)
5151
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_HOLD_TAP app PRIVATE src/behaviors/behavior_hold_tap.c)
@@ -65,6 +65,7 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
6565
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_SENSOR_ROTATE_COMMON app PRIVATE src/behaviors/behavior_sensor_rotate_common.c)
6666
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_MOUSE_KEY_PRESS app PRIVATE src/behaviors/behavior_mouse_key_press.c)
6767
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_STUDIO_UNLOCK app PRIVATE src/behaviors/behavior_studio_unlock.c)
68+
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_INPUT_TWO_AXIS app PRIVATE src/behaviors/behavior_input_two_axis.c)
6869
target_sources(app PRIVATE src/combo.c)
6970
target_sources(app PRIVATE src/behaviors/behavior_tap_dance.c)
7071
target_sources(app PRIVATE src/behavior_queue.c)

app/Kconfig

+1-6
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,7 @@ endif # ZMK_BACKLIGHT
363363

364364
endmenu # Display/LED Options
365365

366-
menu "Mouse Options"
367-
368-
config ZMK_MOUSE
369-
bool "Enable ZMK mouse emulation"
370-
371-
endmenu # Mouse Options
366+
rsource "src/pointing/Kconfig"
372367

373368
menu "Power Management"
374369

app/Kconfig.behaviors

+6-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ config ZMK_BEHAVIOR_KEY_TOGGLE
7171
config ZMK_BEHAVIOR_MOUSE_KEY_PRESS
7272
bool
7373
default y
74-
depends on DT_HAS_ZMK_BEHAVIOR_MOUSE_KEY_PRESS_ENABLED
75-
imply ZMK_MOUSE
74+
depends on DT_HAS_ZMK_BEHAVIOR_MOUSE_KEY_PRESS_ENABLED && ZMK_POINTING
7675

7776
config ZMK_BEHAVIOR_STICKY_KEY
7877
bool
@@ -94,6 +93,11 @@ config ZMK_BEHAVIOR_SOFT_OFF
9493
default y
9594
depends on DT_HAS_ZMK_BEHAVIOR_SOFT_OFF_ENABLED && ZMK_PM_SOFT_OFF
9695

96+
config ZMK_BEHAVIOR_INPUT_TWO_AXIS
97+
bool
98+
default y
99+
depends on DT_HAS_ZMK_BEHAVIOR_INPUT_TWO_AXIS_ENABLED && ZMK_POINTING
100+
97101
config ZMK_BEHAVIOR_SENSOR_ROTATE_COMMON
98102
bool
99103

app/core-coverage.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ include:
2424
nickname: "display"
2525
- board: nice_nano_v2
2626
shield: kyria_left
27-
cmake-args: "-DCONFIG_ZMK_MOUSE=y"
27+
cmake-args: "-DCONFIG_ZMK_POINTING=y"
2828
nickname: "mouse"
2929
- board: sparkfun_pro_micro_rp2040
3030
shield: reviung41

app/dts/behaviors.dtsi

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*
2+
* Copyright (c) 2024 The ZMK Contributors
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
17
#include <behaviors/key_press.dtsi>
28
#include <behaviors/key_toggle.dtsi>
39
#include <behaviors/transparent.dtsi>
@@ -19,6 +25,6 @@
1925
#include <behaviors/key_repeat.dtsi>
2026
#include <behaviors/backlight.dtsi>
2127
#include <behaviors/macros.dtsi>
22-
#include <behaviors/mouse_key_press.dtsi>
2328
#include <behaviors/soft_off.dtsi>
2429
#include <behaviors/studio_unlock.dtsi>
30+
#include <behaviors/mouse_keys.dtsi>

app/dts/behaviors/mouse_key_press.dtsi

+5
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@
1616
#binding-cells = <1>;
1717
};
1818
};
19+
20+
mkp_input_listener: mkp_input_listener {
21+
compatible = "zmk,input-listener";
22+
device = <&mkp>;
23+
};
1924
};

app/dts/behaviors/mouse_keys.dtsi

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright (c) 2024 The ZMK Contributors
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
7+
#include "mouse_key_press.dtsi"
8+
#include "mouse_move.dtsi"
9+
#include "mouse_scroll.dtsi"

app/dts/behaviors/mouse_move.dtsi

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2024 The ZMK Contributors
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
7+
#include <zephyr/dt-bindings/input/input-event-codes.h>
8+
9+
/ {
10+
behaviors {
11+
/omit-if-no-ref/ mmv: mouse_move {
12+
compatible = "zmk,behavior-input-two-axis";
13+
#binding-cells = <1>;
14+
x-input-code = <INPUT_REL_X>;
15+
y-input-code = <INPUT_REL_Y>;
16+
time-to-max-speed-ms = <300>;
17+
acceleration-exponent = <1>;
18+
};
19+
};
20+
21+
mmv_input_listener: mmv_input_listener {
22+
compatible = "zmk,input-listener";
23+
device = <&mmv>;
24+
};
25+
};

app/dts/behaviors/mouse_scroll.dtsi

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
/*
3+
* Copyright (c) 2024 The ZMK Contributors
4+
*
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
#include <zephyr/dt-bindings/input/input-event-codes.h>
9+
10+
/ {
11+
behaviors {
12+
/omit-if-no-ref/ msc: mouse_scroll {
13+
compatible = "zmk,behavior-input-two-axis";
14+
#binding-cells = <1>;
15+
x-input-code = <INPUT_REL_HWHEEL>;
16+
y-input-code = <INPUT_REL_WHEEL>;
17+
time-to-max-speed-ms = <300>;
18+
acceleration-exponent = <0>;
19+
};
20+
};
21+
22+
msc_input_listener: msc_input_listener {
23+
compatible = "zmk,input-listener";
24+
device = <&msc>;
25+
};
26+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2024 The ZMK Contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
description: Two axis input behavior
5+
6+
compatible: "zmk,behavior-input-two-axis"
7+
8+
include: one_param.yaml
9+
10+
properties:
11+
x-input-code:
12+
type: int
13+
required: true
14+
y-input-code:
15+
type: int
16+
required: true
17+
trigger-period-ms:
18+
type: int
19+
default: 16
20+
description: The time (in ms) between generated inputs when an input has non-zero speed.
21+
delay-ms:
22+
type: int
23+
time-to-max-speed-ms:
24+
type: int
25+
required: true
26+
acceleration-exponent:
27+
type: int
28+
default: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2024 The ZMK Contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
properties:
5+
track-remainders:
6+
type: boolean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2024 The ZMK Contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
include: ip_common.yaml
5+
6+
properties:
7+
"#input-processor-cells":
8+
type: int
9+
required: true
10+
const: 1
11+
12+
input-processor-cells:
13+
- param1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (c) 2024 The ZMK Contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
include: ip_common.yaml
5+
6+
properties:
7+
"#input-processor-cells":
8+
type: int
9+
required: true
10+
const: 2
11+
12+
input-processor-cells:
13+
- param1
14+
- param2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2024 The ZMK Contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
include: ip_common.yaml
5+
6+
properties:
7+
"#input-processor-cells":
8+
type: int
9+
required: true
10+
const: 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2024, The ZMK Contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
description: Input Processor for remapping certain input codes to other codes
5+
6+
compatible: "zmk,input-processor-code-mapper"
7+
8+
include: ip_zero_param.yaml
9+
10+
properties:
11+
type:
12+
type: int
13+
required: true
14+
map:
15+
type: array
16+
required: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2024, The ZMK Contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
description: Input Processor for scaling values
5+
6+
compatible: "zmk,input-processor-scaler"
7+
8+
include: ip_two_param.yaml
9+
10+
properties:
11+
type:
12+
type: int
13+
required: true
14+
codes:
15+
type: array
16+
required: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) 2024, The ZMK Contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
description: Input Processor for temporarily enabling a layer after input events
5+
6+
compatible: "zmk,input-processor-temp-layer"
7+
8+
include: ip_two_param.yaml
9+
10+
properties:
11+
require-prior-idle-ms:
12+
type: int
13+
required: false
14+
default: 0
15+
description: Time in milliseconds that must pass after the last keystroke before the layer can be toggled
16+
17+
excluded-positions:
18+
type: array
19+
required: false
20+
default: []
21+
description: Array of key positions that will NOT trigger layer deactivation when pressed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2024, The ZMK Contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
description: Input Processor for transforming values in various ways
5+
6+
compatible: "zmk,input-processor-transform"
7+
8+
include: ip_one_param.yaml
9+
10+
properties:
11+
type:
12+
type: int
13+
x-codes:
14+
type: array
15+
required: true
16+
y-codes:
17+
type: array
18+
required: true
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) 2024 The ZMK Contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
description: |
5+
Listener to subscribe to input events and send HID updates after processing
6+
7+
compatible: "zmk,input-listener"
8+
9+
properties:
10+
device:
11+
type: phandle
12+
required: true
13+
input-processors:
14+
type: phandle-array
15+
16+
child-binding:
17+
description: "Listener overrides for certain layers"
18+
19+
properties:
20+
layers:
21+
type: array
22+
required: true
23+
process-next:
24+
type: boolean
25+
input-processors:
26+
type: phandle-array

app/dts/bindings/zmk,input-split.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2024 The ZMK Contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
include: [base.yaml]
5+
6+
compatible: "zmk,input-split"
7+
8+
description: Device to wire up an input device for split use.
9+
10+
properties:
11+
reg:
12+
required: true
13+
14+
device:
15+
type: phandle
16+
17+
input-processors:
18+
type: phandle-array

app/dts/input/processors.dtsi

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (c) 2024 The ZMK Contributors
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
7+
#include <input/processors/scaler.dtsi>
8+
#include <input/processors/code_mapper.dtsi>
9+
#include <input/processors/transform.dtsi>
10+
#include <input/processors/temp_layer.dtsi>

0 commit comments

Comments
 (0)