Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hassa129 authored and ReFil committed Sep 15, 2023
1 parent 89883eb commit 1ee8b23
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
target_sources_ifdef(CONFIG_ZMK_BEHAVIOR_SENSOR_ROTATE_COMMON app PRIVATE src/behaviors/behavior_sensor_rotate_common.c)
target_sources(app PRIVATE src/combo.c)
target_sources(app PRIVATE src/behaviors/behavior_tap_dance.c)
target_sources(app PRIVATE src/behaviors/behavior_bottom.c)
target_sources(app PRIVATE src/behavior_queue.c)
target_sources(app PRIVATE src/conditional_layer.c)
target_sources(app PRIVATE src/endpoints.c)
Expand Down
3 changes: 2 additions & 1 deletion app/dts/behaviors.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
#include <behaviors/caps_word.dtsi>
#include <behaviors/key_repeat.dtsi>
#include <behaviors/backlight.dtsi>
#include <behaviors/macros.dtsi>
#include <behaviors/macros.dtsi>
#include <behaviors/bottom.dtsi>
16 changes: 16 additions & 0 deletions app/dts/behaviors/bottom.dtsi
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>;
};
};
};
13 changes: 13 additions & 0 deletions app/dts/bindings/behaviors/zmk,behavior-bottom.yaml
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
70 changes: 70 additions & 0 deletions app/src/behaviors/behavior_bottom.c
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

0 comments on commit 1ee8b23

Please sign in to comment.