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) #define MEDAPP LT(MEDIA, KC_APP)
uint8_t current_layer_global = 255;
enum layers { enum layers {
DEFAULT, DEFAULT,
PROG1, PROG1,
@ -87,25 +85,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_______,_______,_______, LT(MISC, KC_SPC), _______,_______,_______,_______, _______,_______,_______, _______,_______), _______,_______,_______, 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 ) { void tap_helper(keyrecord_t *record, uint16_t orig_mod, uint16_t macro_mod, uint16_t macro_kc ) {
if (record->event.pressed) { if (record->event.pressed) {
if (record->tap.count > 0 && !record->tap.interrupted) { 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) { void read_host_led_state(void) {
uint8_t leds = host_keyboard_leds(); led_t led_state = host_keyboard_led_state();
if (leds & (1 << USB_LED_NUM_LOCK)) { if (led_state.num_lock) {
if (led_numlock == false){ if (led_numlock == false){
led_numlock = true;} led_numlock = true;}
} else { } else {
if (led_numlock == true){ if (led_numlock == true){
led_numlock = false;} led_numlock = false;}
} }
if (leds & (1 << USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
if (led_capslock == false){ if (led_capslock == false){
led_capslock = true;} led_capslock = true;}
} else { } else {
if (led_capslock == true){ if (led_capslock == true){
led_capslock = false;} led_capslock = false;}
} }
if (leds & (1 << USB_LED_SCROLL_LOCK)) { if (led_state.scroll_lock) {
if (led_scrolllock == false){ if (led_scrolllock == false){
led_scrolllock = true;} led_scrolllock = true;}
} else { } else {

View file

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

View file

@ -20,14 +20,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "led.h" #include "led.h"
void led_set(uint8_t usb_led) bool led_update_kb(led_t led_state)
{ {
uint8_t ps2_led = 0; 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); 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); 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_led |= (1<<PS2_LED_CAPS_LOCK);
ps2_host_set_led(ps2_led); 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)); 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("Lock:"), false);
oled_write_P(PSTR(" "), false); oled_write_P(PSTR(" "), false);
oled_write_P(PSTR("N"), led_usb_state & (1 << USB_LED_NUM_LOCK)); oled_write_P(PSTR("N"), led_state.num_lock);
oled_write_P(PSTR("C"), led_usb_state & (1 << USB_LED_CAPS_LOCK)); oled_write_P(PSTR("C"), led_state.caps_lock);
oled_write_ln_P(PSTR("S"), led_usb_state & (1 << USB_LED_SCROLL_LOCK)); oled_write_ln_P(PSTR("S"), led_state.scroll_lock);
} }
void render_mod_status(uint8_t modifiers) { void render_mod_status(uint8_t modifiers) {
@ -183,7 +183,7 @@ void render_bootmagic_status(void) {
void render_status_main(void) { void render_status_main(void) {
/* Show Keyboard Layout */ /* Show Keyboard Layout */
render_default_layer_state(); render_default_layer_state();
render_keylock_status(host_keyboard_leds()); render_keylock_status(host_keyboard_led_state());
render_mod_status(get_mods()); render_mod_status(get_mods());
render_bootmagic_status(); render_bootmagic_status();

View file

@ -5,11 +5,11 @@ char host_led_state_str[24];
const char *read_host_led_state(void) 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", snprintf(host_led_state_str, sizeof(host_led_state_str), "NL:%s CL:%s SL:%s",
(leds & (1 << USB_LED_NUM_LOCK)) ? "on" : "- ", (led_state.num_lock) ? "on" : "- ",
(leds & (1 << USB_LED_CAPS_LOCK)) ? "on" : "- ", (led_state.caps_lock) ? "on" : "- ",
(leds & (1 << USB_LED_SCROLL_LOCK)) ? "on" : "- "); (led_state.scroll_lock) ? "on" : "- ");
return host_led_state_str; 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 led_update_kb(led_t led_state) {
bool res = led_update_user(led_state); bool res = led_update_user(led_state);
if(res) { if(res) {
backlight_os_state & (1<<USB_LED_CAPS_LOCK) ? (PORTB &= ~0b00000001) : (PORTB |= 0b00000001); backlight_os_state & 2 ? (PORTB &= ~0b00000001) : (PORTB |= 0b00000001);
backlight_os_state & (1<<USB_LED_SCROLL_LOCK) ? (PORTB &= ~0b00010000) : (PORTB |= 0b00010000); backlight_os_state & 4 ? (PORTB &= ~0b00010000) : (PORTB |= 0b00010000);
} }
return res; return res;
} }

View file

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

View file

@ -24,69 +24,6 @@ enum BACKLIGHT_AREAS {
BACKLIGHT_SWITCH = 0b0001111 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 // Q5, Q6, Q7 is connected to B1 - alphas
// Q8, Q9 is connected to B2 - frow // Q8, Q9 is connected to B2 - frow
// Q1, Q2, Q3 is connected to B3 - mods // 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); 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 // U5 Pin 1, 2, 3 connected to top left LEDs
// U6 Pin 1, 2, 3 connected to bottom right leds col of 3 // 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. // The state of the LEDs requested by the system, as a bitmask.
static uint8_t sys_led_state = 0; static led_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;
// Value to use to switch LEDs on. The default value of 255 is far too bright. // Value to use to switch LEDs on. The default value of 255 is far too bright.
static const uint8_t max_led_value = 20; 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. // Called when the computer wants to change the state of the keyboard LEDs.
void led_set_user(uint8_t usb_led) { bool led_update_user(led_t led_state) {
sys_led_state = usb_led; sys_led_state = led_state;
if (LAYER_ON(SYSLEDS)) { if (LAYER_ON(SYSLEDS)) {
if (sys_led_state & sys_led_mask_caps_lock) { if (sys_led_state.caps_lock) {
led_1_on(); led_1_on();
} else { } else {
led_1_off(); led_1_off();
} }
if (sys_led_state & sys_led_mask_num_lock) { if (sys_led_state.num_lock) {
led_2_on(); led_2_on();
} else { } else {
led_2_off(); led_2_off();
} }
if (sys_led_state & sys_led_mask_scroll_lock) { if (sys_led_state.scroll_lock) {
led_3_on(); led_3_on();
} else { } else {
led_3_off(); led_3_off();
} }
} }
return false;
} }
layer_state_t layer_state_set_user(layer_state_t state) { 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)) { if (LAYER_ON(SYSLEDS)) {
led_set_user(sys_led_state); led_update_user(sys_led_state);
return 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) { bool led_update_user(led_t led_state) {
if (led_state.num_lock) {
if (usb_led & (1 << USB_LED_NUM_LOCK)) { DDRB |= (1 << 5);
DDRB |= (1 << 5); PORTB &= ~(1 << 5); PORTB &= ~(1 << 5);
} else { } else {
DDRB &= ~(1 << 5); PORTB &= ~(1 << 5); DDRB &= ~(1 << 5);
PORTB &= ~(1 << 5);
} }
if (usb_led & (1 << USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
DDRB |= (1 << 6); PORTB &= ~(1 << 6); DDRB |= (1 << 6);
PORTB &= ~(1 << 6);
} else { } else {
DDRB &= ~(1 << 6); PORTB &= ~(1 << 6); DDRB &= ~(1 << 6);
PORTB &= ~(1 << 6);
} }
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { if (led_state.scroll_lock) {
DDRB |= (1 << 7); PORTB &= ~(1 << 7); DDRB |= (1 << 7);
PORTB &= ~(1 << 7);
} else { } 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)) { if (led_state.caps_lock) {
DDRB |= (1 << 5); PORTB &= ~(1 << 5); DDRB |= (1 << 6);
} else { PORTB &= ~(1 << 6);
DDRB &= ~(1 << 5); PORTB &= ~(1 << 5); } else {
} DDRB &= ~(1 << 6);
PORTB &= ~(1 << 6);
}
if (usb_led & (1 << USB_LED_CAPS_LOCK)) { if (led_state.scroll_lock) {
DDRB |= (1 << 6); PORTB &= ~(1 << 6); DDRB |= (1 << 7);
} else { PORTB &= ~(1 << 7);
DDRB &= ~(1 << 6); PORTB &= ~(1 << 6); } else {
} DDRB &= ~(1 << 7);
PORTB &= ~(1 << 7);
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { }
DDRB |= (1 << 7); PORTB &= ~(1 << 7); return false;
} else {
DDRB &= ~(1 << 7); PORTB &= ~(1 << 7);
}
} }

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) {
if (usb_led & (1 << USB_LED_NUM_LOCK)) { DDRB |= (1 << 5);
DDRB |= (1 << 5); PORTB &= ~(1 << 5); PORTB &= ~(1 << 5);
} else { } else {
DDRB &= ~(1 << 5); PORTB &= ~(1 << 5); DDRB &= ~(1 << 5);
PORTB &= ~(1 << 5);
} }
if (usb_led & (1 << USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
DDRB |= (1 << 6); PORTB &= ~(1 << 6); DDRB |= (1 << 6);
PORTB &= ~(1 << 6);
} else { } else {
DDRB &= ~(1 << 6); PORTB &= ~(1 << 6); DDRB &= ~(1 << 6);
PORTB &= ~(1 << 6);
} }
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { if (led_state.scroll_lock) {
DDRB |= (1 << 7); PORTB &= ~(1 << 7); DDRB |= (1 << 7);
PORTB &= ~(1 << 7);
} else { } 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) {
if (usb_led & (1 << USB_LED_NUM_LOCK)) { DDRB |= (1 << 5);
DDRB |= (1 << 5); PORTB &= ~(1 << 5); PORTB &= ~(1 << 5);
} else { } else {
DDRB &= ~(1 << 5); PORTB &= ~(1 << 5); DDRB &= ~(1 << 5);
PORTB &= ~(1 << 5);
} }
if (usb_led & (1 << USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
DDRB |= (1 << 6); PORTB &= ~(1 << 6); DDRB |= (1 << 6);
PORTB &= ~(1 << 6);
} else { } else {
DDRB &= ~(1 << 6); PORTB &= ~(1 << 6); DDRB &= ~(1 << 6);
PORTB &= ~(1 << 6);
} }
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { if (led_state.scroll_lock) {
DDRB |= (1 << 7); PORTB &= ~(1 << 7); DDRB |= (1 << 7);
PORTB &= ~(1 << 7);
} else { } 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)) { if (led_state.caps_lock) {
DDRB |= (1 << 5); PORTB &= ~(1 << 5); DDRB |= (1 << 6);
} else { PORTB &= ~(1 << 6);
DDRB &= ~(1 << 5); PORTB &= ~(1 << 5); } else {
} DDRB &= ~(1 << 6);
PORTB &= ~(1 << 6);
}
if (usb_led & (1 << USB_LED_CAPS_LOCK)) { if (led_state.scroll_lock) {
DDRB |= (1 << 6); PORTB &= ~(1 << 6); DDRB |= (1 << 7);
} else { PORTB &= ~(1 << 7);
DDRB &= ~(1 << 6); PORTB &= ~(1 << 6); } else {
} DDRB &= ~(1 << 7);
PORTB &= ~(1 << 7);
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { }
DDRB |= (1 << 7); PORTB &= ~(1 << 7); return false;
} else {
DDRB &= ~(1 << 7); PORTB &= ~(1 << 7);
}
} }

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)) { if (led_state.caps_lock) {
DDRB |= (1 << 5); PORTB &= ~(1 << 5); DDRB |= (1 << 6);
} else { PORTB &= ~(1 << 6);
DDRB &= ~(1 << 5); PORTB &= ~(1 << 5); } else {
} DDRB &= ~(1 << 6);
PORTB &= ~(1 << 6);
}
if (usb_led & (1 << USB_LED_CAPS_LOCK)) { if (led_state.scroll_lock) {
DDRB |= (1 << 6); PORTB &= ~(1 << 6); DDRB |= (1 << 7);
} else { PORTB &= ~(1 << 7);
DDRB &= ~(1 << 6); PORTB &= ~(1 << 6); } else {
} DDRB &= ~(1 << 7);
PORTB &= ~(1 << 7);
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { }
DDRB |= (1 << 7); PORTB &= ~(1 << 7); return false;
} else {
DDRB &= ~(1 << 7); PORTB &= ~(1 << 7);
}
} }

View file

@ -302,8 +302,9 @@ void matrix_init_user(void) {
#endif #endif
} }
void led_set_user(uint8_t usb_led) { bool led_update_user(led_t led_state) {
lock_led_set(usb_led & (1<<USB_LED_NUM_LOCK), LED_NUM_LOCK); lock_led_set(led_state.num_lock, LED_NUM_LOCK);
lock_led_set(usb_led & (1<<USB_LED_CAPS_LOCK), LED_CAPS_LOCK); lock_led_set(led_state.caps_lock, LED_CAPS_LOCK);
lock_led_set(usb_led & (1<<USB_LED_SCROLL_LOCK), LED_SCROLL_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); writePinHigh(F1);
} else { } else {
writePinLow(F1); writePinLow(F1);
} }
if (IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK)) { if (led_state.scroll_lock) {
writePinHigh(F0); writePinHigh(F0);
} else { } else {
writePinLow(F0); writePinLow(F0);
} }
if (!(IS_LED_ON(usb_led, USB_LED_NUM_LOCK))) { if (!led_state.num_lock) {
tap_code(KC_NUM_LOCK); tap_code(KC_NUM_LOCK);
} }
return false;
} }
bool process_record_user(uint16_t keycode, keyrecord_t *record) { bool process_record_user(uint16_t keycode, keyrecord_t *record) {
static bool sysreq_led = false; 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); writePinHigh(F1);
} else { } else {
writePinLow(F1); writePinLow(F1);
} }
if (IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK)) { if (led_state.scroll_lock) {
writePinHigh(F0); writePinHigh(F0);
} else { } else {
writePinLow(F0); writePinLow(F0);
} }
if (!(IS_LED_ON(usb_led, USB_LED_NUM_LOCK))) { if (!led_state.num_lock) {
tap_code(KC_NUM_LOCK); tap_code(KC_NUM_LOCK);
} }
return false;
} }
bool process_record_user(uint16_t keycode, keyrecord_t *record) { bool process_record_user(uint16_t keycode, keyrecord_t *record) {
static bool sysreq_led = false; static bool sysreq_led = false;

View file

@ -127,13 +127,13 @@ void render_layer_state(void){
} }
// Keylock State // 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(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(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(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); 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_line_end, false);
oled_write_P(oled_layer_keylog_bottom, false); oled_write_P(oled_layer_keylog_bottom, false);
oled_write_P(oled_line_start, 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_layer_line_end, false);
oled_write_P(oled_mods_bottom, false); oled_write_P(oled_mods_bottom, false);
oled_write_P(oled_line_start, false); oled_write_P(oled_line_start, false);

View file

@ -5,13 +5,9 @@
#ifdef OLED_ENABLE #ifdef OLED_ENABLE
void render_host_led_state(void) { void render_host_led_state(void) {
char led_state_str[24]; 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); 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" : "- ");
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" : "- ");
oled_write(led_state_str, false); 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) static inline void set_keylog(uint16_t keycode, keyrecord_t *record)
{ {
char name = ' '; char name = ' ';
uint8_t leds = host_keyboard_leds(); led_t led_state = host_keyboard_led_state();
if (keycode < 60) if (keycode < 60)
{ {
@ -218,9 +218,9 @@ static inline void set_keylog(uint16_t keycode, keyrecord_t *record)
record->event.key.col, record->event.key.col,
keycode, keycode,
name, name,
(leds & (1<<USB_LED_NUM_LOCK)) ? 'N' : ' ', led_state.num_lock ? 'N' : ' ',
(leds & (1<<USB_LED_CAPS_LOCK)) ? 'C' : ' ', led_state.caps_lock ? 'C' : ' ',
(leds & (1<<USB_LED_SCROLL_LOCK)) ? 'S' : ' ' led_state.scroll_lock ? 'S' : ' '
); );
} }
#endif #endif

View file

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

View file

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

View file

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

View file

@ -278,15 +278,16 @@ void led_init_ports(void) {
DDRE |= (1<<6); // OUT DDRE |= (1<<6); // OUT
} }
void led_set_user(uint8_t usb_led) { bool led_update_user(led_t led_state) {
if (usb_led & (1 << USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
DDRD |= (1 << 5); PORTD &= ~(1 << 5); DDRD |= (1 << 5); PORTD &= ~(1 << 5);
} else { } else {
DDRD &= ~(1 << 5); PORTD &= ~(1 << 5); 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); DDRE |= (1 << 6); PORTE &= ~(1 << 6);
} else { } else {
DDRE &= ~(1 << 6); PORTE &= ~(1 << 6); 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 #ifdef RGBLIGHT_ENABLE
__attribute__ ((weak)) bool led_update_kb(led_t led_state) {
void led_set_user(uint8_t usb_led) { bool res = led_update_user(led_state);
if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) { if (res) {
sethsv_raw(HSV_CAPS, (LED_TYPE *)&led[0]); if (led_state.caps_lock) {
} else { sethsv_raw(HSV_CAPS, (LED_TYPE *)&led[0]);
sethsv(HSV_BLACK, (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)) { return false;
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();
} }
__attribute__ ((weak)) __attribute__ ((weak))
void keyboard_post_init_user(void) { void keyboard_post_init_user(void) {
rgblight_set_effect_range(3, RGBLED_NUM-3); 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); wait_ms(300);
led_set_user(0); led_update_kb((led_t){0});
} }
__attribute__ ((weak)) __attribute__ ((weak))

View file

@ -77,23 +77,24 @@ void matrix_scan_user(void) {
#ifdef RGBLIGHT_ENABLE #ifdef RGBLIGHT_ENABLE
// The first three LEDs are used as indicators for CAPS_LOCK, NUM_LOCK and SCROLL_LOCK. // The first three LEDs are used as indicators for CAPS_LOCK, NUM_LOCK and SCROLL_LOCK.
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) {
sethsv_raw(HSV_SOFT_RED, (LED_TYPE *)&led[0]); sethsv_raw(HSV_SOFT_RED, (LED_TYPE *)&led[0]);
} else { } else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[0]); 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]); sethsv_raw(HSV_WARM_WHITE, (LED_TYPE *)&led[1]);
} else { } else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[1]); 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]); sethsv_raw(HSV_SOFT_BLUE, (LED_TYPE *)&led[2]);
} else { } else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[2]); sethsv(HSV_BLACK, (LED_TYPE *)&led[2]);
} }
rgblight_set(); rgblight_set();
return false;
} }
#endif #endif

