Skip to content

Commit

Permalink
quantum: led: simplify #ifdef-fery around available LEDs
Browse files Browse the repository at this point in the history
The outer #ifdef only really protects the inversion of led_state.raw
which the compiler can easily optimize away if it is not needed.
  • Loading branch information
t-8ch committed Aug 31, 2022
1 parent 81b0365 commit a442442
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions quantum/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,25 @@ __attribute__((weak)) bool led_update_kb(led_t led_state) {
/** \brief Write LED state to hardware
*/
void led_update_ports(led_t led_state) {
#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
#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
#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
}

Expand Down

0 comments on commit a442442

Please sign in to comment.