From f365ff795b7a184719ce31277797e1254fa74240 Mon Sep 17 00:00:00 2001 From: tynanbe Date: Sat, 20 Jun 2020 16:07:14 -0500 Subject: [PATCH 1/4] Add eeprom_helpers for toggle, mode, sethsv, speed; add set_speed; add noeeprom versions of toggle, step, hue, sat, val, and speed --- quantum/rgb_matrix.c | 258 ++++++++++++++++++++++++++++++------------- quantum/rgb_matrix.h | 68 ++++++++---- 2 files changed, 233 insertions(+), 93 deletions(-) diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index f3da0ab0f7d5..643a813878a6 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -155,7 +155,7 @@ void eeconfig_update_rgb_matrix_default(void) { } void eeconfig_debug_rgb_matrix(void) { - dprintf("rgb_matrix_config eprom\n"); + dprintf("rgb_matrix_config EEPROM\n"); dprintf("rgb_matrix_config.enable = %d\n", rgb_matrix_config.enable); dprintf("rgb_matrix_config.mode = %d\n", rgb_matrix_config.mode); dprintf("rgb_matrix_config.hsv.h = %d\n", rgb_matrix_config.hsv.h); @@ -462,11 +462,21 @@ void rgb_matrix_set_suspend_state(bool state) { bool rgb_matrix_get_suspend_state(void) { return g_suspend_state; } -void rgb_matrix_toggle(void) { +void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { rgb_matrix_config.enable ^= 1; rgb_task_state = STARTING; - eeconfig_update_rgb_matrix(); + if (write_to_eeprom) { + eeconfig_update_rgb_matrix(); + } + dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", + (write_to_eeprom) + ? "EEPROM" + : "NOEEPROM", + rgb_matrix_config.enable + ); } +void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); } +void rgb_matrix_toggle(void) { rgb_matrix_toggle_eeprom_helper(true); } void rgb_matrix_enable(void) { rgb_matrix_enable_noeeprom(); @@ -490,90 +500,190 @@ void rgb_matrix_disable_noeeprom(void) { uint8_t rgb_matrix_is_enabled(void) { return rgb_matrix_config.enable; } -void rgb_matrix_step(void) { - rgb_matrix_config.mode++; - if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX) rgb_matrix_config.mode = 1; - rgb_task_state = STARTING; - eeconfig_update_rgb_matrix(); -} - -void rgb_matrix_step_reverse(void) { - rgb_matrix_config.mode--; - if (rgb_matrix_config.mode < 1) rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; +void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { + if (!rgb_matrix_config.enable) { + return; + } + if (mode < 1) { + rgb_matrix_config.mode = 1; + } + else if (mode >= RGB_MATRIX_EFFECT_MAX) { + rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; + } + else { + rgb_matrix_config.mode = mode; + } rgb_task_state = STARTING; - eeconfig_update_rgb_matrix(); -} - -void rgb_matrix_increase_hue(void) { - rgb_matrix_config.hsv.h += RGB_MATRIX_HUE_STEP; - eeconfig_update_rgb_matrix(); + if (write_to_eeprom) { + eeconfig_update_rgb_matrix(); + } + dprintf("rgb matrix mode [%s]: %u\n", + (write_to_eeprom) + ? "EEPROM" + : "NOEEPROM", + rgb_matrix_config.mode + ); } +void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); } +void rgb_matrix_mode(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, true); } -void rgb_matrix_decrease_hue(void) { - rgb_matrix_config.hsv.h -= RGB_MATRIX_HUE_STEP; - eeconfig_update_rgb_matrix(); -} +uint8_t rgb_matrix_get_mode(void) { return rgb_matrix_config.mode; } -void rgb_matrix_increase_sat(void) { - rgb_matrix_config.hsv.s = qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP); - eeconfig_update_rgb_matrix(); -} +void rgb_matrix_step_helper(bool write_to_eeprom) { + uint8_t mode = rgb_matrix_config.mode + 1; + rgb_matrix_mode_eeprom_helper( + (mode < RGB_MATRIX_EFFECT_MAX) + ? mode + : 1, + write_to_eeprom + ); +} +void rgb_matrix_step_noeeprom(void) { rgb_matrix_step_helper(false); } +void rgb_matrix_step(void) { rgb_matrix_step_helper(true); } + +void rgb_matrix_step_reverse_helper(bool write_to_eeprom) { + uint8_t mode = rgb_matrix_config.mode - 1; + rgb_matrix_mode_eeprom_helper( + (mode < 1) + ? RGB_MATRIX_EFFECT_MAX - 1 + : mode, + write_to_eeprom + ); +} +void rgb_matrix_step_reverse_noeeprom(void) { rgb_matrix_step_reverse_helper(false); } +void rgb_matrix_step_reverse(void) { rgb_matrix_step_reverse_helper(true); } + +void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { + if (!rgb_matrix_config.enable) { + return; + } + rgb_matrix_config.hsv.h = hue; + rgb_matrix_config.hsv.s = sat; + rgb_matrix_config.hsv.v = + (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) + ? RGB_MATRIX_MAXIMUM_BRIGHTNESS + : val; + if (write_to_eeprom) { + eeconfig_update_rgb_matrix(); + } + 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 + ); +} +void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); } +void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, true); } -void rgb_matrix_decrease_sat(void) { - rgb_matrix_config.hsv.s = qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP); - eeconfig_update_rgb_matrix(); -} +HSV rgb_matrix_get_hsv(void) { return rgb_matrix_config.hsv; } +uint8_t rgb_matrix_get_hue(void) { return rgb_matrix_config.hsv.h; } +uint8_t rgb_matrix_get_sat(void) { return rgb_matrix_config.hsv.s; } +uint8_t rgb_matrix_get_val(void) { return rgb_matrix_config.hsv.v; } -void rgb_matrix_increase_val(void) { - rgb_matrix_config.hsv.v = qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP); - if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS) rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS; - eeconfig_update_rgb_matrix(); +void 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 + ); +} +void rgb_matrix_increase_hue_noeeprom(void) { rgb_matrix_increase_hue_helper(false); } +void rgb_matrix_increase_hue(void) { rgb_matrix_increase_hue_helper(true); } + +void 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 + ); +} +void rgb_matrix_decrease_hue_noeeprom(void) { rgb_matrix_decrease_hue_helper(false); } +void rgb_matrix_decrease_hue(void) { rgb_matrix_decrease_hue_helper(true); } + +void 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 + ); +} +void rgb_matrix_increase_sat_noeeprom(void) { rgb_matrix_increase_sat_helper(false); } +void rgb_matrix_increase_sat(void) { rgb_matrix_increase_sat_helper(true); } + +void 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 + ); +} +void rgb_matrix_decrease_sat_noeeprom(void) { rgb_matrix_decrease_sat_helper(false); } +void rgb_matrix_decrease_sat(void) { rgb_matrix_decrease_sat_helper(true); } + +void 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 + ); +} +void rgb_matrix_increase_val_noeeprom(void) { rgb_matrix_increase_val_helper(false); } +void rgb_matrix_increase_val(void) { rgb_matrix_increase_val_helper(true); } + +void 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 + ); +} +void rgb_matrix_decrease_val_noeeprom(void) { rgb_matrix_decrease_val_helper(false); } +void rgb_matrix_decrease_val(void) { rgb_matrix_decrease_val_helper(true); } + +void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { + rgb_matrix_config.speed = speed; + if (write_to_eeprom) { + eeconfig_update_rgb_matrix(); + } + dprintf("rgb matrix set speed [%s]: %u\n", + (write_to_eeprom) + ? "EEPROM" + : "NOEEPROM", + rgb_matrix_config.speed + ); } +void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); } +void rgb_matrix_set_speed(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, true); } -void rgb_matrix_decrease_val(void) { - rgb_matrix_config.hsv.v = qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP); - eeconfig_update_rgb_matrix(); -} +uint8_t rgb_matrix_get_speed(void) { return rgb_matrix_config.speed; } -void rgb_matrix_increase_speed(void) { - rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); - eeconfig_update_rgb_matrix(); +void 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 + ); } +void rgb_matrix_increase_speed_noeeprom(void) { rgb_matrix_increase_speed_helper(false); } +void rgb_matrix_increase_speed(void) { rgb_matrix_increase_speed_helper(true); } -void rgb_matrix_decrease_speed(void) { - rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); - eeconfig_update_rgb_matrix(); +void 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 + ); } - -uint8_t rgb_matrix_get_speed(void) { return rgb_matrix_config.speed; } +void rgb_matrix_decrease_speed_noeeprom(void) { rgb_matrix_decrease_speed_helper(false); } +void rgb_matrix_decrease_speed(void) { rgb_matrix_decrease_speed_helper(true); } led_flags_t rgb_matrix_get_flags(void) { return rgb_effect_params.flags; } void rgb_matrix_set_flags(led_flags_t flags) { rgb_effect_params.flags = flags; } - -void rgb_matrix_mode(uint8_t mode) { - rgb_matrix_config.mode = mode; - rgb_task_state = STARTING; - eeconfig_update_rgb_matrix(); -} - -void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_config.mode = mode; } - -uint8_t rgb_matrix_get_mode(void) { return rgb_matrix_config.mode; } - -void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { - rgb_matrix_sethsv_noeeprom(hue, sat, val); - eeconfig_update_rgb_matrix(); -} - -void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { - rgb_matrix_config.hsv.h = hue; - rgb_matrix_config.hsv.s = sat; - rgb_matrix_config.hsv.v = val; - if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS) rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS; -} - -HSV rgb_matrix_get_hsv(void) { return rgb_matrix_config.hsv; } -uint8_t rgb_matrix_get_hue(void) { return rgb_matrix_config.hsv.h; } -uint8_t rgb_matrix_get_sat(void) { return rgb_matrix_config.hsv.s; } -uint8_t rgb_matrix_get_val(void) { return rgb_matrix_config.hsv.v; } diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index 03e9e8572c57..30f61751813f 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h @@ -107,62 +107,92 @@ void rgb_matrix_init(void); void rgb_matrix_set_suspend_state(bool state); bool rgb_matrix_get_suspend_state(void); +void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom); void rgb_matrix_toggle(void); +void rgb_matrix_toggle_noeeprom(void); void rgb_matrix_enable(void); void rgb_matrix_enable_noeeprom(void); void rgb_matrix_disable(void); void rgb_matrix_disable_noeeprom(void); uint8_t rgb_matrix_is_enabled(void); +void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom); +void rgb_matrix_mode(uint8_t mode); +void rgb_matrix_mode_noeeprom(uint8_t mode); +uint8_t rgb_matrix_get_mode(void); void rgb_matrix_step(void); +void rgb_matrix_step_noeeprom(void); void rgb_matrix_step_reverse(void); +void rgb_matrix_step_reverse_noeeprom(void); +void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom); +void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val); +void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val); +HSV rgb_matrix_get_hsv(void); +uint8_t rgb_matrix_get_hue(void); +uint8_t rgb_matrix_get_sat(void); +uint8_t rgb_matrix_get_val(void); void rgb_matrix_increase_hue(void); +void rgb_matrix_increase_hue_noeeprom(void); void rgb_matrix_decrease_hue(void); +void rgb_matrix_decrease_hue_noeeprom(void); void rgb_matrix_increase_sat(void); +void rgb_matrix_increase_sat_noeeprom(void); void rgb_matrix_decrease_sat(void); +void rgb_matrix_decrease_sat_noeeprom(void); void rgb_matrix_increase_val(void); +void rgb_matrix_increase_val_noeeprom(void); void rgb_matrix_decrease_val(void); +void rgb_matrix_decrease_val_noeeprom(void); +void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom); +void rgb_matrix_set_speed(uint8_t speed); +void rgb_matrix_set_speed_noeeprom(uint8_t speed); +uint8_t rgb_matrix_get_speed(void); void rgb_matrix_increase_speed(void); +void rgb_matrix_increase_speed_noeeprom(void); void rgb_matrix_decrease_speed(void); -uint8_t rgb_matrix_get_speed(void); +void rgb_matrix_decrease_speed_noeeprom(void); led_flags_t rgb_matrix_get_flags(void); void rgb_matrix_set_flags(led_flags_t flags); -void rgb_matrix_mode(uint8_t mode); -void rgb_matrix_mode_noeeprom(uint8_t mode); -uint8_t rgb_matrix_get_mode(void); -void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val); -void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val); -HSV rgb_matrix_get_hsv(void); -uint8_t rgb_matrix_get_hue(void); -uint8_t rgb_matrix_get_sat(void); -uint8_t rgb_matrix_get_val(void); #ifndef RGBLIGHT_ENABLE # define rgblight_toggle rgb_matrix_toggle +# define rgblight_toggle_noeeprom rgb_matrix_toggle_noeeprom # define rgblight_enable rgb_matrix_enable # define rgblight_enable_noeeprom rgb_matrix_enable_noeeprom # define rgblight_disable rgb_matrix_disable # define rgblight_disable_noeeprom rgb_matrix_disable_noeeprom # define rgblight_is_enabled rgb_matrix_is_enabled +# define rgblight_mode rgb_matrix_mode +# define rgblight_mode_noeeprom rgb_matrix_mode_noeeprom +# define rgblight_get_mode rgb_matrix_get_mode +# define rgblight_get_hue rgb_matrix_get_hue +# define rgblight_get_sat rgb_matrix_get_sat +# define rgblight_get_val rgb_matrix_get_val +# define rgblight_get_hsv rgb_matrix_get_hsv # define rgblight_step rgb_matrix_step +# define rgblight_step_noeeprom rgb_matrix_step_noeeprom +# define rgblight_step_reverse rgb_matrix_step_reverse +# define rgblight_step_reverse_noeeprom rgb_matrix_step_reverse_noeeprom # define rgblight_sethsv rgb_matrix_sethsv # define rgblight_sethsv_noeeprom rgb_matrix_sethsv_noeeprom -# define rgblight_step_reverse rgb_matrix_step_reverse # define rgblight_increase_hue rgb_matrix_increase_hue +# define rgblight_increase_hue_noeeprom rgb_matrix_increase_hue_noeeprom # define rgblight_decrease_hue rgb_matrix_decrease_hue +# define rgblight_decrease_hue_noeeprom rgb_matrix_decrease_hue_noeeprom # define rgblight_increase_sat rgb_matrix_increase_sat +# define rgblight_increase_sat_noeeprom rgb_matrix_increase_sat_noeeprom # define rgblight_decrease_sat rgb_matrix_decrease_sat +# define rgblight_decrease_sat_noeeprom rgb_matrix_decrease_sat_noeeprom # define rgblight_increase_val rgb_matrix_increase_val +# define rgblight_increase_val_noeeprom rgb_matrix_increase_val_noeeprom # define rgblight_decrease_val rgb_matrix_decrease_val +# define rgblight_decrease_val_noeeprom rgb_matrix_decrease_val_noeeprom +# define rgblight_set_speed rgb_matrix_set_speed +# define rgblight_set_speed_noeeprom rgb_matrix_set_speed_noeeprom +# define rgblight_get_speed rgb_matrix_get_speed # define rgblight_increase_speed rgb_matrix_increase_speed +# define rgblight_increase_speed_noeeprom rgb_matrix_increase_speed_noeeprom # define rgblight_decrease_speed rgb_matrix_decrease_speed -# define rgblight_get_speed rgb_matrix_get_speed -# define rgblight_mode rgb_matrix_mode -# define rgblight_mode_noeeprom rgb_matrix_mode_noeeprom -# define rgblight_get_mode rgb_matrix_get_mode -# define rgblight_get_hue rgb_matrix_get_hue -# define rgblight_get_sat rgb_matrix_get_sat -# define rgblight_get_val rgb_matrix_get_val -# define rgblight_get_hsv rgb_matrix_get_hsv +# define rgblight_decrease_speed_noeeprom rgb_matrix_decrease_speed_noeeprom #endif typedef struct { From c2845143e5a73b7a9e5bedef273a08cac9dd1901 Mon Sep 17 00:00:00 2001 From: tynanbe Date: Sun, 21 Jun 2020 20:04:42 -0500 Subject: [PATCH 2/4] qmk cformat rgb_matrix --- quantum/rgb_matrix.c | 123 ++++++------------------------------------- 1 file changed, 17 insertions(+), 106 deletions(-) diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 643a813878a6..c75faa294d09 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -468,12 +468,7 @@ void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom) { if (write_to_eeprom) { eeconfig_update_rgb_matrix(); } - dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", - (write_to_eeprom) - ? "EEPROM" - : "NOEEPROM", - rgb_matrix_config.enable - ); + dprintf("rgb matrix toggle [%s]: rgb_matrix_config.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.enable); } void rgb_matrix_toggle_noeeprom(void) { rgb_matrix_toggle_eeprom_helper(false); } void rgb_matrix_toggle(void) { rgb_matrix_toggle_eeprom_helper(true); } @@ -506,23 +501,16 @@ void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { } if (mode < 1) { rgb_matrix_config.mode = 1; - } - else if (mode >= RGB_MATRIX_EFFECT_MAX) { + } else if (mode >= RGB_MATRIX_EFFECT_MAX) { rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; - } - else { + } else { rgb_matrix_config.mode = mode; } rgb_task_state = STARTING; if (write_to_eeprom) { eeconfig_update_rgb_matrix(); } - dprintf("rgb matrix mode [%s]: %u\n", - (write_to_eeprom) - ? "EEPROM" - : "NOEEPROM", - rgb_matrix_config.mode - ); + dprintf("rgb matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.mode); } void rgb_matrix_mode_noeeprom(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, false); } void rgb_matrix_mode(uint8_t mode) { rgb_matrix_mode_eeprom_helper(mode, true); } @@ -531,24 +519,14 @@ uint8_t rgb_matrix_get_mode(void) { return rgb_matrix_config.mode; } void rgb_matrix_step_helper(bool write_to_eeprom) { uint8_t mode = rgb_matrix_config.mode + 1; - rgb_matrix_mode_eeprom_helper( - (mode < RGB_MATRIX_EFFECT_MAX) - ? mode - : 1, - write_to_eeprom - ); + rgb_matrix_mode_eeprom_helper((mode < RGB_MATRIX_EFFECT_MAX) ? mode : 1, write_to_eeprom); } void rgb_matrix_step_noeeprom(void) { rgb_matrix_step_helper(false); } void rgb_matrix_step(void) { rgb_matrix_step_helper(true); } void rgb_matrix_step_reverse_helper(bool write_to_eeprom) { uint8_t mode = rgb_matrix_config.mode - 1; - rgb_matrix_mode_eeprom_helper( - (mode < 1) - ? RGB_MATRIX_EFFECT_MAX - 1 - : mode, - write_to_eeprom - ); + rgb_matrix_mode_eeprom_helper((mode < 1) ? RGB_MATRIX_EFFECT_MAX - 1 : mode, write_to_eeprom); } void rgb_matrix_step_reverse_noeeprom(void) { rgb_matrix_step_reverse_helper(false); } void rgb_matrix_step_reverse(void) { rgb_matrix_step_reverse_helper(true); } @@ -559,21 +537,11 @@ void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, boo } rgb_matrix_config.hsv.h = hue; rgb_matrix_config.hsv.s = sat; - rgb_matrix_config.hsv.v = - (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) - ? RGB_MATRIX_MAXIMUM_BRIGHTNESS - : val; + rgb_matrix_config.hsv.v = (val > RGB_MATRIX_MAXIMUM_BRIGHTNESS) ? RGB_MATRIX_MAXIMUM_BRIGHTNESS : val; if (write_to_eeprom) { eeconfig_update_rgb_matrix(); } - 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 - ); + 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); } void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, false); } void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { rgb_matrix_sethsv_eeprom_helper(hue, sat, val, true); } @@ -583,69 +551,27 @@ uint8_t rgb_matrix_get_hue(void) { return rgb_matrix_config.hsv.h; } uint8_t rgb_matrix_get_sat(void) { return rgb_matrix_config.hsv.s; } uint8_t rgb_matrix_get_val(void) { return rgb_matrix_config.hsv.v; } -void 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 - ); -} +void 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); } void rgb_matrix_increase_hue_noeeprom(void) { rgb_matrix_increase_hue_helper(false); } void rgb_matrix_increase_hue(void) { rgb_matrix_increase_hue_helper(true); } -void 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 - ); -} +void 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); } void rgb_matrix_decrease_hue_noeeprom(void) { rgb_matrix_decrease_hue_helper(false); } void rgb_matrix_decrease_hue(void) { rgb_matrix_decrease_hue_helper(true); } -void 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 - ); -} +void 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); } void rgb_matrix_increase_sat_noeeprom(void) { rgb_matrix_increase_sat_helper(false); } void rgb_matrix_increase_sat(void) { rgb_matrix_increase_sat_helper(true); } -void 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 - ); -} +void 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); } void rgb_matrix_decrease_sat_noeeprom(void) { rgb_matrix_decrease_sat_helper(false); } void rgb_matrix_decrease_sat(void) { rgb_matrix_decrease_sat_helper(true); } -void 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 - ); -} +void 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); } void rgb_matrix_increase_val_noeeprom(void) { rgb_matrix_increase_val_helper(false); } void rgb_matrix_increase_val(void) { rgb_matrix_increase_val_helper(true); } -void 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 - ); -} +void 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); } void rgb_matrix_decrease_val_noeeprom(void) { rgb_matrix_decrease_val_helper(false); } void rgb_matrix_decrease_val(void) { rgb_matrix_decrease_val_helper(true); } @@ -654,33 +580,18 @@ void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) { if (write_to_eeprom) { eeconfig_update_rgb_matrix(); } - dprintf("rgb matrix set speed [%s]: %u\n", - (write_to_eeprom) - ? "EEPROM" - : "NOEEPROM", - rgb_matrix_config.speed - ); + dprintf("rgb matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", rgb_matrix_config.speed); } void rgb_matrix_set_speed_noeeprom(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, false); } void rgb_matrix_set_speed(uint8_t speed) { rgb_matrix_set_speed_eeprom_helper(speed, true); } uint8_t rgb_matrix_get_speed(void) { return rgb_matrix_config.speed; } -void 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 - ); -} +void 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); } void rgb_matrix_increase_speed_noeeprom(void) { rgb_matrix_increase_speed_helper(false); } void rgb_matrix_increase_speed(void) { rgb_matrix_increase_speed_helper(true); } -void 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 - ); -} +void 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); } void rgb_matrix_decrease_speed_noeeprom(void) { rgb_matrix_decrease_speed_helper(false); } void rgb_matrix_decrease_speed(void) { rgb_matrix_decrease_speed_helper(true); } From bab95c2f2b78953c97ec9c0343bb4d7e3a390d5f Mon Sep 17 00:00:00 2001 From: tynanbe Date: Sun, 21 Jun 2020 20:49:30 -0500 Subject: [PATCH 3/4] Add rgb_matrix_set_speed and *_noeeprom functions --- docs/feature_rgb_matrix.md | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md index 9604bdcc8982..4f8a1269ffeb 100644 --- a/docs/feature_rgb_matrix.md +++ b/docs/feature_rgb_matrix.md @@ -421,8 +421,8 @@ Where `28` is an unused index from `eeconfig.h`. |`rgb_matrix_toggle_noeeprom()` |Toggle effect range LEDs between on and off (not written to EEPROM) | |`rgb_matrix_enable()` |Turn effect range LEDs on, based on their previous state | |`rgb_matrix_enable_noeeprom()` |Turn effect range LEDs on, based on their previous state (not written to EEPROM) | -|`rgb_matrix_disable()` |Turn effect range LEDs off | -|`rgb_matrix_disable_noeeprom()` |Turn effect range LEDs off (not written to EEPROM) | +|`rgb_matrix_disable()` |Turn effect range LEDs off, based on their previous state | +|`rgb_matrix_disable_noeeprom()` |Turn effect range LEDs off, based on their previous state (not written to EEPROM) | ### Change Effect Mode :id=change-effect-mode |Function |Description | @@ -430,19 +430,31 @@ Where `28` is an unused index from `eeconfig.h`. |`rgb_matrix_mode(mode)` |Set the mode, if RGB animations are enabled | |`rgb_matrix_mode_noeeprom(mode)` |Set the mode, if RGB animations are enabled (not written to EEPROM) | |`rgb_matrix_step()` |Change the mode to the next RGB animation in the list of enabled RGB animations | +|`rgb_matrix_step_noeeprom()` |Change the mode to the next RGB animation in the list of enabled RGB animations (not written to EEPROM) | |`rgb_matrix_step_reverse()` |Change the mode to the previous RGB animation in the list of enabled RGB animations | -|`rgb_matrix_increase_speed()` |Increases the speed of the animations | -|`rgb_matrix_decrease_speed()` |Decreases the speed of the animations | +|`rgb_matrix_step_reverse_noeeprom()` |Change the mode to the previous RGB animation in the list of enabled RGB animations (not written to EEPROM) | +|`rgb_matrix_increase_speed()` |Increase the speed of the animations | +|`rgb_matrix_increase_speed_noeeprom()` |Increase the speed of the animations (not written to EEPROM) | +|`rgb_matrix_decrease_speed()` |Decrease the speed of the animations | +|`rgb_matrix_decrease_speed_noeeprom()` |Decrease the speed of the animations (not written to EEPROM) | +|`rgb_matrix_set_speed(speed)` |Set the speed of the animations to the given value where `speed` is between 0 and 255 | +|`rgb_matrix_set_speed_noeeprom(speed)` |Set the speed of the animations to the given value where `speed` is between 0 and 255 (not written to EEPROM) | ### Change Color :id=change-color |Function |Description | |--------------------------------------------|-------------| |`rgb_matrix_increase_hue()` |Increase the hue for effect range LEDs. This wraps around at maximum hue | +|`rgb_matrix_increase_hue_noeeprom()` |Increase the hue for effect range LEDs. This wraps around at maximum hue (not written to EEPROM) | |`rgb_matrix_decrease_hue()` |Decrease the hue for effect range LEDs. This wraps around at minimum hue | +|`rgb_matrix_decrease_hue_noeeprom()` |Decrease the hue for effect range LEDs. This wraps around at minimum hue (not written to EEPROM) | |`rgb_matrix_increase_sat()` |Increase the saturation for effect range LEDs. This wraps around at maximum saturation | +|`rgb_matrix_increase_sat_noeeprom()` |Increase the saturation for effect range LEDs. This wraps around at maximum saturation (not written to EEPROM) | |`rgb_matrix_decrease_sat()` |Decrease the saturation for effect range LEDs. This wraps around at minimum saturation | +|`rgb_matrix_decrease_sat_noeeprom()` |Decrease the saturation for effect range LEDs. This wraps around at minimum saturation (not written to EEPROM) | |`rgb_matrix_increase_val()` |Increase the value for effect range LEDs. This wraps around at maximum value | +|`rgb_matrix_increase_val_noeeprom()` |Increase the value for effect range LEDs. This wraps around at maximum value (not written to EEPROM) | |`rgb_matrix_decrease_val()` |Decrease the value for effect range LEDs. This wraps around at minimum value | +|`rgb_matrix_decrease_val_noeeprom()` |Decrease the value for effect range LEDs. This wraps around at minimum value (not written to EEPROM) | |`rgb_matrix_sethsv(h, s, v)` |Set LEDs to the given HSV value where `h`/`s`/`v` are between 0 and 255 | |`rgb_matrix_sethsv_noeeprom(h, s, v)` |Set LEDs to the given HSV value where `h`/`s`/`v` are between 0 and 255 (not written to EEPROM) | From 10d504c2a5c3a64983bfcdb6d66a5f639d5eba13 Mon Sep 17 00:00:00 2001 From: tynanbe Date: Wed, 29 Jul 2020 14:45:27 -0500 Subject: [PATCH 4/4] Do not expose rgb_matrix_*_eeprom_helper functions --- quantum/rgb_matrix.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index 30f61751813f..733333349faa 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h @@ -107,7 +107,6 @@ void rgb_matrix_init(void); void rgb_matrix_set_suspend_state(bool state); bool rgb_matrix_get_suspend_state(void); -void rgb_matrix_toggle_eeprom_helper(bool write_to_eeprom); void rgb_matrix_toggle(void); void rgb_matrix_toggle_noeeprom(void); void rgb_matrix_enable(void); @@ -115,7 +114,6 @@ void rgb_matrix_enable_noeeprom(void); void rgb_matrix_disable(void); void rgb_matrix_disable_noeeprom(void); uint8_t rgb_matrix_is_enabled(void); -void rgb_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom); void rgb_matrix_mode(uint8_t mode); void rgb_matrix_mode_noeeprom(uint8_t mode); uint8_t rgb_matrix_get_mode(void); @@ -123,7 +121,6 @@ void rgb_matrix_step(void); void rgb_matrix_step_noeeprom(void); void rgb_matrix_step_reverse(void); void rgb_matrix_step_reverse_noeeprom(void); -void rgb_matrix_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom); void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val); void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val); HSV rgb_matrix_get_hsv(void); @@ -142,7 +139,6 @@ void rgb_matrix_increase_val(void); void rgb_matrix_increase_val_noeeprom(void); void rgb_matrix_decrease_val(void); void rgb_matrix_decrease_val_noeeprom(void); -void rgb_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom); void rgb_matrix_set_speed(uint8_t speed); void rgb_matrix_set_speed_noeeprom(uint8_t speed); uint8_t rgb_matrix_get_speed(void);