View file

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

View file

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

View file

@ -32,14 +32,14 @@ void rgblight_set(void) {
} }
} }
if (noah_led_mode) { if (noah_led_mode) {
uint8_t ind_led = host_keyboard_leds(); led_t led_state = host_keyboard_led_state();
if (IS_LED_ON(ind_led, USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
noah_leds[0] = led[0]; noah_leds[0] = led[0];
} }
if (IS_LED_ON(ind_led, USB_LED_SCROLL_LOCK)) { if (led_state.scroll_lock) {
noah_leds[1] = led[1]; noah_leds[1] = led[1];
} }
if (IS_LED_ON(ind_led, USB_LED_NUM_LOCK)) { if (led_state.num_lock) {
noah_leds[2] = led[2]; noah_leds[2] = led[2];
} }
for (int32_t i = 0; i < 4; i++) { for (int32_t i = 0; i < 4; i++) {

View file

@ -87,27 +87,27 @@ static void render_status(void) {
// Host Keyboard LED Status // Host Keyboard LED Status
oled_set_cursor(0, 1); oled_set_cursor(0, 1);
static uint8_t persistent_led_state = 0; static led_t persistent_led_state = {0};
uint8_t led_usb_state = host_keyboard_leds(); led_t led_state = host_keyboard_led_state();
// Only update if the LED state has changed // Only update if the LED state has changed
// Otherwise, the OLED will not turn off if an LED is on. // Otherwise, the OLED will not turn off if an LED is on.
if (persistent_led_state != led_usb_state) { if (persistent_led_state != led_state) {
persistent_led_state = led_usb_state; persistent_led_state = led_state;
oled_write_ln_P(PSTR(""), false); oled_write_ln_P(PSTR(""), false);
if (IS_LED_ON(led_usb_state, USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
oled_set_cursor(0, 1); oled_set_cursor(0, 1);
oled_write_P(PSTR("CAPS"), false); oled_write_P(PSTR("CAPS"), false);
} }
if (IS_LED_ON(led_usb_state, USB_LED_NUM_LOCK)) { if (led_state.num_lock) {
oled_set_cursor(5, 1); oled_set_cursor(5, 1);
oled_write_P(PSTR("NUM"), true); oled_write_P(PSTR("NUM"), true);
} }
if (IS_LED_ON(led_usb_state, USB_LED_SCROLL_LOCK)) { if (led_state.scroll_lock) {
oled_set_cursor(9, 1); oled_set_cursor(9, 1);
oled_write_P(PSTR("SCR"), false); oled_write_P(PSTR("SCR"), false);
} }

View file

@ -114,27 +114,27 @@ static void render_status(void) {
// Host Keyboard LED Status // Host Keyboard LED Status
oled_set_cursor(0, 1); oled_set_cursor(0, 1);
static uint8_t persistent_led_state = 0; static led_t persistent_led_state = {0};
uint8_t led_usb_state = host_keyboard_leds(); led_t led_state = host_keyboard_led_state();
// Only update if the LED state has changed // Only update if the LED state has changed
// Otherwise, the OLED will not turn off if an LED is on. // Otherwise, the OLED will not turn off if an LED is on.
if (persistent_led_state != led_usb_state) { if (persistent_led_state != led_state) {
persistent_led_state = led_usb_state; persistent_led_state = led_state;
oled_write_ln_P(PSTR(""), false); oled_write_ln_P(PSTR(""), false);
if (IS_LED_ON(led_usb_state, USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
oled_set_cursor(0, 1); oled_set_cursor(0, 1);
oled_write_P(PSTR("CAPS"), false); oled_write_P(PSTR("CAPS"), false);
} }
if (IS_LED_ON(led_usb_state, USB_LED_NUM_LOCK)) { if (led_state.num_lock) {
oled_set_cursor(5, 1); oled_set_cursor(5, 1);
oled_write_P(PSTR("NUM"), true); oled_write_P(PSTR("NUM"), true);
} }
if (IS_LED_ON(led_usb_state, USB_LED_SCROLL_LOCK)) { if (led_state.scroll_lock) {
oled_set_cursor(9, 1); oled_set_cursor(9, 1);
oled_write_P(PSTR("SCR"), false); oled_write_P(PSTR("SCR"), false);
} }

View file

@ -94,27 +94,27 @@ static void render_status(void) {
// Host Keyboard LED Status // Host Keyboard LED Status
oled_set_cursor(0, 1); oled_set_cursor(0, 1);
static uint8_t persistent_led_state = 0; static led_t persistent_led_state = {0};
uint8_t led_usb_state = host_keyboard_leds(); led_t led_state = host_keyboard_led_state();
// Only update if the LED state has changed // Only update if the LED state has changed
// Otherwise, the OLED will not turn off if an LED is on. // Otherwise, the OLED will not turn off if an LED is on.
if (persistent_led_state != led_usb_state) { if (persistent_led_state != led_state) {
persistent_led_state = led_usb_state; persistent_led_state = led_state;
oled_write_ln_P(PSTR(" "), false); oled_write_ln_P(PSTR(" "), false);
if (IS_LED_ON(led_usb_state, USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
oled_set_cursor(0, 1); oled_set_cursor(0, 1);
oled_write_P(PSTR("CAPS"), false); oled_write_P(PSTR("CAPS"), false);
} }
if (IS_LED_ON(led_usb_state, USB_LED_NUM_LOCK)) { if (led_state.num_lock) {
oled_set_cursor(5, 1); oled_set_cursor(5, 1);
oled_write_P(PSTR("NUM"), true); oled_write_P(PSTR("NUM"), true);
} }
if (IS_LED_ON(led_usb_state, USB_LED_SCROLL_LOCK)) { if (led_state.scroll_lock) {
oled_set_cursor(9, 1); oled_set_cursor(9, 1);
oled_write_P(PSTR("SCR"), false); oled_write_P(PSTR("SCR"), false);
} }

View file

@ -179,13 +179,13 @@ static void render_wpm_counters(uint8_t current_wpm) {
static void render_led_status(void) { static void render_led_status(void) {
// Host Keyboard LED Status // Host Keyboard LED Status
uint8_t led_usb_state = host_keyboard_leds(); led_t led_state = host_keyboard_led_state();
oled_set_cursor(0, 8); oled_set_cursor(0, 8);
oled_write_P(IS_LED_ON(led_usb_state, USB_LED_CAPS_LOCK) ? PSTR(CAPLCK_STR) : PSTR(EMPTY_STR), false); oled_write_P(led_state.caps_lock ? PSTR(CAPLCK_STR) : PSTR(EMPTY_STR), false);
oled_set_cursor(0, 9); oled_set_cursor(0, 9);
oled_write_P(IS_LED_ON(led_usb_state, USB_LED_NUM_LOCK) ? PSTR(NUMLCK_STR) : PSTR(EMPTY_STR), false); oled_write_P(led_state.num_lock ? PSTR(NUMLCK_STR) : PSTR(EMPTY_STR), false);
oled_set_cursor(0, 10); oled_set_cursor(0, 10);
oled_write_P(IS_LED_ON(led_usb_state, USB_LED_SCROLL_LOCK) ? PSTR(SCRLK_STR) : PSTR(EMPTY_STR), false); oled_write_P(led_state.scroll_lock ? PSTR(SCRLK_STR) : PSTR(EMPTY_STR), false);
} }
// Update WPM snail icon // Update WPM snail icon

View file

@ -52,9 +52,9 @@ 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 (usb_led & (1 << USB_LED_NUM_LOCK)) { if (led_state.num_lock) {
setPinOutput(B0); setPinOutput(B0);
writePinLow(B0); writePinLow(B0);
} else { } else {
@ -62,7 +62,7 @@ void led_set_user(uint8_t usb_led) {
writePinLow(B0); writePinLow(B0);
} }
if (usb_led & (1 << USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
setPinOutput(B1); setPinOutput(B1);
writePinLow(B1); writePinLow(B1);
} else { } else {
@ -70,11 +70,12 @@ void led_set_user(uint8_t usb_led) {
writePinLow(B1); writePinLow(B1);
} }
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { if (led_state.scroll_lock) {
setPinOutput(B2); setPinOutput(B2);
writePinLow(B2); writePinLow(B2);
} else { } else {
setPinInput(B2); setPinInput(B2);
writePinLow(B2); writePinLow(B2);
} }
return false;
} }

View file

@ -80,47 +80,48 @@ void matrix_init_user(void)
println("Matrix Init"); println("Matrix Init");
} }
void led_set_user(uint8_t usb_led) bool led_update_user(led_t led_state)
{ {
static uint8_t old_usb_led = 0; static led_t old_led_state = {0};
_delay_ms(10); // gets rid of tick _delay_ms(10); // gets rid of tick
if (!is_playing_notes()) if (!is_playing_notes())
{ {
if ((usb_led & (1<<USB_LED_CAPS_LOCK)) && !(old_usb_led & (1<<USB_LED_CAPS_LOCK))) if (led_state.caps_lock && !old_led_state.caps_lock)
{ {
// If CAPS LK LED is turning on... // If CAPS LK LED is turning on...
PLAY_SONG(tone_caps_on); PLAY_SONG(tone_caps_on);
} }
else if (!(usb_led & (1<<USB_LED_CAPS_LOCK)) && (old_usb_led & (1<<USB_LED_CAPS_LOCK))) else if (!led_state.caps_lock && old_led_state.caps_lock)
{ {
// If CAPS LK LED is turning off... // If CAPS LK LED is turning off...
PLAY_SONG(tone_caps_off); PLAY_SONG(tone_caps_off);
} }
else if ((usb_led & (1<<USB_LED_NUM_LOCK)) && !(old_usb_led & (1<<USB_LED_NUM_LOCK))) else if (led_state.num_lock && !old_led_state.num_lock)
{ {
// If NUM LK LED is turning on... // If NUM LK LED is turning on...
PLAY_SONG(tone_numlk_on); PLAY_SONG(tone_numlk_on);
} }
else if (!(usb_led & (1<<USB_LED_NUM_LOCK)) && (old_usb_led & (1<<USB_LED_NUM_LOCK))) else if (!led_state.num_lock && old_led_state.num_lock)
{ {
// If NUM LED is turning off... // If NUM LED is turning off...
PLAY_SONG(tone_numlk_off); PLAY_SONG(tone_numlk_off);
} }
else if ((usb_led & (1<<USB_LED_SCROLL_LOCK)) && !(old_usb_led & (1<<USB_LED_SCROLL_LOCK))) else if (led_state.scroll_lock && !old_led_state.scroll_lock)
{ {
// If SCROLL LK LED is turning on... // If SCROLL LK LED is turning on...
PLAY_SONG(tone_scroll_on); PLAY_SONG(tone_scroll_on);
} }
else if (!(usb_led & (1<<USB_LED_SCROLL_LOCK)) && (old_usb_led & (1<<USB_LED_SCROLL_LOCK))) else if (!led_state.scroll_lock && old_led_state.scroll_lock)
{ {
// If SCROLL LED is turning off... // If SCROLL LED is turning off...
PLAY_SONG(tone_scroll_off); PLAY_SONG(tone_scroll_off);
} }
} }
old_usb_led = usb_led; old_led_state = led_state;
return false;
} }

View file

@ -136,14 +136,6 @@ bool oled_task_user(void) {
oled_write_ln_P(PSTR("Undf"), false); oled_write_ln_P(PSTR("Undf"), false);
} }
// Host Keyboard LED Status
// uint8_t led_usb_state = host_keyboard_leds();
// oled_write_P(PSTR("-----"), false);
// oled_write_P(PSTR("Stats"), false);
// oled_write_P(led_usb_state & (1<<USB_LED_NUM_LOCK) ? PSTR("num:*") : PSTR("num:."), false);
// oled_write_P(led_usb_state & (1<<USB_LED_CAPS_LOCK) ? PSTR("cap:*") : PSTR("cap:."), false);
// oled_write_P(led_usb_state & (1<<USB_LED_SCROLL_LOCK) ? PSTR("scr:*") : PSTR("scr:."), false);
oled_write_P(PSTR("-----"), false); oled_write_P(PSTR("-----"), false);
render_backlight_status(); render_backlight_status();

View file

@ -57,24 +57,18 @@ void matrix_init_user(void) {
writePinLow(B3); writePinLow(B3);
} }
void led_set_user(uint8_t usb_led) { bool led_update_user(led_t led_state) {
if (IS_LED_ON(usb_led, USB_LED_NUM_LOCK)) { if (led_state.num_lock) {
writePinHigh(B2); writePinHigh(B2);
} else { } else {
writePinLow(B2); writePinLow(B2);
} }
if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
writePinHigh(B1); writePinHigh(B1);
} else { } else {
writePinLow(B1); writePinLow(B1);
} }
/* return false;
if (IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK)) {
writePinHigh(B3);
} else {
writePinLow(B3);
}*/
} }
//function for layer indicator LED //function for layer indicator LED

View file

@ -85,24 +85,18 @@ void matrix_init_user(void) {
writePinLow(B3); writePinLow(B3);
} }
void led_set_user(uint8_t usb_led) { bool led_update_user(led_t led_state) {
if (IS_LED_ON(usb_led, USB_LED_NUM_LOCK)) { if (led_state.num_lock) {
writePinHigh(B2); writePinHigh(B2);
} else { } else {
writePinLow(B2); writePinLow(B2);
} }
if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
writePinHigh(B1); writePinHigh(B1);
} else { } else {
writePinLow(B1); writePinLow(B1);
} }
/* return false;
if (IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK)) {
writePinHigh(B3);
} else {
writePinLow(B3);
}*/
} }
//function for layer indicator LED //function for layer indicator LED

View file

@ -254,10 +254,10 @@ static void render_status(void) {
} }
// Host Keyboard LED Status // Host Keyboard LED Status
uint8_t led_usb_state = host_keyboard_leds(); led_t led_state = host_keyboard_led_state();
oled_write_P(led_usb_state & (1<<USB_LED_NUM_LOCK) ? PSTR("NUMLOCK ") : PSTR(" "), false); oled_write_P(led_state.num_lock ? PSTR("NUMLOCK ") : 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(led_usb_state & (1<<USB_LED_SCROLL_LOCK) ? PSTR("SCLK ") : PSTR(" "), false); oled_write_P(led_state.scroll_lock ? PSTR("SCLK ") : PSTR(" "), false);
} }
bool oled_task_user(void) { bool oled_task_user(void) {

View file

@ -318,10 +318,10 @@ static void render_status(void) {
} }
// Host Keyboard LED Status // Host Keyboard LED Status
uint8_t led_usb_state = host_keyboard_leds(); led_t led_state = host_keyboard_led_state();
oled_write_P(led_usb_state & (1<<USB_LED_NUM_LOCK) ? PSTR("NUMLOCK ") : PSTR(" "), false); oled_write_P(led_state.num_lock ? PSTR("NUMLOCK ") : 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(led_usb_state & (1<<USB_LED_SCROLL_LOCK) ? PSTR("SCLK ") : PSTR(" "), false); oled_write_P(led_state.scroll_lock ? PSTR("SCLK ") : PSTR(" "), false);
} }
bool oled_task_user(void) { bool oled_task_user(void) {

View file

@ -344,11 +344,11 @@ static void render_status(void) {
} }
// Host Keyboard LED Status // Host Keyboard LED Status
uint8_t led_state = host_keyboard_leds(); led_t led_state = host_keyboard_led_state();
oled_write_P(PSTR("-----"), false); oled_write_P(PSTR("-----"), false);
oled_write_P(IS_LED_ON(led_state, USB_LED_NUM_LOCK) ? PSTR("NUMLK") : PSTR(" "), false); oled_write_P(led_state.num_lock ? PSTR("NUMLK") : PSTR(" "), false);
oled_write_P(IS_LED_ON(led_state, USB_LED_CAPS_LOCK) ? PSTR("CAPLK") : PSTR(" "), false); oled_write_P(led_state.caps_lock ? PSTR("CAPLK") : PSTR(" "), false);
oled_write_P(IS_LED_ON(led_state, USB_LED_SCROLL_LOCK) ? PSTR("SCRLK") : PSTR(" "), false); oled_write_P(led_state.scroll_lock ? PSTR("SCRLK") : PSTR(" "), false);
#ifdef RGB_OLED_MENU #ifdef RGB_OLED_MENU
static char buffer[31] = { 0 }; static char buffer[31] = { 0 };

View file

@ -334,11 +334,11 @@ static void render_status(void) {
} }
// Host Keyboard LED Status // Host Keyboard LED Status
uint8_t led_state = host_keyboard_leds(); led_t led_state = host_keyboard_led_state();
oled_write_P(PSTR("-----"), false); oled_write_P(PSTR("-----"), false);
oled_write_P(IS_LED_ON(led_state, USB_LED_NUM_LOCK) ? PSTR("NUMLK") : PSTR(" "), false); oled_write_P(led_state.num_lock ? PSTR("NUMLK") : PSTR(" "), false);
oled_write_P(IS_LED_ON(led_state, USB_LED_CAPS_LOCK) ? PSTR("CAPLK") : PSTR(" "), false); oled_write_P(led_state.caps_lock ? PSTR("CAPLK") : PSTR(" "), false);
oled_write_P(IS_LED_ON(led_state, USB_LED_SCROLL_LOCK) ? PSTR("SCRLK") : PSTR(" "), false); oled_write_P(led_state.scroll_lock ? PSTR("SCRLK") : PSTR(" "), false);
#ifdef RGB_OLED_MENU #ifdef RGB_OLED_MENU
static char buffer[31] = { 0 }; static char buffer[31] = { 0 };

View file

@ -40,11 +40,11 @@ void render_status(void) {
oled_write_P(layer_name_user(get_highest_layer(layer_state)), false); oled_write_P(layer_name_user(get_highest_layer(layer_state)), false);
// Host Keyboard LED Status // Host Keyboard LED Status
uint8_t led_usb_state = host_keyboard_leds(); led_t led_state = host_keyboard_led_state();
oled_set_cursor(0, oled_max_lines() - 4); // Line 13 oled_set_cursor(0, oled_max_lines() - 4); // Line 13
oled_write_P(led_usb_state & (1<<USB_LED_NUM_LOCK) ? PSTR("NUMLK") : PSTR(" "), false); // Line 14 oled_write_P(led_state.num_lock ? PSTR("NUMLK") : PSTR(" "), false); // Line 14
oled_write_P(led_usb_state & (1<<USB_LED_CAPS_LOCK) ? PSTR("CAPLK") : PSTR(" "), false); // Line 15 oled_write_P(led_state.caps_lock ? PSTR("CAPLK") : PSTR(" "), false); // Line 15
oled_write_P(led_usb_state & (1<<USB_LED_SCROLL_LOCK) ? PSTR("SCRLK") : PSTR(" "), false); // Line 16 oled_write_P(led_state.scroll_lock ? PSTR("SCRLK") : PSTR(" "), false); // Line 16
} }
oled_rotation_t oled_init_kb(oled_rotation_t rotation) { oled_rotation_t oled_init_kb(oled_rotation_t rotation) {

View file

@ -253,10 +253,11 @@ void render_status(struct CharacterMatrix *matrix) {
// Host Keyboard LED Status // Host Keyboard LED Status
char led[40]; char led[40];
led_t led_state = host_keyboard_led_state();
snprintf(led, sizeof(led), "\n%s %s %s", snprintf(led, sizeof(led), "\n%s %s %s",
(host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : " ", led_state.num_lock ? "NUMLOCK" : " ",
(host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ", led_state.caps_lock ? "CAPS" : " ",
(host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " "); led_state.scroll_lock ? "SCLK" : " ");
matrix_write(matrix, led); matrix_write(matrix, led);
} }

View file

@ -216,10 +216,10 @@ static void render_status(void) {
} }
// Host Keyboard LED Status // Host Keyboard LED Status
uint8_t led_usb_state = host_keyboard_leds(); led_t led_state = host_keyboard_led_state();
oled_write_P(led_usb_state & (1<<USB_LED_NUM_LOCK) ? PSTR("NUMLCK ") : PSTR(" "), false); oled_write_P(led_state.num_lock ? PSTR("NUMLCK ") : PSTR(" "), false);
oled_write_P(led_usb_state & (1<<USB_LED_CAPS_LOCK) ? PSTR("CAPLCK ") : PSTR(" "), false); oled_write_P(led_state.caps_lock ? PSTR("CAPLCK ") : PSTR(" "), false);
oled_write_ln_P(led_usb_state & (1<<USB_LED_SCROLL_LOCK) ? PSTR("SCRLCK ") : PSTR(" "), false); oled_write_ln_P(led_state.scroll_lock ? PSTR("SCRLCK ") : PSTR(" "), false);
} }
bool oled_task_user(void) { bool oled_task_user(void) {

View file

@ -4,12 +4,12 @@
char host_led_state_str[22]; char host_led_state_str[22];
const char *read_host_led_state(void) { 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), "Lock: %s%s%s", snprintf(host_led_state_str, sizeof(host_led_state_str), "Lock: %s%s%s",
(leds & (1 << USB_LED_CAPS_LOCK)) ? "CAPL " : "", led_state.caps_lock ? "CAPL " : "",
(leds & (1 << USB_LED_SCROLL_LOCK)) ? "SCRL " : "", led_state.scroll_lock ? "SCRL " : "",
(leds & (1 << USB_LED_NUM_LOCK)) ? "NUML" : ""); led_state.num_lock ? "NUML" : "");
return host_led_state_str; return host_led_state_str;
} }

View file

@ -384,10 +384,10 @@ static void render_status(void) {
oled_write_P(PSTR("\n"), false); oled_write_P(PSTR("\n"), false);
// Host Keyboard LED Status // Host Keyboard LED Status
uint8_t led_usb_state = host_keyboard_leds(); led_t led_state = host_keyboard_led_state();
oled_write_P(IS_LED_ON(led_usb_state, USB_LED_NUM_LOCK) ? PSTR("NUMLCK ") : PSTR(" "), false); oled_write_P(led_state.num_lock ? PSTR("NUMLCK ") : PSTR(" "), false);
oled_write_P(IS_LED_ON(led_usb_state, USB_LED_CAPS_LOCK) ? PSTR("CAPLCK ") : PSTR(" "), false); oled_write_P(led_state.caps_lock ? PSTR("CAPLCK ") : PSTR(" "), false);
oled_write_P(IS_LED_ON(led_usb_state, USB_LED_SCROLL_LOCK) ? PSTR("SCRLCK ") : PSTR(" "), false); oled_write_P(led_state.scroll_lock ? PSTR("SCRLCK ") : PSTR(" "), false);
} }

View file

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

View file

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

View file

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

View file

@ -19,26 +19,27 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS),
}; };
void led_set_user(uint8_t usb_led) { bool led_update_user(led_t led_state) {
setPinOutput(B4); setPinOutput(B4);
setPinOutput(D6); setPinOutput(D6);
setPinOutput(D7); setPinOutput(D7);
if (usb_led & (1 << USB_LED_NUM_LOCK)) { if (led_state.num_lock) {
writePinHigh(D7); writePinHigh(D7);
} else { } else {
writePinLow(D7); writePinLow(D7);
} }
if (usb_led & (1 << USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
writePinHigh(B4); writePinHigh(B4);
} else { } else {
writePinLow(B4); writePinLow(B4);
} }
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { if (led_state.scroll_lock) {
writePinHigh(D6); writePinHigh(D6);
} else { } else {
writePinLow(D6); writePinLow(D6);
} }
return false;
} }

