Skip to content

Commit

Permalink
Slight tidy up of keyboard task loop (#15725)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr authored Jan 9, 2022
1 parent 82d3bdb commit 7562f66
Showing 1 changed file with 48 additions and 35 deletions.
83 changes: 48 additions & 35 deletions quantum/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,32 @@ 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.
Expand All @@ -363,28 +389,17 @@ void switch_events(uint8_t row, uint8_t col, bool pressed) {
#endif
}

/** \brief Keyboard task: Do keyboard routine jobs
*
* Do routine keyboard jobs:
/** \brief Perform scan of keyboard matrix
*
* * scan matrix
* * handle mouse movements
* * handle midi commands
* * light LEDs
*
* This is repeatedly called as fast as possible.
* Any detected changes in state are sent out as part of the processing
*/
void keyboard_task(void) {
bool matrix_scan_task(void) {
static matrix_row_t matrix_prev[MATRIX_ROWS];
static uint8_t led_status = 0;
matrix_row_t matrix_row = 0;
matrix_row_t matrix_change = 0;
#ifdef QMK_KEYS_PER_SCAN
uint8_t keys_processed = 0;
#endif
#ifdef ENCODER_ENABLE
bool encoders_changed = false;
#endif

uint8_t matrix_changed = matrix_scan();
if (matrix_changed) last_matrix_activity_trigger();
Expand Down Expand Up @@ -431,9 +446,24 @@ void keyboard_task(void) {

MATRIX_LOOP_END:

#ifdef DEBUG_MATRIX_SCAN_RATE
matrix_scan_perf_task();
#endif
return matrix_changed;
}

/** \brief Keyboard task: Do keyboard routine jobs
*
* Do routine keyboard jobs:
*
* * scan matrix
* * handle mouse movements
* * handle midi commands
* * light LEDs
*
* This is repeatedly called as fast as possible.
*/
void keyboard_task(void) {
bool matrix_changed = matrix_scan_task();
(void)matrix_changed;

#if defined(RGBLIGHT_ENABLE)
rgblight_task();
Expand All @@ -453,7 +483,7 @@ void keyboard_task(void) {
#endif

#ifdef ENCODER_ENABLE
encoders_changed = encoder_read();
bool encoders_changed = encoder_read();
if (encoders_changed) last_encoder_activity_trigger();
#endif

Expand Down Expand Up @@ -516,22 +546,5 @@ void keyboard_task(void) {
programmable_button_send();
#endif

// update LED
if (led_status != host_keyboard_leds()) {
led_status = host_keyboard_leds();
keyboard_set_leds(led_status);
}
}

/** \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);
led_task();
}

0 comments on commit 7562f66

Please sign in to comment.