Get rid of USB_LED_SCROLL_LOCK (#21405)

This commit is contained in:
Ryan 2023-07-03 04:24:22 +10:00 committed by GitHub
parent 9dbad1fa5c
commit 7ff80a57cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
62 changed files with 399 additions and 479 deletions

View File

@ -3,8 +3,6 @@
#define MEDAPP LT(MEDIA, KC_APP)
uint8_t current_layer_global = 255;
enum layers {
DEFAULT,
PROG1,
@ -87,25 +85,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_______,_______,_______, LT(MISC, KC_SPC), _______,_______,_______,_______, _______,_______,_______, _______,_______),
};
void matrix_scan_user(void) {
uint8_t layer;
layer = get_highest_layer(layer_state);
if (current_layer_global != layer) {
current_layer_global = layer;
// unset CAPSLOCK and SCROLL LOCK LEDs
led_set(host_keyboard_leds() & ~(1<<USB_LED_CAPS_LOCK));
led_set(host_keyboard_leds() & ~(1<<USB_LED_SCROLL_LOCK));
// set SCROLL LOCK LED when the mouse layer is active, CAPS LOCK when PROG layer is active
if (layer == MOUSE1 || layer == MOUSE2) {
led_set(host_keyboard_leds() | (1<<USB_LED_SCROLL_LOCK));
} else if (layer == PROG1 || layer == PROG2) {
led_set(host_keyboard_leds() | (1<<USB_LED_CAPS_LOCK));
}
}
}
void tap_helper(keyrecord_t *record, uint16_t orig_mod, uint16_t macro_mod, uint16_t macro_kc ) {
if (record->event.pressed) {
if (record->tap.count > 0 && !record->tap.interrupted) {

View File

@ -243,22 +243,22 @@ void via_custom_value_command(uint8_t *data, uint8_t length) {
void read_host_led_state(void) {
uint8_t leds = host_keyboard_leds();
if (leds & (1 << USB_LED_NUM_LOCK)) {
led_t led_state = host_keyboard_led_state();
if (led_state.num_lock) {
if (led_numlock == false){
led_numlock = true;}
} else {
if (led_numlock == true){
led_numlock = false;}
}
if (leds & (1 << USB_LED_CAPS_LOCK)) {
if (led_state.caps_lock) {
if (led_capslock == false){
led_capslock = true;}
} else {
if (led_capslock == true){
led_capslock = false;}
}
if (leds & (1 << USB_LED_SCROLL_LOCK)) {
if (led_state.scroll_lock) {
if (led_scrolllock == false){
led_scrolllock = true;}
} else {

View File

@ -75,10 +75,10 @@ bool oled_task_user(void) {
}
// Host Keyboard LED Status
uint8_t usb_led = host_keyboard_leds();
oled_write_P(IS_LED_ON(usb_led, USB_LED_NUM_LOCK) ? PSTR("NUMLCK ") : PSTR(" "), false);
oled_write_P(IS_LED_ON(usb_led, USB_LED_CAPS_LOCK) ? PSTR("CAPLCK ") : PSTR(" "), false);
oled_write_P(IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK) ? PSTR("SCRLCK ") : PSTR(" "), false);
led_t led_state = host_keyboard_led_state();
oled_write_P(led_state.num_lock ? PSTR("NUMLCK ") : PSTR(" "), false);
oled_write_P(led_state.caps_lock ? PSTR("CAPLCK ") : PSTR(" "), false);
oled_write_P(led_state.scroll_lock ? PSTR("SCRLCK ") : PSTR(" "), false);
return false;
}
#endif

View File

@ -20,14 +20,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "led.h"
void led_set(uint8_t usb_led)
bool led_update_kb(led_t led_state)
{
uint8_t ps2_led = 0;
if (usb_led & (1<<USB_LED_SCROLL_LOCK))
if (led_state.scroll_lock)
ps2_led |= (1<<PS2_LED_SCROLL_LOCK);
if (usb_led & (1<<USB_LED_NUM_LOCK))
if (led_state.num_lock)
ps2_led |= (1<<PS2_LED_NUM_LOCK);
if (usb_led & (1<<USB_LED_CAPS_LOCK))
if (led_state.caps_lock)
ps2_led |= (1<<PS2_LED_CAPS_LOCK);
ps2_host_set_led(ps2_led);
return false;
}

View File

@ -147,12 +147,12 @@ void render_layer_state(void) {
oled_write_P(PSTR("Raise"), layer_state_is(_RAISE));
}
void render_keylock_status(uint8_t led_usb_state) {
void render_keylock_status(led_t led_state) {
oled_write_P(PSTR("Lock:"), false);
oled_write_P(PSTR(" "), false);
oled_write_P(PSTR("N"), led_usb_state & (1 << USB_LED_NUM_LOCK));
oled_write_P(PSTR("C"), led_usb_state & (1 << USB_LED_CAPS_LOCK));
oled_write_ln_P(PSTR("S"), led_usb_state & (1 << USB_LED_SCROLL_LOCK));
oled_write_P(PSTR("N"), led_state.num_lock);
oled_write_P(PSTR("C"), led_state.caps_lock);
oled_write_ln_P(PSTR("S"), led_state.scroll_lock);
}
void render_mod_status(uint8_t modifiers) {
@ -183,7 +183,7 @@ void render_bootmagic_status(void) {
void render_status_main(void) {
/* Show Keyboard Layout */
render_default_layer_state();
render_keylock_status(host_keyboard_leds());
render_keylock_status(host_keyboard_led_state());
render_mod_status(get_mods());
render_bootmagic_status();

View File

@ -5,11 +5,11 @@ char host_led_state_str[24];
const char *read_host_led_state(void)
{
uint8_t leds = host_keyboard_leds();
led_t led_state = host_keyboard_led_state();
snprintf(host_led_state_str, sizeof(host_led_state_str), "NL:%s CL:%s SL:%s",
(leds & (1 << USB_LED_NUM_LOCK)) ? "on" : "- ",
(leds & (1 << USB_LED_CAPS_LOCK)) ? "on" : "- ",
(leds & (1 << USB_LED_SCROLL_LOCK)) ? "on" : "- ");
(led_state.num_lock) ? "on" : "- ",
(led_state.caps_lock) ? "on" : "- ",
(led_state.scroll_lock) ? "on" : "- ");
return host_led_state_str;
}

View File

@ -43,8 +43,8 @@ void backlight_set(uint8_t level) {
bool led_update_kb(led_t led_state) {
bool res = led_update_user(led_state);
if(res) {
backlight_os_state & (1<<USB_LED_CAPS_LOCK) ? (PORTB &= ~0b00000001) : (PORTB |= 0b00000001);
backlight_os_state & (1<<USB_LED_SCROLL_LOCK) ? (PORTB &= ~0b00010000) : (PORTB |= 0b00010000);
backlight_os_state & 2 ? (PORTB &= ~0b00000001) : (PORTB |= 0b00000001);
backlight_os_state & 4 ? (PORTB &= ~0b00010000) : (PORTB |= 0b00010000);
}
return res;
}

View File

@ -101,17 +101,17 @@ bool led_update_kb(led_t led_state) {
bool res = led_update_user(led_state);
if(res) {
bool status[7] = {
backlight_os_state & (1<<USB_LED_CAPS_LOCK),
backlight_os_state & (1<<USB_LED_SCROLL_LOCK),
backlight_os_state & (1<<USB_LED_NUM_LOCK),
backlight_os_state & 2,
backlight_os_state & 4,
backlight_os_state & 1,
backlight_layer_state & (1<<1),
backlight_layer_state & (1<<2),
backlight_layer_state & (1<<3),
backlight_layer_state & (1<<4)
};
indicator_leds_set(status);
backlight_os_state & (1<<USB_LED_CAPS_LOCK) ? (PORTB &= ~0b00000001) : (PORTB |= 0b00000001);
backlight_os_state & (1<<USB_LED_SCROLL_LOCK) ? (PORTB &= ~0b00010000) : (PORTB |= 0b00010000);
backlight_os_state & 2 ? (PORTB &= ~0b00000001) : (PORTB |= 0b00000001);
backlight_os_state & 4 ? (PORTB &= ~0b00010000) : (PORTB |= 0b00010000);
}
return res;
}

View File

@ -24,69 +24,6 @@ enum BACKLIGHT_AREAS {
BACKLIGHT_SWITCH = 0b0001111
};
// uint8_t backlight_rgb_r = 255;
// uint8_t backlight_rgb_g = 0;
// uint8_t backlight_rgb_b = 0;
// uint8_t backlight_os_state = 0;
// uint32_t backlight_layer_state = 0;
// void backlight_toggle_rgb(bool enabled)
// {
// if(enabled) {
// uint8_t rgb[17][3] = {
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b},
// {backlight_rgb_r, backlight_rgb_g, backlight_rgb_b}
// };
// backlight_set_rgb(rgb);
// } else {
// uint8_t rgb[17][3] = {
// {0, 0, 0},
// {0, 0, 0},
// {0, 0, 0},
// {0, 0, 0},
// {0, 0, 0},
// {0, 0, 0},
// {0, 0, 0},
// {0, 0, 0},
// {0, 0, 0},
// {0, 0, 0},
// {0, 0, 0},
// {0, 0, 0},
// {0, 0, 0},
// {0, 0, 0},
// {0, 0, 0},
// {0, 0, 0},
// {0, 0, 0}
// };
// backlight_set_rgb(rgb);
// }
// }
// void backlight_set_rgb(uint8_t cfg[17][3])
// {
// cli();
// for(uint8_t i = 0; i < 17; ++i) {
// send_color(cfg[i][0], cfg[i][1], cfg[i][2], Device_PCBRGB);
// }
// sei();
// show();
// }
// Q5, Q6, Q7 is connected to B1 - alphas
// Q8, Q9 is connected to B2 - frow
// Q1, Q2, Q3 is connected to B3 - mods
@ -99,26 +36,6 @@ void backlight_set(uint8_t level) {
level & BACKLIGHT_MACRO ? (PORTE |= 0b01000000) : (PORTE &= ~0b01000000);
}
// // Port from backlight_update_state
// bool led_update_kb(led_t led_state) {
// bool res = led_update_user(led_state);
// if(res) {
// bool status[7] = {
// backlight_os_state & (1<<USB_LED_CAPS_LOCK),
// backlight_os_state & (1<<USB_LED_SCROLL_LOCK),
// backlight_os_state & (1<<USB_LED_NUM_LOCK),
// backlight_layer_state & (1<<1),
// backlight_layer_state & (1<<2),
// backlight_layer_state & (1<<3),
// backlight_layer_state & (1<<4)
// };
// indicator_leds_set(status);
// backlight_os_state & (1<<USB_LED_CAPS_LOCK) ? (PORTB &= ~0b00000001) : (PORTB |= 0b00000001);
// backlight_os_state & (1<<USB_LED_SCROLL_LOCK) ? (PORTB &= ~0b00010000) : (PORTB |= 0b00010000);
// }
// return res;
// }
// U5 Pin 1, 2, 3 connected to top left LEDs
// U6 Pin 1, 2, 3 connected to bottom right leds col of 3

View File

@ -253,12 +253,7 @@ void matrix_scan_user(void) {
};
// The state of the LEDs requested by the system, as a bitmask.
static uint8_t sys_led_state = 0;
// Use these masks to read the system LEDs state.
static const uint8_t sys_led_mask_num_lock = 1 << USB_LED_NUM_LOCK;
static const uint8_t sys_led_mask_caps_lock = 1 << USB_LED_CAPS_LOCK;
static const uint8_t sys_led_mask_scroll_lock = 1 << USB_LED_SCROLL_LOCK;
static led_t sys_led_state = {0};
// Value to use to switch LEDs on. The default value of 255 is far too bright.
static const uint8_t max_led_value = 20;
@ -294,25 +289,26 @@ void led_3_off(void) {
}
// Called when the computer wants to change the state of the keyboard LEDs.
void led_set_user(uint8_t usb_led) {
sys_led_state = usb_led;
bool led_update_user(led_t led_state) {
sys_led_state = led_state;
if (LAYER_ON(SYSLEDS)) {
if (sys_led_state & sys_led_mask_caps_lock) {
if (sys_led_state.caps_lock) {
led_1_on();
} else {
led_1_off();
}
if (sys_led_state & sys_led_mask_num_lock) {
if (sys_led_state.num_lock) {
led_2_on();
} else {
led_2_off();
}
if (sys_led_state & sys_led_mask_scroll_lock) {
if (sys_led_state.scroll_lock) {
led_3_on();
} else {
led_3_off();
}
}
return false;
}
layer_state_t layer_state_set_user(layer_state_t state) {
@ -327,7 +323,7 @@ layer_state_t layer_state_set_user(layer_state_t state) {
}
if (LAYER_ON(SYSLEDS)) {
led_set_user(sys_led_state);
led_update_user(sys_led_state);
return state;
}

View File

@ -12,23 +12,29 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};
void led_set_user(uint8_t usb_led) {
if (usb_led & (1 << USB_LED_NUM_LOCK)) {
DDRB |= (1 << 5); PORTB &= ~(1 << 5);
bool led_update_user(led_t led_state) {
if (led_state.num_lock) {
DDRB |= (1 << 5);
PORTB &= ~(1 << 5);
} else {
DDRB &= ~(1 << 5); PORTB &= ~(1 << 5);
DDRB &= ~(1 << 5);
PORTB &= ~(1 << 5);
}
if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
DDRB |= (1 << 6); PORTB &= ~(1 << 6);
if (led_state.caps_lock) {
DDRB |= (1 << 6);
PORTB &= ~(1 << 6);
} else {
DDRB &= ~(1 << 6); PORTB &= ~(1 << 6);
DDRB &= ~(1 << 6);
PORTB &= ~(1 << 6);
}
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) {
DDRB |= (1 << 7); PORTB &= ~(1 << 7);
if (led_state.scroll_lock) {
DDRB |= (1 << 7);
PORTB &= ~(1 << 7);
} else {
DDRB &= ~(1 << 7); PORTB &= ~(1 << 7);
DDRB &= ~(1 << 7);
PORTB &= ~(1 << 7);
}
return false;
}

View File

@ -12,23 +12,29 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};
void led_set_user(uint8_t usb_led) {
bool led_update_user(led_t led_state) {
if (led_state.num_lock) {
DDRB |= (1 << 5);
PORTB &= ~(1 << 5);
} else {
DDRB &= ~(1 << 5);
PORTB &= ~(1 << 5);
}
if (usb_led & (1 << USB_LED_NUM_LOCK)) {
DDRB |= (1 << 5); PORTB &= ~(1 << 5);
} else {
DDRB &= ~(1 << 5); PORTB &= ~(1 << 5);
}
if (led_state.caps_lock) {
DDRB |= (1 << 6);
PORTB &= ~(1 << 6);
} else {
DDRB &= ~(1 << 6);
PORTB &= ~(1 << 6);
}
if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
DDRB |= (1 << 6); PORTB &= ~(1 << 6);
} else {
DDRB &= ~(1 << 6); PORTB &= ~(1 << 6);
}
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) {
DDRB |= (1 << 7); PORTB &= ~(1 << 7);
} else {
DDRB &= ~(1 << 7); PORTB &= ~(1 << 7);
}
if (led_state.scroll_lock) {
DDRB |= (1 << 7);
PORTB &= ~(1 << 7);
} else {
DDRB &= ~(1 << 7);
PORTB &= ~(1 << 7);
}
return false;
}

View File

@ -12,23 +12,29 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};
void led_set_user(uint8_t usb_led) {
if (usb_led & (1 << USB_LED_NUM_LOCK)) {
DDRB |= (1 << 5); PORTB &= ~(1 << 5);
bool led_update_user(led_t led_state) {
if (led_state.num_lock) {
DDRB |= (1 << 5);
PORTB &= ~(1 << 5);
} else {
DDRB &= ~(1 << 5); PORTB &= ~(1 << 5);
DDRB &= ~(1 << 5);
PORTB &= ~(1 << 5);
}
if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
DDRB |= (1 << 6); PORTB &= ~(1 << 6);
if (led_state.caps_lock) {
DDRB |= (1 << 6);
PORTB &= ~(1 << 6);
} else {
DDRB &= ~(1 << 6); PORTB &= ~(1 << 6);
DDRB &= ~(1 << 6);
PORTB &= ~(1 << 6);
}
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) {
DDRB |= (1 << 7); PORTB &= ~(1 << 7);
if (led_state.scroll_lock) {
DDRB |= (1 << 7);
PORTB &= ~(1 << 7);
} else {
DDRB &= ~(1 << 7); PORTB &= ~(1 << 7);
DDRB &= ~(1 << 7);
PORTB &= ~(1 << 7);
}
return false;
}

View File

@ -12,23 +12,29 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};
void led_set_user(uint8_t usb_led) {
if (usb_led & (1 << USB_LED_NUM_LOCK)) {
DDRB |= (1 << 5); PORTB &= ~(1 << 5);
bool led_update_user(led_t led_state) {
if (led_state.num_lock) {
DDRB |= (1 << 5);
PORTB &= ~(1 << 5);
} else {
DDRB &= ~(1 << 5); PORTB &= ~(1 << 5);
DDRB &= ~(1 << 5);
PORTB &= ~(1 << 5);
}
if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
DDRB |= (1 << 6); PORTB &= ~(1 << 6);
if (led_state.caps_lock) {
DDRB |= (1 << 6);
PORTB &= ~(1 << 6);
} else {
DDRB &= ~(1 << 6); PORTB &= ~(1 << 6);
DDRB &= ~(1 << 6);
PORTB &= ~(1 << 6);
}
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) {
DDRB |= (1 << 7); PORTB &= ~(1 << 7);
if (led_state.scroll_lock) {
DDRB |= (1 << 7);
PORTB &= ~(1 << 7);
} else {
DDRB &= ~(1 << 7); PORTB &= ~(1 << 7);
DDRB &= ~(1 << 7);
PORTB &= ~(1 << 7);
}
return false;
}

View File

@ -12,23 +12,29 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};
void led_set_user(uint8_t usb_led) {
bool led_update_user(led_t led_state) {
if (led_state.num_lock) {
DDRB |= (1 << 5);
PORTB &= ~(1 << 5);
} else {
DDRB &= ~(1 << 5);
PORTB &= ~(1 << 5);
}
if (usb_led & (1 << USB_LED_NUM_LOCK)) {
DDRB |= (1 << 5); PORTB &= ~(1 << 5);
} else {
DDRB &= ~(1 << 5); PORTB &= ~(1 << 5);
}
if (led_state.caps_lock) {
DDRB |= (1 << 6);
PORTB &= ~(1 << 6);
} else {
DDRB &= ~(1 << 6);
PORTB &= ~(1 << 6);
}
if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
DDRB |= (1 << 6); PORTB &= ~(1 << 6);
} else {
DDRB &= ~(1 << 6); PORTB &= ~(1 << 6);
}
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) {
DDRB |= (1 << 7); PORTB &= ~(1 << 7);
} else {
DDRB &= ~(1 << 7); PORTB &= ~(1 << 7);
}
if (led_state.scroll_lock) {
DDRB |= (1 << 7);
PORTB &= ~(1 << 7);
} else {
DDRB &= ~(1 << 7);
PORTB &= ~(1 << 7);
}
return false;
}

View File

@ -12,23 +12,29 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};
void led_set_user(uint8_t usb_led) {
bool led_update_user(led_t led_state) {
if (led_state.num_lock) {
DDRB |= (1 << 5);
PORTB &= ~(1 << 5);
} else {
DDRB &= ~(1 << 5);
PORTB &= ~(1 << 5);
}
if (usb_led & (1 << USB_LED_NUM_LOCK)) {
DDRB |= (1 << 5); PORTB &= ~(1 << 5);
} else {
DDRB &= ~(1 << 5); PORTB &= ~(1 << 5);
}
if (led_state.caps_lock) {
DDRB |= (1 << 6);
PORTB &= ~(1 << 6);
} else {
DDRB &= ~(1 << 6);
PORTB &= ~(1 << 6);
}
if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
DDRB |= (1 << 6); PORTB &= ~(1 << 6);
} else {
DDRB &= ~(1 << 6); PORTB &= ~(1 << 6);
}
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) {
DDRB |= (1 << 7); PORTB &= ~(1 << 7);
} else {
DDRB &= ~(1 << 7); PORTB &= ~(1 << 7);
}
if (led_state.scroll_lock) {
DDRB |= (1 << 7);
PORTB &= ~(1 << 7);
} else {
DDRB &= ~(1 << 7);
PORTB &= ~(1 << 7);
}
return false;
}

View File

@ -302,8 +302,9 @@ void matrix_init_user(void) {
#endif
}
void led_set_user(uint8_t usb_led) {
lock_led_set(usb_led & (1<<USB_LED_NUM_LOCK), LED_NUM_LOCK);
lock_led_set(usb_led & (1<<USB_LED_CAPS_LOCK), LED_CAPS_LOCK);
lock_led_set(usb_led & (1<<USB_LED_SCROLL_LOCK), LED_SCROLL_LOCK);
bool led_update_user(led_t led_state) {
lock_led_set(led_state.num_lock, LED_NUM_LOCK);
lock_led_set(led_state.caps_lock, LED_CAPS_LOCK);
lock_led_set(led_state.scroll_lock, LED_SCROLL_LOCK);
return false;
}

View File

@ -22,23 +22,24 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};
void led_set_user(uint8_t usb_led) {
bool led_update_user(led_t led_state) {
if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) {
if (led_state.caps_lock) {
writePinHigh(F1);
} else {
writePinLow(F1);
}
if (IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK)) {
if (led_state.scroll_lock) {
writePinHigh(F0);
} else {
writePinLow(F0);
}
if (!(IS_LED_ON(usb_led, USB_LED_NUM_LOCK))) {
if (!led_state.num_lock) {
tap_code(KC_NUM_LOCK);
}
return false;
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
static bool sysreq_led = false;

View File

@ -22,23 +22,24 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};
void led_set_user(uint8_t usb_led) {
bool led_update_user(led_t led_state) {
if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) {
if (led_state.caps_lock) {
writePinHigh(F1);
} else {
writePinLow(F1);
}
if (IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK)) {
if (led_state.scroll_lock) {
writePinHigh(F0);
} else {
writePinLow(F0);
}
if (!(IS_LED_ON(usb_led, USB_LED_NUM_LOCK))) {
if (!led_state.num_lock) {
tap_code(KC_NUM_LOCK);
}
return false;
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
static bool sysreq_led = false;

View File

@ -127,13 +127,13 @@ void render_layer_state(void){
}
// Keylock State
void render_keylock_status(uint8_t led_usb_state) {
void render_keylock_status(led_t led_state) {
oled_write_P(PSTR(" "), false);
oled_write_P(led_usb_state & (1<<USB_LED_NUM_LOCK) ? PSTR("-NUML") : PSTR("-----"), false);
oled_write_P(led_state.num_lock ? PSTR("-NUML") : PSTR("-----"), false);
oled_write_P(PSTR(" "), false);
oled_write_P(led_usb_state & (1<<USB_LED_CAPS_LOCK) ? PSTR("-CAPS") : PSTR("-----"), false);
oled_write_P(led_state.caps_lock ? PSTR("-CAPS") : PSTR("-----"), false);
oled_write_P(PSTR(" "), false);
oled_write_P(led_usb_state & (1<<USB_LED_SCROLL_LOCK) ? PSTR("-SCRL") : PSTR("-----"), false);
oled_write_P(led_state.scroll_lock ? PSTR("-SCRL") : PSTR("-----"), false);
oled_write_P(PSTR(" "), false);
}
@ -213,7 +213,7 @@ if (is_keyboard_master()) {
oled_write_P(oled_layer_line_end, false);
oled_write_P(oled_layer_keylog_bottom, false);
oled_write_P(oled_line_start, false);
render_keylock_status(host_keyboard_leds());
render_keylock_status(host_keyboard_led_state());
oled_write_P(oled_layer_line_end, false);
oled_write_P(oled_mods_bottom, false);
oled_write_P(oled_line_start, false);

View File

@ -5,13 +5,9 @@
#ifdef OLED_ENABLE
void render_host_led_state(void) {
char led_state_str[24];
uint8_t leds = host_keyboard_leds();
led_t led_state = host_keyboard_led_state();
bool is_num_lock_enabled = leds & (1 << USB_LED_NUM_LOCK);
bool is_caps_lock_enabled = leds & (1 << USB_LED_CAPS_LOCK);
bool is_scroll_lock_enabled = leds & (1 << USB_LED_SCROLL_LOCK);
snprintf(led_state_str, sizeof(led_state_str), "NL:%s CL:%s SL:%s", is_num_lock_enabled ? "on" : "- ", is_caps_lock_enabled ? "on" : "- ", is_scroll_lock_enabled ? "on" : "- ");
snprintf(led_state_str, sizeof(led_state_str), "NL:%s CL:%s SL:%s", led_state.num_lock ? "on" : "- ", led_state.caps_lock ? "on" : "- ", led_state.scroll_lock ? "on" : "- ");
oled_write(led_state_str, false);
}

View File

@ -205,7 +205,7 @@ const char code_to_name[60] = {
static inline void set_keylog(uint16_t keycode, keyrecord_t *record)
{
char name = ' ';
uint8_t leds = host_keyboard_leds();
led_t led_state = host_keyboard_led_state();
if (keycode < 60)
{
@ -218,9 +218,9 @@ static inline void set_keylog(uint16_t keycode, keyrecord_t *record)
record->event.key.col,
keycode,
name,
(leds & (1<<USB_LED_NUM_LOCK)) ? 'N' : ' ',
(leds & (1<<USB_LED_CAPS_LOCK)) ? 'C' : ' ',
(leds & (1<<USB_LED_SCROLL_LOCK)) ? 'S' : ' '
led_state.num_lock ? 'N' : ' ',
led_state.caps_lock ? 'C' : ' ',
led_state.scroll_lock ? 'S' : ' '
);
}
#endif

View File

@ -704,9 +704,10 @@ void render_status(struct CharacterMatrix *matrix) {
int rows = 0;
//Set Indicator icon
if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) { rown = 4; } else { rown = 0; }
if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) { rowa = 4; } else { rowa = 0; }
if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) { rows = 4; } else { rows = 0; }
led_t led_state = host_keyboard_led_state();
if (led_state.num_lock) { rown = 4; } else { rown = 0; }
if (led_state.caps_lock) { rowa = 4; } else { rowa = 0; }
if (led_state.scroll_lock) { rows = 4; } else { rows = 0; }
if (layer_state == L_FUNC) { rowf = 4; }
matrix_write(matrix, indctr[rown] [0]);
@ -813,9 +814,10 @@ void render_status(void) {
int rows = 0;
//Set Indicator icon
if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) { rown = 4; } else { rown = 0; }
if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) { rowa = 4; } else { rowa = 0; }
if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) { rows = 4; } else { rows = 0; }
led_t led_state = host_keyboard_led_state();
if (led_state.num_lock) { rown = 4; } else { rown = 0; }
if (led_state.caps_lock) { rowa = 4; } else { rowa = 0; }
if (led_state.scroll_lock) { rows = 4; } else { rows = 0; }
if (layer_state == L_FUNC) { rowf = 4; }
oled_write(indctr[rown] [0], false);

View File

@ -782,9 +782,10 @@ void render_status(struct CharacterMatrix *matrix) {
int rowj = 1;
//Set Indicator icon
if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) { rown = 4; }
if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) { rowa = 4; }
if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) { rows = 4; }
led_t led_state = host_keyboard_led_state();
if (led_state.num_lock) { rown = 4; }
if (led_state.caps_lock) { rowa = 4; }
if (led_state.scroll_lock) { rows = 4; }
if (IS_LAYER_ON(_FUNC)) { rowf = 4; }
//Set Mode icon
@ -909,9 +910,10 @@ void render_status(void) {
int rowj = 1;
//Set Indicator icon
if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) { rown = 4; }
if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) { rowa = 4; }
if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) { rows = 4; }
led_t led_state = host_keyboard_led_state();
if (led_state.num_lock) { rown = 4; }
if (led_state.caps_lock) { rowa = 4; }
if (led_state.scroll_lock) { rows = 4; }
if (IS_LAYER_ON(_FUNC)) { rowf = 4; }
//Set Mode icon

View File

@ -459,12 +459,10 @@ void render_status(struct CharacterMatrix *matrix) {
matrix_write_P(matrix, PSTR("\n"));
// Host Keyboard LED Status
matrix_write_P(matrix, (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ?
PSTR("NUMLOCK") : PSTR(" "));
matrix_write_P(matrix, (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ?
PSTR("CAPS") : PSTR(" "));
matrix_write_P(matrix, (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ?
PSTR("SCLK") : PSTR(" "));
led_t led_state = host_keyboard_led_state();
matrix_write_P(matrix, led_state.num_lock ? PSTR("NUMLOCK") : PSTR(" "));
matrix_write_P(matrix, led_state.caps_lock ? PSTR("CAPS") : PSTR(" "));
matrix_write_P(matrix, led_state.scroll_lock ? PSTR("SCLK") : PSTR(" "));
matrix_write_P(matrix, PSTR("\n"));
render_rgbled_status(true, matrix);
}
@ -580,12 +578,10 @@ void render_status(void) {
render_layer_status();
// Host Keyboard LED Status
oled_write_P((host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ?
PSTR("NUMLOCK") : PSTR(" "), false);
oled_write_P((host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ?
PSTR("CAPS") : PSTR(" "), false);
oled_write_P((host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ?
PSTR("SCLK") : PSTR(" "), false);
led_t led_state = host_keyboard_led_state();
oled_write_P(led_state.num_lock ? PSTR("NUMLOCK") : PSTR(" "), false);
oled_write_P(led_state.caps_lock ? PSTR("CAPS") : PSTR(" "), false);
oled_write_P(led_state.scroll_lock ? PSTR("SCLK") : PSTR(" "), false);
oled_write_P(PSTR("\n"), false);
render_rgbled_status(true);
oled_write_P(PSTR("\n"), false);

View File

@ -278,15 +278,16 @@ void led_init_ports(void) {
DDRE |= (1<<6); // OUT
}
void led_set_user(uint8_t usb_led) {
if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
bool led_update_user(led_t led_state) {
if (led_state.caps_lock) {
DDRD |= (1 << 5); PORTD &= ~(1 << 5);
} else {
DDRD &= ~(1 << 5); PORTD &= ~(1 << 5);
}
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) {
if (led_state.scroll_lock) {
DDRE |= (1 << 6); PORTE &= ~(1 << 6);
} else {
DDRE &= ~(1 << 6); PORTE &= ~(1 << 6);
}
return false;
}

View File

@ -45,32 +45,40 @@ void eeconfig_init_kb(void) { // EEPROM is getting reset!
#ifdef RGBLIGHT_ENABLE
__attribute__ ((weak))
void led_set_user(uint8_t usb_led) {
if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) {
sethsv_raw(HSV_CAPS, (LED_TYPE *)&led[0]);
} else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[0]);
bool led_update_kb(led_t led_state) {
bool res = led_update_user(led_state);
if (res) {
if (led_state.caps_lock) {
sethsv_raw(HSV_CAPS, (LED_TYPE *)&led[0]);
} else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[0]);
}
if (led_state.num_lock) {
sethsv_raw(HSV_NLCK, (LED_TYPE *)&led[1]);
} else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[1]);
}
if (led_state.scroll_lock) {
sethsv_raw(HSV_SCRL, (LED_TYPE *)&led[2]);
} else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[2]);
}
rgblight_set();
}
if (IS_LED_ON(usb_led, USB_LED_NUM_LOCK)) {
sethsv_raw(HSV_NLCK, (LED_TYPE *)&led[1]);
} else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[1]);
}
if (IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK)) {
sethsv_raw(HSV_SCRL, (LED_TYPE *)&led[2]);
} else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[2]);
}
rgblight_set();
return false;
}
__attribute__ ((weak))
void keyboard_post_init_user(void) {
rgblight_set_effect_range(3, RGBLED_NUM-3);
led_set_user(_BV(USB_LED_CAPS_LOCK)|_BV(USB_LED_NUM_LOCK)|_BV(USB_LED_SCROLL_LOCK));
led_t led_state = {
.caps_lock = true,
.num_lock = true,
.scroll_lock = true
};
led_update_kb(led_state);
wait_ms(300);
led_set_user(0);
led_update_kb((led_t){0});
}
__attribute__ ((weak))

View File

@ -77,23 +77,24 @@ void matrix_scan_user(void) {
#ifdef RGBLIGHT_ENABLE
// The first three LEDs are used as indicators for CAPS_LOCK, NUM_LOCK and SCROLL_LOCK.
void led_set_user(uint8_t usb_led) {
if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) {
bool led_update_user(led_t led_state) {
if (led_state.caps_lock) {
sethsv_raw(HSV_SOFT_RED, (LED_TYPE *)&led[0]);
} else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[0]);
}
if (IS_LED_ON(usb_led, USB_LED_NUM_LOCK)) {
if (led_state.num_lock) {
sethsv_raw(HSV_WARM_WHITE, (LED_TYPE *)&led[1]);
} else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[1]);
}
if (IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK)) {
if (led_state.scroll_lock) {
sethsv_raw(HSV_SOFT_BLUE, (LED_TYPE *)&led[2]);
} else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[2]);
}
rgblight_set();
return false;
}
#endif

View File

@ -57,10 +57,10 @@ bool oled_task_user(void) {
}
// Host Keyboard LED Status
uint8_t led_usb_state = host_keyboard_leds();
oled_write_P(IS_LED_ON(led_usb_state, USB_LED_NUM_LOCK) ? PSTR("NLCK ") : PSTR(" "), false);
oled_write_P(IS_LED_ON(led_usb_state, USB_LED_CAPS_LOCK) ? PSTR("CAPS ") : PSTR(" "), false);
oled_write_P(IS_LED_ON(led_usb_state, USB_LED_SCROLL_LOCK) ? PSTR("SCRLK") : PSTR(" "), false);
led_t led_state = host_keyboard_led_state();
oled_write_P(led_state.num_lock ? PSTR("NLCK ") : PSTR(" "), false);
oled_write_P(led_state.caps_lock ? PSTR("CAPS ") : PSTR(" "), false);
oled_write_P(led_state.scroll_lock ? PSTR("SCRLK") : PSTR(" "), false);
return false;
}

View File

@ -43,10 +43,10 @@ void render_key_status(void) {
static char lock_buf[24] = "Lock state ready.\n";
void update_lock_status(void) {
uint8_t leds = host_keyboard_leds();
char *num_lock = (leds & (1<<USB_LED_NUM_LOCK)) ? "Num" : "";
char *caps_lock = (leds & (1<<USB_LED_CAPS_LOCK)) ? "Caps" : "";
char *scrl_lock = (leds & (1<<USB_LED_SCROLL_LOCK)) ? "Scrn" : "";
led_t led_state = host_keyboard_led_state();
char *num_lock = led_state.num_lock ? "Num" : "";
char *caps_lock = led_state.caps_lock ? "Caps" : "";
char *scrl_lock = led_state.scroll_lock ? "Scrn" : "";
snprintf(lock_buf, sizeof(lock_buf) - 1, "Lock:%s %s %s\n",
num_lock, caps_lock, scrl_lock);
}

Some files were not shown because too many files have changed in this diff Show More