chore(&sleep): misc code updates from PR #649

This commit is contained in:
KemoNine 2021-03-13 19:24:05 +00:00
parent 8e5e5b9dd7
commit f9699eb1bf
3 changed files with 16 additions and 3 deletions

View file

@ -6,7 +6,7 @@
/ { / {
behaviors { behaviors {
sleep: behavior_sleep { /omit-if-no-ref/ sleep: behavior_sleep {
compatible = "zmk,behavior-sleep"; compatible = "zmk,behavior-sleep";
label = "SLEEP"; label = "SLEEP";
#binding-cells = <0>; #binding-cells = <0>;

View file

@ -9,4 +9,4 @@
enum zmk_activity_state { ZMK_ACTIVITY_ACTIVE, ZMK_ACTIVITY_IDLE, ZMK_ACTIVITY_SLEEP }; enum zmk_activity_state { ZMK_ACTIVITY_ACTIVE, ZMK_ACTIVITY_IDLE, ZMK_ACTIVITY_SLEEP };
enum zmk_activity_state zmk_activity_get_state(); enum zmk_activity_state zmk_activity_get_state();
int activity_set_state(enum zmk_activity_state state); int zmk_activity_set_state(enum zmk_activity_state state);

View file

@ -13,18 +13,31 @@
#include <zmk/behavior.h> #include <zmk/behavior.h>
#include <zmk/activity.h> #include <zmk/activity.h>
#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
static int behavior_sleep_init(const struct device *dev) { return 0; }; static int behavior_sleep_init(const struct device *dev) { return 0; };
static int on_keymap_binding_released(struct zmk_behavior_binding *binding, static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) { struct zmk_behavior_binding_event event) {
#if IS_ENABLED(CONFIG_ZMK_SLEEP)
return activity_set_state(ZMK_ACTIVITY_SLEEP); return activity_set_state(ZMK_ACTIVITY_SLEEP);
#endif
return ZMK_BEHAVIOR_OPAQUE;
}
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
return ZMK_BEHAVIOR_OPAQUE;
} }
static const struct behavior_driver_api behavior_sleep_driver_api = { static const struct behavior_driver_api behavior_sleep_driver_api = {
.binding_released = on_keymap_binding_released, .binding_released = on_keymap_binding_released,
.binding_pressed = on_keymap_binding_pressed,
}; };
DEVICE_AND_API_INIT(behavior_sleep, DT_INST_LABEL(0), behavior_sleep_init, NULL, NULL, APPLICATION, DEVICE_AND_API_INIT(behavior_sleep, DT_INST_LABEL(0), behavior_sleep_init, NULL, NULL, APPLICATION,
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_sleep_driver_api); CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_sleep_driver_api);
#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */