Skip to content

Commit

Permalink
(feat) Allow setting underglow color by key press
Browse files Browse the repository at this point in the history
  • Loading branch information
KemoNine committed Dec 15, 2020
1 parent b5e17e3 commit 393fbe2
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 44 deletions.
19 changes: 9 additions & 10 deletions app/drivers/kscan/kscan_gpio_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,15 @@ static int kscan_gpio_config_interrupts(const struct device **devices,
COND_CODE_0(DT_ENUM_IDX(DT_DRV_INST(n), diode_direction), (cfg->rows), (cfg->cols))); \
} \
COND_CODE_1(CONFIG_ZMK_KSCAN_MATRIX_POLLING, (), \
( \
static int kscan_gpio_enable_interrupts_##n(const struct device *dev) { \
return kscan_gpio_config_interrupts( \
kscan_gpio_input_devices_##n(dev), kscan_gpio_input_configs_##n(dev), \
INST_INPUT_LEN(n), GPIO_INT_LEVEL_ACTIVE); \
} static int kscan_gpio_disable_interrupts_##n(const struct device *dev) { \
return kscan_gpio_config_interrupts(kscan_gpio_input_devices_##n(dev), \
kscan_gpio_input_configs_##n(dev), \
INST_INPUT_LEN(n), GPIO_INT_DISABLE); \
})) \
(static int kscan_gpio_enable_interrupts_##n(const struct device *dev) { \
return kscan_gpio_config_interrupts(kscan_gpio_input_devices_##n(dev), \
kscan_gpio_input_configs_##n(dev), \
INST_INPUT_LEN(n), GPIO_INT_LEVEL_ACTIVE); \
} static int kscan_gpio_disable_interrupts_##n(const struct device *dev) { \
return kscan_gpio_config_interrupts(kscan_gpio_input_devices_##n(dev), \
kscan_gpio_input_configs_##n(dev), \
INST_INPUT_LEN(n), GPIO_INT_DISABLE); \
})) \
static void kscan_gpio_set_output_state_##n(const struct device *dev, int value) { \
int err; \
for (int i = 0; i < INST_OUTPUT_LEN(n); i++) { \
Expand Down
15 changes: 8 additions & 7 deletions app/dts/behaviors/rgb_underglow.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
*/

/ {
behaviors {
rgb_ug: behavior_rgb_underglow {
compatible = "zmk,behavior-rgb-underglow";
label = "RGB_UNDERGLOW";
#binding-cells = <1>;
};
};
behaviors {
rgb_ug:
behavior_rgb_underglow {
compatible = "zmk,behavior-rgb-underglow";
label = "RGB_UNDERGLOW";
#binding - cells = < 2>;
};
};
};
10 changes: 5 additions & 5 deletions app/dts/bindings/behaviors/zmk,behavior-rgb-underglow.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright (c) 2020 The ZMK Contributors
# SPDX-License-Identifier: MIT
#Copyright(c) 2020 The ZMK Contributors
#SPDX - License - Identifier : MIT

description: RGB Underglow Action
description : RGB Underglow Action

compatible: "zmk,behavior-rgb-underglow"
compatible : "zmk,behavior-rgb-underglow"

include: one_param.yaml
include : two_param.yaml
37 changes: 26 additions & 11 deletions app/include/dt-bindings/zmk/rgb.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,29 @@
* SPDX-License-Identifier: MIT
*/

#define RGB_TOG 0
#define RGB_HUI 1
#define RGB_HUD 2
#define RGB_SAI 3
#define RGB_SAD 4
#define RGB_BRI 5
#define RGB_BRD 6
#define RGB_SPI 7
#define RGB_SPD 8
#define RGB_EFF 9
#define RGB_EFR 10
#define RGB_TOG_CMD 0
#define RGB_HUI_CMD 1
#define RGB_HUD_CMD 2
#define RGB_SAI_CMD 3
#define RGB_SAD_CMD 4
#define RGB_BRI_CMD 5
#define RGB_BRD_CMD 6
#define RGB_SPI_CMD 7
#define RGB_SPD_CMD 8
#define RGB_EFF_CMD 9
#define RGB_EFR_CMD 10
#define RGB_HSB_COLOR_CMD 11

#define RGB_TOG RGB_TOG_CMD 0
#define RGB_HUI RGB_HUI_CMD 0
#define RGB_HUD RGB_HUD_CMD 0
#define RGB_SAI RGB_SAI_CMD 0
#define RGB_SAD RGB_SAD_CMD 0
#define RGB_BRI RGB_BRI_CMD 0
#define RGB_BRD RGB_BRD_CMD 0
#define RGB_SPI RGB_SPI_CMD 0
#define RGB_SPD RGB_SPD_CMD 0
#define RGB_EFF RGB_EFF_CMD 0
#define RGB_EFR RGB_EFR_CMD 0
#define RGB_COLOR_HSB(h, s, v) RGB_HSB_COLOR_CMD(((h) << 16) + ((s) << 8) + (v))
#define RGB_COLOR_HSV RGB_COLOR_HSB
1 change: 1 addition & 0 deletions app/include/zmk/rgb_underglow.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ int zmk_rgb_underglow_change_hue(int direction);
int zmk_rgb_underglow_change_sat(int direction);
int zmk_rgb_underglow_change_brt(int direction);
int zmk_rgb_underglow_change_spd(int direction);
int zmk_rgb_underglow_set_hsb(uint16_t hue, uint8_t saturation, uint8_t brightness);
25 changes: 14 additions & 11 deletions app/src/behaviors/behavior_rgb_underglow.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,31 @@ static int behavior_rgb_underglow_init(const struct device *dev) { return 0; }
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
switch (binding->param1) {
case RGB_TOG:
case RGB_TOG_CMD:
return zmk_rgb_underglow_toggle();
case RGB_HUI:
case RGB_HUI_CMD:
return zmk_rgb_underglow_change_hue(1);
case RGB_HUD:
case RGB_HUD_CMD:
return zmk_rgb_underglow_change_hue(-1);
case RGB_SAI:
case RGB_SAI_CMD:
return zmk_rgb_underglow_change_sat(1);
case RGB_SAD:
case RGB_SAD_CMD:
return zmk_rgb_underglow_change_sat(-1);
case RGB_BRI:
case RGB_BRI_CMD:
return zmk_rgb_underglow_change_brt(1);
case RGB_BRD:
case RGB_BRD_CMD:
return zmk_rgb_underglow_change_brt(-1);
case RGB_SPI:
case RGB_SPI_CMD:
return zmk_rgb_underglow_change_spd(1);
case RGB_SPD:
case RGB_SPD_CMD:
return zmk_rgb_underglow_change_spd(-1);
case RGB_EFF:
case RGB_EFF_CMD:
return zmk_rgb_underglow_cycle_effect(1);
case RGB_EFR:
case RGB_EFR_CMD:
return zmk_rgb_underglow_cycle_effect(-1);
case RGB_HSB_COLOR_CMD:
return zmk_rgb_underglow_set_hsb((binding->param2 >> 16) & 0xFFFF,
(binding->param2 >> 8) & 0xFF, binding->param2 & 0xFF);
}

return -ENOTSUP;
Expand Down
13 changes: 13 additions & 0 deletions app/src/rgb_underglow.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,19 @@ int zmk_rgb_underglow_toggle() {
return zmk_rgb_underglow_save_state();
}

int zmk_rgb_underglow_set_hsb(uint16_t hue, uint8_t saturation, uint8_t brightness) {
if (hue > 360 || saturation > 100 || brightness > 100) {
return -ENOTSUP;
}

state.hue = hue;
state.saturation = saturation;
state.brightness = brightness;
state.current_effect = UNDERGLOW_EFFECT_SOLID;

return 0;
}

int zmk_rgb_underglow_change_hue(int direction) {
if (!led_strip)
return -ENODEV;
Expand Down

0 comments on commit 393fbe2

Please sign in to comment.