forked from zmkfirmware/zmk
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. Co-authored-by: Alexander Krikun <[email protected]> Co-authored-by: Robert U <[email protected]> Co-authored-by: Shawn Meier <[email protected]>
- Loading branch information
1 parent
6b4d591
commit e90e11d
Showing
69 changed files
with
2,157 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ mmv: mouse_move { | ||
compatible = "zmk,behavior-input-two-axis"; | ||
#binding-cells = <1>; | ||
trigger-period-ms = <3>; | ||
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>; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
/* | ||
* 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>; | ||
trigger-period-ms = <3>; | ||
x-input-code = <INPUT_REL_HWHEEL>; | ||
y-input-code = <INPUT_REL_WHEEL>; | ||
time-to-max-speed-ms = <300>; | ||
acceleration-exponent = <1>; | ||
}; | ||
}; | ||
|
||
msc_input_listener: msc_input_listener { | ||
compatible = "zmk,input-listener"; | ||
device = <&msc>; | ||
}; | ||
}; |
25 changes: 25 additions & 0 deletions
25
app/dts/bindings/behaviors/zmk,behavior-input-two-axis.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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: 5 | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
16 changes: 16 additions & 0 deletions
16
app/dts/bindings/input_processors/zmk,input-processor-code-mapper.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
16 changes: 16 additions & 0 deletions
16
app/dts/bindings/input_processors/zmk,input-processor-scaler.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
8 changes: 8 additions & 0 deletions
8
app/dts/bindings/input_processors/zmk,input-processor-temp-layer.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# 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 |
18 changes: 18 additions & 0 deletions
18
app/dts/bindings/input_processors/zmk,input-processor-transform.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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 | ||
inherit: | ||
type: boolean | ||
input-processors: | ||
type: phandle-array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) 2020 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <zephyr/types.h> | ||
#include <stddef.h> | ||
#include <zephyr/sys/util.h> | ||
#include <string.h> | ||
#include <zephyr/device.h> | ||
#include <zephyr/input/input.h> | ||
|
||
struct zmk_input_processor_state { | ||
float *remainder; | ||
}; | ||
|
||
// TODO: Need the ability to store remainders? Some data passed in? | ||
typedef int (*zmk_input_processor_handle_event_callback_t)(const struct device *dev, | ||
struct input_event *event, | ||
uint32_t param1, uint32_t param2, | ||
struct zmk_input_processor_state *state); | ||
|
||
__subsystem struct zmk_input_processor_driver_api { | ||
zmk_input_processor_handle_event_callback_t handle_event; | ||
}; | ||
|
||
__syscall int zmk_input_processor_handle_event(const struct device *dev, struct input_event *event, | ||
uint32_t param1, uint32_t param2, | ||
struct zmk_input_processor_state *state); | ||
|
||
static inline int z_impl_zmk_input_processor_handle_event(const struct device *dev, | ||
struct input_event *event, | ||
uint32_t param1, uint32_t param2, | ||
struct zmk_input_processor_state *state) { | ||
const struct zmk_input_processor_driver_api *api = | ||
(const struct zmk_input_processor_driver_api *)dev->api; | ||
|
||
if (api->handle_event == NULL) { | ||
return -ENOTSUP; | ||
} | ||
|
||
return api->handle_event(dev, event, param1, param2, state); | ||
} | ||
|
||
#include <syscalls/input_processor.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright (c) 2024 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
#define ZMK_INPUT_EXPLICIT_CODE(type, code) ((type << 16) & code) | ||
|
||
#define ZMK_INPUT_EXPLICIT_CODE_TYPE(val) ((val >> 16) & 0xFF) | ||
#define ZMK_INPUT_EXPLICIT_CODE_CODE(val) (val & 0xFFFF) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <zephyr/dt-bindings/dt-util.h> | ||
|
||
#define INPUT_TRANSFORM_XY_SWAP BIT(0) | ||
#define INPUT_TRANSFORM_X_INVERT BIT(1) | ||
#define INPUT_TRANSFORM_Y_INVERT BIT(2) |
Oops, something went wrong.