forked from zmkfirmware/zmk
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Showing
5 changed files
with
102 additions
and
1 deletion.
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,16 @@ | ||
/* | ||
* Copyright (c) 2021 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
/ { | ||
behaviors { | ||
/omit-if-no-ref/ bottom: behavior_bottom { | ||
compatible = "zmk,behavior-bottom"; | ||
label = "BOTTOM"; | ||
#binding-cells = <0>; | ||
delay_ms = <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,13 @@ | ||
# Copyright (c) 2020 The ZMK Contributors | ||
# SPDX-License-Identifier: MIT | ||
|
||
description: Keyboard Keysmash Behavior | ||
|
||
compatible: "zmk,behavior-bottom" | ||
|
||
include: zero_param.yaml | ||
|
||
properties: | ||
delay_ms: | ||
type: int | ||
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,70 @@ | ||
/* | ||
* Copyright (c) 2021 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#define DT_DRV_COMPAT zmk_behavior_bottom | ||
|
||
#include <device.h> | ||
#include <drivers/behavior.h> | ||
#include <kernel.h> | ||
#include <logging/log.h> | ||
#include <zmk/behavior.h> | ||
#include <random/rand32.h> | ||
#include <zmk/event_manager.h> | ||
#include <zmk/events/keycode_state_changed.h> | ||
|
||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); | ||
|
||
#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) | ||
|
||
struct behavior_bottom_config { | ||
int delay_ms; | ||
}; | ||
|
||
static void zmk_bottom_tick(struct k_work *work) { | ||
int key = (sys_rand32_get() % 26) + 4; | ||
ZMK_EVENT_RAISE(zmk_keycode_state_changed_from_encoded(key, true, k_uptime_get())); | ||
k_msleep(5); | ||
ZMK_EVENT_RAISE(zmk_keycode_state_changed_from_encoded(key, false, k_uptime_get())); | ||
} | ||
|
||
K_WORK_DEFINE(bottom_work, zmk_bottom_tick); | ||
|
||
static void zmk_bottom_tick_handler(struct k_timer *timer) { k_work_submit(&bottom_work); } | ||
|
||
K_TIMER_DEFINE(bottom_tick, zmk_bottom_tick_handler, NULL); | ||
|
||
static int on_bottom_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_bottom_config *cfg = dev->config; | ||
|
||
k_timer_start(&bottom_tick, K_NO_WAIT, K_MSEC(cfg->delay_ms)); | ||
|
||
return ZMK_BEHAVIOR_OPAQUE; | ||
} | ||
|
||
static int on_bottom_binding_released(struct zmk_behavior_binding *binding, | ||
struct zmk_behavior_binding_event event) { | ||
k_timer_stop(&bottom_tick); | ||
return ZMK_BEHAVIOR_OPAQUE; | ||
} | ||
|
||
static const struct behavior_driver_api behavior_bottom_driver_api = { | ||
.binding_pressed = on_bottom_binding_pressed, | ||
.binding_released = on_bottom_binding_released, | ||
}; | ||
|
||
static int behavior_bottom_init(const struct device *dev) { return 0; } | ||
|
||
static struct behavior_bottom_config behavior_bottom_config = { | ||
.delay_ms = DT_INST_PROP(0, delay_ms), | ||
}; | ||
|
||
DEVICE_DT_INST_DEFINE(0, behavior_bottom_init, device_pm_control_nop, NULL, &behavior_bottom_config, | ||
APPLICATION, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, | ||
&behavior_bottom_driver_api); | ||
|
||
#endif |