From c9b71e25fb3558bd341e6d335aae3857d6bb3c50 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Wed, 14 Dec 2016 21:00:37 +0900 Subject: [PATCH] kimera: Some minor fixes for RGB LED --- keyboard/kimera/Makefile | 1 + keyboard/kimera/config.h | 1 - keyboard/kimera/keymap_default.c | 2 ++ keyboard/kimera/keymap_two_headed.c | 31 +++++++++++++++++++++++++++++ keyboard/kimera/matrix.c | 2 ++ keyboard/kimera/rgb.c | 23 ++++++++++++++++----- 6 files changed, 54 insertions(+), 6 deletions(-) diff --git a/keyboard/kimera/Makefile b/keyboard/kimera/Makefile index 227af26a..fb0bc572 100644 --- a/keyboard/kimera/Makefile +++ b/keyboard/kimera/Makefile @@ -129,6 +129,7 @@ endif ifdef DEFS OPT_DEFS += $(foreach DEF,$(DEFS),-D$(DEF)) endif +OPT_DEFS += -DRGB_LED_ENABLE # Build Options # comment out to disable the options. diff --git a/keyboard/kimera/config.h b/keyboard/kimera/config.h index 400da69a..2ae301f6 100644 --- a/keyboard/kimera/config.h +++ b/keyboard/kimera/config.h @@ -57,7 +57,6 @@ along with this program. If not, see . /* enable customized backlight logic */ #define BACKLIGHT_CUSTOM #define CUSTOM_LED_ENABLE -#define RGB_LED_ENABLE /* number of leds */ #define LED_COUNT 4 diff --git a/keyboard/kimera/keymap_default.c b/keyboard/kimera/keymap_default.c index 7e750b4f..418537ca 100644 --- a/keyboard/kimera/keymap_default.c +++ b/keyboard/kimera/keymap_default.c @@ -61,6 +61,7 @@ enum function_id { void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) { +#ifdef RGB_LED_ENABLE if (record->event.pressed) { switch (id) { case AF_RGB_TOGGLE: @@ -77,5 +78,6 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) break; } } +#endif } #endif diff --git a/keyboard/kimera/keymap_two_headed.c b/keyboard/kimera/keymap_two_headed.c index 6f09142d..5d42c42e 100644 --- a/keyboard/kimera/keymap_two_headed.c +++ b/keyboard/kimera/keymap_two_headed.c @@ -60,3 +60,34 @@ uint16_t fn_actions_count(void) { return sizeof(fn_actions) / sizeof(fn_actions[0]); } #endif + +#ifndef NO_ACTION_FUNCTION +enum function_id { + AF_RGB_TOGGLE = 0, + AF_RGB_DECREASE, + AF_RGB_INCREASE, + AF_RGB_STEP +}; + +void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) +{ +#ifdef RGB_LED_ENABLE + if (record->event.pressed) { + switch (id) { + case AF_RGB_TOGGLE: + rgb_toggle(); + break; + case AF_RGB_DECREASE: + rgb_decrease(); + break; + case AF_RGB_INCREASE: + rgb_increase(); + break; + case AF_RGB_STEP: + rgb_step(); + break; + } + } +#endif +} +#endif diff --git a/keyboard/kimera/matrix.c b/keyboard/kimera/matrix.c index 752d09ec..769d2ffb 100644 --- a/keyboard/kimera/matrix.c +++ b/keyboard/kimera/matrix.c @@ -77,6 +77,8 @@ void matrix_init(void) kimera_init(); kimera_scan_timestamp = timer_read(); + rgb_init(); + // initialize row and col kimera_unselect_rows(); diff --git a/keyboard/kimera/rgb.c b/keyboard/kimera/rgb.c index 4954a996..460c1921 100644 --- a/keyboard/kimera/rgb.c +++ b/keyboard/kimera/rgb.c @@ -40,7 +40,9 @@ static void rgb_write_config(void); static void rgb_read_config(void); static void rgb_set_level(uint8_t level); static void rgb_refresh(void); +#if 0 static void hue_to_rgb(uint16_t hue, struct cRGB *rgb); +#endif static void hsb_to_rgb(uint16_t hue, uint8_t saturation, uint8_t brightness, struct cRGB *rgb); void rgb_init(void) @@ -63,7 +65,7 @@ void rgb_read_config(void) void rgb_write_config(void) { - eeprom_write_byte(EECONFIG_RGB, rgb_config.raw); + eeprom_update_byte(EECONFIG_RGB, rgb_config.raw); } void rgb_toggle(void) @@ -118,19 +120,28 @@ void rgb_step(void) rgb_config.level = 0; } rgb_config.enable = (rgb_config.level != 0); + rgb_write_config(); rgb_set_level(rgb_config.level); } void rgb_set_level(uint8_t level) { dprintf("RGB Level: %d\n", level); + if (level == RGB_OFF) { + rgb_brightness = 0; + } + else if (backlight_config.enable) { + if (backlight_config.level >= 1 && backlight_config.level <= 3) { + rgb_brightness = backlight_brightness; + } + } + else { + rgb_brightness = 16; + } if (level <= RGB_WHITE) { rgb_fading_enable = 0; rgb_rainbow = 0; - if (level == RGB_OFF) { - rgb_brightness = 0; - } - else { + if (level != RGB_OFF) { if (level == RGB_WHITE) { rgb_saturation = 0; } @@ -186,6 +197,7 @@ void rgb_refresh(void) ws2812_setleds(rgb_color, RGB_LED_COUNT); } +#if 0 void hue_to_rgb(uint16_t hue, struct cRGB *rgb) { uint8_t hi = hue / 60; @@ -200,6 +212,7 @@ void hue_to_rgb(uint16_t hue, struct cRGB *rgb) case 5: rgb->r = 255; rgb->g = 0; rgb->b = q; break; } } +#endif /* * original code: https://blog.adafruit.com/2012/03/14/constant-brightness-hsb-to-rgb-algorithm/