diff options
Diffstat (limited to 'quantum/via.c')
-rw-r--r-- | quantum/via.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/quantum/via.c b/quantum/via.c index 320bd5546d..d2ef0862cc 100644 --- a/quantum/via.c +++ b/quantum/via.c @@ -64,6 +64,7 @@ void via_qmk_rgblight_get_value(uint8_t *data); #endif #if defined(VIA_QMK_RGB_MATRIX_ENABLE) +# include <lib/lib8tion/lib8tion.h> void via_qmk_rgb_matrix_set_value(uint8_t *data); void via_qmk_rgb_matrix_get_value(uint8_t *data); void eeconfig_update_rgb_matrix(void); @@ -421,7 +422,7 @@ void via_qmk_backlight_get_value(uint8_t *data) { switch (*value_id) { case id_qmk_backlight_brightness: { // level / BACKLIGHT_LEVELS * 255 - value_data[0] = ((uint16_t)get_backlight_level()) * 255 / BACKLIGHT_LEVELS; + value_data[0] = ((uint16_t)get_backlight_level() * UINT8_MAX) / BACKLIGHT_LEVELS; break; } case id_qmk_backlight_effect: { @@ -441,7 +442,7 @@ void via_qmk_backlight_set_value(uint8_t *data) { switch (*value_id) { case id_qmk_backlight_brightness: { // level / 255 * BACKLIGHT_LEVELS - backlight_level_noeeprom(((uint16_t)value_data[0]) * BACKLIGHT_LEVELS / 255); + backlight_level_noeeprom(((uint16_t)value_data[0] * BACKLIGHT_LEVELS) / UINT8_MAX); break; } case id_qmk_backlight_effect: { @@ -460,13 +461,16 @@ void via_qmk_backlight_set_value(uint8_t *data) { #endif // #if defined(VIA_QMK_BACKLIGHT_ENABLE) #if defined(VIA_QMK_RGBLIGHT_ENABLE) +# ifndef RGBLIGHT_LIMIT_VAL +# define RGBLIGHT_LIMIT_VAL 255 +# endif void via_qmk_rgblight_get_value(uint8_t *data) { uint8_t *value_id = &(data[0]); uint8_t *value_data = &(data[1]); switch (*value_id) { case id_qmk_rgblight_brightness: { - value_data[0] = rgblight_get_val(); + value_data[0] = ((uint16_t)rgblight_get_val() * UINT8_MAX) / RGBLIGHT_LIMIT_VAL; break; } case id_qmk_rgblight_effect: { @@ -490,7 +494,7 @@ void via_qmk_rgblight_set_value(uint8_t *data) { uint8_t *value_data = &(data[1]); switch (*value_id) { case id_qmk_rgblight_brightness: { - rgblight_sethsv_noeeprom(rgblight_get_hue(), rgblight_get_sat(), value_data[0]); + rgblight_sethsv_noeeprom(rgblight_get_hue(), rgblight_get_sat(), ((uint16_t)value_data[0] * RGBLIGHT_LIMIT_VAL) / UINT8_MAX); break; } case id_qmk_rgblight_effect: { @@ -517,6 +521,11 @@ void via_qmk_rgblight_set_value(uint8_t *data) { #if defined(VIA_QMK_RGB_MATRIX_ENABLE) +# if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX +# undef RGB_MATRIX_MAXIMUM_BRIGHTNESS +# define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX +# endif + // VIA supports only 4 discrete values for effect speed; map these to some // useful speed values for RGB Matrix. enum speed_values { @@ -557,7 +566,7 @@ void via_qmk_rgb_matrix_get_value(uint8_t *data) { uint8_t *value_data = &(data[1]); switch (*value_id) { case id_qmk_rgblight_brightness: - value_data[0] = rgb_matrix_get_val(); + value_data[0] = ((uint16_t)rgb_matrix_get_val() * UINT8_MAX) / RGB_MATRIX_MAXIMUM_BRIGHTNESS; break; case id_qmk_rgblight_effect: value_data[0] = rgb_matrix_get_mode(); @@ -577,7 +586,7 @@ void via_qmk_rgb_matrix_set_value(uint8_t *data) { uint8_t *value_data = &(data[1]); switch (*value_id) { case id_qmk_rgblight_brightness: - rgb_matrix_sethsv_noeeprom(rgb_matrix_get_hue(), rgb_matrix_get_sat(), value_data[0]); + rgb_matrix_sethsv_noeeprom(rgb_matrix_get_hue(), rgb_matrix_get_sat(), scale8(value_data[0], RGB_MATRIX_MAXIMUM_BRIGHTNESS)); break; case id_qmk_rgblight_effect: rgb_matrix_mode_noeeprom(value_data[0]); |