aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/feature_rgblight.md35
-rw-r--r--quantum/rgblight.c93
-rw-r--r--quantum/rgblight.h9
-rw-r--r--quantum/rgblight_list.h24
-rw-r--r--tmk_core/common/avr/suspend.c4
5 files changed, 137 insertions, 28 deletions
diff --git a/docs/feature_rgblight.md b/docs/feature_rgblight.md
index 0f1e649ef..5369d2fb7 100644
--- a/docs/feature_rgblight.md
+++ b/docs/feature_rgblight.md
@@ -88,11 +88,36 @@ const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90};
88Look in `rgblights.h` for all available functions, but if you want to control all or some LEDs your goto functions are: 88Look in `rgblights.h` for all available functions, but if you want to control all or some LEDs your goto functions are:
89 89
90```c 90```c
91rgblight_disable(); // turn all lights off 91// turn all lights off (stored in EEPROM)
92rgblight_enable(); // turn lights on, based on their previous state (stored in EEPROM) 92rgblight_disable();
93// turn lights on, based on their previous state (stored in EEPROM)
94rgblight_enable();
95
96// turn all lights off (not stored in EEPROM)
97rgblight_disable_noeeprom();
98// turn lights on, based on their previous state (not stored in EEPROM)
99rgblight_enable_noeeprom();
100
101// where r/g/b is a number from 0..255. Turns all the LEDs to this color (ignores mode, not stored in EEPROM).
102rgblight_setrgb(r, g, b);
103// HSV color control - h is a value from 0..360 and s/v is a value from 0..255 (stored in EEPROM)
104rgblight_sethsv(h, s, v);
105// HSV color control - h is a value from 0..360 and s/v is a value from 0..255 (not stored in EEPROM)
106rgblight_sethsv_noeeprom(h, s, v);
107
108// Sets the mode, if rgb animations are enabled (stored in eeprom)
109rgblight_mode(x);
110// Sets the mode, if rgb animations are enabled (not stored in eeprom)
111rgblight_mode_noeeprom(x);
112// MODE 1, solid color
113// MODE 2-5, breathing
114// MODE 6-8, rainbow mood
115// MODE 9-14, rainbow swirl
116// MODE 15-20, snake
117// MODE 21-23, knight
118// MODE 24, xmas
119// MODE 25-34, static rainbow
93 120
94rgblight_setrgb(r, g, b); // where r/g/b is a number from 0..255. Turns all the LEDs to this color
95rgblight_sethsv(h, s, v); // HSV color control - h is a value from 0..360 and s/v is a value from 0..255
96rgblight_setrgb_at(r,g,b, LED); // control a single LED. 0 <= LED < RGBLED_NUM 121rgblight_setrgb_at(r,g,b, LED); // control a single LED. 0 <= LED < RGBLED_NUM
97rgblight_sethsv_at(h,s,v, LED); // control a single LED. 0 <= LED < RGBLED_NUM 122rgblight_sethsv_at(h,s,v, LED); // control a single LED. 0 <= LED < RGBLED_NUM
98``` 123```
@@ -126,7 +151,7 @@ note: for backwards compatibility, `RGB_SMOD` is an alias for `RGB_MOD`.
126 151
127## Hardware Modification 152## Hardware Modification
128 153
129![Planck with RGB Underglow](https://raw.githubusercontent.com/qmk/qmk_firmware/master/keyboards/planck/keymaps/yang/planck-with-rgb-underglow.jpg) 154![Planck with RGB Underglow](https://raw.githubusercontent.com/qmk/qmk_firmware/3774a7fcdab5544fc787f4c200be05fcd417e31f/keyboards/planck/keymaps/yang/planck-with-rgb-underglow.jpg)
130 155
131Here is a quick demo on Youtube (with NPKC KC60) (https://www.youtube.com/watch?v=VKrpPAHlisY). 156Here is a quick demo on Youtube (with NPKC KC60) (https://www.youtube.com/watch?v=VKrpPAHlisY).
132 157
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index 75512e97a..db66e735b 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -44,7 +44,6 @@ __attribute__ ((weak))
44const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90}; 44const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90};
45 45
46rgblight_config_t rgblight_config; 46rgblight_config_t rgblight_config;
47rgblight_config_t inmem_config;
48 47
49LED_TYPE led[RGBLED_NUM]; 48LED_TYPE led[RGBLED_NUM];
50uint8_t rgblight_inited = 0; 49uint8_t rgblight_inited = 0;
@@ -161,7 +160,7 @@ void rgblight_init(void) {
161 #endif 160 #endif
162 161
163 if (rgblight_config.enable) { 162 if (rgblight_config.enable) {
164 rgblight_mode(rgblight_config.mode); 163 rgblight_mode_noeeprom(rgblight_config.mode);
165 } 164 }
166} 165}
167 166
@@ -218,7 +217,7 @@ uint32_t rgblight_get_mode(void) {
218 return rgblight_config.mode; 217 return rgblight_config.mode;
219} 218}
220 219
221void rgblight_mode(uint8_t mode) { 220void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
222 if (!rgblight_config.enable) { 221 if (!rgblight_config.enable) {
223 return; 222 return;
224 } 223 }
@@ -229,8 +228,12 @@ void rgblight_mode(uint8_t mode) {
229 } else { 228 } else {
230 rgblight_config.mode = mode; 229 rgblight_config.mode = mode;
231 } 230 }
232 eeconfig_update_rgblight(rgblight_config.raw); 231 if (write_to_eeprom) {
233 xprintf("rgblight mode: %u\n", rgblight_config.mode); 232 eeconfig_update_rgblight(rgblight_config.raw);
233 xprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode);
234 } else {
235 xprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode);
236 }
234 if (rgblight_config.mode == 1) { 237 if (rgblight_config.mode == 1) {
235 #ifdef RGBLIGHT_ANIMATIONS 238 #ifdef RGBLIGHT_ANIMATIONS
236 rgblight_timer_disable(); 239 rgblight_timer_disable();
@@ -254,11 +257,20 @@ void rgblight_mode(uint8_t mode) {
254 rgblight_timer_disable(); 257 rgblight_timer_disable();
255 #endif 258 #endif
256 } 259 }
257 rgblight_sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); 260 rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
261}
262
263void rgblight_mode(uint8_t mode) {
264 rgblight_mode_eeprom_helper(mode, true);
265}
266
267void rgblight_mode_noeeprom(uint8_t mode) {
268 rgblight_mode_eeprom_helper(mode, false);
258} 269}
259 270
271
260void rgblight_toggle(void) { 272void rgblight_toggle(void) {
261 xprintf("rgblight toggle: rgblight_config.enable = %u\n", !rgblight_config.enable); 273 xprintf("rgblight toggle [EEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable);
262 if (rgblight_config.enable) { 274 if (rgblight_config.enable) {
263 rgblight_disable(); 275 rgblight_disable();
264 } 276 }
@@ -267,17 +279,34 @@ void rgblight_toggle(void) {
267 } 279 }
268} 280}
269 281
282void rgblight_toggle_noeeprom(void) {
283 xprintf("rgblight toggle [NOEEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable);
284 if (rgblight_config.enable) {
285 rgblight_disable_noeeprom();
286 }
287 else {
288 rgblight_enable_noeeprom();
289 }
290}
291
270void rgblight_enable(void) { 292void rgblight_enable(void) {
271 rgblight_config.enable = 1; 293 rgblight_config.enable = 1;
272 eeconfig_update_rgblight(rgblight_config.raw); 294 // No need to update EEPROM here. rgblight_mode() will do that, actually
273 xprintf("rgblight enable: rgblight_config.enable = %u\n", rgblight_config.enable); 295 //eeconfig_update_rgblight(rgblight_config.raw);
296 xprintf("rgblight enable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
274 rgblight_mode(rgblight_config.mode); 297 rgblight_mode(rgblight_config.mode);
275} 298}
276 299
300void rgblight_enable_noeeprom(void) {
301 rgblight_config.enable = 1;
302 xprintf("rgblight enable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
303 rgblight_mode_noeeprom(rgblight_config.mode);
304}
305
277void rgblight_disable(void) { 306void rgblight_disable(void) {
278 rgblight_config.enable = 0; 307 rgblight_config.enable = 0;
279 eeconfig_update_rgblight(rgblight_config.raw); 308 eeconfig_update_rgblight(rgblight_config.raw);
280 xprintf("rgblight disable: rgblight_config.enable = %u\n", rgblight_config.enable); 309 xprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
281 #ifdef RGBLIGHT_ANIMATIONS 310 #ifdef RGBLIGHT_ANIMATIONS
282 rgblight_timer_disable(); 311 rgblight_timer_disable();
283 #endif 312 #endif
@@ -285,6 +314,17 @@ void rgblight_disable(void) {
285 rgblight_set(); 314 rgblight_set();
286} 315}
287 316
317void rgblight_disable_noeeprom(void) {
318 rgblight_config.enable = 0;
319 xprintf("rgblight disable [noEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
320 #ifdef RGBLIGHT_ANIMATIONS
321 rgblight_timer_disable();
322 #endif
323 _delay_ms(50);
324 rgblight_set();
325}
326
327
288// Deals with the messy details of incrementing an integer 328// Deals with the messy details of incrementing an integer
289uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { 329uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) {
290 int16_t new_value = value; 330 int16_t new_value = value;
@@ -358,23 +398,22 @@ void rgblight_decrease_speed(void) {
358 eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this 398 eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this
359} 399}
360 400
361void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { 401void rgblight_sethsv_noeeprom_old(uint16_t hue, uint8_t sat, uint8_t val) {
362 inmem_config.raw = rgblight_config.raw;
363 if (rgblight_config.enable) { 402 if (rgblight_config.enable) {
364 LED_TYPE tmp_led; 403 LED_TYPE tmp_led;
365 sethsv(hue, sat, val, &tmp_led); 404 sethsv(hue, sat, val, &tmp_led);
366 inmem_config.hue = hue;
367 inmem_config.sat = sat;
368 inmem_config.val = val;
369 // dprintf("rgblight set hue [MEMORY]: %u,%u,%u\n", inmem_config.hue, inmem_config.sat, inmem_config.val); 405 // dprintf("rgblight set hue [MEMORY]: %u,%u,%u\n", inmem_config.hue, inmem_config.sat, inmem_config.val);
370 rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); 406 rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
371 } 407 }
372} 408}
373void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { 409
410void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) {
374 if (rgblight_config.enable) { 411 if (rgblight_config.enable) {
375 if (rgblight_config.mode == 1) { 412 if (rgblight_config.mode == 1) {
376 // same static color 413 // same static color
377 rgblight_sethsv_noeeprom(hue, sat, val); 414 LED_TYPE tmp_led;
415 sethsv(hue, sat, val, &tmp_led);
416 rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
378 } else { 417 } else {
379 // all LEDs in same color 418 // all LEDs in same color
380 if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { 419 if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) {
@@ -399,11 +438,23 @@ void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
399 rgblight_config.hue = hue; 438 rgblight_config.hue = hue;
400 rgblight_config.sat = sat; 439 rgblight_config.sat = sat;
401 rgblight_config.val = val; 440 rgblight_config.val = val;
402 eeconfig_update_rgblight(rgblight_config.raw); 441 if (write_to_eeprom) {
403 xprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); 442 eeconfig_update_rgblight(rgblight_config.raw);
443 xprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
444 } else {
445 xprintf("rgblight set hsv [NOEEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
446 }
404 } 447 }
405} 448}
406 449
450void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
451 rgblight_sethsv_eeprom_helper(hue, sat, val, true);
452}
453
454void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) {
455 rgblight_sethsv_eeprom_helper(hue, sat, val, false);
456}
457
407uint16_t rgblight_get_hue(void) { 458uint16_t rgblight_get_hue(void) {
408 return rgblight_config.hue; 459 return rgblight_config.hue;
409} 460}
@@ -546,7 +597,7 @@ void rgblight_effect_breathing(uint8_t interval) {
546 597
547 // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ 598 // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
548 val = (exp(sin((pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)); 599 val = (exp(sin((pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E));
549 rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, val); 600 rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val);
550 pos = (pos + 1) % 256; 601 pos = (pos + 1) % 256;
551} 602}
552void rgblight_effect_rainbow_mood(uint8_t interval) { 603void rgblight_effect_rainbow_mood(uint8_t interval) {
@@ -557,7 +608,7 @@ void rgblight_effect_rainbow_mood(uint8_t interval) {
557 return; 608 return;
558 } 609 }
559 last_timer = timer_read(); 610 last_timer = timer_read();
560 rgblight_sethsv_noeeprom(current_hue, rgblight_config.sat, rgblight_config.val); 611 rgblight_sethsv_noeeprom_old(current_hue, rgblight_config.sat, rgblight_config.val);
561 current_hue = (current_hue + 1) % 360; 612 current_hue = (current_hue + 1) % 360;
562} 613}
563void rgblight_effect_rainbow_swirl(uint8_t interval) { 614void rgblight_effect_rainbow_swirl(uint8_t interval) {
diff --git a/quantum/rgblight.h b/quantum/rgblight.h
index a6593af98..569424506 100644
--- a/quantum/rgblight.h
+++ b/quantum/rgblight.h
@@ -134,7 +134,16 @@ void rgb_matrix_decrease(void);
134 134
135void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); 135void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1);
136void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1); 136void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1);
137
137void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val); 138void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
139void rgblight_mode_noeeprom(uint8_t mode);
140void rgblight_toggle_noeeprom(void);
141void rgblight_enable_noeeprom(void);
142void rgblight_disable_noeeprom(void);
143
144void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom);
145void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom);
146
138 147
139#define EZ_RGB(val) rgblight_show_solid_color((val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF) 148#define EZ_RGB(val) rgblight_show_solid_color((val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF)
140void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b); 149void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b);
diff --git a/quantum/rgblight_list.h b/quantum/rgblight_list.h
index 29b280226..407fd8e9d 100644
--- a/quantum/rgblight_list.h
+++ b/quantum/rgblight_list.h
@@ -77,6 +77,30 @@
77#define rgblight_sethsv_pink() rgblight_sethsv (330, 128, 255) 77#define rgblight_sethsv_pink() rgblight_sethsv (330, 128, 255)
78 78
79/* SET HSV List */ 79/* SET HSV List */
80/* If you're doing layer indication, this is best, as it won't */
81/* write to the eeprom, since it's limited (very high value). */
82/* If you want to use modes with this (since you can), then you */
83/* want to use rgblight_mode_noeeprom(x) instead. */
84#define rgblight_sethsv_noeeprom_white() rgblight_sethsv_noeeprom ( 0, 0, 255)
85#define rgblight_sethsv_noeeprom_red() rgblight_sethsv_noeeprom ( 0, 255, 255)
86#define rgblight_sethsv_noeeprom_coral() rgblight_sethsv_noeeprom ( 16, 176, 255)
87#define rgblight_sethsv_noeeprom_orange() rgblight_sethsv_noeeprom ( 39, 255, 255)
88#define rgblight_sethsv_noeeprom_goldenrod() rgblight_sethsv_noeeprom ( 43, 218, 218)
89#define rgblight_sethsv_noeeprom_gold() rgblight_sethsv_noeeprom ( 51, 255, 255)
90#define rgblight_sethsv_noeeprom_yellow() rgblight_sethsv_noeeprom ( 60, 255, 255)
91#define rgblight_sethsv_noeeprom_chartreuse() rgblight_sethsv_noeeprom ( 90, 255, 255)
92#define rgblight_sethsv_noeeprom_green() rgblight_sethsv_noeeprom (120, 255, 255)
93#define rgblight_sethsv_noeeprom_springgreen() rgblight_sethsv_noeeprom (150, 255, 255)
94#define rgblight_sethsv_noeeprom_turquoise() rgblight_sethsv_noeeprom (174, 90, 112)
95#define rgblight_sethsv_noeeprom_teal() rgblight_sethsv_noeeprom (180, 255, 128)
96#define rgblight_sethsv_noeeprom_cyan() rgblight_sethsv_noeeprom (180, 255, 255)
97#define rgblight_sethsv_noeeprom_azure() rgblight_sethsv_noeeprom (186, 102, 255)
98#define rgblight_sethsv_noeeprom_blue() rgblight_sethsv_noeeprom (240, 255, 255)
99#define rgblight_sethsv_noeeprom_purple() rgblight_sethsv_noeeprom (270, 255, 255)
100#define rgblight_sethsv_noeeprom_magenta() rgblight_sethsv_noeeprom (300, 255, 255)
101#define rgblight_sethsv_noeeprom_pink() rgblight_sethsv_noeeprom (330, 128, 255)
102
103/* SET HSV List */
80#define rgblight_sethsv_white_at(at) rgblight_sethsv_at ( 0, 0, 255, at) 104#define rgblight_sethsv_white_at(at) rgblight_sethsv_at ( 0, 0, 255, at)
81#define rgblight_sethsv_red_at(at) rgblight_sethsv_at ( 0, 255, 255, at) 105#define rgblight_sethsv_red_at(at) rgblight_sethsv_at ( 0, 255, 255, at)
82#define rgblight_sethsv_coral_at(at) rgblight_sethsv_at ( 16, 176, 255, at) 106#define rgblight_sethsv_coral_at(at) rgblight_sethsv_at ( 16, 176, 255, at)
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c
index 81e426641..3aa3d1247 100644
--- a/tmk_core/common/avr/suspend.c
+++ b/tmk_core/common/avr/suspend.c
@@ -101,7 +101,7 @@ static void power_down(uint8_t wdto)
101#ifdef RGBLIGHT_ANIMATIONS 101#ifdef RGBLIGHT_ANIMATIONS
102 rgblight_timer_disable(); 102 rgblight_timer_disable();
103#endif 103#endif
104 rgblight_disable(); 104 rgblight_disable_noeeprom();
105#endif 105#endif
106 // TODO: more power saving 106 // TODO: more power saving
107 // See PicoPower application note 107 // See PicoPower application note
@@ -157,7 +157,7 @@ void suspend_wakeup_init(void)
157#endif 157#endif
158 led_set(host_keyboard_leds()); 158 led_set(host_keyboard_leds());
159#ifdef RGBLIGHT_SLEEP 159#ifdef RGBLIGHT_SLEEP
160 rgblight_enable(); 160 rgblight_enable_noeeprom();
161#ifdef RGBLIGHT_ANIMATIONS 161#ifdef RGBLIGHT_ANIMATIONS
162 rgblight_timer_enable(); 162 rgblight_timer_enable();
163#endif 163#endif