diff --git a/keyboards/anne_pro/anne_pro.c b/keyboards/anne_pro/anne_pro.c index daa6fcba25..ee087b6bcd 100644 --- a/keyboards/anne_pro/anne_pro.c +++ b/keyboards/anne_pro/anne_pro.c @@ -91,3 +91,45 @@ void keyboard_post_init_kb(void) { matrix_init_user(); } + +/* Current state of the matrix */ +static matrix_row_t matrix_status[MATRIX_ROWS]; +/* Buffer for the keystate packet */ +static uint8_t keystate[12] = {9, 10, 7, 0}; + +/* Update the reactive lighting on every keymatrix scan when lighting is enabled */ +void matrix_scan_kb(void) { + matrix_row_t matrix_row = 0; + matrix_row_t matrix_change = 0; + + /* Determine if the matrix state has changed, and update the state */ + for (uint8_t r = 0; r < MATRIX_ROWS; r++) { + matrix_row = matrix_get_row(r); + matrix_change |= matrix_row ^ matrix_status[r]; + matrix_status[r] = matrix_row; + } + + /* If the leds are enabled and the state changed */ + if (leds_enabled && matrix_change) { + /* Go through every scan position */ + for (uint8_t r = 0; r < MATRIX_ROWS; r++) { + for (uint8_t c = 0; c < MATRIX_COLS; c++) { + int position = r * MATRIX_COLS + c; + int index = position / 8; + int bit = position % 8; + + /* Update the keystate based on the state of the matrix */ + if (matrix_status[r] & (1 << c)) { + keystate[3 + index] |= (1 << bit); + } else { + keystate[3 + index] &= ~(1 << bit); + } + } + } + /* Send the keystate to the LED controller */ + uartStartSend(&UARTD3, 12, keystate); + } + + /* Run matrix_scan_user code */ + matrix_scan_user(); +}