forked from kofal.net/zmk
feat(mouse): Add mouse move and scroll support (#2477)
* 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>
This commit is contained in:
75
app/src/pointing/input_processor_scaler.c
Normal file
75
app/src/pointing/input_processor_scaler.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2024 The ZMK Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#define DT_DRV_COMPAT zmk_input_processor_scaler
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <drivers/input_processor.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
||||
|
||||
struct scaler_config {
|
||||
uint8_t type;
|
||||
size_t codes_len;
|
||||
uint16_t codes[];
|
||||
};
|
||||
|
||||
static int scale_val(struct input_event *event, uint32_t mul, uint32_t div,
|
||||
struct zmk_input_processor_state *state) {
|
||||
int16_t value_mul = event->value * (int16_t)mul;
|
||||
|
||||
if (state && state->remainder) {
|
||||
value_mul += *state->remainder;
|
||||
}
|
||||
|
||||
int16_t scaled = value_mul / (int16_t)div;
|
||||
|
||||
if (state && state->remainder) {
|
||||
*state->remainder = value_mul - (scaled * (int16_t)div);
|
||||
}
|
||||
|
||||
LOG_DBG("scaled %d with %d/%d to %d with remainder %d", event->value, mul, div, scaled,
|
||||
(state && state->remainder) ? *state->remainder : 0);
|
||||
|
||||
event->value = scaled;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int scaler_handle_event(const struct device *dev, struct input_event *event, uint32_t param1,
|
||||
uint32_t param2, struct zmk_input_processor_state *state) {
|
||||
const struct scaler_config *cfg = dev->config;
|
||||
|
||||
if (event->type != cfg->type) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < cfg->codes_len; i++) {
|
||||
if (cfg->codes[i] == event->code) {
|
||||
return scale_val(event, param1, param2, state);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct zmk_input_processor_driver_api scaler_driver_api = {
|
||||
.handle_event = scaler_handle_event,
|
||||
};
|
||||
|
||||
#define SCALER_INST(n) \
|
||||
static const struct scaler_config scaler_config_##n = { \
|
||||
.type = DT_INST_PROP_OR(n, type, INPUT_EV_REL), \
|
||||
.codes_len = DT_INST_PROP_LEN(n, codes), \
|
||||
.codes = DT_INST_PROP(n, codes), \
|
||||
}; \
|
||||
DEVICE_DT_INST_DEFINE(n, NULL, NULL, NULL, &scaler_config_##n, POST_KERNEL, \
|
||||
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &scaler_driver_api);
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(SCALER_INST)
|
||||
Reference in New Issue
Block a user