diff --git a/keyboards/zeal60/keymaps/tusing/config.h b/keyboards/zeal60/keymaps/tusing/config.h index a5d63b11e1c1..c92aaea12649 100644 --- a/keyboards/zeal60/keymaps/tusing/config.h +++ b/keyboards/zeal60/keymaps/tusing/config.h @@ -30,7 +30,11 @@ // Enable current limiting for RGB underglow. #define USB_MAX_POWER_CONSUMPTION 900 -#define RGBSTRIP_CURRENT_LIMIT 400 // Strip current limit in mA. -#define RGBSTRIP_MAX_CURRENT_PER_LIGHT 60 // mA per light when at max brightness. +#define RGBSTRIP_CURRENT_LIMIT 800 // Strip current limit in mA. +#define RGBSTRIP_MAX_CURRENT_PER_LIGHT 40 // mA per light when at max brightness. + +// Scale brightnes according to BRIGHTNESS_CORRECTION_TABLE in quantum/rgblight.c. +// This allows to mitigate uneven brightness from LED underglow strips. +// #define LED_BRIGHTNESS_CORRECTION #endif diff --git a/keyboards/zeal60/keymaps/tusing/keymap.c b/keyboards/zeal60/keymaps/tusing/keymap.c index f386a12d128a..b1caeefa423b 100644 --- a/keyboards/zeal60/keymaps/tusing/keymap.c +++ b/keyboards/zeal60/keymaps/tusing/keymap.c @@ -6,6 +6,7 @@ #define _______ KC_TRNS #define _x_ KC_NO + // Zeal60-specific keys: // EF_INC, EF_DEC, // next/previous backlight effect // H1_INC, H1_DEC, // Color 1 hue increase/decrease @@ -19,21 +20,21 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // Default layer: Pressing caps-lock momentarily switches to Layer 1. // This is the default layer. Pressing an invalid keycode on another layer will take you here. [0] = { - {KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC}, + {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC}, {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS}, {MO(1), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, _x_ }, {KC_LSFT, _x_ , KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, _x_ }, - {KC_LCTL, KC_LGUI, KC_LALT, _x_ , _x_ , _x_ , _x_ , KC_SPC, _x_ , _x_ , KC_UP, KC_DOWN, KC_LEFT, KC_RGHT} + {KC_LCTL, KC_LGUI, KC_LALT, _x_ , _x_ , _x_ , _x_ , KC_SPC, _x_ , _x_ , KC_LEFT, KC_UP, KC_DOWN, KC_RGHT} }, // Layer 1: Pressing Ctrl switches to layer 2. // This is a momentary layer: once you let go of caps, you'll be back in layer 1. [1] = { - {KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL }, - {KC_VOLD, KC_MUTE, KC_VOLU, _______, _______, _______, _______, _______, KC_PSCR, KC_SLCK, KC_PAUS, KC_INS, KC_DEL, _______}, - {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _x_ }, + {KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL }, + {_______, KC_VOLD, KC_MUTE, KC_VOLU, _______, _______, _______, _______, KC_PSCR, KC_SLCK, KC_PAUS, KC_INS, KC_DEL, _______}, + {_______, KC_MPRV, KC_MPLY, KC_MNXT, _______, _______, _______, _______, _______, _______, _______, _______, _______, _x_ }, {KC_CAPS, _x_ , _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _x_ }, - {TO(2), _______, _______, _x_ , _x_ , _x_ , _x_ , _______, _x_ , _x_ , KC_PGUP, KC_PGDN, KC_HOME, KC_END} + {TO(2), _______, _______, _x_ , _x_ , _x_ , _x_ , _______, _x_ , _x_ , KC_HOME, KC_PGUP, KC_PGDN, KC_END} }, diff --git a/keyboards/zeal60/zeal_backlight.c b/keyboards/zeal60/zeal_backlight.c index 9a5785ff5f28..cf6cf7616f25 100644 --- a/keyboards/zeal60/zeal_backlight.c +++ b/keyboards/zeal60/zeal_backlight.c @@ -64,7 +64,7 @@ const Point g_map_led_to_point[72] PROGMEM = { {144,0}, {160,0}, {176,0}, {192,0}, {216,0}, {224,0}, {255,255}, {255,255}, {255,255}, {136,16}, {152,16}, {168,16}, {184,16}, {200,16}, {220,16}, {255,255}, {255,255}, {255,255}, // LC0..LC17 - {102,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {60,48}, {43,64}, {23,64}, + {102,64}, {100,48}, {84,48}, {68,48}, {52,48}, {36,48}, {60,64}, {43,64}, {23,64}, {108,32}, {92,32}, {76,32}, {60,32}, {44,32}, {28,32}, {20,48}, {2,48}, {3,64}, // LD0..LD17 {124,32}, {140,32}, {156,32}, {172,32}, {188,32}, {214,32}, {180,48}, {210,48}, {224,48}, diff --git a/quantum/rgblight.c b/quantum/rgblight.c index a2f51ef7c933..51017929eb94 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -56,6 +56,13 @@ const uint8_t RGBLED_BREATHING_TABLE[] PROGMEM = { 10, 9, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0 }; +const float BRIGHTNESS_CORRECTION_TABLE[] PROGMEM = { + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0, 1.0 +}; + __attribute__ ((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; __attribute__ ((weak)) @@ -370,6 +377,38 @@ void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { rgblight_set(); } +void scale_led(int i, float multiplier) { + /** Scale led[i]'s brightness by multiplier. */ + + // Prevent multipliers greater than 1 from overflowing + // the 8-bit unsigned int that governs LED brightness. + if (multiplier > 1.0) { + uint8_t max_value = 0; + uint8_t led_array[] = {led[i].r, led[i].g, led[i].b}; + for (uint8_t i = 0; i < 3; i++) { + if (led_array[i] > max_value) { + max_value = led_array[i]; + } + } + + if ((max_value * multiplier) > 255) { + multiplier = 255.0 / max_value; + } + } + + led[i].r = (uint8_t)(led[i].r * multiplier); + led[i].g = (uint8_t)(led[i].g * multiplier); + led[i].b = (uint8_t)(led[i].b * multiplier); +} + +void correct_brightness(void) { + /** Correct brightness for uneven underglow LEDs as defined by + scaling factors in BRIGHTNESS_CORRECTION_TABLE. */ + for (uint8_t i = 0; i < RGBLED_NUM; i++) { + scale_led(i, pgm_read_float(&BRIGHTNESS_CORRECTION_TABLE[i])); + } +} + void adjust_current(void) { /** Dims RGB strip if it exceeds defined current limit. */ // Convert 1 milliamp to an R+G+B brightness value. @@ -388,18 +427,22 @@ void adjust_current(void) { if (strip_rgbw_total > strip_rgbw_limit) { float multiplier = strip_rgbw_limit / strip_rgbw_total; for (uint8_t i = 0; i < RGBLED_NUM; i++) { - led[i].r = (uint8_t)(led[i].r * multiplier); - led[i].g = (uint8_t)(led[i].g * multiplier); - led[i].b = (uint8_t)(led[i].b * multiplier); + scale_led(i, multiplier); } } } __attribute__ ((weak)) void rgblight_set(void) { -#if defined(RGBSTRIP_CURRENT_LIMIT) && defined(RGBSTRIP_MAX_CURRENT_PER_LIGHT) - adjust_current(); -#endif + + #if defined(RGBSTRIP_CURRENT_LIMIT) && defined(RGBSTRIP_MAX_CURRENT_PER_LIGHT) + adjust_current(); + #endif + + #ifdef LED_BRIGHTNESS_CORRECTION + correct_brightness(); + #endif + if (rgblight_config.enable) { #ifdef RGBW ws2812_setleds_rgbw(led, RGBLED_NUM);