forked from moergo-sc/zmk
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
underglow-layer: use behaviors to control RGBs
- Loading branch information
Showing
20 changed files
with
319 additions
and
26 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
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
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,15 @@ | ||
/* | ||
* Copyright (c) 2024 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
/ { | ||
behaviors { | ||
ug: ugcolor { | ||
compatible = "zmk,behavior-underglow-color"; | ||
#binding-cells = <1>; | ||
display-name = "Underglow Color"; | ||
}; | ||
}; | ||
}; |
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,33 @@ | ||
/* | ||
* Copyright (c) 2024 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <dt-bindings/zmk/hid_indicators.h> | ||
|
||
/ { | ||
behaviors { | ||
ug_nl: ugnumlk { | ||
compatible = "zmk,behavior-underglow-indicators"; | ||
indicator = <NUM_LOCK>; | ||
#binding-cells = <2>; | ||
display-name = "Underglow NumLock indicator"; | ||
}; | ||
|
||
ug_cl: ugcapslk { | ||
compatible = "zmk,behavior-underglow-indicators"; | ||
indicator = <CAPS_LOCK>; | ||
#binding-cells = <2>; | ||
display-name = "Underglow CapsLock indicator"; | ||
}; | ||
|
||
ug_sl: ugscrllk { | ||
compatible = "zmk,behavior-underglow-indicators"; | ||
indicator = <SCROLL_LOCK>; | ||
#binding-cells = <2>; | ||
display-name = "Underglow ScrollLock indicator"; | ||
}; | ||
|
||
}; | ||
}; |
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,8 @@ | ||
# Copyright (c) 2024, The ZMK Contributors | ||
# SPDX-License-Identifier: MIT | ||
|
||
description: Set underglow to specified color | ||
|
||
compatible: "zmk,behavior-underglow-color" | ||
|
||
include: one_param.yaml |
13 changes: 13 additions & 0 deletions
13
app/dts/bindings/behaviors/zmk,behavior-underglow-indicators.yaml
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) 2024, The ZMK Contributors | ||
# SPDX-License-Identifier: MIT | ||
|
||
description: Set underglow for num lock indicator | ||
|
||
compatible: "zmk,behavior-underglow-indicators" | ||
|
||
include: two_param.yaml | ||
|
||
properties: | ||
indicator: | ||
type: int | ||
default: 0 |
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,9 @@ | ||
/* | ||
* Copyright (c) 2020 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#define NUM_LOCK 0 | ||
#define CAPS_LOCK 1 | ||
#define SCROLL_LOCK 2 |
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) 2024 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <zmk/event_manager.h> | ||
|
||
struct zmk_underglow_color_changed {}; | ||
|
||
ZMK_EVENT_DECLARE(zmk_underglow_color_changed); |
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,39 @@ | ||
/* | ||
* Copyright (c) 2024 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#define DT_DRV_COMPAT zmk_behavior_underglow_color | ||
|
||
// Dependencies | ||
#include <zephyr/device.h> | ||
#include <drivers/behavior.h> | ||
#include <zephyr/logging/log.h> | ||
|
||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); | ||
|
||
#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) | ||
|
||
// Initialization Function | ||
static int underglow_color_init(const struct device *dev) { return 0; }; | ||
|
||
static int underglow_color_process(struct zmk_behavior_binding *binding, | ||
struct zmk_behavior_binding_event event) { | ||
return binding->param1; | ||
} | ||
|
||
// API Structure | ||
static const struct behavior_driver_api underglow_color_driver_api = { | ||
.binding_pressed = underglow_color_process, | ||
.locality = BEHAVIOR_LOCALITY_GLOBAL, | ||
#if IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) | ||
.get_parameter_metadata = zmk_behavior_get_empty_param_metadata, | ||
#endif // IS_ENABLED(CONFIG_ZMK_BEHAVIOR_METADATA) | ||
|
||
}; | ||
|
||
BEHAVIOR_DT_INST_DEFINE(0, underglow_color_init, NULL, NULL, NULL, POST_KERNEL, | ||
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &underglow_color_driver_api); | ||
|
||
#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */ |
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,77 @@ | ||
/* | ||
* Copyright (c) 2024 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#define DT_DRV_COMPAT zmk_behavior_underglow_indicators | ||
|
||
// Dependencies | ||
#include <zephyr/device.h> | ||
#include <drivers/behavior.h> | ||
#include <zephyr/logging/log.h> | ||
#include <zmk/hid_indicators.h> | ||
#include <zmk/event_manager.h> | ||
#include <zmk/events/hid_indicators_changed.h> | ||
#include <zmk/events/underglow_color_changed.h> | ||
|
||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); | ||
|
||
#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) | ||
|
||
struct underglow_indicators_data { | ||
zmk_hid_indicators_t indicators; | ||
}; | ||
|
||
struct underglow_indicators_config { | ||
int indicator; | ||
}; | ||
|
||
static int underglow_indicators_init(const struct device *dev) { return 0; }; | ||
|
||
static int underglow_indicators_process(struct zmk_behavior_binding *binding, | ||
struct zmk_behavior_binding_event event) { | ||
const struct device *dev = zmk_behavior_get_binding(binding->behavior_dev); | ||
struct underglow_indicators_data *data = dev->data; | ||
struct underglow_indicators_config *config = dev->config; | ||
|
||
if (data->indicators & BIT(config->indicator)) | ||
return binding->param2; | ||
else | ||
return binding->param1; | ||
} | ||
|
||
static const struct behavior_driver_api underglow_indicators_driver_api = { | ||
.binding_pressed = underglow_indicators_process, | ||
.locality = BEHAVIOR_LOCALITY_GLOBAL, | ||
#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 underglow_indicators_listener(const zmk_event_t *eh); | ||
|
||
ZMK_LISTENER(behavior_underglow_indicators, underglow_indicators_listener); | ||
ZMK_SUBSCRIPTION(behavior_underglow_indicators, zmk_hid_indicators_changed); | ||
|
||
static struct underglow_indicators_data underglow_indicators_data = {.indicators = 0}; | ||
|
||
static int underglow_indicators_listener(const zmk_event_t *eh) { | ||
const struct zmk_hid_indicators_changed *ev = as_zmk_hid_indicators_changed(eh); | ||
underglow_indicators_data.indicators = ev->indicators; | ||
raise_zmk_underglow_color_changed((struct zmk_underglow_color_changed){}); | ||
|
||
return ZMK_EV_EVENT_BUBBLE; | ||
} | ||
|
||
#define KP_INST(n) \ | ||
static struct underglow_indicators_config underglow_indicators_config_##n = { \ | ||
.indicator = DT_INST_PROP(n, indicator)}; \ | ||
BEHAVIOR_DT_INST_DEFINE(n, underglow_indicators_init, NULL, &underglow_indicators_data, \ | ||
&underglow_indicators_config_##n, POST_KERNEL, \ | ||
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \ | ||
&underglow_indicators_driver_api); | ||
|
||
DT_INST_FOREACH_STATUS_OKAY(KP_INST) | ||
|
||
#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */ |
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 @@ | ||
/* | ||
* Copyright (c) 2020 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <zephyr/kernel.h> | ||
#include <zmk/events/underglow_color_changed.h> | ||
|
||
ZMK_EVENT_IMPL(zmk_underglow_color_changed); |
Oops, something went wrong.