aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-02-16 15:14:56 -0700
committerJack Sangdahl <[email protected]>2025-02-16 15:14:56 -0700
commit7c8b8e30e1dc5a5cac38bae4555bd5f1cd6512f8 (patch)
tree9ae1f84f09785e6357fc4d63fc6c01d9f8c4e878
parentd371171a4c574ebe419873d47a374e43ca7853fc (diff)
downloadqmk_me-7c8b8e30e1dc5a5cac38bae4555bd5f1cd6512f8.tar.gz
qmk_me-7c8b8e30e1dc5a5cac38bae4555bd5f1cd6512f8.zip
Re-add custom hsv_to_rgb implementaton
Fix bug with `OLED_FONT_H` in use with -Os Tidy crkbd keymap
-rw-r--r--jack/color.c140
-rw-r--r--jack/config.h14
-rw-r--r--jack/rules.mk3
-rw-r--r--keymaps/crkbd/keymap.c8
4 files changed, 142 insertions, 23 deletions
diff --git a/jack/color.c b/jack/color.c
new file mode 100644
index 0000000..9728d99
--- /dev/null
+++ b/jack/color.c
@@ -0,0 +1,140 @@
+// Copyright 2025 [email protected]
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include "color.h"
+#include <lib/lib8tion/lib8tion.h>
+
+#define K255 255
+#define K171 171
+#define K170 170
+#define K85 85
+
+// Adapted from https://fastled.io/docs/hsv2rgb_8cpp_source.html
+// void hsv2rgb_rainbow() function
+RGB rgb_matrix_hsv_to_rgb(const HSV hsv) {
+ // Yellow has a higher inherent brightness than
+ // any other color; 'pure' yellow is perceived to
+ // be 93% as bright as white. In order to make
+ // yellow appear the correct relative brightness,
+ // it has to be rendered brighter than all other
+ // colors.
+ const uint8_t hue = hsv.h;
+ const uint8_t sat = hsv.s;
+ uint8_t val = hsv.v;
+
+ // offset8 = (hue [0..31]) * 8
+ uint8_t offset8 = hue & 0x1F;
+ offset8 <<= 3;
+
+ uint8_t third = scale8(offset8, (256 / 3)); // max = 85
+ uint8_t r, g, b;
+ if (!(hue & 0x80)) {
+ // 0XX
+ if (!(hue & 0x40)) {
+ // 00X
+ // section 0-1
+ if (!(hue & 0x20)) {
+ // 000
+ // case 0: // R -> O
+ r = K255 - third;
+ g = third;
+ b = 0;
+ } else {
+ // 001
+ // case 1: // O -> Y
+ r = K171;
+ g = K85 + third;
+ b = 0;
+ }
+ } else {
+ // 01X
+ // section 2-3
+ if (!(hue & 0x20)) {
+ // 010
+ // case 2: // Y -> G
+ // uint8_t twothirds = (third << 1);
+ uint8_t twothirds = scale8(offset8, ((256 * 2) / 3)); // max=170
+ r = K171 - twothirds;
+ g = K170 + third;
+ b = 0;
+ } else {
+ // 011
+ // case 3: // G -> A
+ r = 0;
+ g = K255 - third;
+ b = third;
+ }
+ }
+ } else {
+ // section 4-7
+ // 1XX
+ if (!(hue & 0x40)) {
+ // 10X
+ if (!(hue & 0x20)) {
+ // 100
+ // case 4: // A -> B
+ r = 0;
+ // uint8_t twothirds = (third << 1);
+ uint8_t twothirds = scale8(offset8, ((256 * 2) / 3)); // max=170
+ g = K171 - twothirds; // K170?
+ b = K85 + twothirds;
+ } else {
+ // 101
+ // case 5: // B -> P
+ r = third;
+ g = 0;
+ b = K255 - third;
+ }
+ } else {
+ if (!(hue & 0x20)) {
+ // 110
+ // case 6: // P -- K
+ r = K85 + third;
+ g = 0;
+ b = K171 - third;
+ } else {
+ // 111
+ // case 7: // K -> R
+ r = K170 + third;
+ g = 0;
+ b = K85 - third;
+ }
+ }
+ }
+ // This is one of the good places to scale the green down,
+ // although the client can scale green down as well.
+ g >>= 1;
+ // Scale down colors if we're desaturated at all
+ // and add the brightness_floor to r, g, and b.
+ if (sat != 255) {
+ if (sat == 0) {
+ r = 255;
+ b = 255;
+ g = 255;
+ } else {
+ uint8_t desat = 255 - sat;
+ desat = scale8_video(desat, desat);
+ uint8_t satscale = 255 - desat;
+ r = scale8(r, satscale);
+ g = scale8(g, satscale);
+ b = scale8(b, satscale);
+ uint8_t brightness_floor = desat;
+ r += brightness_floor;
+ g += brightness_floor;
+ b += brightness_floor;
+ }
+ }
+ // Now scale everything down if we're at value < 255.
+ if (val != 255) {
+ val = scale8_video(val, val);
+ if (val == 0) {
+ r = 0;
+ g = 0;
+ b = 0;
+ } else {
+ r = scale8(r, val);
+ g = scale8(g, val);
+ b = scale8(b, val);
+ }
+ }
+ return (RGB){.r = r, .g = g, .b = b};
+}
diff --git a/jack/config.h b/jack/config.h
index e1e631a..3017f4d 100644
--- a/jack/config.h
+++ b/jack/config.h
@@ -35,21 +35,7 @@
#ifdef RGB_MATRIX_ENABLE
#define RGB_MATRIX_SLEEP
#define RGB_MATRIX_TIMEOUT 300000
-#undef RGB_MATRIX_DEFAULT_MODE
-#define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_ALPHAS_MODS
-#define ENABLE_RGB_MATRIX_ALPHAS_MODS
-#define ENABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT
-#define ENABLE_RGB_MATRIX_CYCLE_SPIRAL
-#define ENABLE_RGB_MATRIX_RAINDROPS
-#define ENABLE_RGB_MATRIX_FRAMEBUFFER_EFFECTS
-#define ENABLE_RGB_MATRIX_TYPING_HEATMAP
-#define ENABLE_RGB_MATRIX_KEYPRESSES
-#define ENABLE_RGB_MATRIX_SOLID_REACTIVE
-#define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH
-#define ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
-#define ENABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
#define RGB_MATRIX_KEYPRESSES
-#define ENABLE_RGB_MATRIX_SOLID_REACTIVE
#define PALETTEFX_ENABLE_ALL_EFFECTS
#define PALETTEFX_ENABLE_ALL_PALETTES
#endif
diff --git a/jack/rules.mk b/jack/rules.mk
index 26f8f6b..7c6548a 100644
--- a/jack/rules.mk
+++ b/jack/rules.mk
@@ -27,6 +27,7 @@ endif
ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes)
RGB_MATRIX_CUSTOM_USER = yes
+ SRC += color.c
endif
ifeq ($(strip $(UNICODE_COMMON)), yes)
@@ -40,7 +41,7 @@ ifeq ($(strip $(CUSTOM_TAP_CODE_ENABLE)), yes)
endif
ifeq ($(PLATFORM), CHIBIOS)
- EXTRAFLAGS += -Os
+ EXTRAFLAGS += -O3
endif
ifneq ($(findstring Gentoo, $(shell arm-none-eabi-gcc --version)),)
diff --git a/keymaps/crkbd/keymap.c b/keymaps/crkbd/keymap.c
index eca3a2a..1e634ab 100644
--- a/keymaps/crkbd/keymap.c
+++ b/keymaps/crkbd/keymap.c
@@ -109,12 +109,4 @@ void matrix_init_user(void) {
4, 4, 4, 2, 2, 2, 2, 2, 2, 1, 1, 1, 4, 4, 4, 4, 4, 1,
1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 1, 2, 2, 2, 2, 2, 2}};
}
-
-bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
- rgb_matrix_sethsv_noeeprom(43, 255, 120);
- for (uint8_t i = led_min; i <= led_max; i++)
- if (g_led_config.flags[i] & LED_FLAG_UNDERGLOW)
- rgb_matrix_set_color(i, RGB_RED);
- return false;
-}
#endif // rgb matrix