diff --git a/keyboards/planck/light/light.c b/keyboards/planck/light/light.c index eda9b0fa..67be5d11 100644 --- a/keyboards/planck/light/light.c +++ b/keyboards/planck/light/light.c @@ -82,8 +82,8 @@ const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = { /*{row | col << 4} | {x=0..224, y=0..64} - | | modifier - | | | */ + | | modifier + | | | */ {{0|(0<<4)}, {20.36*0, 21.33*0}, 1}, {{0|(1<<4)}, {20.36*1, 21.33*0}, 0}, {{0|(2<<4)}, {20.36*2, 21.33*0}, 0}, @@ -110,32 +110,32 @@ const rgb_led g_rgb_leds[DRIVER_LED_TOTAL] = { {{1|(10<<4)}, {20.36*10,21.33*1}, 0}, {{1|(11<<4)}, {20.36*11,21.33*1}, 1}, - {{2|(0<<4)}, {20.36*0, 21.33*2}, 1}, - {{2|(1<<4)}, {20.36*1, 21.33*2}, 0}, - {{2|(2<<4)}, {20.36*2, 21.33*2}, 0}, - {{2|(3<<4)}, {20.36*3, 21.33*2}, 0}, - {{2|(4<<4)}, {20.36*4, 21.33*2}, 0}, - {{2|(5<<4)}, {20.36*5, 21.33*2}, 0}, - {{2|(6<<4)}, {20.36*6, 21.33*2}, 0}, - {{2|(7<<4)}, {20.36*7, 21.33*2}, 0}, - {{2|(8<<4)}, {20.36*8, 21.33*2}, 0}, - {{2|(9<<4)}, {20.36*9, 21.33*2}, 0}, - {{2|(10<<4)}, {20.36*10,21.33*2}, 0}, - {{2|(11<<4)}, {20.36*11,21.33*2}, 1}, - - {{3|(0<<4)}, {20.36*0, 21.33*3}, 1}, - {{3|(1<<4)}, {20.36*1, 21.33*3}, 1}, - {{3|(2<<4)}, {20.36*2, 21.33*3}, 1}, - {{3|(3<<4)}, {20.36*3, 21.33*3}, 1}, - {{3|(4<<4)}, {20.36*4, 21.33*3}, 1}, - {{3|(5<<4)}, {20.36*5, 21.33*3}, 0}, - {{3|(5<<4)}, {20.36*5.5, 21.33*3}, 0}, - {{3|(6<<4)}, {20.36*6, 21.33*3}, 0}, - {{3|(7<<4)}, {20.36*7, 21.33*3}, 1}, - {{3|(8<<4)}, {20.36*8, 21.33*3}, 1}, - {{3|(9<<4)}, {20.36*9, 21.33*3}, 1}, - {{3|(10<<4)}, {20.36*10,21.33*3}, 1}, - {{3|(11<<4)}, {20.36*11,21.33*3}, 1} + {{2|(0<<4)}, {20.36*0, 21.33*2}, 1}, + {{2|(1<<4)}, {20.36*1, 21.33*2}, 0}, + {{2|(2<<4)}, {20.36*2, 21.33*2}, 0}, + {{2|(3<<4)}, {20.36*3, 21.33*2}, 0}, + {{2|(4<<4)}, {20.36*4, 21.33*2}, 0}, + {{2|(5<<4)}, {20.36*5, 21.33*2}, 0}, + {{2|(6<<4)}, {20.36*6, 21.33*2}, 0}, + {{2|(7<<4)}, {20.36*7, 21.33*2}, 0}, + {{2|(8<<4)}, {20.36*8, 21.33*2}, 0}, + {{2|(9<<4)}, {20.36*9, 21.33*2}, 0}, + {{2|(10<<4)}, {20.36*10,21.33*2}, 0}, + {{2|(11<<4)}, {20.36*11,21.33*2}, 1}, + + {{3|(0<<4)}, {20.36*0, 21.33*3}, 1}, + {{3|(1<<4)}, {20.36*1, 21.33*3}, 1}, + {{3|(2<<4)}, {20.36*2, 21.33*3}, 1}, + {{3|(3<<4)}, {20.36*3, 21.33*3}, 1}, + {{3|(4<<4)}, {20.36*4, 21.33*3}, 1}, + {{3|(5<<4)}, {20.36*5, 21.33*3}, 0}, + {{3|(5<<4)}, {20.36*5.5,21.33*3}, 0}, + {{3|(6<<4)}, {20.36*6, 21.33*3}, 0}, + {{3|(7<<4)}, {20.36*7, 21.33*3}, 1}, + {{3|(8<<4)}, {20.36*8, 21.33*3}, 1}, + {{3|(9<<4)}, {20.36*9, 21.33*3}, 1}, + {{3|(10<<4)}, {20.36*10,21.33*3}, 1}, + {{3|(11<<4)}, {20.36*11,21.33*3}, 1} }; void matrix_init_kb(void) { diff --git a/quantum/rgb.h b/quantum/rgb.h index 792b6308..fbdda293 100644 --- a/quantum/rgb.h +++ b/quantum/rgb.h @@ -23,6 +23,9 @@ void rgblight_toggle(void) {}; __attribute__((weak)) void rgblight_step(void) {}; +__attribute__((weak)) +void rgblight_step_reverse(void) {}; + __attribute__((weak)) void rgblight_increase_hue(void) {}; diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index eee10306..cef5e193 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -27,19 +27,17 @@ #include "lufa.h" #include -#define BACKLIGHT_EFFECT_MAX 17 - -rgb_matrix_config g_config = { - .enabled = 1, - .brightness = 255, - .effect = 7, - .color_1 = { .h = 130, .s = 255, .v = 255 }, - .color_2 = { .h = 70, .s = 255, .v = 255 }, - .caps_lock_indicator = { .color = { .h = 0, .s = 0, .v = 255 }, .index = 255 }, - .layer_1_indicator = { .color = { .h = 0, .s = 0, .v = 255 }, .index = 255 }, - .layer_2_indicator = { .color = { .h = 0, .s = 0, .v = 255 }, .index = 255 }, - .layer_3_indicator = { .color = { .h = 0, .s = 0, .v = 255 }, .index = 255 }, -}; +#define RGB_MATRIX_EFFECT_MAX 17 + +rgb_config_t rgb_matrix_config; + +#ifndef RGB_DISABLE_AFTER_TIMEOUT + #define RGB_DISABLE_AFTER_TIMEOUT 0 +#endif + +#ifndef RGB_DISABLE_WHEN_USB_SUSPENDED + #define RGB_DISABLE_WHEN_USB_SUSPENDED false +#endif bool g_suspend_state = false; uint8_t g_indicator_state = 0; @@ -57,12 +55,35 @@ uint32_t g_any_key_hit = 0; #define PI 3.14159265 #endif +uint32_t eeconfig_read_rgblight(void) { + return eeprom_read_dword(EECONFIG_RGBLIGHT); +} +void eeconfig_update_rgblight(uint32_t val) { + eeprom_update_dword(EECONFIG_RGBLIGHT, val); +} +void eeconfig_update_rgblight_default(void) { + dprintf("eeconfig_update_rgblight_default\n"); + rgb_matrix_config.enable = 1; + rgb_matrix_config.mode = 7; + rgb_matrix_config.hue = 0; + rgb_matrix_config.sat = 255; + rgb_matrix_config.val = 255; + eeconfig_update_rgblight(rgb_matrix_config.raw); +} +void eeconfig_debug_rgblight(void) { + dprintf("rgb_matrix_config eprom\n"); + dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable); + dprintf("rghlight_config.mode = %d\n", rgb_matrix_config.mode); + dprintf("rgb_matrix_config.hue = %d\n", rgb_matrix_config.hue); + dprintf("rgb_matrix_config.sat = %d\n", rgb_matrix_config.sat); + dprintf("rgb_matrix_config.val = %d\n", rgb_matrix_config.val); +} + // Last led hit #define LED_HITS_TO_REMEMBER 8 uint8_t g_last_led_hit[LED_HITS_TO_REMEMBER] = {255}; uint8_t g_last_led_count = 0; - void map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i, uint8_t *led_count) { rgb_led led; @@ -249,7 +270,7 @@ void backlight_effect_all_off(void) // Solid color void backlight_effect_solid_color(void) { - HSV hsv = { .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness }; + HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; RGB rgb = hsv_to_rgb( hsv ); backlight_set_color_all( rgb.r, rgb.g, rgb.b ); } @@ -262,7 +283,7 @@ void backlight_effect_solid_reactive(void) uint16_t offset2 = g_key_hit[i]<<2; offset2 = (offset2<=130) ? (130-offset2) : 0; - HSV hsv = { .h = g_config.color_1.h+offset2, .s = 255, .v = g_config.brightness }; + HSV hsv = { .h = rgb_matrix_config.hue+offset2, .s = 255, .v = rgb_matrix_config.val }; RGB rgb = hsv_to_rgb( hsv ); backlight_set_color( i, rgb.r, rgb.g, rgb.b ); } @@ -271,8 +292,8 @@ void backlight_effect_solid_reactive(void) // alphas = color1, mods = color2 void backlight_effect_alphas_mods(void) { - RGB rgb1 = hsv_to_rgb( (HSV){ .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness } ); - RGB rgb2 = hsv_to_rgb( (HSV){ .h = g_config.color_2.h, .s = g_config.color_2.s, .v = g_config.brightness } ); + RGB rgb1 = hsv_to_rgb( (HSV){ .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val } ); + RGB rgb2 = hsv_to_rgb( (HSV){ .h = (rgb_matrix_config.hue + 180) % 360, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val } ); rgb_led led; for (int i = 0; i < DRIVER_LED_TOTAL; i++) { @@ -292,8 +313,8 @@ void backlight_effect_alphas_mods(void) void backlight_effect_gradient_up_down(void) { - int16_t h1 = g_config.color_1.h; - int16_t h2 = g_config.color_2.h; + int16_t h1 = rgb_matrix_config.hue; + int16_t h2 = (rgb_matrix_config.hue + 180) % 360; int16_t deltaH = h2 - h1; // Take the shortest path between hues @@ -308,11 +329,11 @@ void backlight_effect_gradient_up_down(void) // Divide delta by 4, this gives the delta per row deltaH /= 4; - int16_t s1 = g_config.color_1.s; - int16_t s2 = g_config.color_2.s; + int16_t s1 = rgb_matrix_config.sat; + int16_t s2 = rgb_matrix_config.hue; int16_t deltaS = ( s2 - s1 ) / 4; - HSV hsv = { .h = 0, .s = 255, .v = g_config.brightness }; + HSV hsv = { .h = 0, .s = 255, .v = rgb_matrix_config.val }; RGB rgb; Point point; for ( int i=0; i>4); // Relies on hue being 8-bit and wrapping - hsv.h = g_config.color_1.h + ( deltaH * y ); - hsv.s = g_config.color_1.s + ( deltaS * y ); + hsv.h = rgb_matrix_config.hue + ( deltaH * y ); + hsv.s = rgb_matrix_config.sat + ( deltaS * y ); rgb = hsv_to_rgb( hsv ); backlight_set_color( i, rgb.r, rgb.g, rgb.b ); } @@ -331,8 +352,8 @@ void backlight_effect_gradient_up_down(void) void backlight_effect_raindrops(bool initialize) { - int16_t h1 = g_config.color_1.h; - int16_t h2 = g_config.color_2.h; + int16_t h1 = rgb_matrix_config.hue; + int16_t h2 = (rgb_matrix_config.hue + 180) % 360; int16_t deltaH = h2 - h1; deltaH /= 4; @@ -346,8 +367,8 @@ void backlight_effect_raindrops(bool initialize) deltaH += 256; } - int16_t s1 = g_config.color_1.s; - int16_t s2 = g_config.color_2.s; + int16_t s1 = rgb_matrix_config.sat; + int16_t s2 = rgb_matrix_config.sat; int16_t deltaS = ( s2 - s1 ) / 4; HSV hsv; @@ -365,7 +386,7 @@ void backlight_effect_raindrops(bool initialize) hsv.h = h1 + ( deltaH * ( rand() & 0x03 ) ); hsv.s = s1 + ( deltaS * ( rand() & 0x03 ) ); // Override brightness with global brightness control - hsv.v = g_config.brightness;; + hsv.v = rgb_matrix_config.val; rgb = hsv_to_rgb( hsv ); backlight_set_color( i, rgb.r, rgb.g, rgb.b ); @@ -388,7 +409,7 @@ void backlight_effect_cycle_all(void) uint16_t offset2 = g_key_hit[i]<<2; offset2 = (offset2<=63) ? (63-offset2) : 0; - HSV hsv = { .h = offset+offset2, .s = 255, .v = g_config.brightness }; + HSV hsv = { .h = offset+offset2, .s = 255, .v = rgb_matrix_config.val }; RGB rgb = hsv_to_rgb( hsv ); backlight_set_color( i, rgb.r, rgb.g, rgb.b ); } @@ -398,7 +419,7 @@ void backlight_effect_cycle_all(void) void backlight_effect_cycle_left_right(void) { uint8_t offset = g_tick & 0xFF; - HSV hsv = { .h = 0, .s = 255, .v = g_config.brightness }; + HSV hsv = { .h = 0, .s = 255, .v = rgb_matrix_config.val }; RGB rgb; Point point; rgb_led led; @@ -423,7 +444,7 @@ void backlight_effect_cycle_left_right(void) void backlight_effect_cycle_up_down(void) { uint8_t offset = g_tick & 0xFF; - HSV hsv = { .h = 0, .s = 255, .v = g_config.brightness }; + HSV hsv = { .h = 0, .s = 255, .v = rgb_matrix_config.val }; RGB rgb; Point point; rgb_led led; @@ -447,50 +468,50 @@ void backlight_effect_cycle_up_down(void) void backlight_effect_dual_beacon(void) { - HSV hsv = { .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness }; + HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; RGB rgb; rgb_led led; for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { led = g_rgb_leds[i]; - hsv.h = ((led.point.y - 32.0)* cos(g_tick * PI / 128) / 32 + (led.point.x - 112.0) * sin(g_tick * PI / 128) / (112)) * (g_config.color_2.h - g_config.color_1.h) + g_config.color_1.h; + hsv.h = ((led.point.y - 32.0)* cos(g_tick * PI / 128) / 32 + (led.point.x - 112.0) * sin(g_tick * PI / 128) / (112)) * (180) + rgb_matrix_config.hue; rgb = hsv_to_rgb( hsv ); backlight_set_color( i, rgb.r, rgb.g, rgb.b ); } } void backlight_effect_rainbow_beacon(void) { - HSV hsv = { .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness }; + HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; RGB rgb; rgb_led led; for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { led = g_rgb_leds[i]; - hsv.h = 1.5 * (led.point.y - 32.0)* cos(g_tick * PI / 128) + 1.5 * (led.point.x - 112.0) * sin(g_tick * PI / 128) + g_config.color_1.h; + hsv.h = 1.5 * (led.point.y - 32.0)* cos(g_tick * PI / 128) + 1.5 * (led.point.x - 112.0) * sin(g_tick * PI / 128) + rgb_matrix_config.hue; rgb = hsv_to_rgb( hsv ); backlight_set_color( i, rgb.r, rgb.g, rgb.b ); } } void backlight_effect_rainbow_pinwheels(void) { - HSV hsv = { .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness }; + HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; RGB rgb; rgb_led led; for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { led = g_rgb_leds[i]; - hsv.h = 2 * (led.point.y - 32.0)* cos(g_tick * PI / 128) + 2 * (66 - abs(led.point.x - 112.0)) * sin(g_tick * PI / 128) + g_config.color_1.h; + hsv.h = 2 * (led.point.y - 32.0)* cos(g_tick * PI / 128) + 2 * (66 - abs(led.point.x - 112.0)) * sin(g_tick * PI / 128) + rgb_matrix_config.hue; rgb = hsv_to_rgb( hsv ); backlight_set_color( i, rgb.r, rgb.g, rgb.b ); } } void backlight_effect_rainbow_moving_chevron(void) { - HSV hsv = { .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness }; + HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; RGB rgb; rgb_led led; for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { led = g_rgb_leds[i]; // uint8_t r = g_tick; uint8_t r = 32; - hsv.h = 1.5 * abs(led.point.y - 32.0)* sin(r * PI / 128) + 1.5 * (led.point.x - (g_tick / 256.0 * 224)) * cos(r * PI / 128) + g_config.color_1.h; + hsv.h = 1.5 * abs(led.point.y - 32.0)* sin(r * PI / 128) + 1.5 * (led.point.x - (g_tick / 256.0 * 224)) * cos(r * PI / 128) + rgb_matrix_config.hue; rgb = hsv_to_rgb( hsv ); backlight_set_color( i, rgb.r, rgb.g, rgb.b ); } @@ -514,7 +535,7 @@ void backlight_effect_jellybean_raindrops( bool initialize ) hsv.h = rand() & 0xFF; hsv.s = rand() & 0xFF; // Override brightness with global brightness control - hsv.v = g_config.brightness;; + hsv.v = rgb_matrix_config.val; rgb = hsv_to_rgb( hsv ); backlight_set_color( i, rgb.r, rgb.g, rgb.b ); @@ -524,7 +545,7 @@ void backlight_effect_jellybean_raindrops( bool initialize ) void backlight_effect_multisplash(void) { // if (g_any_key_hit < 0xFF) { - HSV hsv = { .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness }; + HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; RGB rgb; rgb_led led; for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { @@ -542,7 +563,7 @@ void backlight_effect_multisplash(void) { // } else { // d = 255; // } - hsv.h = (g_config.color_1.h + c) % 256; + hsv.h = (rgb_matrix_config.hue + c) % 256; hsv.v = MAX(MIN(d, 255), 0); rgb = hsv_to_rgb( hsv ); backlight_set_color( i, rgb.r, rgb.g, rgb.b ); @@ -561,7 +582,7 @@ void backlight_effect_splash(void) { void backlight_effect_solid_multisplash(void) { // if (g_any_key_hit < 0xFF) { - HSV hsv = { .h = g_config.color_1.h, .s = g_config.color_1.s, .v = g_config.brightness }; + HSV hsv = { .h = rgb_matrix_config.hue, .s = rgb_matrix_config.sat, .v = rgb_matrix_config.val }; RGB rgb; rgb_led led; for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { @@ -593,95 +614,24 @@ void backlight_effect_solid_splash(void) { backlight_effect_solid_multisplash(); } -void backlight_effect_custom(void) -{ - HSV hsv; - RGB rgb; - for ( int i=0; i 0 && g_any_key_hit > g_config.disable_after_timeout * 60 * 20)); - uint8_t effect = suspend_backlight ? 0 : g_config.effect; + bool suspend_backlight = ((g_suspend_state && RGB_DISABLE_WHEN_USB_SUSPENDED) || + (RGB_DISABLE_AFTER_TIMEOUT > 0 && g_any_key_hit > RGB_DISABLE_AFTER_TIMEOUT * 60 * 20)); + uint8_t effect = suspend_backlight ? 0 : rgb_matrix_config.mode; // Keep track of the effect used last time, // detect change in effect, so each effect can @@ -816,16 +766,6 @@ void backlight_rgb_task(void) { // } // } -void backlight_config_load(void) -{ - eeprom_read_block( &g_config, EEPROM_BACKLIGHT_CONFIG_ADDR, sizeof(rgb_matrix_config) ); -} - -void backlight_config_save(void) -{ - eeprom_update_block( &g_config, EEPROM_BACKLIGHT_CONFIG_ADDR, sizeof(rgb_matrix_config) ); -} - void backlight_init_drivers(void) { //sei(); @@ -851,6 +791,20 @@ void backlight_init_drivers(void) { g_key_hit[led] = 255; } + + + if (!eeconfig_is_enabled()) { + dprintf("backlight_init_drivers eeconfig is not enabled.\n"); + eeconfig_init(); + eeconfig_update_rgblight_default(); + } + rgb_matrix_config.raw = eeconfig_read_rgblight(); + if (!rgb_matrix_config.mode) { + dprintf("backlight_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n"); + eeconfig_update_rgblight_default(); + rgb_matrix_config.raw = eeconfig_read_rgblight(); + } + eeconfig_debug_rgblight(); // display current eeprom values } // Deals with the messy details of incrementing an integer @@ -868,106 +822,34 @@ uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) return MIN( MAX( new_value, min ), max ); } -void backlight_effect_increase(void) -{ - g_config.effect = increment( g_config.effect, 1, 0, BACKLIGHT_EFFECT_MAX ); - backlight_config_save(); -} - -void backlight_effect_decrease(void) -{ - g_config.effect = decrement( g_config.effect, 1, 0, BACKLIGHT_EFFECT_MAX ); - backlight_config_save(); -} - -void backlight_brightness_increase(void) -{ - g_config.brightness = increment( g_config.brightness, 8, 0, 255 ); - backlight_config_save(); -} - -void backlight_brightness_decrease(void) -{ - g_config.brightness = decrement( g_config.brightness, 8, 0, 255 ); - backlight_config_save(); -} - -void backlight_color_1_hue_increase(void) -{ - g_config.color_1.h = increment( g_config.color_1.h, 8, 0, 255 ); - backlight_config_save(); -} - -void backlight_color_1_hue_decrease(void) -{ - g_config.color_1.h = decrement( g_config.color_1.h, 8, 0, 255 ); - backlight_config_save(); -} - -void backlight_color_1_sat_increase(void) -{ - g_config.color_1.s = increment( g_config.color_1.s, 8, 0, 255 ); - backlight_config_save(); -} - -void backlight_color_1_sat_decrease(void) -{ - g_config.color_1.s = decrement( g_config.color_1.s, 8, 0, 255 ); - backlight_config_save(); -} - -void backlight_color_2_hue_increase(void) -{ - g_config.color_2.h = increment( g_config.color_2.h, 8, 0, 255 ); - backlight_config_save(); -} - -void backlight_color_2_hue_decrease(void) -{ - g_config.color_2.h = decrement( g_config.color_2.h, 8, 0, 255 ); - backlight_config_save(); -} - -void backlight_color_2_sat_increase(void) -{ - g_config.color_2.s = increment( g_config.color_2.s, 8, 0, 255 ); - backlight_config_save(); -} - -void backlight_color_2_sat_decrease(void) -{ - g_config.color_2.s = decrement( g_config.color_2.s, 8, 0, 255 ); - backlight_config_save(); -} - -void *backlight_get_custom_key_color_eeprom_address( uint8_t led ) -{ - // 3 bytes per color - return EEPROM_BACKLIGHT_KEY_COLOR_ADDR + ( led * 3 ); -} +// void *backlight_get_custom_key_color_eeprom_address( uint8_t led ) +// { +// // 3 bytes per color +// return EECONFIG_RGBLIGHT + ( led * 3 ); +// } -void backlight_get_key_color( uint8_t led, HSV *hsv ) -{ - void *address = backlight_get_custom_key_color_eeprom_address( led ); - hsv->h = eeprom_read_byte(address); - hsv->s = eeprom_read_byte(address+1); - hsv->v = eeprom_read_byte(address+2); -} +// void backlight_get_key_color( uint8_t led, HSV *hsv ) +// { +// void *address = backlight_get_custom_key_color_eeprom_address( led ); +// hsv->h = eeprom_read_byte(address); +// hsv->s = eeprom_read_byte(address+1); +// hsv->v = eeprom_read_byte(address+2); +// } -void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv ) -{ - uint8_t led[8], led_count; - map_row_column_to_led(row,column,led,&led_count); - for(uint8_t i = 0; i < led_count; i++) { - if ( led[i] < DRIVER_LED_TOTAL ) - { - void *address = backlight_get_custom_key_color_eeprom_address(led[i]); - eeprom_update_byte(address, hsv.h); - eeprom_update_byte(address+1, hsv.s); - eeprom_update_byte(address+2, hsv.v); - } - } -} +// void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv ) +// { +// uint8_t led[8], led_count; +// map_row_column_to_led(row,column,led,&led_count); +// for(uint8_t i = 0; i < led_count; i++) { +// if ( led[i] < DRIVER_LED_TOTAL ) +// { +// void *address = backlight_get_custom_key_color_eeprom_address(led[i]); +// eeprom_update_byte(address, hsv.h); +// eeprom_update_byte(address+1, hsv.s); +// eeprom_update_byte(address+2, hsv.v); +// } +// } +// } void backlight_test_led( uint8_t index, bool red, bool green, bool blue ) { @@ -989,73 +871,58 @@ uint32_t backlight_get_tick(void) return g_tick; } -void backlight_debug_led( bool state ) -{ - // if (state) - // { - // // Output high. - // DDRD |= (1<<6); - // PORTD |= (1<<6); - // } - // else - // { - // // Output low. - // DDRD &= ~(1<<6); - // PORTD &= ~(1<<6); - // } -} - void rgblight_toggle(void) { - g_config.enabled ^= 1; - backlight_config_save(); + rgb_matrix_config.enable ^= 1; + eeconfig_update_rgblight(rgb_matrix_config.raw); } void rgblight_step(void) { - g_config.effect = (g_config.effect + 1) % (BACKLIGHT_EFFECT_MAX + 1); - backlight_config_save(); + rgb_matrix_config.mode = (rgb_matrix_config.mode + 1) % (RGB_MATRIX_EFFECT_MAX + 1); + eeconfig_update_rgblight(rgb_matrix_config.raw); } void rgblight_step_reverse(void) { - g_config.effect = (g_config.effect - 1) % (BACKLIGHT_EFFECT_MAX + 1); - backlight_config_save(); + if (rgb_matrix_config.mode > 1) { + rgb_matrix_config.mode = (rgb_matrix_config.mode - 1) % (RGB_MATRIX_EFFECT_MAX + 1); + eeconfig_update_rgblight(rgb_matrix_config.raw); + } } void rgblight_increase_hue(void) { - backlight_color_1_hue_increase(); - backlight_color_2_hue_increase(); + rgb_matrix_config.hue = increment( rgb_matrix_config.hue, 8, 0, 255 ); + eeconfig_update_rgblight(rgb_matrix_config.raw); } void rgblight_decrease_hue(void) { - backlight_color_1_hue_decrease(); - backlight_color_2_hue_decrease(); + rgb_matrix_config.hue = decrement( rgb_matrix_config.hue, 8, 0, 255 ); + eeconfig_update_rgblight(rgb_matrix_config.raw); } void rgblight_increase_sat(void) { - backlight_color_1_sat_increase(); - backlight_color_2_sat_increase(); + rgb_matrix_config.sat = increment( rgb_matrix_config.sat, 8, 0, 255 ); + eeconfig_update_rgblight(rgb_matrix_config.raw); } void rgblight_decrease_sat(void) { - backlight_color_1_sat_decrease(); - backlight_color_2_sat_decrease(); + rgb_matrix_config.sat = decrement( rgb_matrix_config.sat, 8, 0, 255 ); + eeconfig_update_rgblight(rgb_matrix_config.raw); } void rgblight_increase_val(void) { - g_config.color_1.v = increment( g_config.color_1.s, 8, 0, 255 ); - g_config.color_2.v = increment( g_config.color_1.s, 8, 0, 255 ); - backlight_config_save(); + rgb_matrix_config.val = increment( rgb_matrix_config.val, 8, 0, 255 ); + eeconfig_update_rgblight(rgb_matrix_config.raw); } void rgblight_decrease_val(void) { - g_config.color_1.v = decrement( g_config.color_1.s, 8, 0, 255 ); - g_config.color_2.v = decrement( g_config.color_1.s, 8, 0, 255 ); - backlight_config_save(); + rgb_matrix_config.val = decrement( rgb_matrix_config.val, 8, 0, 255 ); + eeconfig_update_rgblight(rgb_matrix_config.raw); } void rgblight_mode(uint8_t mode) { - g_config.effect = mode; + rgb_matrix_config.mode = mode; + eeconfig_update_rgblight(rgb_matrix_config.raw); } uint32_t rgblight_get_mode(void) { - return g_config.effect; + return rgb_matrix_config.mode; } diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index bb0956b7..ec8454bd 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h @@ -50,33 +50,21 @@ typedef struct uint8_t index; } rgb_indicator; -typedef struct -{ - bool enabled:1; // | - bool use_split_left_shift:1; // | - bool use_split_right_shift:1; // | - bool use_7u_spacebar:1; // | - bool use_iso_enter:1; // | - bool disable_when_usb_suspended:1; // | - bool __pad6:1; // | - bool __pad7:1; // 1 byte - uint8_t disable_after_timeout; // 1 byte - uint8_t brightness; // 1 byte - uint8_t effect; // 1 byte - HSV color_1; // 3 bytes - HSV color_2; // 3 bytes - rgb_indicator caps_lock_indicator; // 4 bytes - rgb_indicator layer_1_indicator; // 4 bytes - rgb_indicator layer_2_indicator; // 4 bytes - rgb_indicator layer_3_indicator; // 4 bytes - uint16_t alphas_mods[5]; // 10 bytes -} rgb_matrix_config; // = 36 bytes - -#define EEPROM_BACKLIGHT_CONFIG_ADDR ((void*)35) -// rgb_matrix_config uses 36 bytes -// 35+36=71 -#define EEPROM_BACKLIGHT_KEY_COLOR_ADDR ((void*)71) - +typedef union { + uint32_t raw; + struct { + bool enable :1; + uint8_t mode :6; + uint16_t hue :9; + uint8_t sat :8; + uint8_t val :8; + }; +} rgb_config_t; + +// This runs after another backlight effect and replaces +// colors already set +__attribute__((weak)) +void backlight_effect_indicators(void) {}; void backlight_effect_single_LED_test(void); @@ -108,18 +96,6 @@ void backlight_unset_key_hit(uint8_t row, uint8_t col); void backlight_effect_increase(void); void backlight_effect_decrease(void); -void backlight_brightness_increase(void); -void backlight_brightness_decrease(void); - -void backlight_color_1_hue_increase(void); -void backlight_color_1_hue_decrease(void); -void backlight_color_1_sat_increase(void); -void backlight_color_1_sat_decrease(void); -void backlight_color_2_hue_increase(void); -void backlight_color_2_hue_decrease(void); -void backlight_color_2_sat_increase(void); -void backlight_color_2_sat_decrease(void); - void *backlight_get_key_color_eeprom_address(uint8_t led); void backlight_get_key_color( uint8_t led, HSV *hsv ); void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv );