Refactor some led_set_kb instances (#19179)
* Refactor some led_set_kb instances * Apply suggestions from code review Co-authored-by: Ryan <fauxpark@gmail.com> Co-authored-by: Ryan <fauxpark@gmail.com>master
parent
ba6ee29040
commit
99cd0b13e1
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
#include "modelm101.h"
|
||||
|
||||
void keyboard_pre_init_kb(void) {
|
||||
void led_init_ports(void) {
|
||||
/* Setting status LEDs pins to output and +5V (off) */
|
||||
setPinOutput(B4);
|
||||
setPinOutput(B5);
|
||||
|
@ -25,22 +25,12 @@ void keyboard_pre_init_kb(void) {
|
|||
writePinHigh(B6);
|
||||
}
|
||||
|
||||
void led_set_kb(uint8_t usb_led) {
|
||||
if (usb_led & (1<<USB_LED_NUM_LOCK)) {
|
||||
writePinLow(B4);
|
||||
} else {
|
||||
writePinHigh(B4);
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
writePin(B4, !led_state.num_lock);
|
||||
writePin(B6, !led_state.caps_lock);
|
||||
writePin(B5, !led_state.scroll_lock);
|
||||
}
|
||||
if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
|
||||
writePinLow(B6);
|
||||
} else {
|
||||
writePinHigh(B6);
|
||||
}
|
||||
if (usb_led & (1<<USB_LED_SCROLL_LOCK)) {
|
||||
writePinLow(B5);
|
||||
} else {
|
||||
writePinHigh(B5);
|
||||
}
|
||||
|
||||
led_set_user(usb_led);
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -42,12 +42,13 @@ void backlight_set(uint8_t level) {
|
|||
}
|
||||
}
|
||||
|
||||
// Port from backlight_update_state
|
||||
void led_set_kb(uint8_t usb_led) {
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
bool status[8] = {
|
||||
host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK), /* LED 3 */
|
||||
host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK), /* LED 2 */
|
||||
host_keyboard_leds() & (1<<USB_LED_NUM_LOCK), /* LED 1 */
|
||||
led_state.scroll_lock, /* LED 3 */
|
||||
led_state.caps_lock, /* LED 2 */
|
||||
led_state.num_lock, /* LED 1 */
|
||||
|
||||
layer_state & (1<<2), /* LED 6 */
|
||||
layer_state & (1<<1), /* LED 5 */
|
||||
|
@ -58,4 +59,6 @@ void led_set_kb(uint8_t usb_led) {
|
|||
};
|
||||
|
||||
indicator_leds_set(status);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -95,22 +95,25 @@ void backlight_update_state()
|
|||
show();
|
||||
}
|
||||
|
||||
void led_set_kb(uint8_t usb_led)
|
||||
{
|
||||
if(usb_led & (1<<USB_LED_CAPS_LOCK)) {
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
if(led_state.caps_lock) {
|
||||
backlight_state_led |= 1<<STATE_LED_CAPS_LOCK;
|
||||
} else {
|
||||
backlight_state_led &= ~(1<<STATE_LED_CAPS_LOCK);
|
||||
}
|
||||
if(usb_led & (1<<USB_LED_SCROLL_LOCK)) {
|
||||
if(led_state.scroll_lock) {
|
||||
backlight_state_led |= 1<<STATE_LED_SCROLL_LOCK;
|
||||
} else {
|
||||
backlight_state_led &= ~(1<<STATE_LED_SCROLL_LOCK);
|
||||
}
|
||||
if(usb_led & (1<<USB_LED_NUM_LOCK)) {
|
||||
if(led_state.num_lock) {
|
||||
backlight_state_led |= 1<<STATE_LED_NUM_LOCK;
|
||||
} else {
|
||||
backlight_state_led &= ~(1<<STATE_LED_NUM_LOCK);
|
||||
}
|
||||
backlight_update_state();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -39,11 +39,13 @@ void backlight_set(uint8_t level) {
|
|||
}
|
||||
}
|
||||
|
||||
void led_set_kb(uint8_t usb_led) {
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
bool leds[8] = {
|
||||
usb_led & (1<<USB_LED_CAPS_LOCK),
|
||||
usb_led & (1<<USB_LED_SCROLL_LOCK),
|
||||
usb_led & (1<<USB_LED_NUM_LOCK),
|
||||
led_state.caps_lock,
|
||||
led_state.scroll_lock,
|
||||
led_state.num_lock,
|
||||
layer_state & (1<<1),
|
||||
layer_state & (1<<2),
|
||||
layer_state & (1<<3),
|
||||
|
@ -51,6 +53,6 @@ void led_set_kb(uint8_t usb_led) {
|
|||
layer_state & (1<<5)
|
||||
};
|
||||
indicator_leds_set(leds);
|
||||
|
||||
led_set_user(usb_led);
|
||||
}
|
||||
return res;
|
||||
}
|
|
@ -62,8 +62,10 @@ void matrix_init_kb(void) {
|
|||
matrix_init_user();
|
||||
}
|
||||
|
||||
void led_set_kb(uint8_t usb_led) {
|
||||
// put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
|
||||
writePin(LED_02, !IS_LED_ON(usb_led, USB_LED_NUM_LOCK));
|
||||
led_set_user(usb_led);
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
writePin(LED_02, !led_state.num_lock);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -62,8 +62,10 @@ void matrix_init_kb(void) {
|
|||
matrix_init_user();
|
||||
}
|
||||
|
||||
void led_set_kb(uint8_t usb_led) {
|
||||
// put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
|
||||
writePin(LED_02, !IS_LED_ON(usb_led, USB_LED_NUM_LOCK));
|
||||
led_set_user(usb_led);
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
writePin(LED_02, !led_state.num_lock);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -62,8 +62,10 @@ void matrix_init_kb(void) {
|
|||
matrix_init_user();
|
||||
}
|
||||
|
||||
void led_set_kb(uint8_t usb_led) {
|
||||
// put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
|
||||
writePin(LED_02, !IS_LED_ON(usb_led, USB_LED_NUM_LOCK));
|
||||
led_set_user(usb_led);
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
writePin(LED_02, !led_state.num_lock);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -100,20 +100,10 @@ void matrix_init_user(void) {
|
|||
setPinOutput(C6);
|
||||
}
|
||||
|
||||
void led_set_kb(uint8_t usb_led) {
|
||||
if (IS_LED_OFF(usb_led, USB_LED_NUM_LOCK)) {
|
||||
writePinLow(C4);
|
||||
} else {
|
||||
writePinHigh(C4);
|
||||
}
|
||||
if (IS_LED_OFF(usb_led, USB_LED_CAPS_LOCK)) {
|
||||
writePinLow(C5);
|
||||
} else {
|
||||
writePinHigh(C5);
|
||||
}
|
||||
if (IS_LED_OFF(usb_led, USB_LED_SCROLL_LOCK)) {
|
||||
writePinLow(C6);
|
||||
} else {
|
||||
writePinHigh(C6);
|
||||
}
|
||||
bool led_update_user(led_t led_state) {
|
||||
writePin(C4, led_state.num_lock);
|
||||
writePin(C5, led_state.caps_lock);
|
||||
writePin(C6, led_state.scroll_lock);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
#include "quantum.h"
|
||||
|
||||
void battery_poll(uint8_t level);
|
||||
void led_set_kb(uint8_t usb_led);
|
||||
void led_set_user(uint8_t usb_led);
|
||||
|
||||
#define XXX KC_NO
|
||||
|
||||
|
|
|
@ -12,36 +12,13 @@ void matrix_init_kb(void) {
|
|||
matrix_init_user();
|
||||
};
|
||||
|
||||
void led_set_kb(uint8_t usb_led) {
|
||||
// put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
writePin(D0, !led_state.caps_lock);
|
||||
writePin(D1, !led_state.num_lock);
|
||||
writePin(C6, !led_state.scroll_lock);
|
||||
|
||||
if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
|
||||
// output low
|
||||
DDRD |= (1<<0);
|
||||
PORTD &= ~(1<<0);
|
||||
} else {
|
||||
// Hi-Z
|
||||
DDRD &= ~(1<<0);
|
||||
PORTD &= ~(1<<0);
|
||||
}
|
||||
if (usb_led & (1<<USB_LED_NUM_LOCK)) {
|
||||
// output low
|
||||
DDRD |= (1<<1);
|
||||
PORTD &= ~(1<<1);
|
||||
} else {
|
||||
// Hi-Z
|
||||
DDRD &= ~(1<<1);
|
||||
PORTD &= ~(1<<1);
|
||||
}
|
||||
if (usb_led & (1<<USB_LED_SCROLL_LOCK)) {
|
||||
// output low
|
||||
DDRC |= (1<<6);
|
||||
PORTC &= ~(1<<6);
|
||||
} else {
|
||||
// Hi-Z
|
||||
DDRC &= ~(1<<6);
|
||||
PORTC &= ~(1<<6);
|
||||
}
|
||||
|
||||
led_set_user(usb_led);
|
||||
};
|
||||
return res;
|
||||
}
|
|
@ -70,19 +70,20 @@ void blink_all_leds(void)
|
|||
matrix_init_user();
|
||||
}
|
||||
|
||||
void led_set_kb(uint8_t usb_led) {
|
||||
// put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
|
||||
//Copyright 2014 Warren Janssens <warren.janssens@gmail.com>
|
||||
uint8_t leds = 0xF0;
|
||||
if (usb_led & 1 << USB_LED_NUM_LOCK)
|
||||
if (led_state.num_lock)
|
||||
leds &= ~0x10;
|
||||
if (usb_led & 1 << USB_LED_CAPS_LOCK)
|
||||
if (led_state.caps_lock)
|
||||
leds &= ~0x80;
|
||||
if (usb_led & 1 << USB_LED_SCROLL_LOCK)
|
||||
if (led_state.scroll_lock)
|
||||
leds &= ~0x20;
|
||||
PORTD = (PORTD & 0x0F) | leds;
|
||||
|
||||
led_set_user(usb_led);
|
||||
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -151,11 +151,12 @@ void reset_keyboard_kb() {
|
|||
reset_keyboard();
|
||||
}
|
||||
|
||||
void led_set_kb(uint8_t usb_led) {
|
||||
// put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
#ifdef ISSI_ENABLE
|
||||
# ifdef CAPSLOCK_LED
|
||||
if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
|
||||
if (led_state.caps_lock) {
|
||||
activateLED(0, 3, 7, 255);
|
||||
} else {
|
||||
activateLED(0, 3, 7, 0);
|
||||
|
@ -163,7 +164,8 @@ void led_set_kb(uint8_t usb_led) {
|
|||
# endif // CAPSLOCK_LED
|
||||
#endif // ISS_ENABLE
|
||||
|
||||
led_set_user(usb_led);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// LFK lighting info
|
||||
|
|
|
@ -128,15 +128,17 @@ void reset_keyboard_kb(){
|
|||
reset_keyboard();
|
||||
}
|
||||
|
||||
void led_set_kb(uint8_t usb_led)
|
||||
{
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
// Set capslock LED to Blue
|
||||
if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
|
||||
if (led_state.caps_lock) {
|
||||
set_rgb(31, 0x00, 0x00, 0x7F);
|
||||
}else{
|
||||
} else{
|
||||
set_rgb(31, 0x00, 0x00, 0x00);
|
||||
}
|
||||
led_set_user(usb_led);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// Lighting info, see lighting.h for details
|
||||
|
|
|
@ -134,15 +134,17 @@ void reset_keyboard_kb(){
|
|||
reset_keyboard();
|
||||
}
|
||||
|
||||
void led_set_kb(uint8_t usb_led)
|
||||
{
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
// Set capslock LED to Blue
|
||||
if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
|
||||
if (led_state.caps_lock) {
|
||||
set_rgb(31, 0x00, 0x00, 0x7F);
|
||||
}else{
|
||||
} else{
|
||||
set_rgb(31, 0x00, 0x00, 0x00);
|
||||
}
|
||||
led_set_user(usb_led);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// Lighting info, see lighting.h for details
|
||||
|
|
|
@ -22,13 +22,13 @@ void led_init_ports(void) {
|
|||
setPinOutput(D2);
|
||||
|
||||
}
|
||||
void led_set_kb(uint8_t usb_led) {
|
||||
if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) {
|
||||
writePinHigh(B2);
|
||||
} else {
|
||||
writePinLow(B2);
|
||||
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
writePin(B2, led_state.caps_lock);
|
||||
}
|
||||
led_set_user(usb_led);
|
||||
return res;
|
||||
}
|
||||
|
||||
layer_state_t layer_state_set_user(layer_state_t state)
|
||||
|
|
|
@ -8,12 +8,14 @@ extern inline void org60_caps_led_off(void);
|
|||
extern inline void org60_bl_led_off(void);
|
||||
|
||||
|
||||
void led_set_kb(uint8_t usb_led) {
|
||||
if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
if (led_state.caps_lock) {
|
||||
org60_caps_led_on();
|
||||
} else {
|
||||
org60_caps_led_off();
|
||||
}
|
||||
|
||||
led_set_user(usb_led);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -8,26 +8,14 @@ extern inline void xd60_caps_led_off(void);
|
|||
extern inline void xd60_bl_led_off(void);
|
||||
|
||||
|
||||
void led_set_kb(uint8_t usb_led) {
|
||||
// put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
|
||||
|
||||
if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
if (led_state.caps_lock) {
|
||||
xd60_caps_led_on();
|
||||
} else {
|
||||
xd60_caps_led_off();
|
||||
}
|
||||
|
||||
// if (usb_led & (1<<USB_LED_NUM_LOCK)) {
|
||||
// xd60_esc_led_on();
|
||||
// } else {
|
||||
// xd60_esc_led_off();
|
||||
// }
|
||||
|
||||
// if (usb_led & (1<<USB_LED_SCROLL_LOCK)) {
|
||||
// xd60_fn_led_on();
|
||||
// } else {
|
||||
// xd60_fn_led_off();
|
||||
// }
|
||||
|
||||
led_set_user(usb_led);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -27,14 +27,11 @@ void matrix_init_kb(void) {
|
|||
matrix_init_user();
|
||||
}
|
||||
|
||||
void led_set_kb(uint8_t usb_led) {
|
||||
// Bit 3 is Green LED, bit 4 is Red LED.
|
||||
if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) {
|
||||
send_data = 0x18;
|
||||
} else {
|
||||
send_data = 0x10;
|
||||
}
|
||||
bool led_update_kb(led_t led_state) {
|
||||
bool res = led_update_user(led_state);
|
||||
if(res) {
|
||||
send_data = led_state.caps_lock ? 0x18 : 0x10;
|
||||
i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x09, &send_data, 1, 20);
|
||||
|
||||
led_set_user(usb_led);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue