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