summaryrefslogtreecommitdiff
path: root/users/drashna/rgb
diff options
context:
space:
mode:
Diffstat (limited to 'users/drashna/rgb')
-rw-r--r--users/drashna/rgb/readme.md52
-rw-r--r--users/drashna/rgb/rgb_matrix_stuff.c129
-rw-r--r--users/drashna/rgb/rgb_matrix_stuff.h15
-rw-r--r--users/drashna/rgb/rgb_stuff.c117
-rw-r--r--users/drashna/rgb/rgb_stuff.h12
5 files changed, 325 insertions, 0 deletions
diff --git a/users/drashna/rgb/readme.md b/users/drashna/rgb/readme.md
new file mode 100644
index 0000000000..4deaa0a463
--- /dev/null
+++ b/users/drashna/rgb/readme.md
@@ -0,0 +1,52 @@
+# RGB
+
+Custom RGB code can be disabled by setting `CUSTOM_RGBLIGHT = no` or `CUSTOM_RGB_MATRIX = no` in your `rules.mk`
+
+## RGB Light
+
+### Layer Indication Code
+
+At least for RGB Light, the `layer_state_set` function is used to detect the current highest layer, and change the underglow based on that layer.
+
+This works for both the regular layers, and for the default layers, too.
+
+I use the sethsv variants of the commands, so that different modes can be used, as well.
+
+RGB Matrix uses a custom, per board implementation, at the moment.
+
+### RGB Light Startup Animation
+
+On startup, if enabled, the board will cycle through the entire hue wheel, starting and ending on the default layer color.
+
+```c
+void keyboard_post_init_rgb(void) {
+#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_STARTUP_ANIMATION)
+ if (userspace_config.rgb_layer_change) { rgblight_enable_noeeprom(); }
+ if (rgblight_config.enable) {
+ layer_state_set_user(layer_state);
+ uint16_t old_hue = rgblight_config.hue;
+ rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
+ for (uint16_t i = 255; i > 0; i--) {
+ rgblight_sethsv_noeeprom( ( i + old_hue) % 255, 255, 255);
+ matrix_scan();
+ wait_ms(10);
+ }
+ }
+#endif
+ layer_state_set_user(layer_state);
+}
+```
+
+This could probably benefit from some cleanup and better handling.
+
+## RGB Matrix
+
+### Idle Animation
+
+This feature can be toggled with the `RGB_IDL` keycode.
+
+This sets the mode to the Heatmap Animation when typing, but will switch to the cycle in animations when idle.
+
+### Layer Indication
+
+This sets the modifier keys to indicate the current layer state, with the option to override the behavior.
diff --git a/users/drashna/rgb/rgb_matrix_stuff.c b/users/drashna/rgb/rgb_matrix_stuff.c
new file mode 100644
index 0000000000..e6d631466d
--- /dev/null
+++ b/users/drashna/rgb/rgb_matrix_stuff.c
@@ -0,0 +1,129 @@
+// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "drashna.h"
+#include "rgb_matrix.h"
+#include "lib/lib8tion/lib8tion.h"
+extern led_config_t g_led_config;
+
+static uint32_t hypno_timer;
+
+void rgb_matrix_layer_helper(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode, uint8_t speed, uint8_t led_type, uint8_t led_min, uint8_t led_max) {
+ HSV hsv = {hue, sat, val};
+ if (hsv.v > rgb_matrix_get_val()) {
+ hsv.v = rgb_matrix_get_val();
+ }
+
+ switch (mode) {
+ case 1: // breathing
+ {
+ uint16_t time = scale16by8(g_rgb_timer, speed / 8);
+ hsv.v = scale8(abs8(sin8(time) - 128) * 2, hsv.v);
+ RGB rgb = hsv_to_rgb(hsv);
+ for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
+ if (HAS_FLAGS(g_led_config.flags[i], led_type)) {
+ RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b);
+ }
+ }
+ break;
+ }
+ default: // Solid Color
+ {
+ RGB rgb = hsv_to_rgb(hsv);
+ for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) {
+ if (HAS_FLAGS(g_led_config.flags[i], led_type)) {
+ RGB_MATRIX_INDICATOR_SET_COLOR(i, rgb.r, rgb.g, rgb.b);
+ }
+ }
+ break;
+ }
+ }
+}
+
+__attribute__((weak)) void rgb_matrix_indicator_keymap(void) {}
+
+void matrix_scan_rgb_matrix(void) {
+#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
+ if (userspace_config.rgb_matrix_idle_anim && rgb_matrix_get_mode() == RGB_MATRIX_TYPING_HEATMAP && sync_timer_elapsed32(hypno_timer) > 15000) {
+ rgb_matrix_mode_noeeprom(RGB_MATRIX_REST_MODE);
+ }
+#endif
+ rgb_matrix_indicator_keymap();
+}
+
+void keyboard_post_init_rgb_matrix(void) {
+#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
+ if (userspace_config.rgb_matrix_idle_anim) {
+ rgb_matrix_mode_noeeprom(RGB_MATRIX_REST_MODE);
+ }
+#endif
+}
+
+bool process_record_user_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
+#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
+ hypno_timer = sync_timer_read32();
+ if (userspace_config.rgb_matrix_idle_anim && rgb_matrix_get_mode() == RGB_MATRIX_REST_MODE) {
+ rgb_matrix_mode_noeeprom(RGB_MATRIX_TYPING_HEATMAP);
+ }
+#endif
+ switch (keycode) {
+ case RGB_IDL: // This allows me to use underglow as layer indication, or as normal
+#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS)
+ if (record->event.pressed) {
+ userspace_config.rgb_matrix_idle_anim ^= 1;
+ dprintf("RGB Matrix Idle Animation [EEPROM]: %u\n", userspace_config.rgb_matrix_idle_anim);
+ eeconfig_update_user(userspace_config.raw);
+ if (userspace_config.rgb_matrix_idle_anim) {
+ rgb_matrix_mode_noeeprom(RGB_MATRIX_TYPING_HEATMAP);
+ }
+ }
+#endif
+ break;
+ }
+ return true;
+}
+
+__attribute__((weak)) bool rgb_matrix_indicators_advanced_keymap(uint8_t led_min, uint8_t led_max) { return true; }
+void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
+ if (!rgb_matrix_indicators_advanced_keymap(led_min, led_max)) { return; }
+
+#if defined(RGBLIGHT_ENABLE)
+ if (!userspace_config.rgb_layer_change)
+#else
+ if (userspace_config.rgb_layer_change)
+#endif
+ {
+ switch (get_highest_layer(layer_state | default_layer_state)) {
+ case _DEFAULT_LAYER_1:
+ rgb_matrix_layer_helper(DEFAULT_LAYER_1_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
+ break;
+ case _DEFAULT_LAYER_2:
+ rgb_matrix_layer_helper(DEFAULT_LAYER_2_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
+ break;
+ case _DEFAULT_LAYER_3:
+ rgb_matrix_layer_helper(DEFAULT_LAYER_3_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
+ break;
+ case _DEFAULT_LAYER_4:
+ rgb_matrix_layer_helper(DEFAULT_LAYER_4_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
+ break;
+ case _GAMEPAD:
+ rgb_matrix_layer_helper(HSV_ORANGE, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
+ break;
+ case _DIABLO:
+ rgb_matrix_layer_helper(HSV_RED, 1, rgb_matrix_config.speed * 8, LED_FLAG_MODIFIER, led_min, led_max);
+ break;
+ case _RAISE:
+ rgb_matrix_layer_helper(HSV_YELLOW, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
+ break;
+ case _LOWER:
+ rgb_matrix_layer_helper(HSV_GREEN, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
+ break;
+ case _ADJUST:
+ rgb_matrix_layer_helper(HSV_RED, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
+ break;
+ }
+ }
+}
+
+__attribute__((weak)) bool rgb_matrix_indicators_keymap(void) { return true; }
+void rgb_matrix_indicators_user(void) { rgb_matrix_indicators_keymap(); }
diff --git a/users/drashna/rgb/rgb_matrix_stuff.h b/users/drashna/rgb/rgb_matrix_stuff.h
new file mode 100644
index 0000000000..7c6f6c271e
--- /dev/null
+++ b/users/drashna/rgb/rgb_matrix_stuff.h
@@ -0,0 +1,15 @@
+// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+#include "quantum.h"
+
+bool process_record_user_rgb_matrix(uint16_t keycode, keyrecord_t *record);
+void keyboard_post_init_rgb_matrix(void);
+void matrix_scan_rgb_matrix(void);
+
+void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
+void rgb_matrix_layer_helper(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode, uint8_t speed, uint8_t led_type, uint8_t led_min, uint8_t led_max);
+
+bool rgb_matrix_indicators_advanced_keymap(uint8_t led_min, uint8_t led_max);
+bool rgb_matrix_indicators_keymap(void);
diff --git a/users/drashna/rgb/rgb_stuff.c b/users/drashna/rgb/rgb_stuff.c
new file mode 100644
index 0000000000..09071f7151
--- /dev/null
+++ b/users/drashna/rgb/rgb_stuff.c
@@ -0,0 +1,117 @@
+// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#ifdef RGBLIGHT_ENABLE
+
+# include "drashna.h"
+# include "rgb_stuff.h"
+# include "eeprom.h"
+
+bool has_initialized;
+
+void rgblight_sethsv_default_helper(uint8_t index) { rgblight_sethsv_at(rgblight_get_hue(), rgblight_get_sat(), rgblight_get_val(), index); }
+void rgblight_set_hsv_and_mode(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode) {
+ rgblight_sethsv_noeeprom(hue, sat, val);
+ // wait_us(175); // Add a slight delay between color and mode to ensure it's processed correctly
+ rgblight_mode_noeeprom(mode);
+}
+
+bool process_record_user_rgb_light(uint16_t keycode, keyrecord_t *record) { return true; }
+
+# if defined(RGBLIGHT_STARTUP_ANIMATION)
+static bool is_enabled;
+static bool is_rgblight_startup;
+static HSV old_hsv;
+static uint8_t old_mode;
+deferred_token rgb_startup_token;
+# endif
+
+uint32_t rgb_startup_animation(uint32_t triger_time, void *cb_arg) {
+ if (is_rgblight_startup && is_keyboard_master()) {
+ static uint8_t counter = 0;
+ counter++;
+ rgblight_sethsv_noeeprom((counter + old_hsv.h) % 255, 255, 255);
+ if (counter >= 255) {
+ is_rgblight_startup = false;
+ if (userspace_config.rgb_layer_change) {
+ layer_state_set_rgb_light(layer_state);
+ } else {
+ rgblight_set_hsv_and_mode(old_hsv.h, old_hsv.s, old_hsv.v, old_mode);
+ }
+ if (!is_enabled) {
+ rgblight_disable_noeeprom();
+ }
+ }
+ }
+ return is_rgblight_startup ? 10 : 0;
+}
+
+void keyboard_post_init_rgb_light(void) {
+# if defined(RGBLIGHT_STARTUP_ANIMATION)
+ is_enabled = rgblight_is_enabled();
+ if (userspace_config.rgb_layer_change) {
+ layer_state_set_rgb_light(layer_state);
+ }
+ old_hsv = rgblight_get_hsv();
+ old_mode = rgblight_get_mode();
+ rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
+ is_rgblight_startup = true;
+# endif
+ if (userspace_config.rgb_layer_change) {
+ layer_state_set_rgb_light(layer_state);
+ }
+ rgb_startup_token = defer_exec(300, rgb_startup_animation, NULL);
+
+}
+
+layer_state_t layer_state_set_rgb_light(layer_state_t state) {
+# ifdef RGBLIGHT_ENABLE
+ if (userspace_config.rgb_layer_change) {
+ switch (get_highest_layer(state | default_layer_state)) {
+ case _MOUSE: // mouse
+ if (!layer_state_cmp(state, _GAMEPAD) && !layer_state_cmp(state, _DIABLO)) {
+# if defined(RGBLIGHT_EFFECT_TWINKLE)
+ rgblight_set_hsv_and_mode(HSV_CHARTREUSE, RGBLIGHT_MODE_TWINKLE + 5);
+# else
+ rgblight_set_hsv_and_mode(HSV_CHARTREUSE, RGBLIGHT_MODE_BREATHING + 3);
+# endif
+ }
+ break;
+ case _MEDIA:
+ rgblight_set_hsv_and_mode(HSV_CHARTREUSE, RGBLIGHT_MODE_KNIGHT + 1);
+ break;
+ case _GAMEPAD:
+ rgblight_set_hsv_and_mode(HSV_ORANGE, RGBLIGHT_MODE_SNAKE + 2);
+ break;
+ case _DIABLO:
+ rgblight_set_hsv_and_mode(HSV_RED, RGBLIGHT_MODE_BREATHING + 3);
+ break;
+ case _RAISE:
+ rgblight_set_hsv_and_mode(HSV_YELLOW, RGBLIGHT_MODE_BREATHING + 3);
+ break;
+ case _LOWER:
+ rgblight_set_hsv_and_mode(HSV_GREEN, RGBLIGHT_MODE_BREATHING + 3);
+ break;
+ case _ADJUST:
+ rgblight_set_hsv_and_mode(HSV_RED, RGBLIGHT_MODE_KNIGHT + 2);
+ break;
+ case _DEFAULT_LAYER_1:
+ rgblight_set_hsv_and_mode(DEFAULT_LAYER_1_HSV, RGBLIGHT_MODE_STATIC_LIGHT);
+ break;
+ case _DEFAULT_LAYER_2:
+ rgblight_set_hsv_and_mode(DEFAULT_LAYER_2_HSV, RGBLIGHT_MODE_STATIC_LIGHT);
+ break;
+ case _DEFAULT_LAYER_3:
+ rgblight_set_hsv_and_mode(DEFAULT_LAYER_3_HSV, RGBLIGHT_MODE_STATIC_LIGHT);
+ break;
+ case _DEFAULT_LAYER_4:
+ rgblight_set_hsv_and_mode(DEFAULT_LAYER_4_HSV, RGBLIGHT_MODE_STATIC_LIGHT);
+ break;
+ }
+ }
+# endif // RGBLIGHT_ENABLE
+
+ return state;
+}
+
+#endif
diff --git a/users/drashna/rgb/rgb_stuff.h b/users/drashna/rgb/rgb_stuff.h
new file mode 100644
index 0000000000..d720275b60
--- /dev/null
+++ b/users/drashna/rgb/rgb_stuff.h
@@ -0,0 +1,12 @@
+// Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+#include "quantum.h"
+
+bool process_record_user_rgb_light(uint16_t keycode, keyrecord_t *record);
+void keyboard_post_init_rgb_light(void);
+void matrix_scan_rgb_light(void);
+layer_state_t layer_state_set_rgb_light(layer_state_t state);
+layer_state_t default_layer_state_set_rgb_light(layer_state_t state);
+void rgblight_sethsv_default_helper(uint8_t index);