Browse Source
* Fine grainted press/release/tap actions. * TIming between actions can be controlled. * Processed async, to avoid blocking.xmkb
Peter Johanson
3 years ago
committed by
Pete Johanson
36 changed files with 732 additions and 0 deletions
@ -0,0 +1,54 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2022 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#define ZMK_MACRO_STRINGIFY(x) #x |
||||||
|
#define ZMK_MACRO(name,...) \ |
||||||
|
name: name { \ |
||||||
|
label = ZMK_MACRO_STRINGIFY(ZM_ ## name); \ |
||||||
|
compatible = "zmk,behavior-macro"; \ |
||||||
|
#binding-cells = <0>; \ |
||||||
|
__VA_ARGS__ \ |
||||||
|
}; |
||||||
|
|
||||||
|
/ { |
||||||
|
behaviors { |
||||||
|
macro_tap: macro_control_mode_tap { |
||||||
|
compatible = "zmk,macro-control-mode-tap"; |
||||||
|
label = "MAC_TAP"; |
||||||
|
#binding-cells = <0>; |
||||||
|
}; |
||||||
|
|
||||||
|
macro_press: macro_control_mode_press { |
||||||
|
compatible = "zmk,macro-control-mode-press"; |
||||||
|
label = "MAC_PRESS"; |
||||||
|
#binding-cells = <0>; |
||||||
|
}; |
||||||
|
|
||||||
|
macro_release: macro_control_mode_release { |
||||||
|
compatible = "zmk,macro-control-mode-release"; |
||||||
|
label = "MAC_REL"; |
||||||
|
#binding-cells = <0>; |
||||||
|
}; |
||||||
|
|
||||||
|
macro_tap_time: macro_control_tap_time { |
||||||
|
compatible = "zmk,macro-control-tap-time"; |
||||||
|
label = "MAC_TAP_TIME"; |
||||||
|
#binding-cells = <1>; |
||||||
|
}; |
||||||
|
|
||||||
|
macro_wait_time: macro_control_wait_time { |
||||||
|
compatible = "zmk,macro-control-wait-time"; |
||||||
|
label = "MAC_WAIT_TIME"; |
||||||
|
#binding-cells = <1>; |
||||||
|
}; |
||||||
|
|
||||||
|
macro_pause_for_release: macro_pause_for_release { |
||||||
|
compatible = "zmk,macro-pause-for-release"; |
||||||
|
label = "MAC_WAIT_REL"; |
||||||
|
#binding-cells = <0>; |
||||||
|
}; |
||||||
|
}; |
||||||
|
}; |
@ -0,0 +1,21 @@ |
|||||||
|
# Copyright (c) 2022 The ZMK Contributors |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: Macro Behavior |
||||||
|
|
||||||
|
compatible: "zmk,behavior-macro" |
||||||
|
|
||||||
|
include: zero_param.yaml |
||||||
|
|
||||||
|
properties: |
||||||
|
bindings: |
||||||
|
type: phandle-array |
||||||
|
required: true |
||||||
|
wait-ms: |
||||||
|
type: int |
||||||
|
default: 100 |
||||||
|
description: The default time to wait (in milliseconds) before triggering the next behavior in the macro bindings list. |
||||||
|
tap-ms: |
||||||
|
type: int |
||||||
|
default: 100 |
||||||
|
description: The default time to wait (in milliseconds) between the press and release events on a tapped macro behavior binding |
@ -0,0 +1,8 @@ |
|||||||
|
# Copyright (c) 2022 The ZMK Contributors |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: Set Macro To Press Mode |
||||||
|
|
||||||
|
compatible: "zmk,macro-control-mode-press" |
||||||
|
|
||||||
|
include: zero_param.yaml |
@ -0,0 +1,8 @@ |
|||||||
|
# Copyright (c) 2022 The ZMK Contributors |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: Set Macro To Release Mode |
||||||
|
|
||||||
|
compatible: "zmk,macro-control-mode-release" |
||||||
|
|
||||||
|
include: zero_param.yaml |
@ -0,0 +1,8 @@ |
|||||||
|
# Copyright (c) 2022 The ZMK Contributors |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: Set Macro To Tap Mode |
||||||
|
|
||||||
|
compatible: "zmk,macro-control-mode-tap" |
||||||
|
|
||||||
|
include: zero_param.yaml |
@ -0,0 +1,8 @@ |
|||||||
|
# Copyright (c) 2022 The ZMK Contributors |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: Set Macro Tap Duration |
||||||
|
|
||||||
|
compatible: "zmk,macro-control-tap-time" |
||||||
|
|
||||||
|
include: one_param.yaml |
@ -0,0 +1,8 @@ |
|||||||
|
# Copyright (c) 2022 The ZMK Contributors |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: Set Macro Wait Duration |
||||||
|
|
||||||
|
compatible: "zmk,macro-control-wait-time" |
||||||
|
|
||||||
|
include: one_param.yaml |
@ -0,0 +1,8 @@ |
|||||||
|
# Copyright (c) 2022 The ZMK Contributors |
||||||
|
# SPDX-License-Identifier: MIT |
||||||
|
|
||||||
|
description: Macro Pause Until Release Marker |
||||||
|
|
||||||
|
compatible: "zmk,macro-pause-for-release" |
||||||
|
|
||||||
|
include: zero_param.yaml |
@ -0,0 +1,14 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <kernel.h> |
||||||
|
#include <stdint.h> |
||||||
|
#include <zmk/behavior.h> |
||||||
|
|
||||||
|
int zmk_behavior_queue_add(uint32_t position, const struct zmk_behavior_binding behavior, |
||||||
|
bool press, uint32_t wait); |
@ -0,0 +1,66 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <zmk/behavior_queue.h> |
||||||
|
|
||||||
|
#include <kernel.h> |
||||||
|
#include <logging/log.h> |
||||||
|
#include <drivers/behavior.h> |
||||||
|
|
||||||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
||||||
|
|
||||||
|
struct q_item { |
||||||
|
uint32_t position; |
||||||
|
struct zmk_behavior_binding binding; |
||||||
|
bool press : 1; |
||||||
|
uint32_t wait : 31; |
||||||
|
}; |
||||||
|
|
||||||
|
K_MSGQ_DEFINE(zmk_behavior_queue_msgq, sizeof(struct q_item), CONFIG_ZMK_BEHAVIORS_QUEUE_SIZE, 4); |
||||||
|
|
||||||
|
static void behavior_queue_process_next(struct k_work *work); |
||||||
|
static K_DELAYED_WORK_DEFINE(queue_work, behavior_queue_process_next); |
||||||
|
|
||||||
|
static void behavior_queue_process_next(struct k_work *work) { |
||||||
|
struct q_item item = {.wait = 0}; |
||||||
|
|
||||||
|
while (k_msgq_get(&zmk_behavior_queue_msgq, &item, K_NO_WAIT) == 0) { |
||||||
|
LOG_DBG("Invoking %s: 0x%02x 0x%02x", log_strdup(item.binding.behavior_dev), |
||||||
|
item.binding.param1, item.binding.param2); |
||||||
|
|
||||||
|
struct zmk_behavior_binding_event event = {.position = item.position, |
||||||
|
.timestamp = k_uptime_get()}; |
||||||
|
|
||||||
|
if (item.press) { |
||||||
|
behavior_keymap_binding_pressed(&item.binding, event); |
||||||
|
} else { |
||||||
|
behavior_keymap_binding_released(&item.binding, event); |
||||||
|
} |
||||||
|
|
||||||
|
LOG_DBG("Processing next queued behavior in %dms", item.wait); |
||||||
|
|
||||||
|
if (item.wait > 0) { |
||||||
|
k_delayed_work_submit(&queue_work, K_MSEC(item.wait)); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
int zmk_behavior_queue_add(uint32_t position, const struct zmk_behavior_binding binding, bool press, |
||||||
|
uint32_t wait) { |
||||||
|
struct q_item item = {.press = press, .binding = binding, .wait = wait}; |
||||||
|
|
||||||
|
const int ret = k_msgq_put(&zmk_behavior_queue_msgq, &item, K_NO_WAIT); |
||||||
|
if (ret < 0) { |
||||||
|
return ret; |
||||||
|
} |
||||||
|
|
||||||
|
if (!k_delayed_work_pending(&queue_work)) { |
||||||
|
behavior_queue_process_next(&queue_work.work); |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
@ -0,0 +1,187 @@ |
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#define DT_DRV_COMPAT zmk_behavior_macro |
||||||
|
|
||||||
|
#include <device.h> |
||||||
|
#include <drivers/behavior.h> |
||||||
|
#include <logging/log.h> |
||||||
|
#include <zmk/behavior.h> |
||||||
|
#include <zmk/behavior_queue.h> |
||||||
|
#include <zmk/keymap.h> |
||||||
|
|
||||||
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); |
||||||
|
|
||||||
|
#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) |
||||||
|
|
||||||
|
enum behavior_macro_mode { |
||||||
|
MACRO_MODE_TAP, |
||||||
|
MACRO_MODE_PRESS, |
||||||
|
MACRO_MODE_RELEASE, |
||||||
|
}; |
||||||
|
|
||||||
|
struct behavior_macro_trigger_state { |
||||||
|
uint32_t wait_ms; |
||||||
|
uint32_t tap_ms; |
||||||
|
enum behavior_macro_mode mode; |
||||||
|
uint16_t start_index; |
||||||
|
uint16_t count; |
||||||
|
}; |
||||||
|
|
||||||
|
struct behavior_macro_state { |
||||||
|
struct behavior_macro_trigger_state release_state; |
||||||
|
|
||||||
|
uint32_t press_bindings_count; |
||||||
|
}; |
||||||
|
|
||||||
|
struct behavior_macro_config { |
||||||
|
uint32_t default_wait_ms; |
||||||
|
uint32_t default_tap_ms; |
||||||
|
uint32_t count; |
||||||
|
struct zmk_behavior_binding bindings[]; |
||||||
|
}; |
||||||
|
|
||||||
|
#define TAP_MODE DT_LABEL(DT_INST(0, zmk_macro_control_mode_tap)) |
||||||
|
#define PRESS_MODE DT_LABEL(DT_INST(0, zmk_macro_control_mode_press)) |
||||||
|
#define REL_MODE DT_LABEL(DT_INST(0, zmk_macro_control_mode_release)) |
||||||
|
|
||||||
|
#define TAP_TIME DT_LABEL(DT_INST(0, zmk_macro_control_tap_time)) |
||||||
|
#define WAIT_TIME DT_LABEL(DT_INST(0, zmk_macro_control_wait_time)) |
||||||
|
#define WAIT_REL DT_LABEL(DT_INST(0, zmk_macro_pause_for_release)) |
||||||
|
|
||||||
|
#define ZM_IS_NODE_MATCH(a, b) (strcmp(a, b) == 0) |
||||||
|
#define IS_TAP_MODE(dev) ZM_IS_NODE_MATCH(dev, TAP_MODE) |
||||||
|
#define IS_PRESS_MODE(dev) ZM_IS_NODE_MATCH(dev, PRESS_MODE) |
||||||
|
#define IS_RELEASE_MODE(dev) ZM_IS_NODE_MATCH(dev, REL_MODE) |
||||||
|
|
||||||
|
#define IS_TAP_TIME(dev) ZM_IS_NODE_MATCH(dev, TAP_TIME) |
||||||
|
#define IS_WAIT_TIME(dev) ZM_IS_NODE_MATCH(dev, WAIT_TIME) |
||||||
|
#define IS_PAUSE(dev) ZM_IS_NODE_MATCH(dev, WAIT_REL) |
||||||
|
|
||||||
|
static bool handle_control_binding(struct behavior_macro_trigger_state *state, |
||||||
|
const struct zmk_behavior_binding *binding) { |
||||||
|
if (IS_TAP_MODE(binding->behavior_dev)) { |
||||||
|
state->mode = MACRO_MODE_TAP; |
||||||
|
LOG_DBG("macro mode set: tap"); |
||||||
|
} else if (IS_PRESS_MODE(binding->behavior_dev)) { |
||||||
|
state->mode = MACRO_MODE_PRESS; |
||||||
|
LOG_DBG("macro mode set: press"); |
||||||
|
} else if (IS_RELEASE_MODE(binding->behavior_dev)) { |
||||||
|
state->mode = MACRO_MODE_RELEASE; |
||||||
|
LOG_DBG("macro mode set: release"); |
||||||
|
} else if (IS_TAP_TIME(binding->behavior_dev)) { |
||||||
|
state->tap_ms = binding->param1; |
||||||
|
LOG_DBG("macro tap time set: %d", state->tap_ms); |
||||||
|
} else if (IS_WAIT_TIME(binding->behavior_dev)) { |
||||||
|
state->wait_ms = binding->param1; |
||||||
|
LOG_DBG("macro wait time set: %d", state->wait_ms); |
||||||
|
} else { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
static int behavior_macro_init(const struct device *dev) { |
||||||
|
const struct behavior_macro_config *cfg = dev->config; |
||||||
|
struct behavior_macro_state *state = dev->data; |
||||||
|
state->press_bindings_count = cfg->count; |
||||||
|
state->release_state.start_index = cfg->count; |
||||||
|
state->release_state.count = 0; |
||||||
|
|
||||||
|
LOG_DBG("Precalculate initial release state:"); |
||||||
|
for (int i = 0; i < cfg->count; i++) { |
||||||
|
if (handle_control_binding(&state->release_state, &cfg->bindings[i])) { |
||||||
|
// Updated state used for initial state on release.
|
||||||
|
} else if (IS_PAUSE(cfg->bindings[i].behavior_dev)) { |
||||||
|
state->release_state.start_index = i + 1; |
||||||
|
state->release_state.count = cfg->count - state->release_state.start_index; |
||||||
|
state->press_bindings_count = i; |
||||||
|
LOG_DBG("Release will resume at %d", state->release_state.start_index); |
||||||
|
break; |
||||||
|
} else { |
||||||
|
// Ignore regular invokable bindings
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
}; |
||||||
|
|
||||||
|
static void queue_macro(uint32_t position, const struct zmk_behavior_binding bindings[], |
||||||
|
struct behavior_macro_trigger_state state) { |
||||||
|
LOG_DBG("Iterating macro bindings - starting: %d, count: %d", state.start_index, state.count); |
||||||
|
for (int i = state.start_index; i < state.start_index + state.count; i++) { |
||||||
|
if (!handle_control_binding(&state, &bindings[i])) { |
||||||
|
switch (state.mode) { |
||||||
|
case MACRO_MODE_TAP: |
||||||
|
zmk_behavior_queue_add(position, bindings[i], true, state.tap_ms); |
||||||
|
zmk_behavior_queue_add(position, bindings[i], false, state.wait_ms); |
||||||
|
break; |
||||||
|
case MACRO_MODE_PRESS: |
||||||
|
zmk_behavior_queue_add(position, bindings[i], true, state.wait_ms); |
||||||
|
break; |
||||||
|
case MACRO_MODE_RELEASE: |
||||||
|
zmk_behavior_queue_add(position, bindings[i], false, state.wait_ms); |
||||||
|
break; |
||||||
|
default: |
||||||
|
LOG_ERR("Unknown macro mode: %d", state.mode); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static int on_macro_binding_pressed(struct zmk_behavior_binding *binding, |
||||||
|
struct zmk_behavior_binding_event event) { |
||||||
|
const struct device *dev = device_get_binding(binding->behavior_dev); |
||||||
|
const struct behavior_macro_config *cfg = dev->config; |
||||||
|
struct behavior_macro_state *state = dev->data; |
||||||
|
struct behavior_macro_trigger_state trigger_state = {.mode = MACRO_MODE_TAP, |
||||||
|
.tap_ms = cfg->default_tap_ms, |
||||||
|
.wait_ms = cfg->default_wait_ms, |
||||||
|
.start_index = 0, |
||||||
|
.count = state->press_bindings_count}; |
||||||
|
|
||||||
|
queue_macro(event.position, cfg->bindings, trigger_state); |
||||||
|
|
||||||
|
return ZMK_BEHAVIOR_OPAQUE; |
||||||
|
} |
||||||
|
|
||||||
|
static int on_macro_binding_released(struct zmk_behavior_binding *binding, |
||||||
|
struct zmk_behavior_binding_event event) { |
||||||
|
const struct device *dev = device_get_binding(binding->behavior_dev); |
||||||
|
const struct behavior_macro_config *cfg = dev->config; |
||||||
|
struct behavior_macro_state *state = dev->data; |
||||||
|
|
||||||
|
queue_macro(event.position, cfg->bindings, state->release_state); |
||||||
|
|
||||||
|
return ZMK_BEHAVIOR_OPAQUE; |
||||||
|
} |
||||||
|
|
||||||
|
static const struct behavior_driver_api behavior_macro_driver_api = { |
||||||
|
.binding_pressed = on_macro_binding_pressed, |
||||||
|
.binding_released = on_macro_binding_released, |
||||||
|
}; |
||||||
|
|
||||||
|
#define BINDING_WITH_COMMA(idx, drv_inst) ZMK_KEYMAP_EXTRACT_BINDING(idx, DT_DRV_INST(drv_inst)), |
||||||
|
|
||||||
|
#define TRANSFORMED_BEHAVIORS(n) \ |
||||||
|
{UTIL_LISTIFY(DT_PROP_LEN(DT_DRV_INST(n), bindings), BINDING_WITH_COMMA, n)}, |
||||||
|
|
||||||
|
#define MACRO_INST(n) \ |
||||||
|
static struct behavior_macro_state behavior_macro_state_##n = {}; \
|
||||||
|
static struct behavior_macro_config behavior_macro_config_##n = { \
|
||||||
|
.default_wait_ms = DT_INST_PROP_OR(n, wait_ms, 100), \
|
||||||
|
.default_tap_ms = DT_INST_PROP_OR(n, tap_ms, 100), \
|
||||||
|
.count = DT_INST_PROP_LEN(n, bindings), \
|
||||||
|
.bindings = TRANSFORMED_BEHAVIORS(n)}; \
|
||||||
|
DEVICE_DT_INST_DEFINE(n, behavior_macro_init, device_pm_control_nop, \
|
||||||
|
&behavior_macro_state_##n, &behavior_macro_config_##n, APPLICATION, \
|
||||||
|
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_macro_driver_api); |
||||||
|
|
||||||
|
DT_INST_FOREACH_STATUS_OKAY(MACRO_INST) |
||||||
|
|
||||||
|
#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */ |
@ -0,0 +1,2 @@ |
|||||||
|
s/.*hid_listener_keycode/kp/p |
||||||
|
s/.*behavior_queue_process_next/queue_process_next/p |
@ -0,0 +1,18 @@ |
|||||||
|
queue_process_next: Invoking KEY_PRESS: 0x70004 0x00 |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 50ms |
||||||
|
queue_process_next: Invoking KEY_PRESS: 0x70004 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 10ms |
||||||
|
queue_process_next: Invoking KEY_PRESS: 0x70005 0x00 |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 50ms |
||||||
|
queue_process_next: Invoking KEY_PRESS: 0x70005 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 10ms |
||||||
|
queue_process_next: Invoking KEY_PRESS: 0x70006 0x00 |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 50ms |
||||||
|
queue_process_next: Invoking KEY_PRESS: 0x70006 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 10ms |
@ -0,0 +1,14 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2022 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <dt-bindings/zmk/keys.h> |
||||||
|
#include <behaviors.dtsi> |
||||||
|
#include <dt-bindings/zmk/kscan_mock.h> |
||||||
|
#include "../behavior_keymap.dtsi" |
||||||
|
|
||||||
|
&kscan { |
||||||
|
events = <ZMK_MOCK_PRESS(0,0,10) ZMK_MOCK_RELEASE(0,0,1000)>; |
||||||
|
}; |
@ -0,0 +1,68 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2022 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <dt-bindings/zmk/keys.h> |
||||||
|
#include <behaviors.dtsi> |
||||||
|
#include <dt-bindings/zmk/kscan_mock.h> |
||||||
|
|
||||||
|
/ { |
||||||
|
macros { |
||||||
|
ZMK_MACRO(abc_macro, |
||||||
|
wait-ms = <10>; |
||||||
|
tap-ms = <50>; |
||||||
|
bindings = <&kp A &kp B &kp C>; |
||||||
|
) |
||||||
|
|
||||||
|
ZMK_MACRO(hold_shift_macro, |
||||||
|
bindings |
||||||
|
= <¯o_press &kp LSHFT> |
||||||
|
, <¯o_tap> |
||||||
|
, <&kp D &kp O &kp G> |
||||||
|
, <¯o_release &kp LSHFT> |
||||||
|
; |
||||||
|
) |
||||||
|
|
||||||
|
ZMK_MACRO(custom_timing, |
||||||
|
bindings |
||||||
|
= <¯o_wait_time 50> |
||||||
|
, <&kp A> |
||||||
|
, <¯o_tap_time 20> |
||||||
|
, <&kp B &kp C> |
||||||
|
; |
||||||
|
) |
||||||
|
|
||||||
|
ZMK_MACRO(dual_sequence_macro, |
||||||
|
wait-ms = <10>; |
||||||
|
tap-ms = <40>; |
||||||
|
bindings |
||||||
|
= <¯o_press &kp LALT> |
||||||
|
, <¯o_tap> |
||||||
|
, <&kp TAB> |
||||||
|
, <¯o_pause_for_release> |
||||||
|
, <¯o_release &kp LALT> |
||||||
|
; |
||||||
|
) |
||||||
|
}; |
||||||
|
|
||||||
|
keymap { |
||||||
|
compatible = "zmk,keymap"; |
||||||
|
label ="Default keymap"; |
||||||
|
|
||||||
|
default_layer { |
||||||
|
bindings = < |
||||||
|
&abc_macro &mo 1 |
||||||
|
&hold_shift_macro &custom_timing>; |
||||||
|
}; |
||||||
|
|
||||||
|
extra_layer { |
||||||
|
bindings = < |
||||||
|
&dual_sequence_macro &trans |
||||||
|
&kp TAB &none>; |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
}; |
||||||
|
}; |
@ -0,0 +1 @@ |
|||||||
|
s/.*hid_listener_keycode/kp/p |
@ -0,0 +1,4 @@ |
|||||||
|
kp_pressed: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00 |
@ -0,0 +1,57 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2022 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <dt-bindings/zmk/keys.h> |
||||||
|
#include <behaviors.dtsi> |
||||||
|
#include <dt-bindings/zmk/kscan_mock.h> |
||||||
|
|
||||||
|
/ { |
||||||
|
macros { |
||||||
|
ZMK_MACRO( |
||||||
|
mo_mod_macro, |
||||||
|
wait-ms = <0>; |
||||||
|
tap-ms = <20>; |
||||||
|
bindings |
||||||
|
= <¯o_press &mo 1 &kp LSHFT> |
||||||
|
, <¯o_pause_for_release> |
||||||
|
, <¯o_release &mo 1 &kp LSHFT>; |
||||||
|
) |
||||||
|
}; |
||||||
|
|
||||||
|
behaviors { |
||||||
|
mth: macro_tap_hold { |
||||||
|
compatible = "zmk,behavior-hold-tap"; |
||||||
|
label = "MACRO_TAP_HOLD"; |
||||||
|
#binding-cells = <2>; |
||||||
|
flavor = "tap-unless-interrupted"; |
||||||
|
tapping-term-ms = <200>; |
||||||
|
bindings = <&mo_mod_macro>, <&kp>; |
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
keymap { |
||||||
|
compatible = "zmk,keymap"; |
||||||
|
label ="Default keymap"; |
||||||
|
|
||||||
|
default_layer { |
||||||
|
bindings = < |
||||||
|
&mth 0 TAB &kp A |
||||||
|
&kp B &kp C>; |
||||||
|
}; |
||||||
|
|
||||||
|
extra_layer { |
||||||
|
bindings = < |
||||||
|
&kp D &kp E |
||||||
|
&kp F &kp G>; |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
&kscan { |
||||||
|
events = <ZMK_MOCK_PRESS(0,0,20) ZMK_MOCK_PRESS(0,1,10) ZMK_MOCK_RELEASE(0,1,10) ZMK_MOCK_RELEASE(0,0,1000)>; |
||||||
|
}; |
@ -0,0 +1 @@ |
|||||||
|
s/.*hid_listener_keycode/kp/p |
@ -0,0 +1,4 @@ |
|||||||
|
kp_pressed: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0x08 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00 |
@ -0,0 +1,46 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2022 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <dt-bindings/zmk/keys.h> |
||||||
|
#include <behaviors.dtsi> |
||||||
|
#include <dt-bindings/zmk/kscan_mock.h> |
||||||
|
|
||||||
|
/ { |
||||||
|
macros { |
||||||
|
ZMK_MACRO( |
||||||
|
mo_mod_macro, |
||||||
|
wait-ms = <0>; |
||||||
|
tap-ms = <20>; |
||||||
|
bindings |
||||||
|
= <¯o_press &mo 1 &kp LSHFT> |
||||||
|
, <¯o_pause_for_release> |
||||||
|
, <¯o_release &mo 1 &kp LSHFT>; |
||||||
|
) |
||||||
|
}; |
||||||
|
|
||||||
|
keymap { |
||||||
|
compatible = "zmk,keymap"; |
||||||
|
label ="Default keymap"; |
||||||
|
|
||||||
|
default_layer { |
||||||
|
bindings = < |
||||||
|
&mo_mod_macro &kp A |
||||||
|
&kp B &kp C>; |
||||||
|
}; |
||||||
|
|
||||||
|
extra_layer { |
||||||
|
bindings = < |
||||||
|
&kp D &kp E |
||||||
|
&kp F &kp G>; |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
&kscan { |
||||||
|
events = <ZMK_MOCK_PRESS(0,0,20) ZMK_MOCK_PRESS(0,1,10) ZMK_MOCK_RELEASE(0,1,10) ZMK_MOCK_RELEASE(0,0,1000)>; |
||||||
|
}; |
@ -0,0 +1,2 @@ |
|||||||
|
s/.*hid_listener_keycode/kp/p |
||||||
|
s/.*keymap_apply_position_state/pos_state/p |
@ -0,0 +1,10 @@ |
|||||||
|
pos_state: layer: 0 position: 0, binding name: ZM_abc_macro |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
pos_state: layer: 0 position: 0, binding name: ZM_abc_macro |
||||||
|
pos_state: layer: 0 position: 1, binding name: MO |
||||||
|
pos_state: layer: 0 position: 1, binding name: MO |
||||||
|
kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00 |
@ -0,0 +1,14 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2022 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <dt-bindings/zmk/keys.h> |
||||||
|
#include <behaviors.dtsi> |
||||||
|
#include <dt-bindings/zmk/kscan_mock.h> |
||||||
|
#include "../behavior_keymap.dtsi" |
||||||
|
|
||||||
|
&kscan { |
||||||
|
events = <ZMK_MOCK_PRESS(0,0,10) ZMK_MOCK_RELEASE(0,0,1) ZMK_MOCK_PRESS(0,1,10) ZMK_MOCK_RELEASE(0,1,1000)>; |
||||||
|
}; |
@ -0,0 +1 @@ |
|||||||
|
s/.*hid_listener_keycode/kp/p |
@ -0,0 +1,8 @@ |
|||||||
|
kp_pressed: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x07 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0x07 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x12 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0x12 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x0a implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0x0a implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0xe1 implicit_mods 0x00 explicit_mods 0x00 |
@ -0,0 +1,14 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2022 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <dt-bindings/zmk/keys.h> |
||||||
|
#include <behaviors.dtsi> |
||||||
|
#include <dt-bindings/zmk/kscan_mock.h> |
||||||
|
#include "../behavior_keymap.dtsi" |
||||||
|
|
||||||
|
&kscan { |
||||||
|
events = <ZMK_MOCK_PRESS(1,0,10) ZMK_MOCK_RELEASE(1,0,1000)>; |
||||||
|
}; |
@ -0,0 +1,2 @@ |
|||||||
|
s/.*hid_listener_keycode/kp/p |
||||||
|
s/.*behavior_queue_process_next/queue_process_next/p |
@ -0,0 +1,18 @@ |
|||||||
|
queue_process_next: Invoking KEY_PRESS: 0x70004 0x00 |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 100ms |
||||||
|
queue_process_next: Invoking KEY_PRESS: 0x70004 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0x04 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 50ms |
||||||
|
queue_process_next: Invoking KEY_PRESS: 0x70005 0x00 |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 20ms |
||||||
|
queue_process_next: Invoking KEY_PRESS: 0x70005 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0x05 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 50ms |
||||||
|
queue_process_next: Invoking KEY_PRESS: 0x70006 0x00 |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 20ms |
||||||
|
queue_process_next: Invoking KEY_PRESS: 0x70006 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0x06 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 50ms |
@ -0,0 +1,14 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2022 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <dt-bindings/zmk/keys.h> |
||||||
|
#include <behaviors.dtsi> |
||||||
|
#include <dt-bindings/zmk/kscan_mock.h> |
||||||
|
#include "../behavior_keymap.dtsi" |
||||||
|
|
||||||
|
&kscan { |
||||||
|
events = <ZMK_MOCK_PRESS(1,1,10) ZMK_MOCK_RELEASE(1,1,750)>; |
||||||
|
}; |
@ -0,0 +1,3 @@ |
|||||||
|
s/.*hid_listener_keycode/kp/p |
||||||
|
s/.*behavior_queue_process_next/queue_process_next/p |
||||||
|
s/.*queue_macro/qm/p |
@ -0,0 +1,16 @@ |
|||||||
|
qm: Iterating macro bindings - starting: 0, count: 4 |
||||||
|
queue_process_next: Invoking KEY_PRESS: 0x700e2 0x00 |
||||||
|
kp_pressed: usage_page 0x07 keycode 0xe2 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 10ms |
||||||
|
queue_process_next: Invoking KEY_PRESS: 0x7002b 0x00 |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 40ms |
||||||
|
queue_process_next: Invoking KEY_PRESS: 0x7002b 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 10ms |
||||||
|
kp_pressed: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0x2b implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
qm: Iterating macro bindings - starting: 5, count: 2 |
||||||
|
queue_process_next: Invoking KEY_PRESS: 0x700e2 0x00 |
||||||
|
kp_released: usage_page 0x07 keycode 0xe2 implicit_mods 0x00 explicit_mods 0x00 |
||||||
|
queue_process_next: Processing next queued behavior in 0ms |
@ -0,0 +1,14 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2022 The ZMK Contributors |
||||||
|
* |
||||||
|
* SPDX-License-Identifier: MIT |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <dt-bindings/zmk/keys.h> |
||||||
|
#include <behaviors.dtsi> |
||||||
|
#include <dt-bindings/zmk/kscan_mock.h> |
||||||
|
#include "../behavior_keymap.dtsi" |
||||||
|
|
||||||
|
&kscan { |
||||||
|
events = <ZMK_MOCK_PRESS(0,1,10) ZMK_MOCK_PRESS(0,0,400) ZMK_MOCK_PRESS(1,0,400) ZMK_MOCK_RELEASE(1,0,10) ZMK_MOCK_RELEASE(0,0,1000) ZMK_MOCK_RELEASE(0,1,1000)>; |
||||||
|
}; |
Loading…
Reference in new issue