-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mouse): Initial mouse keys support.
* Add HID report/descriptor for a new report with mouse buttons, and x/y/wheel deltas. * New mouse key press behavior for press/release of mouse keys. * Add constants for HID main item values (e.g. data/array/absolute) * Define and use constants for our HID report IDs.
- Loading branch information
1 parent
8776911
commit d7d9eed
Showing
27 changed files
with
618 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/ { | ||
behaviors { | ||
/omit-if-no-ref/ mkp: behavior_mouse_key_press { | ||
compatible = "zmk,behavior-mouse-key-press"; | ||
label = "MOUSE_KEY_PRESS"; | ||
#binding-cells = <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,5 @@ | ||
description: Mouse key press/release behavior | ||
|
||
compatible: "zmk,behavior-mouse-key-press" | ||
|
||
include: one_param.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
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,24 @@ | ||
/* | ||
* Copyright (c) 2020 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
#pragma once | ||
|
||
#include <zephyr/dt-bindings/dt-util.h> | ||
|
||
/* Mouse press behavior */ | ||
/* Left click */ | ||
#define MB1 BIT(0) | ||
#define LCLK (MB1) | ||
|
||
/* Right click */ | ||
#define MB2 BIT(1) | ||
#define RCLK (MB2) | ||
|
||
/* Middle click */ | ||
#define MB3 BIT(2) | ||
#define MCLK (MB3) | ||
|
||
#define MB4 BIT(3) | ||
#define MB5 BIT(4) |
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,26 @@ | ||
|
||
/* | ||
* Copyright (c) 2020 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <zmk/hid.h> | ||
#include <zmk/event_manager.h> | ||
#include <zmk/mouse.h> | ||
|
||
struct zmk_mouse_button_state_changed { | ||
zmk_mouse_button_t buttons; | ||
bool state; | ||
int64_t timestamp; | ||
}; | ||
|
||
ZMK_EVENT_DECLARE(zmk_mouse_button_state_changed); | ||
|
||
static inline struct zmk_mouse_button_state_changed_event * | ||
zmk_mouse_button_state_changed_from_encoded(uint32_t encoded, bool pressed, int64_t timestamp) { | ||
return new_zmk_mouse_button_state_changed((struct zmk_mouse_button_state_changed){ | ||
.buttons = ZMK_HID_USAGE_ID(encoded), .state = pressed, .timestamp = timestamp}); | ||
} |
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,12 @@ | ||
/* | ||
* Copyright (c) 2021 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <dt-bindings/zmk/mouse.h> | ||
|
||
typedef uint8_t zmk_mouse_button_flags_t; | ||
typedef uint16_t zmk_mouse_button_t; |
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,48 @@ | ||
/* | ||
* Copyright (c) 2021 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#define DT_DRV_COMPAT zmk_behavior_mouse_key_press | ||
|
||
#include <zephyr/device.h> | ||
#include <drivers/behavior.h> | ||
#include <zephyr/logging/log.h> | ||
|
||
#include <zmk/behavior.h> | ||
#include <zmk/event_manager.h> | ||
#include <zmk/events/mouse_button_state_changed.h> | ||
|
||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); | ||
|
||
#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) | ||
|
||
static int behavior_mouse_key_press_init(const struct device *dev) { return 0; }; | ||
|
||
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, | ||
struct zmk_behavior_binding_event event) { | ||
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1); | ||
|
||
return ZMK_EVENT_RAISE( | ||
zmk_mouse_button_state_changed_from_encoded(binding->param1, true, event.timestamp)); | ||
} | ||
|
||
static int on_keymap_binding_released(struct zmk_behavior_binding *binding, | ||
struct zmk_behavior_binding_event event) { | ||
LOG_DBG("position %d keycode 0x%02X", event.position, binding->param1); | ||
return ZMK_EVENT_RAISE( | ||
zmk_mouse_button_state_changed_from_encoded(binding->param1, false, event.timestamp)); | ||
} | ||
|
||
static const struct behavior_driver_api behavior_mouse_key_press_driver_api = { | ||
.binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released}; | ||
|
||
#define MKP_INST(n) \ | ||
DEVICE_DT_INST_DEFINE(n, behavior_mouse_key_press_init, NULL, NULL, NULL, APPLICATION, \ | ||
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ | ||
&behavior_mouse_key_press_driver_api); | ||
|
||
DT_INST_FOREACH_STATUS_OKAY(MKP_INST) | ||
|
||
#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */ |
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) 2020 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <zmk/events/mouse_button_state_changed.h> | ||
|
||
ZMK_EVENT_IMPL(zmk_mouse_button_state_changed); |
Oops, something went wrong.