mirror of
https://github.com/zmkfirmware/zmk.git
synced 2026-03-20 04:55:20 -05:00
* 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>
62 lines
2.1 KiB
C
62 lines
2.1 KiB
C
/*
|
|
* 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/hid.h>
|
|
#include <zephyr/input/input.h>
|
|
#include <zephyr/dt-bindings/input/input-event-codes.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 void process_key_state(const struct device *dev, int32_t val, bool pressed) {
|
|
for (int i = 0; i < ZMK_HID_MOUSE_NUM_BUTTONS; i++) {
|
|
if (val & BIT(i)) {
|
|
WRITE_BIT(val, i, 0);
|
|
input_report_key(dev, INPUT_BTN_0 + i, pressed ? 1 : 0, val == 0, K_FOREVER);
|
|
}
|
|
}
|
|
}
|
|
|
|
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);
|
|
|
|
process_key_state(zmk_behavior_get_binding(binding->behavior_dev), binding->param1, true);
|
|
|
|
return 0;
|
|
}
|
|
|
|
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);
|
|
|
|
process_key_state(zmk_behavior_get_binding(binding->behavior_dev), binding->param1, false);
|
|
|
|
return 0;
|
|
}
|
|
|
|
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) \
|
|
BEHAVIOR_DT_INST_DEFINE(n, behavior_mouse_key_press_init, NULL, NULL, NULL, POST_KERNEL, \
|
|
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) */
|