Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quantum: led: split out led_update_ports() for customization of led behaviour #14452

Merged
merged 3 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/feature_led_indicators.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ The `host_keyboard_led_state()` function will report the LED state returned from
bool caps = host_keyboard_led_state().caps_lock;
```

## `led_update_ports()`

This function writes the LED state to the actual hardware. Call it manually
from your `led_update_*()` callbacks to modify the handling of the standard
keyboard LEDs.
For example when repurposing a standard LED indicator as layer indicator.

## Setting Physical LED State

Some keyboard implementations provide convenient methods for setting the state of the physical LEDs.
Expand Down
48 changes: 26 additions & 22 deletions quantum/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,36 @@ __attribute__((weak)) bool led_update_user(led_t led_state) {
__attribute__((weak)) bool led_update_kb(led_t led_state) {
bool res = led_update_user(led_state);
if (res) {
#if defined(LED_NUM_LOCK_PIN) || defined(LED_CAPS_LOCK_PIN) || defined(LED_SCROLL_LOCK_PIN) || defined(LED_COMPOSE_PIN) || defined(LED_KANA_PIN)
# if LED_PIN_ON_STATE == 0
// invert the whole thing to avoid having to conditionally !led_state.x later
led_state.raw = ~led_state.raw;
# endif

# ifdef LED_NUM_LOCK_PIN
writePin(LED_NUM_LOCK_PIN, led_state.num_lock);
# endif
# ifdef LED_CAPS_LOCK_PIN
writePin(LED_CAPS_LOCK_PIN, led_state.caps_lock);
# endif
# ifdef LED_SCROLL_LOCK_PIN
writePin(LED_SCROLL_LOCK_PIN, led_state.scroll_lock);
# endif
# ifdef LED_COMPOSE_PIN
writePin(LED_COMPOSE_PIN, led_state.compose);
# endif
# ifdef LED_KANA_PIN
writePin(LED_KANA_PIN, led_state.kana);
# endif
#endif
led_update_ports(led_state);
}
return res;
}

/** \brief Write LED state to hardware
*/
__attribute__((weak)) void led_update_ports(led_t led_state) {
#if LED_PIN_ON_STATE == 0
// invert the whole thing to avoid having to conditionally !led_state.x later
led_state.raw = ~led_state.raw;
fauxpark marked this conversation as resolved.
Show resolved Hide resolved
#endif

#ifdef LED_NUM_LOCK_PIN
writePin(LED_NUM_LOCK_PIN, led_state.num_lock);
#endif
#ifdef LED_CAPS_LOCK_PIN
writePin(LED_CAPS_LOCK_PIN, led_state.caps_lock);
#endif
#ifdef LED_SCROLL_LOCK_PIN
writePin(LED_SCROLL_LOCK_PIN, led_state.scroll_lock);
#endif
#ifdef LED_COMPOSE_PIN
writePin(LED_COMPOSE_PIN, led_state.compose);
#endif
#ifdef LED_KANA_PIN
writePin(LED_KANA_PIN, led_state.kana);
#endif
}

/** \brief Initialise any LED related hardware and/or state
*/
__attribute__((weak)) void led_init_ports(void) {
Expand Down
1 change: 1 addition & 0 deletions quantum/led.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ 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);
void led_update_ports(led_t led_state);

uint32_t last_led_activity_time(void); // Timestamp of the LED activity
uint32_t last_led_activity_elapsed(void); // Number of milliseconds since the last LED activity
Expand Down