aboutsummaryrefslogtreecommitdiff
path: root/quantum/rgb_matrix.c
diff options
context:
space:
mode:
authorTynan Beatty <38031130+tynanbe@users.noreply.github.com>2020-08-07 16:43:57 -0500
committerJames Young <18669334+noroadsleft@users.noreply.github.com>2020-08-29 14:30:02 -0700
commite34eca361fdd9ff61b8827fec545202da179648c (patch)
treec8581b9d1b379f6d9703dd4e6a4597f8b3cf0c8d /quantum/rgb_matrix.c
parentc990dc1e6cdcabbfe280d60e981f9e7cc733d5db (diff)
downloadqmk_firmware-e34eca361fdd9ff61b8827fec545202da179648c.tar.gz
qmk_firmware-e34eca361fdd9ff61b8827fec545202da179648c.zip
Noeeprom functions for rgb_matrix (#9487)
* Add eeprom_helpers for toggle, mode, sethsv, speed; add set_speed; add noeeprom versions of toggle, step, hue, sat, val, and speed * qmk cformat rgb_matrix * Add rgb_matrix_set_speed and *_noeeprom functions * Do not expose rgb_matrix_*_eeprom_helper functions
Diffstat (limited to 'quantum/rgb_matrix.c')
-rw-r--r--quantum/rgb_matrix.c155
1 files changed, 88 insertions, 67 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c
index 615b4b0a7..802c5afce 100644
--- a/quantum/rgb_matrix.c
+++ b/quantum/rgb_matrix.c
@@ -155,7 +155,7 @@ void eeconfig_update_rgb_matrix_default(void) {
155} 155}
156 156
157void eeconfig_debug_rgb_matrix(void) { 157void eeconfig_debug_rgb_matrix(void) {
158 dprintf("rgb_matrix_config eprom\n"); 158 dprintf("rgb_matrix_config EEPROM\n");
159 dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable); 159 dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable);
160 dprintf("rgb_matrix_config.mode = %d\n", rgb_matrix_config.mode); 160 dprintf("rgb_matrix_config.mode = %d\n", rgb_matrix_config.mode);
161 dprintf("rgb_matrix_config.hsv.h = %d\n", rgb_matrix_config.hsv.h); 161 dprintf("rgb_matrix_config.hsv.h = %d\n", rgb_matrix_config.hsv.h);
@@ -462,11 +462,16 @@ void rgb_matrix_set_suspend_state(bool state) {
462 462
463bool rgb_matrix_get_suspend_state(void) { return g_suspend_state; } 463bool rgb_matrix_get_suspend_state(void) { return g_suspend_state; }
464 464
465void rgb_matrix_toggle(void) { 465void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
466 rgb_matrix_config.enable ^= 1; 466 rgb_matrix_config.enable ^= 1;
467 rgb_task_state = STARTING; 467 rgb_task_state = STARTING;
468 eeconfig_update_rgb_matrix(); 468 if (write_to_eeprom) {
469 eeconfig_update_rgb_matrix();
470 }
471 dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable);
469} 472}
473void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); }
474void rgb_matrix_toggle(void) { rgb_matrix_toggle_eeprom_helper(true); }
470 475
471void rgb_matrix_enable(void) { 476void rgb_matrix_enable(void) {
472 rgb_matrix_enable_noeeprom(); 477 rgb_matrix_enable_noeeprom();
@@ -490,90 +495,106 @@ void rgb_matrix_disable_noeeprom(void) {
490 495
491uint8_t rgb_matrix_is_enabled(void) { return rgb_matrix_config.enable; } 496uint8_t rgb_matrix_is_enabled(void) { return rgb_matrix_config.enable; }
492 497
493void rgb_matrix_step(void) { 498void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
494 rgb_matrix_config.mode++; 499 if (!rgb_matrix_config.enable) {
495 if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX) rgb_matrix_config.mode = 1; 500 return;
501 }
502 if (mode < 1) {
503 rgb_matrix_config.mode = 1;
504 } else if (mode >= RGB_MATRIX_EFFECT_MAX) {
505 rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1;
506 } else {
507 rgb_matrix_config.mode = mode;
508 }
496 rgb_task_state = STARTING; 509 rgb_task_state = STARTING;
497 eeconfig_update_rgb_matrix(); 510 if (write_to_eeprom) {
511 eeconfig_update_rgb_matrix();
512 }
513 dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode);
498} 514}
515void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); }
516void rgb_matrix_mode(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, true); }
499 517
500void rgb_matrix_step_reverse(void) { 518uint8_t rgb_matrix_get_mode(void) { return rgb_matrix_config.mode; }
501 rgb_matrix_config.mode--;
502 if (rgb_matrix_config.mode < 1) rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1;
503 rgb_task_state = STARTING;
504 eeconfig_update_rgb_matrix();
505}
506 519
507void rgb_matrix_increase_hue(void) { 520void rgb_matrix_step_helper(bool write_to_eeprom) {
508 rgb_matrix_config.hsv.h += RGB_MATRIX_HUE_STEP; 521 uint8_t mode = rgb_matrix_config.mode + 1;
509 eeconfig_update_rgb_matrix(); 522 rgb_matrix_mode_eeprom_helper((mode < RGB_MATRIX_EFFECT_MAX) ? mode : 1, write_to_eeprom);
510} 523}
524void rgb_matrix_step_noeeprom(void) { rgb_matrix_step_helper(false); }
525void rgb_matrix_step(void) { rgb_matrix_step_helper(true); }
511 526
512void rgb_matrix_decrease_hue(void) { 527void rgb_matrix_step_reverse_helper(bool write_to_eeprom) {
513 rgb_matrix_config.hsv.h -= RGB_MATRIX_HUE_STEP; 528 uint8_t mode = rgb_matrix_config.mode - 1;
514 eeconfig_update_rgb_matrix(); 529 rgb_matrix_mode_eeprom_helper((mode < 1) ? RGB_MATRIX_EFFECT_MAX - 1 : mode, write_to_eeprom);
515} 530}
531void rgb_matrix_step_reverse_noeeprom(void) { rgb_matrix_step_reverse_helper(false); }
532void rgb_matrix_step_reverse(void) { rgb_matrix_step_reverse_helper(true); }
516 533
517void rgb_matrix_increase_sat(void) { 534void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) {
518 rgb_matrix_config.hsv.s = qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP); 535 if (!rgb_matrix_config.enable) {
519 eeconfig_update_rgb_matrix(); 536 return;
520} 537 }
521 538 rgb_matrix_config.hsv.h = hue;
522void rgb_matrix_decrease_sat(void) { 539 rgb_matrix_config.hsv.s = sat;
523 rgb_matrix_config.hsv.s = qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP); 540 rgb_matrix_config.hsv.v = (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) ? RGB_MATRIX_MAXIMUM_BRIGHTNESS : val;
524 eeconfig_update_rgb_matrix(); 541 if (write_to_eeprom) {
542 eeconfig_update_rgb_matrix();
543 }
544 dprintf("rgb matrix set hsv [%s]: %u,%u,%u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v);
525} 545}
546void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); }
547void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, true); }
526 548
527void rgb_matrix_increase_val(void) { 549HSV rgb_matrix_get_hsv(void) { return rgb_matrix_config.hsv; }
528 rgb_matrix_config.hsv.v = qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP); 550uint8_t rgb_matrix_get_hue(void) { return rgb_matrix_config.hsv.h; }
529 if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS) rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS; 551uint8_t rgb_matrix_get_sat(void) { return rgb_matrix_config.hsv.s; }
530 eeconfig_update_rgb_matrix(); 552uint8_t rgb_matrix_get_val(void) { return rgb_matrix_config.hsv.v; }
531}
532 553
533void rgb_matrix_decrease_val(void) { 554void rgb_matrix_increase_hue_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h + RGB_MATRIX_HUE_STEP, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, write_to_eeprom); }
534 rgb_matrix_config.hsv.v = qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP); 555void rgb_matrix_increase_hue_noeeprom(void) { rgb_matrix_increase_hue_helper(false); }
535 eeconfig_update_rgb_matrix(); 556void rgb_matrix_increase_hue(void) { rgb_matrix_increase_hue_helper(true); }
536}
537 557
538void rgb_matrix_increase_speed(void) { 558void rgb_matrix_decrease_hue_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h - RGB_MATRIX_HUE_STEP, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v, write_to_eeprom); }
539 rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); 559void rgb_matrix_decrease_hue_noeeprom(void) { rgb_matrix_decrease_hue_helper(false); }
540 eeconfig_update_rgb_matrix(); 560void rgb_matrix_decrease_hue(void) { rgb_matrix_decrease_hue_helper(true); }
541}
542 561
543void rgb_matrix_decrease_speed(void) { 562void rgb_matrix_increase_sat_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP), rgb_matrix_config.hsv.v, write_to_eeprom); }
544 rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); 563void rgb_matrix_increase_sat_noeeprom(void) { rgb_matrix_increase_sat_helper(false); }
545 eeconfig_update_rgb_matrix(); 564void rgb_matrix_increase_sat(void) { rgb_matrix_increase_sat_helper(true); }
546}
547 565
548uint8_t rgb_matrix_get_speed(void) { return rgb_matrix_config.speed; } 566void rgb_matrix_decrease_sat_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP), rgb_matrix_config.hsv.v, write_to_eeprom); }
567void rgb_matrix_decrease_sat_noeeprom(void) { rgb_matrix_decrease_sat_helper(false); }
568void rgb_matrix_decrease_sat(void) { rgb_matrix_decrease_sat_helper(true); }
549 569
550led_flags_t rgb_matrix_get_flags(void) { return rgb_effect_params.flags; } 570void rgb_matrix_increase_val_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom); }
571void rgb_matrix_increase_val_noeeprom(void) { rgb_matrix_increase_val_helper(false); }
572void rgb_matrix_increase_val(void) { rgb_matrix_increase_val_helper(true); }
551 573
552void rgb_matrix_set_flags(led_flags_t flags) { rgb_effect_params.flags = flags; } 574void rgb_matrix_decrease_val_helper(bool write_to_eeprom) { rgb_matrix_sethsv_eeprom_helper(rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP), write_to_eeprom); }
575void rgb_matrix_decrease_val_noeeprom(void) { rgb_matrix_decrease_val_helper(false); }
576void rgb_matrix_decrease_val(void) { rgb_matrix_decrease_val_helper(true); }
553 577
554void rgb_matrix_mode(uint8_t mode) { 578void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) {
555 rgb_matrix_config.mode = mode; 579 rgb_matrix_config.speed = speed;
556 rgb_task_state = STARTING; 580 if (write_to_eeprom) {
557 eeconfig_update_rgb_matrix(); 581 eeconfig_update_rgb_matrix();
582 }
583 dprintf("rgb matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.speed);
558} 584}
585void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); }
586void rgb_matrix_set_speed(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, true); }
559 587
560void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_config.mode = mode; } 588uint8_t rgb_matrix_get_speed(void) { return rgb_matrix_config.speed; }
561 589
562uint8_t rgb_matrix_get_mode(void) { return rgb_matrix_config.mode; } 590void rgb_matrix_increase_speed_helper(bool write_to_eeprom) { rgb_matrix_set_speed_eeprom_helper(qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP), write_to_eeprom); }
591void rgb_matrix_increase_speed_noeeprom(void) { rgb_matrix_increase_speed_helper(false); }
592void rgb_matrix_increase_speed(void) { rgb_matrix_increase_speed_helper(true); }
563 593
564void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { 594void rgb_matrix_decrease_speed_helper(bool write_to_eeprom) { rgb_matrix_set_speed_eeprom_helper(qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP), write_to_eeprom); }
565 rgb_matrix_sethsv_noeeprom(hue, sat, val); 595void rgb_matrix_decrease_speed_noeeprom(void) { rgb_matrix_decrease_speed_helper(false); }
566 eeconfig_update_rgb_matrix(); 596void rgb_matrix_decrease_speed(void) { rgb_matrix_decrease_speed_helper(true); }
567}
568 597
569void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { 598led_flags_t rgb_matrix_get_flags(void) { return rgb_effect_params.flags; }
570 rgb_matrix_config.hsv.h = hue;
571 rgb_matrix_config.hsv.s = sat;
572 rgb_matrix_config.hsv.v = val;
573 if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS) rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
574}
575 599
576HSV rgb_matrix_get_hsv(void) { return rgb_matrix_config.hsv; } 600void rgb_matrix_set_flags(led_flags_t flags) { rgb_effect_params.flags = flags; }
577uint8_t rgb_matrix_get_hue(void) { return rgb_matrix_config.hsv.h; }
578uint8_t rgb_matrix_get_sat(void) { return rgb_matrix_config.hsv.s; }
579uint8_t rgb_matrix_get_val(void) { return rgb_matrix_config.hsv.v; }