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
Joel Challis 2022-12-09 01:42:22 +00:00 committed by GitHub
parent ba6ee29040
commit 99cd0b13e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 165 additions and 202 deletions

View File

@ -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);
} }

View File

@ -42,12 +42,13 @@ 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 */
@ -58,4 +59,6 @@ void led_set_kb(uint8_t usb_led) {
}; };
indicator_leds_set(status); indicator_leds_set(status);
}
return res;
} }

View File

@ -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) {
if(led_state.caps_lock) {
backlight_state_led |= 1<<STATE_LED_CAPS_LOCK; backlight_state_led |= 1<<STATE_LED_CAPS_LOCK;
} else { } else {
backlight_state_led &= ~(1<<STATE_LED_CAPS_LOCK); 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; backlight_state_led |= 1<<STATE_LED_SCROLL_LOCK;
} else { } else {
backlight_state_led &= ~(1<<STATE_LED_SCROLL_LOCK); 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; backlight_state_led |= 1<<STATE_LED_NUM_LOCK;
} else { } else {
backlight_state_led &= ~(1<<STATE_LED_NUM_LOCK); backlight_state_led &= ~(1<<STATE_LED_NUM_LOCK);
} }
backlight_update_state(); backlight_update_state();
}
return res;
} }

View File

@ -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] = { bool leds[8] = {
usb_led & (1<<USB_LED_CAPS_LOCK), led_state.caps_lock,
usb_led & (1<<USB_LED_SCROLL_LOCK), led_state.scroll_lock,
usb_led & (1<<USB_LED_NUM_LOCK), led_state.num_lock,
layer_state & (1<<1), layer_state & (1<<1),
layer_state & (1<<2), layer_state & (1<<2),
layer_state & (1<<3), layer_state & (1<<3),
@ -51,6 +53,6 @@ void led_set_kb(uint8_t usb_led) {
layer_state & (1<<5) layer_state & (1<<5)
}; };
indicator_leds_set(leds); indicator_leds_set(leds);
}
led_set_user(usb_led); return res;
} }

View File

@ -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;
} }

View File

@ -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;
} }

View File

@ -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;
} }

View File

@ -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);
}
} }

View File

@ -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

View File

@ -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);
};

View File

@ -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;
} }

View File

@ -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

View File

@ -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);
if(res) {
// Set capslock LED to Blue // Set capslock LED to Blue
if (usb_led & (1 << USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
set_rgb(31, 0x00, 0x00, 0x7F); set_rgb(31, 0x00, 0x00, 0x7F);
}else{ } else{
set_rgb(31, 0x00, 0x00, 0x00); 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

View File

@ -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);
if(res) {
// Set capslock LED to Blue // Set capslock LED to Blue
if (usb_led & (1 << USB_LED_CAPS_LOCK)) { if (led_state.caps_lock) {
set_rgb(31, 0x00, 0x00, 0x7F); set_rgb(31, 0x00, 0x00, 0x7F);
}else{ } else{
set_rgb(31, 0x00, 0x00, 0x00); 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

View File

@ -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)

View File

@ -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);
if(res) {
if (led_state.caps_lock) {
org60_caps_led_on(); org60_caps_led_on();
} else { } else {
org60_caps_led_off(); org60_caps_led_off();
} }
}
led_set_user(usb_led); return res;
} }

View File

@ -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);
} }

View File

@ -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 {
send_data = 0x10;
}
i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x09, &send_data, 1, 20); i2c_writeReg((PORT_EXPANDER_ADDRESS << 1), 0x09, &send_data, 1, 20);
}
led_set_user(usb_led); return res;
} }