View file

@ -22,24 +22,25 @@ 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) {
DDRB |= (1 << 4) | (1 << 5) | (1 << 6); DDRB |= (1 << 4) | (1 << 5) | (1 << 6);
if (usb_led & (1 << USB_LED_NUM_LOCK)) { if (led_state.num_lock) {
PORTB |= (1 << 4); PORTB |= (1 << 4);
} else { } else {
PORTB &= ~(1 << 4); PORTB &= ~(1 << 4);
} }
if (usb_led & (1 << USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
PORTB |= (1 << 5); PORTB |= (1 << 5);
} else { } else {
PORTB &= ~(1 << 5); PORTB &= ~(1 << 5);
} }
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { if (led_state.scroll_lock) {
PORTB |= (1 << 6); PORTB |= (1 << 6);
} else { } else {
PORTB &= ~(1 << 6); PORTB &= ~(1 << 6);
} }
return false;
} }

View file

@ -4,11 +4,11 @@ char host_led_state_str[24];
const char *read_host_led_state(void) 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", snprintf(host_led_state_str, sizeof(host_led_state_str), "NL:%s CL:%s SL:%s",
(leds & (1 << USB_LED_NUM_LOCK)) ? "on" : "- ", led_state.num_lock ? "on" : "- ",
(leds & (1 << USB_LED_CAPS_LOCK)) ? "on" : "- ", led_state.caps_lock ? "on" : "- ",
(leds & (1 << USB_LED_SCROLL_LOCK)) ? "on" : "- "); led_state.scroll_lock ? "on" : "- ");
return host_led_state_str; return host_led_state_str;
} }

