Skip to content

Commit 98a7ed3

Browse files
committed
feat(mouse): Add PS/2 mouse/trackpoint/etc support
1 parent 309359b commit 98a7ed3

File tree

11 files changed

+2265
-1
lines changed

11 files changed

+2265
-1
lines changed

app/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ target_sources_ifdef(CONFIG_USB_DEVICE_STACK app PRIVATE src/usb.c)
8585
target_sources_ifdef(CONFIG_ZMK_USB app PRIVATE src/usb_hid.c)
8686
target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/rgb_underglow.c)
8787
target_sources_ifdef(CONFIG_ZMK_BACKLIGHT app PRIVATE src/backlight.c)
88+
89+
target_sources_ifdef(CONFIG_ZMK_MOUSE_PS2 app PRIVATE src/mouse/mouse_ps2.c)
90+
target_sources_ifdef(CONFIG_ZMK_MOUSE_PS2 app PRIVATE src/behaviors/behavior_mouse_setting.c)
91+
8892
target_sources(app PRIVATE src/main.c)
8993

9094
add_subdirectory(src/display/)

app/dts/arm/nordic/override.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define NRF_DEFAULT_IRQ_PRIORITY 3

app/dts/behaviors.dtsi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
#include <behaviors/caps_word.dtsi>
1919
#include <behaviors/key_repeat.dtsi>
2020
#include <behaviors/backlight.dtsi>
21-
#include <behaviors/macros.dtsi>
21+
#include <behaviors/macros.dtsi>
22+
#include <behaviors/mouse_setting.dtsi>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2020 The ZMK Contributors
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
7+
/ {
8+
behaviors {
9+
mms: behavior_mouse_setting {
10+
compatible = "zmk,behavior-mouse-setting";
11+
label = "MOUSE_SETTING";
12+
#binding-cells = <1>;
13+
};
14+
};
15+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
description: Mouse Setting
2+
3+
compatible: "zmk,behavior-mouse-setting"
4+
5+
include: one_param.yaml
6+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
description: PS2 mouse configuration
2+
3+
compatible: "zmk,mouse-ps2"
4+
5+
properties:
6+
ps2-device:
7+
type: phandle
8+
required: true
9+
description: |
10+
The ps2 device the mouse should use.
11+
12+
rst-gpios:
13+
type: phandle-array
14+
required: false
15+
description: GPIO to which the RST pin of the device is connected and on which the Power-On-Reset will be performed.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2020 The ZMK Contributors
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
#pragma once
7+
8+
#define MS_TP_SENSITIVITY_INCR 10
9+
#define MS_TP_SENSITIVITY_DECR 11
10+
11+
#define MS_TP_NEG_INERTIA_INCR 12
12+
#define MS_TP_NEG_INERTIA_DECR 13
13+
14+
#define MS_TP_VALUE6_INCR 14
15+
#define MS_TP_VALUE6_DECR 15
16+
17+
#define MS_TP_PTS_THRESHOLD_INCR 16
18+
#define MS_TP_PTS_THRESHOLD_DECR 17

app/include/zmk/mouse_ps2.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) 2021 The ZMK Contributors
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
7+
#pragma once
8+
9+
int zmk_mouse_ps2_tp_sensitivity_change(int amount);
10+
int zmk_mouse_ps2_tp_neg_inertia_change(int amount);
11+
int zmk_mouse_ps2_tp_value6_upper_plateau_speed_change(int amount);
12+
int zmk_mouse_ps2_tp_pts_threshold_change(int amount);
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#define DT_DRV_COMPAT zmk_behavior_mouse_setting
2+
3+
#include <zephyr/device.h>
4+
#include <drivers/behavior.h>
5+
#include <zephyr/logging/log.h>
6+
7+
#include <dt-bindings/zmk/mouse_settings.h>
8+
#include <zmk/mouse_ps2.h>
9+
#include <zmk/mouse.h>
10+
11+
#define INCREMENT_TP_SENSITIVITY 10
12+
#define INCREMENT_TP_NEG_INERTIA 1
13+
#define INCREMENT_TP_VALUE6 5
14+
#define INCREMENT_TP_PTS_THRESHOLD 1
15+
16+
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
17+
18+
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
19+
struct zmk_behavior_binding_event event)
20+
{
21+
switch (binding->param1) {
22+
23+
case MS_TP_SENSITIVITY_INCR:
24+
return zmk_mouse_ps2_tp_sensitivity_change(
25+
INCREMENT_TP_SENSITIVITY
26+
);
27+
case MS_TP_SENSITIVITY_DECR:
28+
return zmk_mouse_ps2_tp_sensitivity_change(
29+
-INCREMENT_TP_SENSITIVITY
30+
);
31+
32+
case MS_TP_NEG_INERTIA_INCR:
33+
return zmk_mouse_ps2_tp_neg_inertia_change(
34+
INCREMENT_TP_NEG_INERTIA
35+
);
36+
case MS_TP_NEG_INERTIA_DECR:
37+
return zmk_mouse_ps2_tp_neg_inertia_change(
38+
-INCREMENT_TP_NEG_INERTIA
39+
);
40+
41+
case MS_TP_VALUE6_INCR:
42+
return zmk_mouse_ps2_tp_value6_upper_plateau_speed_change(
43+
INCREMENT_TP_VALUE6
44+
);
45+
case MS_TP_VALUE6_DECR:
46+
return zmk_mouse_ps2_tp_value6_upper_plateau_speed_change(
47+
-INCREMENT_TP_VALUE6
48+
);
49+
50+
case MS_TP_PTS_THRESHOLD_INCR:
51+
return zmk_mouse_ps2_tp_pts_threshold_change(
52+
INCREMENT_TP_PTS_THRESHOLD
53+
);
54+
case MS_TP_PTS_THRESHOLD_DECR:
55+
return zmk_mouse_ps2_tp_pts_threshold_change(
56+
-INCREMENT_TP_PTS_THRESHOLD
57+
);
58+
}
59+
60+
return -ENOTSUP;
61+
}
62+
63+
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
64+
struct zmk_behavior_binding_event event)
65+
{
66+
return ZMK_BEHAVIOR_OPAQUE;
67+
}
68+
69+
// Initialization Function
70+
static int zmk_behavior_mouse_setting_init(const struct device *dev) {
71+
return 0;
72+
};
73+
74+
static const struct behavior_driver_api
75+
zmk_behavior_mouse_setting_driver_api = {
76+
.binding_pressed = on_keymap_binding_pressed,
77+
.binding_released = on_keymap_binding_released
78+
};
79+
80+
DEVICE_DT_INST_DEFINE(
81+
0,
82+
zmk_behavior_mouse_setting_init, NULL,
83+
NULL, NULL,
84+
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
85+
&zmk_behavior_mouse_setting_driver_api
86+
);

app/src/mouse/Kconfig

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) 2021 The ZMK Contributors
2+
# SPDX-License-Identifier: MIT
3+
4+
DT_COMPAT_ZMK_PS2_MOUSE := zmk,mouse-ps2
5+
6+
config ZMK_MOUSE_PS2
7+
bool
8+
default $(dt_compat_enabled,$(DT_COMPAT_ZMK_PS2_MOUSE))
9+
depends on (!ZMK_SPLIT || ZMK_SPLIT_ROLE_CENTRAL)
10+
select ZMK_MOUSE
11+
select PS2
12+
13+
if ZMK_MOUSE_PS2
14+
15+
config ZMK_MOUSE_PS2_SAMPLING_RATE
16+
int "Sets how many mouse activity reports should be sent per second. The default is 100. You can reduce this setting if you see a lot of PS/2 transmission errors. Increasing it will not lead to significant improvements, because mouse reports are accumulated and only sent over bluetooth every `CONFIG_ZMK_MOUSE_TICK_DURATION` ms."
17+
default 100
18+
19+
config ZMK_MOUSE_PS2_ENABLE_CLICKING
20+
bool "Enables clicking events."
21+
default y
22+
23+
config ZMK_MOUSE_PS2_INVERT_X
24+
bool "Invert the mouse movement x axis."
25+
default n
26+
27+
config ZMK_MOUSE_PS2_INVERT_Y
28+
bool "Invert the mouse movement y axis."
29+
default n
30+
31+
config ZMK_MOUSE_PS2_SWAP_XY
32+
bool "Swaps the X and Y axis."
33+
default n
34+
35+
config ZMK_MOUSE_PS2_SCROLL
36+
bool "Enable scroll wheel on mouse devices supporting the Intellimouse extension."
37+
default n
38+
39+
config ZMK_MOUSE_PS2_TP_TAP_TO_SELECT
40+
bool "Enables the ability to left-click by tapping the trackpoint."
41+
default n
42+
43+
config ZMK_MOUSE_PS2_TP_INVERT_X
44+
bool "Inverts x on the trackpoint. This is sets the setting directly in the trackpoint firmware and should therefore correctly impact the trackpoint algorithms."
45+
default n
46+
47+
config ZMK_MOUSE_PS2_TP_INVERT_Y
48+
bool "Inverts y on the trackpoint. This is sets the setting directly in the trackpoint firmware and should therefore correctly impact the trackpoint algorithms."
49+
default n
50+
51+
config ZMK_MOUSE_PS2_TP_SWAP_XY
52+
bool "Swaps the x and y axis on the trackpoint. This is sets the swap settingin the trackpoint firmware and should therefore correctly impact the trackpoint algorithms. But this setting is not supported by all trackpoints."
53+
default n
54+
55+
endif # ZMK_MOUSE_PS2

0 commit comments

Comments
 (0)