-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae1381d
commit 40b4401
Showing
15 changed files
with
182 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright (c) 2025 The ZMK Contributors | ||
# SPDX-License-Identifier: MIT | ||
|
||
description: Array of Behaviors | ||
|
||
compatible: "zmk,behavior-array" | ||
|
||
include: one_param.yaml | ||
|
||
properties: | ||
bindings: | ||
type: phandle-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,79 @@ | ||
/* | ||
* Copyright (c) 2025 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#define DT_DRV_COMPAT zmk_behavior_array | ||
|
||
#include <zephyr/device.h> | ||
#include <drivers/behavior.h> | ||
#include <zephyr/logging/log.h> | ||
#include <zmk/keymap.h> | ||
|
||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); | ||
|
||
#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) | ||
|
||
struct behavior_array_config { | ||
size_t behavior_count; | ||
struct zmk_behavior_binding *behaviors; | ||
}; | ||
|
||
static int on_array_binding_pressed(struct zmk_behavior_binding *binding, | ||
struct zmk_behavior_binding_event event) { | ||
const struct device *dev = zmk_behavior_get_binding(binding->behavior_dev); | ||
const struct behavior_array_config *cfg = dev->config; | ||
int index = binding->param1; | ||
|
||
if (index >= cfg->behavior_count || index < 0) { | ||
LOG_ERR("Trying to trigger an index beyond the size of the behavior array."); | ||
return -ENOTSUP; | ||
} | ||
return zmk_behavior_invoke_binding((struct zmk_behavior_binding *)&cfg->behaviors[index], event, | ||
true); | ||
} | ||
|
||
static int on_array_binding_released(struct zmk_behavior_binding *binding, | ||
struct zmk_behavior_binding_event event) { | ||
const struct device *dev = zmk_behavior_get_binding(binding->behavior_dev); | ||
const struct behavior_array_config *cfg = dev->config; | ||
int index = binding->param1; | ||
|
||
if (index >= cfg->behavior_count || index < 0) { | ||
LOG_ERR("Trying to trigger an index beyond the size of the behavior array."); | ||
return -ENOTSUP; | ||
} | ||
return zmk_behavior_invoke_binding((struct zmk_behavior_binding *)&cfg->behaviors[index], event, | ||
false); | ||
} | ||
|
||
static const struct behavior_driver_api behavior_array_driver_api = { | ||
.binding_pressed = on_array_binding_pressed, | ||
.binding_released = on_array_binding_released, | ||
#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) | ||
.get_parameter_metadata = zmk_behavior_get_empty_param_metadata, | ||
#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) | ||
}; | ||
|
||
static int behavior_array_init(const struct device *dev) { return 0; } | ||
|
||
#define _TRANSFORM_ENTRY(idx, node) ZMK_KEYMAP_EXTRACT_BINDING(idx, node) | ||
|
||
#define TRANSFORMED_BINDINGS(node) \ | ||
{LISTIFY(DT_INST_PROP_LEN(node, bindings), _TRANSFORM_ENTRY, (, ), DT_DRV_INST(node))} | ||
|
||
#define ARR_INST(n) \ | ||
static struct zmk_behavior_binding \ | ||
behavior_array_config_##n##_bindings[DT_INST_PROP_LEN(n, bindings)] = \ | ||
TRANSFORMED_BINDINGS(n); \ | ||
static struct behavior_array_config behavior_array_config_##n = { \ | ||
.behaviors = behavior_array_config_##n##_bindings, \ | ||
.behavior_count = DT_INST_PROP_LEN(n, bindings)}; \ | ||
BEHAVIOR_DT_INST_DEFINE(n, behavior_array_init, NULL, NULL, &behavior_array_config_##n, \ | ||
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ | ||
&behavior_array_driver_api); | ||
|
||
DT_INST_FOREACH_STATUS_OKAY(ARR_INST) | ||
|
||
#endif |
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 @@ | ||
s/.*hid_listener_keycode_//p |
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,4 @@ | ||
pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 | ||
released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 | ||
pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00 | ||
released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00 |
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 @@ | ||
#include "../behavior_keymap.dtsi" | ||
|
||
&kscan { | ||
events = < | ||
ZMK_MOCK_PRESS(0,0,10) | ||
ZMK_MOCK_RELEASE(0,0,10) | ||
ZMK_MOCK_PRESS(0,1,10) | ||
ZMK_MOCK_RELEASE(0,1,10) | ||
>; | ||
}; |
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 @@ | ||
s/.*hid_listener_keycode_//p |
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,4 @@ | ||
pressed: usage_page 0x07 keycode 0x29 implicit_mods 0x00 explicit_mods 0x00 | ||
released: usage_page 0x07 keycode 0x29 implicit_mods 0x00 explicit_mods 0x00 | ||
pressed: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00 | ||
released: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00 |
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 @@ | ||
#include "../behavior_keymap.dtsi" | ||
|
||
&kscan { | ||
events = < | ||
ZMK_MOCK_PRESS(1,0,10) | ||
ZMK_MOCK_RELEASE(1,0,10) | ||
ZMK_MOCK_PRESS(1,0,500) | ||
ZMK_MOCK_RELEASE(1,0,10) | ||
>; | ||
}; |
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 @@ | ||
s/.*hid_listener_keycode_//p |
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,4 @@ | ||
pressed: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 | ||
pressed: usage_page 0x07 keycode 0x35 implicit_mods 0x00 explicit_mods 0x00 | ||
released: usage_page 0x07 keycode 0x35 implicit_mods 0x00 explicit_mods 0x00 | ||
released: usage_page 0x07 keycode 0xE1 implicit_mods 0x00 explicit_mods 0x00 |
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 @@ | ||
#include "../behavior_keymap.dtsi" | ||
|
||
&kscan { | ||
events = < | ||
ZMK_MOCK_PRESS(0,0,10) | ||
ZMK_MOCK_PRESS(1,1,10) | ||
ZMK_MOCK_RELEASE(1,1,10) | ||
ZMK_MOCK_RELEASE(0,0,10) | ||
>; | ||
}; |
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,32 @@ | ||
#include <dt-bindings/zmk/keys.h> | ||
#include <behaviors.dtsi> | ||
#include <dt-bindings/zmk/kscan_mock.h> | ||
|
||
/ { | ||
behaviors { | ||
arr: behavior_array { | ||
compatible = "zmk,behavior-array"; | ||
#binding-cells = <1>; | ||
bindings = <&mt LEFT_SHIFT A &kp B &kp C &gresc>; | ||
}; | ||
|
||
ht_bal: behavior_hold_tap_balanced { | ||
compatible = "zmk,behavior-hold-tap"; | ||
#binding-cells = <2>; | ||
flavor = "balanced"; | ||
tapping-term-ms = <200>; | ||
bindings = <&arr>, <&arr>; | ||
}; | ||
}; | ||
|
||
keymap { | ||
compatible = "zmk,keymap"; | ||
|
||
default_layer { | ||
bindings = < | ||
&arr 0 &arr 1 | ||
&ht_bal 2 3 &arr 3 | ||
>; | ||
}; | ||
}; | ||
}; |
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