From bbb96e484ba514506657bf2fc746fae03475f7cf Mon Sep 17 00:00:00 2001 From: Tushar Singal Date: Fri, 6 Jan 2017 15:18:59 -0500 Subject: [PATCH 1/5] Improved arrow key positions in keymap. --- keyboards/zeal60/keymaps/tusing/config.h | 4 ++-- keyboards/zeal60/keymaps/tusing/keymap.c | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/keyboards/zeal60/keymaps/tusing/config.h b/keyboards/zeal60/keymaps/tusing/config.h index a5d63b11e1c1..cd1d26290574 100644 --- a/keyboards/zeal60/keymaps/tusing/config.h +++ b/keyboards/zeal60/keymaps/tusing/config.h @@ -30,7 +30,7 @@ // 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 600 // Strip current limit in mA. +#define RGBSTRIP_MAX_CURRENT_PER_LIGHT 40 // mA per light when at max brightness. #endif diff --git a/keyboards/zeal60/keymaps/tusing/keymap.c b/keyboards/zeal60/keymaps/tusing/keymap.c index f386a12d128a..2a9859a2efb7 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 @@ -23,17 +24,17 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { {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_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} }, From c5be7fd5263c14c7416138cd46b8045cb00cd5fd Mon Sep 17 00:00:00 2001 From: Tushar Singal Date: Sat, 7 Jan 2017 17:14:15 -0500 Subject: [PATCH 2/5] Added functionality to correct uneven RGB underglow. Refactored related code. --- keyboards/zeal60/keymaps/tusing/config.h | 6 ++- quantum/rgblight.c | 55 +++++++++++++++++++++--- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/keyboards/zeal60/keymaps/tusing/config.h b/keyboards/zeal60/keymaps/tusing/config.h index cd1d26290574..8f7e1acf150c 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 600 // Strip current limit in mA. +#define RGBSTRIP_CURRENT_LIMIT 700 // 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/quantum/rgblight.c b/quantum/rgblight.c index a2f51ef7c933..b7d28a695b51 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 + + #ifdef LED_BRIGHTNESS_CORRECTION + correct_brightness(); + #endif + + #if defined(RGBSTRIP_CURRENT_LIMIT) && defined(RGBSTRIP_MAX_CURRENT_PER_LIGHT) + adjust_current(); + #endif + if (rgblight_config.enable) { #ifdef RGBW ws2812_setleds_rgbw(led, RGBLED_NUM); From 490433dd52dcd13460e27211ee443b7d230e63ec Mon Sep 17 00:00:00 2001 From: Tushar Singal Date: Sat, 7 Jan 2017 17:29:05 -0500 Subject: [PATCH 3/5] Reverted to safer values for underglow. --- keyboards/zeal60/keymaps/tusing/config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keyboards/zeal60/keymaps/tusing/config.h b/keyboards/zeal60/keymaps/tusing/config.h index 8f7e1acf150c..04596833e8c3 100644 --- a/keyboards/zeal60/keymaps/tusing/config.h +++ b/keyboards/zeal60/keymaps/tusing/config.h @@ -30,8 +30,8 @@ // Enable current limiting for RGB underglow. #define USB_MAX_POWER_CONSUMPTION 900 -#define RGBSTRIP_CURRENT_LIMIT 700 // Strip current limit in mA. -#define RGBSTRIP_MAX_CURRENT_PER_LIGHT 40 // mA per light when at max brightness. +#define RGBSTRIP_CURRENT_LIMIT 400 // Strip current limit in mA. +#define RGBSTRIP_MAX_CURRENT_PER_LIGHT 60 // 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. From 4f32bcb604b6a72b17841caeb42097746ab72d77 Mon Sep 17 00:00:00 2001 From: Tushar Singal Date: Wed, 18 Jan 2017 03:39:11 -0800 Subject: [PATCH 4/5] Custom LED brightness scaling will take place after current adjustment in order to avoid being overridden. --- keyboards/zeal60/keymaps/tusing/config.h | 6 +++--- keyboards/zeal60/keymaps/tusing/keymap.c | 4 ++-- quantum/rgblight.c | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/keyboards/zeal60/keymaps/tusing/config.h b/keyboards/zeal60/keymaps/tusing/config.h index 04596833e8c3..c92aaea12649 100644 --- a/keyboards/zeal60/keymaps/tusing/config.h +++ b/keyboards/zeal60/keymaps/tusing/config.h @@ -30,11 +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 +// #define LED_BRIGHTNESS_CORRECTION #endif diff --git a/keyboards/zeal60/keymaps/tusing/keymap.c b/keyboards/zeal60/keymaps/tusing/keymap.c index 2a9859a2efb7..b1caeefa423b 100644 --- a/keyboards/zeal60/keymaps/tusing/keymap.c +++ b/keyboards/zeal60/keymaps/tusing/keymap.c @@ -20,7 +20,7 @@ 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_ }, @@ -30,7 +30,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { // 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_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_ }, diff --git a/quantum/rgblight.c b/quantum/rgblight.c index b7d28a695b51..51017929eb94 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -434,15 +434,15 @@ void adjust_current(void) { __attribute__ ((weak)) void rgblight_set(void) { + + #if defined(RGBSTRIP_CURRENT_LIMIT) && defined(RGBSTRIP_MAX_CURRENT_PER_LIGHT) + adjust_current(); + #endif #ifdef LED_BRIGHTNESS_CORRECTION correct_brightness(); #endif - #if defined(RGBSTRIP_CURRENT_LIMIT) && defined(RGBSTRIP_MAX_CURRENT_PER_LIGHT) - adjust_current(); - #endif - if (rgblight_config.enable) { #ifdef RGBW ws2812_setleds_rgbw(led, RGBLED_NUM); From 1e100733e7239d1a68c5240aa778083ba5d16d78 Mon Sep 17 00:00:00 2001 From: Tushar Singal Date: Mon, 23 Jan 2017 15:43:48 -0800 Subject: [PATCH 5/5] Fixed bug where left spacebar stabilizer LED (LC06) would adopt color of row above. --- keyboards/zeal60/zeal_backlight.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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},