View file

@ -882,7 +882,7 @@ __attribute__((weak)) void register_code(uint8_t code) {
} else if (KC_LOCKING_CAPS_LOCK == code) { } else if (KC_LOCKING_CAPS_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE # ifdef LOCKING_RESYNC_ENABLE
// Resync: ignore if caps lock already is on // Resync: ignore if caps lock already is on
if (host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK)) return; if (host_keyboard_led_state().caps_lock) return;
# endif # endif
add_key(KC_CAPS_LOCK); add_key(KC_CAPS_LOCK);
send_keyboard_report(); send_keyboard_report();
@ -892,7 +892,7 @@ __attribute__((weak)) void register_code(uint8_t code) {
} else if (KC_LOCKING_NUM_LOCK == code) { } else if (KC_LOCKING_NUM_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE # ifdef LOCKING_RESYNC_ENABLE
if (host_keyboard_leds() & (1 << USB_LED_NUM_LOCK)) return; if (host_keyboard_led_state().num_lock) return;
# endif # endif
add_key(KC_NUM_LOCK); add_key(KC_NUM_LOCK);
send_keyboard_report(); send_keyboard_report();
@ -902,7 +902,7 @@ __attribute__((weak)) void register_code(uint8_t code) {
} else if (KC_LOCKING_SCROLL_LOCK == code) { } else if (KC_LOCKING_SCROLL_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE # ifdef LOCKING_RESYNC_ENABLE
if (host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK)) return; if (host_keyboard_led_state().scroll_lock) return;
# endif # endif
add_key(KC_SCROLL_LOCK); add_key(KC_SCROLL_LOCK);
send_keyboard_report(); send_keyboard_report();
@ -952,7 +952,7 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
} else if (KC_LOCKING_CAPS_LOCK == code) { } else if (KC_LOCKING_CAPS_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE # ifdef LOCKING_RESYNC_ENABLE
// Resync: ignore if caps lock already is off // Resync: ignore if caps lock already is off
if (!(host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK))) return; if (!host_keyboard_led_state().caps_lock) return;
# endif # endif
add_key(KC_CAPS_LOCK); add_key(KC_CAPS_LOCK);
send_keyboard_report(); send_keyboard_report();
@ -961,7 +961,7 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
} else if (KC_LOCKING_NUM_LOCK == code) { } else if (KC_LOCKING_NUM_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE # ifdef LOCKING_RESYNC_ENABLE
if (!(host_keyboard_leds() & (1 << USB_LED_NUM_LOCK))) return; if (!host_keyboard_led_state().num_lock) return;
# endif # endif
add_key(KC_NUM_LOCK); add_key(KC_NUM_LOCK);
send_keyboard_report(); send_keyboard_report();
@ -970,7 +970,7 @@ __attribute__((weak)) void unregister_code(uint8_t code) {
} else if (KC_LOCKING_SCROLL_LOCK == code) { } else if (KC_LOCKING_SCROLL_LOCK == code) {
# ifdef LOCKING_RESYNC_ENABLE # ifdef LOCKING_RESYNC_ENABLE
if (!(host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK))) return; if (!host_keyboard_led_state().scroll_lock) return;
# endif # endif
add_key(KC_SCROLL_LOCK); add_key(KC_SCROLL_LOCK);
send_keyboard_report(); send_keyboard_report();

View file

@ -25,7 +25,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* keyboard LEDs */ /* keyboard LEDs */
#define USB_LED_NUM_LOCK 0 #define USB_LED_NUM_LOCK 0
#define USB_LED_CAPS_LOCK 1 #define USB_LED_CAPS_LOCK 1
#define USB_LED_SCROLL_LOCK 2
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View file

@ -86,12 +86,12 @@ void render_layer_state(void) {
oled_write_P(PSTR(" Mods"), layer_state_is(_MODS)); oled_write_P(PSTR(" Mods"), layer_state_is(_MODS));
} }
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("Lock:"), false);
oled_write_P(PSTR(" "), false); oled_write_P(PSTR(" "), false);
oled_write_P(PSTR("N"), led_usb_state & (1 << USB_LED_NUM_LOCK)); oled_write_P(PSTR("N"), led_state.num_lock);
oled_write_P(PSTR("C"), led_usb_state & (1 << USB_LED_CAPS_LOCK)); oled_write_P(PSTR("C"), led_state.caps_lock);
oled_write_ln_P(PSTR("S"), led_usb_state & (1 << USB_LED_SCROLL_LOCK)); oled_write_ln_P(PSTR("S"), led_state.scroll_lock);
} }
void render_mod_status(uint8_t modifiers) { void render_mod_status(uint8_t modifiers) {
@ -129,7 +129,7 @@ void render_user_status(void) {
void render_status_main(void) { void render_status_main(void) {
/* Show Keyboard Layout */ /* Show Keyboard Layout */
render_default_layer_state(); render_default_layer_state();
render_keylock_status(host_keyboard_leds()); render_keylock_status(host_keyboard_led_state());
render_bootmagic_status(); render_bootmagic_status();
render_user_status(); render_user_status();

View file

@ -32,11 +32,11 @@ void oled_render_locale(void) {
} }
} }
void oled_render_keylock_status(uint8_t led_usb_state) { void oled_render_keylock_status(led_t led_state) {
oled_write_P(PSTR(" Lock:"), false); oled_write_P(PSTR(" Lock:"), false);
oled_write_P(PSTR("N"), led_usb_state & (1 << USB_LED_NUM_LOCK)); oled_write_P(PSTR("N"), led_state.num_lock);
oled_write_P(PSTR("C"), led_usb_state & (1 << USB_LED_CAPS_LOCK)); oled_write_P(PSTR("C"), led_state.caps_lock);
oled_write_P(PSTR("S"), led_usb_state & (1 << USB_LED_SCROLL_LOCK)); oled_write_P(PSTR("S"), led_state.scroll_lock);
} }
void oled_render_mod_status(uint8_t modifiers) { void oled_render_mod_status(uint8_t modifiers) {
@ -49,7 +49,7 @@ void oled_render_mod_status(uint8_t modifiers) {
void oled_render_mod_lock_status(void){ void oled_render_mod_lock_status(void){
oled_render_mod_status(get_mods() | get_oneshot_mods()); oled_render_mod_status(get_mods() | get_oneshot_mods());
oled_render_keylock_status(host_keyboard_leds()); oled_render_keylock_status(host_keyboard_led_state());
} }
@ -187,6 +187,3 @@ bool oled_task_user(void) {
} }
#endif #endif
/* oled_render_keylock_status(host_keyboard_leds()); */
/* oled_render_mod_status(get_mods() | get_oneshot_mods()); */

View file

@ -73,9 +73,9 @@ const rgblight_segment_t *const PROGMEM _rgb_layers[] = {
[LAYER_OFFSET + _NUMPAD] = _layer1_layer, [LAYER_OFFSET + _NUMPAD] = _layer1_layer,
[LAYER_OFFSET + _FN] = _layer2_layer, [LAYER_OFFSET + _FN] = _layer2_layer,
[LOCK_OFFSET + USB_LED_NUM_LOCK] = _numlock_layer, [LOCK_OFFSET + 0] = _numlock_layer,
[LOCK_OFFSET + USB_LED_CAPS_LOCK] = _capslock_layer, [LOCK_OFFSET + 1] = _capslock_layer,
[LOCK_OFFSET + USB_LED_SCROLL_LOCK] = _scrolllock_layer, [LOCK_OFFSET + 2] = _scrolllock_layer,
[MISC_OFFSET + 0] = _gflock_layer, [MISC_OFFSET + 0] = _gflock_layer,
[MISC_OFFSET + 1] = _glyphreplace_layer, [MISC_OFFSET + 1] = _glyphreplace_layer,
@ -374,9 +374,9 @@ layer_state_t layer_state_set_user_rgb(layer_state_t state) {
} }
bool led_update_user_rgb(led_t led_state) { bool led_update_user_rgb(led_t led_state) {
rgblight_set_layer_state(LOCK_OFFSET + USB_LED_NUM_LOCK, led_state.num_lock); rgblight_set_layer_state(LOCK_OFFSET + 0, led_state.num_lock);
rgblight_set_layer_state(LOCK_OFFSET + USB_LED_CAPS_LOCK, led_state.caps_lock); rgblight_set_layer_state(LOCK_OFFSET + 1, led_state.caps_lock);
rgblight_set_layer_state(LOCK_OFFSET + USB_LED_SCROLL_LOCK, led_state.scroll_lock); rgblight_set_layer_state(LOCK_OFFSET + 2, led_state.scroll_lock);
return true; return true;
} }

View file

@ -71,15 +71,15 @@ static void render_layer(void)
static void render_keyboard_leds(void) static void render_keyboard_leds(void)
{ {
// Host Keyboard LED Status // Host Keyboard LED Status
uint8_t led_state = host_keyboard_leds(); led_t led_state = host_keyboard_led_state();
#ifdef OLED_90ROTATION #ifdef OLED_90ROTATION
oled_write_P(IS_LED_ON(led_state, USB_LED_NUM_LOCK) ? PSTR("NUMLK") : PSTR(" "), false); oled_write_P(led_state.num_lock ? PSTR("NUMLK") : PSTR(" "), false);
oled_write_P(IS_LED_ON(led_state, USB_LED_CAPS_LOCK) ? PSTR("CAPLK") : PSTR(" "), false); oled_write_P(led_state.caps_lock ? PSTR("CAPLK") : PSTR(" "), false);
oled_write_P(IS_LED_ON(led_state, USB_LED_SCROLL_LOCK) ? PSTR("SCRLK") : PSTR(" "), false); oled_write_P(led_state.scroll_lock ? PSTR("SCRLK") : PSTR(" "), false);
#else #else
oled_write_P(IS_LED_ON(led_state, USB_LED_NUM_LOCK) ? PSTR("NUM ") : PSTR(" "), false); oled_write_P(led_state.num_lock ? PSTR("NUM ") : PSTR(" "), false);
oled_write_P(IS_LED_ON(led_state, USB_LED_CAPS_LOCK) ? PSTR("CAPS ") : PSTR(" "), false); oled_write_P(led_state.caps_lock ? PSTR("CAPS ") : PSTR(" "), false);
oled_write_P(IS_LED_ON(led_state, USB_LED_SCROLL_LOCK) ? PSTR("SCRL") : PSTR(" "), false); oled_write_P(led_state.scroll_lock ? PSTR("SCRL") : PSTR(" "), false);
#endif #endif
} }

View file

@ -69,8 +69,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return process_record_keymap(keycode, record); return process_record_keymap(keycode, record);
} }
void led_set_user(uint8_t usb_led) { bool led_update_user(led_t led_state) {
if (usb_led & (1 << USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
rbw_led_keys[RBW_LCAP].status = ENABLED; rbw_led_keys[RBW_LCAP].status = ENABLED;
rbw_led_keys[RBW_RCAP].status = ENABLED; rbw_led_keys[RBW_RCAP].status = ENABLED;
} else { } else {
@ -78,11 +78,12 @@ void led_set_user(uint8_t usb_led) {
rbw_led_keys[RBW_RCAP].status = DISABLED; rbw_led_keys[RBW_RCAP].status = DISABLED;
} }
if (usb_led & (1 << USB_LED_SCROLL_LOCK)) { if (led_state.scroll_lock) {
rbw_led_keys[RBW_SCRL].status = ENABLED; rbw_led_keys[RBW_SCRL].status = ENABLED;
} else { } else {
rbw_led_keys[RBW_SCRL].status = DISABLED; rbw_led_keys[RBW_SCRL].status = DISABLED;
} }
led_set_keymap(usb_led); led_set_keymap(led_state.raw);
return false;
} }