From 99cd0b13e109bb14f1e5af023c5fcb5e50a78e0a Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Fri, 9 Dec 2022 01:42:22 +0000 Subject: Refactor some led_set_kb instances (#19179) * Refactor some led_set_kb instances * Apply suggestions from code review Co-authored-by: Ryan Co-authored-by: Ryan --- keyboards/converter/modelm101/modelm101.c | 26 +++++---------- keyboards/duck/eagle_viper/v2/v2.c | 27 ++++++++------- keyboards/duck/jetfire/jetfire.c | 39 ++++++++++++---------- keyboards/duck/lightsaver/lightsaver.c | 32 +++++++++--------- keyboards/dumbpad/v1x/v1x.c | 10 +++--- .../dumbpad/v1x_dualencoder/v1x_dualencoder.c | 10 +++--- keyboards/dumbpad/v1x_right/v1x_right.c | 10 +++--- .../handwired/daishi/keymaps/default/keymap.c | 22 ++++-------- keyboards/handwired/promethium/promethium.h | 2 -- keyboards/handwired/retro_refit/retro_refit.c | 39 +++++----------------- keyboards/kinesis/alvicstep/alvicstep.c | 27 +++++++-------- keyboards/lfkeyboards/lfk78/lfk78.c | 10 +++--- keyboards/lfkeyboards/lfk87/lfk87.c | 18 +++++----- keyboards/lfkeyboards/mini1800/mini1800.c | 18 +++++----- keyboards/mechlovin/hannah910/hannah910.c | 14 ++++---- keyboards/org60/org60.c | 18 +++++----- keyboards/xiudi/xd60/xd60.c | 32 ++++++------------ keyboards/yiancardesigns/gingham/gingham.c | 15 ++++----- 18 files changed, 166 insertions(+), 203 deletions(-) diff --git a/keyboards/converter/modelm101/modelm101.c b/keyboards/converter/modelm101/modelm101.c index 708259cab4..02d861b917 100644 --- a/keyboards/converter/modelm101/modelm101.c +++ b/keyboards/converter/modelm101/modelm101.c @@ -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< - uint8_t leds = 0xF0; - if (usb_led & 1 << USB_LED_NUM_LOCK) - leds &= ~0x10; - if (usb_led & 1 << USB_LED_CAPS_LOCK) - leds &= ~0x80; - if (usb_led & 1 << USB_LED_SCROLL_LOCK) - leds &= ~0x20; - PORTD = (PORTD & 0x0F) | leds; - - led_set_user(usb_led); - + uint8_t leds = 0xF0; + if (led_state.num_lock) + leds &= ~0x10; + if (led_state.caps_lock) + leds &= ~0x80; + if (led_state.scroll_lock) + leds &= ~0x20; + PORTD = (PORTD & 0x0F) | leds; + + } + return res; } diff --git a/keyboards/lfkeyboards/lfk78/lfk78.c b/keyboards/lfkeyboards/lfk78/lfk78.c index 6f61d6e2e2..110bbd4168 100644 --- a/keyboards/lfkeyboards/lfk78/lfk78.c +++ b/keyboards/lfkeyboards/lfk78/lfk78.c @@ -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 diff --git a/keyboards/lfkeyboards/lfk87/lfk87.c b/keyboards/lfkeyboards/lfk87/lfk87.c index 553c66da6d..18ddd86adc 100644 --- a/keyboards/lfkeyboards/lfk87/lfk87.c +++ b/keyboards/lfkeyboards/lfk87/lfk87.c @@ -128,15 +128,17 @@ void reset_keyboard_kb(){ reset_keyboard(); } -void led_set_kb(uint8_t usb_led) -{ - // Set capslock LED to Blue - if (usb_led & (1 << USB_LED_CAPS_LOCK)) { - set_rgb(31, 0x00, 0x00, 0x7F); - }else{ - set_rgb(31, 0x00, 0x00, 0x00); +bool led_update_kb(led_t led_state) { + bool res = led_update_user(led_state); + if(res) { + // Set capslock LED to Blue + if (led_state.caps_lock) { + set_rgb(31, 0x00, 0x00, 0x7F); + } else{ + set_rgb(31, 0x00, 0x00, 0x00); + } } - led_set_user(usb_led); + return res; } // Lighting info, see lighting.h for details diff --git a/keyboards/lfkeyboards/mini1800/mini1800.c b/keyboards/lfkeyboards/mini1800/mini1800.c index ac6b0533b4..cf7e42f134 100644 --- a/keyboards/lfkeyboards/mini1800/mini1800.c +++ b/keyboards/lfkeyboards/mini1800/mini1800.c @@ -134,15 +134,17 @@ void reset_keyboard_kb(){ reset_keyboard(); } -void led_set_kb(uint8_t usb_led) -{ - // Set capslock LED to Blue - if (usb_led & (1 << USB_LED_CAPS_LOCK)) { - set_rgb(31, 0x00, 0x00, 0x7F); - }else{ - set_rgb(31, 0x00, 0x00, 0x00); +bool led_update_kb(led_t led_state) { + bool res = led_update_user(led_state); + if(res) { + // Set capslock LED to Blue + if (led_state.caps_lock) { + set_rgb(31, 0x00, 0x00, 0x7F); + } else{ + set_rgb(31, 0x00, 0x00, 0x00); + } } - led_set_user(usb_led); + return res; } // Lighting info, see lighting.h for details diff --git a/keyboards/mechlovin/hannah910/hannah910.c b/keyboards/mechlovin/hannah910/hannah910.c index 70c1a7b8e3..fa5b04ea76 100644 --- a/keyboards/mechlovin/hannah910/hannah910.c +++ b/keyboards/mechlovin/hannah910/hannah910.c @@ -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); - } - led_set_user(usb_led); + +bool led_update_kb(led_t led_state) { + bool res = led_update_user(led_state); + if(res) { + writePin(B2, led_state.caps_lock); + } + return res; } layer_state_t layer_state_set_user(layer_state_t state) diff --git a/keyboards/org60/org60.c b/keyboards/org60/org60.c index 77a5e7c18b..940067538e 100644 --- a/keyboards/org60/org60.c +++ b/keyboards/org60/org60.c @@ -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<