Skip to content

Commit

Permalink
feat(mouse): Add PS/2 mouse/trackpoint/etc support
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/CMakeLists.txt
  • Loading branch information
infused-kim committed Oct 4, 2023
1 parent aab47ea commit bdb29a0
Show file tree
Hide file tree
Showing 11 changed files with 2,262 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ target_sources_ifdef(CONFIG_ZMK_USB app PRIVATE src/usb_hid.c)
target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/rgb_underglow.c)
target_sources_ifdef(CONFIG_ZMK_BACKLIGHT app PRIVATE src/backlight.c)
target_sources(app PRIVATE src/workqueue.c)

target_sources_ifdef(CONFIG_ZMK_MOUSE_PS2 app PRIVATE src/mouse/mouse_ps2.c)
target_sources_ifdef(CONFIG_ZMK_MOUSE_PS2 app PRIVATE src/behaviors/behavior_mouse_setting.c)

target_sources(app PRIVATE src/main.c)

add_subdirectory(src/display/)
Expand Down
1 change: 1 addition & 0 deletions app/dts/arm/nordic/override.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define NRF_DEFAULT_IRQ_PRIORITY 3
1 change: 1 addition & 0 deletions app/dts/behaviors.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <behaviors/key_repeat.dtsi>
#include <behaviors/backlight.dtsi>
#include <behaviors/macros.dtsi>
#include <behaviors/mouse_setting.dtsi>
#include <behaviors/mouse_key_press.dtsi>
#include <behaviors/mouse_move.dtsi>
#include <behaviors/mouse_scroll.dtsi>
15 changes: 15 additions & 0 deletions app/dts/behaviors/mouse_setting.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2020 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

/ {
behaviors {
mms: behavior_mouse_setting {
compatible = "zmk,behavior-mouse-setting";
label = "MOUSE_SETTING";
#binding-cells = <1>;
};
};
};
6 changes: 6 additions & 0 deletions app/dts/bindings/behaviors/zmk,behavior-mouse-setting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
description: Mouse Setting

compatible: "zmk,behavior-mouse-setting"

include: one_param.yaml

15 changes: 15 additions & 0 deletions app/dts/bindings/zmk,mouse-ps2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
description: PS2 mouse configuration

compatible: "zmk,mouse-ps2"

properties:
ps2-device:
type: phandle
required: true
description: |
The ps2 device the mouse should use.
rst-gpios:
type: phandle-array
required: false
description: GPIO to which the RST pin of the device is connected and on which the Power-On-Reset will be performed.
18 changes: 18 additions & 0 deletions app/include/dt-bindings/zmk/mouse_settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2020 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#pragma once

#define MS_TP_SENSITIVITY_INCR 10
#define MS_TP_SENSITIVITY_DECR 11

#define MS_TP_NEG_INERTIA_INCR 12
#define MS_TP_NEG_INERTIA_DECR 13

#define MS_TP_VALUE6_INCR 14
#define MS_TP_VALUE6_DECR 15

#define MS_TP_PTS_THRESHOLD_INCR 16
#define MS_TP_PTS_THRESHOLD_DECR 17
12 changes: 12 additions & 0 deletions app/include/zmk/mouse_ps2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2021 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

#pragma once

int zmk_mouse_ps2_tp_sensitivity_change(int amount);
int zmk_mouse_ps2_tp_neg_inertia_change(int amount);
int zmk_mouse_ps2_tp_value6_upper_plateau_speed_change(int amount);
int zmk_mouse_ps2_tp_pts_threshold_change(int amount);
86 changes: 86 additions & 0 deletions app/src/behaviors/behavior_mouse_setting.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#define DT_DRV_COMPAT zmk_behavior_mouse_setting

#include <zephyr/device.h>
#include <drivers/behavior.h>
#include <zephyr/logging/log.h>

#include <dt-bindings/zmk/mouse_settings.h>
#include <zmk/mouse_ps2.h>
#include <zmk/mouse.h>

#define INCREMENT_TP_SENSITIVITY 10
#define INCREMENT_TP_NEG_INERTIA 1
#define INCREMENT_TP_VALUE6 5
#define INCREMENT_TP_PTS_THRESHOLD 1

LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event)
{
switch (binding->param1) {

case MS_TP_SENSITIVITY_INCR:
return zmk_mouse_ps2_tp_sensitivity_change(
INCREMENT_TP_SENSITIVITY
);
case MS_TP_SENSITIVITY_DECR:
return zmk_mouse_ps2_tp_sensitivity_change(
-INCREMENT_TP_SENSITIVITY
);

case MS_TP_NEG_INERTIA_INCR:
return zmk_mouse_ps2_tp_neg_inertia_change(
INCREMENT_TP_NEG_INERTIA
);
case MS_TP_NEG_INERTIA_DECR:
return zmk_mouse_ps2_tp_neg_inertia_change(
-INCREMENT_TP_NEG_INERTIA
);

case MS_TP_VALUE6_INCR:
return zmk_mouse_ps2_tp_value6_upper_plateau_speed_change(
INCREMENT_TP_VALUE6
);
case MS_TP_VALUE6_DECR:
return zmk_mouse_ps2_tp_value6_upper_plateau_speed_change(
-INCREMENT_TP_VALUE6
);

case MS_TP_PTS_THRESHOLD_INCR:
return zmk_mouse_ps2_tp_pts_threshold_change(
INCREMENT_TP_PTS_THRESHOLD
);
case MS_TP_PTS_THRESHOLD_DECR:
return zmk_mouse_ps2_tp_pts_threshold_change(
-INCREMENT_TP_PTS_THRESHOLD
);
}

return -ENOTSUP;
}

static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event)
{
return ZMK_BEHAVIOR_OPAQUE;
}

// Initialization Function
static int zmk_behavior_mouse_setting_init(const struct device *dev) {
return 0;
};

static const struct behavior_driver_api
zmk_behavior_mouse_setting_driver_api = {
.binding_pressed = on_keymap_binding_pressed,
.binding_released = on_keymap_binding_released
};

DEVICE_DT_INST_DEFINE(
0,
zmk_behavior_mouse_setting_init, NULL,
NULL, NULL,
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
&zmk_behavior_mouse_setting_driver_api
);
53 changes: 53 additions & 0 deletions app/src/mouse/Kconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) 2021 The ZMK Contributors
# SPDX-License-Identifier: MIT

DT_COMPAT_ZMK_PS2_MOUSE := zmk,mouse-ps2

menuconfig ZMK_MOUSE
bool "Enable ZMK mouse emulation"
default n
Expand Down Expand Up @@ -36,3 +38,54 @@ config ZMK_MOUSE_DEDICATED_THREAD_PRIORITY
endif # ZMK_MOUSE_WORK_QUEUE_DEDICATED

endif

config ZMK_MOUSE_PS2
bool
default $(dt_compat_enabled,$(DT_COMPAT_ZMK_PS2_MOUSE))
depends on (!ZMK_SPLIT || ZMK_SPLIT_ROLE_CENTRAL)
select ZMK_MOUSE
select PS2

if ZMK_MOUSE_PS2

config ZMK_MOUSE_PS2_SAMPLING_RATE
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."
default 100

config ZMK_MOUSE_PS2_ENABLE_CLICKING
bool "Enables clicking events."
default y

config ZMK_MOUSE_PS2_INVERT_X
bool "Invert the mouse movement x axis."
default n

config ZMK_MOUSE_PS2_INVERT_Y
bool "Invert the mouse movement y axis."
default n

config ZMK_MOUSE_PS2_SWAP_XY
bool "Swaps the X and Y axis."
default n

config ZMK_MOUSE_PS2_SCROLL
bool "Enable scroll wheel on mouse devices supporting the Intellimouse extension."
default n

config ZMK_MOUSE_PS2_TP_TAP_TO_SELECT
bool "Enables the ability to left-click by tapping the trackpoint."
default n

config ZMK_MOUSE_PS2_TP_INVERT_X
bool "Inverts x on the trackpoint. This is sets the setting directly in the trackpoint firmware and should therefore correctly impact the trackpoint algorithms."
default n

config ZMK_MOUSE_PS2_TP_INVERT_Y
bool "Inverts y on the trackpoint. This is sets the setting directly in the trackpoint firmware and should therefore correctly impact the trackpoint algorithms."
default n

config ZMK_MOUSE_PS2_TP_SWAP_XY
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."
default n

endif # ZMK_MOUSE_PS2
Loading

0 comments on commit bdb29a0

Please sign in to comment.