Align location of some host led logic (#15954)

* Align location of host led logic

* Move more

* align ifdefs

* Fix up includes

* Move callback defs

* Convert comment to build message
This commit is contained in:
Joel Challis 2022-01-22 21:17:02 +00:00 committed by GitHub
parent 448a90f6b0
commit 6e83b44940
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 58 additions and 46 deletions

View File

@ -185,7 +185,7 @@ extern "C"
// restore LED state when keyboard comes up
if (usb_state == USB_STATE_RUNNING) {
dprintf("speed: %s\n", usb_host.getVbusState()==FSHOST ? "full" : "low");
keyboard_set_leds(host_keyboard_leds());
led_set(host_keyboard_leds());
}
}
matrix_scan_quantum();

View File

@ -166,7 +166,7 @@ extern "C"
// restore LED state when keyboard comes up
if (usb_state == USB_STATE_RUNNING) {
dprintf("speed: %s\n", usb_host.getVbusState()==FSHOST ? "full" : "low");
keyboard_set_leds(host_keyboard_leds());
led_set(host_keyboard_leds());
}
}
return 1;

View File

@ -350,32 +350,6 @@ void keyboard_init(void) {
keyboard_post_init_kb(); /* Always keep this last */
}
/** \brief keyboard set leds
*
* FIXME: needs doc
*/
void keyboard_set_leds(uint8_t leds) {
if (debug_keyboard) {
debug("keyboard_set_led: ");
debug_hex8(leds);
debug("\n");
}
led_set(leds);
}
/** \brief set host led state
*
* Only sets state if change detected
*/
void led_task(void) {
static uint8_t led_status = 0;
// update LED
if (led_status != host_keyboard_leds()) {
led_status = host_keyboard_leds();
keyboard_set_leds(led_status);
}
}
/** \brief key_event_task
*
* This function is responsible for calling into other systems when they need to respond to electrical switch press events.

View File

@ -58,8 +58,6 @@ void keyboard_setup(void);
void keyboard_init(void);
/* it runs repeatedly in main loop */
void keyboard_task(void);
/* it runs when host LED status is updated */
void keyboard_set_leds(uint8_t leds);
/* it runs whenever code has to behave differently on a slave */
bool is_keyboard_master(void);
/* it runs whenever code has to behave differently on left vs right split */

View File

@ -13,13 +13,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "quantum.h"
#include "led.h"
#include "host.h"
#include "debug.h"
#ifdef BACKLIGHT_ENABLE
# include "backlight.h"
extern backlight_config_t backlight_config;
#else
// Cannot use BACKLIGHT_CAPS_LOCK without backlight being enabled
# pragma message "Cannot use BACKLIGHT_CAPS_LOCK without backlight being enabled"
# undef BACKLIGHT_CAPS_LOCK
#endif
@ -135,3 +137,41 @@ __attribute__((weak)) void led_set(uint8_t usb_led) {
led_set_kb(usb_led);
led_update_kb((led_t)usb_led);
}
/** \brief Trigger behaviour on transition to suspend
*/
void led_suspend(void) {
uint8_t leds_off = 0;
#ifdef BACKLIGHT_CAPS_LOCK
if (is_backlight_enabled()) {
// Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off
leds_off |= (1 << USB_LED_CAPS_LOCK);
}
#endif
led_set(leds_off);
}
/** \brief Trigger behaviour on transition from suspend
*/
void led_wakeup(void) { led_set(host_keyboard_leds()); }
/** \brief set host led state
*
* Only sets state if change detected
*/
void led_task(void) {
static uint8_t last_led_status = 0;
// update LED
uint8_t led_status = host_keyboard_leds();
if (last_led_status != led_status) {
last_led_status = led_status;
if (debug_keyboard) {
debug("led_task: ");
debug_hex8(led_status);
debug("\n");
}
led_set(led_status);
}
}

View File

@ -49,6 +49,18 @@ void led_set(uint8_t usb_led);
void led_init_ports(void);
void led_suspend(void);
void led_wakeup(void);
void led_task(void);
/* Callbacks */
void led_set_user(uint8_t usb_led);
void led_set_kb(uint8_t usb_led);
bool led_update_user(led_t led_state);
bool led_update_kb(led_t led_state);
#ifdef __cplusplus
}
#endif

View File

@ -433,14 +433,7 @@ void suspend_power_down_quantum(void) {
# endif
// Turn off LED indicators
uint8_t leds_off = 0;
# if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE)
if (is_backlight_enabled()) {
// Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off
leds_off |= (1 << USB_LED_CAPS_LOCK);
}
# endif
led_set(leds_off);
led_suspend();
// Turn off audio
# ifdef AUDIO_ENABLE
@ -491,7 +484,7 @@ __attribute__((weak)) void suspend_wakeup_init_quantum(void) {
#endif
// Restore LED indicators
led_set(host_keyboard_leds());
led_wakeup();
// Wake up underglow
#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)

View File

@ -249,11 +249,6 @@ void register_code16(uint16_t code);
void unregister_code16(uint16_t code);
void tap_code16(uint16_t code);
void led_set_user(uint8_t usb_led);
void led_set_kb(uint8_t usb_led);
bool led_update_user(led_t led_state);
bool led_update_kb(led_t led_state);
const char *get_numeric_str(char *buf, size_t buf_len, uint32_t curr_num, char curr_pad);
const char *get_u8_str(uint8_t curr_num, char curr_pad);
const char *get_u16_str(uint16_t curr_num, char curr_pad);