1
+ /*
2
+ * Copyright (c) 2024 The ZMK Contributors
3
+ *
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+
7
+ #define DT_DRV_COMPAT zmk_input_split
8
+
9
+ #include <zephyr/kernel.h>
10
+ #include <zephyr/device.h>
11
+ #include <zephyr/input/input.h>
12
+ #include <drivers/input_processor.h>
13
+
14
+ #include <zephyr/logging/log.h>
15
+
16
+ LOG_MODULE_DECLARE (zmk , CONFIG_ZMK_LOG_LEVEL );
17
+
18
+ #if IS_ENABLED (CONFIG_ZMK_SPLIT_ROLE_CENTRAL )
19
+
20
+ struct zis_entry {
21
+ uint8_t reg ;
22
+ const struct device * dev ;
23
+ };
24
+
25
+ #define ZIS_ENTRY (n ) {.reg = DT_INST_REG_ADDR(n), .dev = DEVICE_DT_GET(DT_DRV_INST(n))},
26
+
27
+ static const struct zis_entry proxy_inputs [] = {DT_INST_FOREACH_STATUS_OKAY (ZIS_ENTRY )};
28
+
29
+ int zmk_input_split_report_peripheral_event (uint8_t reg , uint8_t type , uint16_t code , int32_t value ,
30
+ bool sync ) {
31
+ LOG_DBG ("Got peripheral event for %d!" , reg );
32
+ for (size_t i = 0 ; i < ARRAY_SIZE (proxy_inputs ); i ++ ) {
33
+ if (reg == proxy_inputs [i ].reg ) {
34
+ return input_report (proxy_inputs [i ].dev , type , code , value , sync , K_NO_WAIT );
35
+ }
36
+ }
37
+
38
+ return - ENODEV ;
39
+ }
40
+
41
+ #define ZIS_INST (n ) \
42
+ DEVICE_DT_INST_DEFINE(n, NULL, NULL, NULL, NULL, POST_KERNEL, \
43
+ CONFIG_ZMK_INPUT_SPLIT_INIT_PRIORITY, NULL);
44
+
45
+ #else
46
+
47
+ #include <zmk/split/bluetooth/service.h>
48
+
49
+ #define ZIS_INST (n ) \
50
+ static const struct zmk_input_processor_entry processors_##n[] = \
51
+ COND_CODE_1(DT_INST_NODE_HAS_PROP(n, input_processors), \
52
+ ({LISTIFY(DT_INST_PROP_LEN(n, input_processors), \
53
+ ZMK_INPUT_PROCESSOR_ENTRY_AT_IDX, (, ), DT_DRV_INST(n))}), \
54
+ ({})); \
55
+ BUILD_ASSERT(DT_INST_NODE_HAS_PROP(n, device), \
56
+ "Peripheral input splits need an `input` property set"); \
57
+ void split_input_handler_##n(struct input_event *evt) { \
58
+ for (size_t i = 0; i < ARRAY_SIZE(processors_##n); i++) { \
59
+ zmk_input_processor_handle_event(processors_##n[i].dev, evt, processors_##n[i].param1, \
60
+ processors_##n[i].param2, NULL); \
61
+ } \
62
+ zmk_split_bt_report_input(DT_INST_REG_ADDR(n), evt->type, evt->code, evt->value, \
63
+ evt->sync); \
64
+ } \
65
+ INPUT_CALLBACK_DEFINE(DEVICE_DT_GET(DT_INST_PHANDLE(n, device)), split_input_handler_##n);
66
+
67
+ #endif
68
+
69
+ DT_INST_FOREACH_STATUS_OKAY (ZIS_INST )
0 commit comments