|
|
@ -145,6 +145,132 @@ bool is_keyboard_master(void) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief Get the number of currently connected matrices
|
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Implement this if you support multiple matrices, see qwiic_keyboard.c for an example |
|
|
|
|
|
|
|
* NOTE: It should return the number of additional matrices, the master is always implied. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
__attribute__((weak)) |
|
|
|
|
|
|
|
uint8_t multimatrix_get_num_matrices(void) { |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief Get the number of columns of a connected matrix
|
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Implement this if you support multiple matrices, see qwiic_keyboard.c for an example |
|
|
|
|
|
|
|
* NOTE: The matrix index 0 is the first remote matrix, the function is not called for the master |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
__attribute__((weak)) |
|
|
|
|
|
|
|
uint8_t multimatrix_get_num_cols(uint8_t matrix) { |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief Get the number of rows of a connected matrix
|
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Implement this if you support multiple matrices, see qwiic_keyboard.c for an example |
|
|
|
|
|
|
|
* NOTE: The matrix index 0 is the first remote matrix, the function is not called for the master |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
__attribute__((weak)) |
|
|
|
|
|
|
|
uint8_t multimatrix_get_num_rows(uint8_t matrix) { |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief Get the row status of a connected matrix
|
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Implement this if you support multiple matrices, see qwiic_keyboard.c for an example |
|
|
|
|
|
|
|
* NOTE: The matrix index 0 is the first remote matrix, the function is not called for the master |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
__attribute__((weak)) |
|
|
|
|
|
|
|
uint32_t multimatrix_get_row(uint8_t matrix, uint8_t row) { |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief Get the row cache of a connected matrix
|
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Implement this if you support multiple matrices, see qwiic_keyboard.c for an example |
|
|
|
|
|
|
|
* NOTE: The matrix index 0 is the first remote matrix, the function is not called for the master |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
__attribute__((weak)) |
|
|
|
|
|
|
|
uint32_t multimatrix_get_row_cache(uint8_t matrix, uint8_t row) { |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief Set the row cache of a connected matrix
|
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Implement this if you support multiple matrices, see qwiic_keyboard.c for an example |
|
|
|
|
|
|
|
* NOTE: The matrix index 0 is the first remote matrix, the function is not called for the master |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
__attribute__((weak)) |
|
|
|
|
|
|
|
void multimatrix_set_row_cache(uint8_t matrix, uint8_t row, uint32_t value) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief Get the number of currently connected matrices
|
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* For normal keyboards this usually returns 1, but for multi-matrix keyboards this will |
|
|
|
|
|
|
|
* return the total number of connected keyboards/modules including the master |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
uint8_t keyboard_get_num_matrices(void) { |
|
|
|
|
|
|
|
return 1 + multimatrix_get_num_matrices(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief Get the number of columns of a connected matrix
|
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Specify the matrix index to query connected multi-matrix keyboards/modules |
|
|
|
|
|
|
|
* 0 is always the master |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
uint8_t keyboard_get_num_cols(uint8_t matrix) { |
|
|
|
|
|
|
|
if (matrix == 0) { |
|
|
|
|
|
|
|
return MATRIX_COLS; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return multimatrix_get_num_cols(matrix - 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief Get the number of rows of a connected matrix
|
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Specify the matrix index to query connected multi-matrix keyboards/modules |
|
|
|
|
|
|
|
* 0 is always the master |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
uint8_t keyboard_get_num_rows(uint8_t matrix) { |
|
|
|
|
|
|
|
if (matrix == 0) { |
|
|
|
|
|
|
|
return MATRIX_ROWS; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return multimatrix_get_num_rows(matrix - 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief Get the row status of a connected matrix
|
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* Specify the matrix index to query connected multi-matrix keyboards/modules |
|
|
|
|
|
|
|
* 0 is always the master |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
uint32_t keyboard_get_row(uint8_t matrix, uint8_t row) { |
|
|
|
|
|
|
|
if (matrix == 0) { |
|
|
|
|
|
|
|
return matrix_get_row(row); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return multimatrix_get_row(matrix - 1, row); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static matrix_row_t matrix_prev[MATRIX_ROWS]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t get_row_cache(uint8_t matrix, uint8_t row) { |
|
|
|
|
|
|
|
if (matrix == 0) { |
|
|
|
|
|
|
|
return matrix_prev[row]; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return multimatrix_get_row_cache(matrix - 1, row); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void set_row_cache(uint8_t matrix, uint8_t row, uint32_t value) { |
|
|
|
|
|
|
|
if (matrix == 0) { |
|
|
|
|
|
|
|
matrix_prev[row] = value; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return multimatrix_set_row_cache(matrix - 1, row, value); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** \brief keyboard_init
|
|
|
|
/** \brief keyboard_init
|
|
|
|
* |
|
|
|
* |
|
|
|
* FIXME: needs doc |
|
|
|
* FIXME: needs doc |
|
|
@ -203,53 +329,57 @@ void keyboard_init(void) { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void keyboard_task(void) |
|
|
|
void keyboard_task(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
static matrix_row_t matrix_prev[MATRIX_ROWS]; |
|
|
|
|
|
|
|
#ifdef MATRIX_HAS_GHOST |
|
|
|
|
|
|
|
// static matrix_row_t matrix_ghost[MATRIX_ROWS];
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
static uint8_t led_status = 0; |
|
|
|
static uint8_t led_status = 0; |
|
|
|
matrix_row_t matrix_row = 0; |
|
|
|
uint32_t matrix_row = 0; |
|
|
|
matrix_row_t matrix_change = 0; |
|
|
|
uint32_t matrix_change = 0; |
|
|
|
#ifdef QMK_KEYS_PER_SCAN |
|
|
|
#ifdef QMK_KEYS_PER_SCAN |
|
|
|
uint8_t keys_processed = 0; |
|
|
|
uint8_t keys_processed = 0; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
matrix_scan(); |
|
|
|
matrix_scan(); |
|
|
|
if (is_keyboard_master()) { |
|
|
|
if (is_keyboard_master()) { |
|
|
|
for (uint8_t r = 0; r < MATRIX_ROWS; r++) { |
|
|
|
for (uint8_t m = 0; m < keyboard_get_num_matrices(); m++) { |
|
|
|
matrix_row = matrix_get_row(r); |
|
|
|
uint8_t num_cols = keyboard_get_num_cols(m); |
|
|
|
matrix_change = matrix_row ^ matrix_prev[r]; |
|
|
|
uint8_t num_rows = keyboard_get_num_rows(m); |
|
|
|
if (matrix_change) { |
|
|
|
for (uint8_t r = 0; r < num_rows; r++) { |
|
|
|
|
|
|
|
matrix_row = keyboard_get_row(m, r); |
|
|
|
|
|
|
|
uint32_t row_cache = get_row_cache(m, r); |
|
|
|
|
|
|
|
matrix_change = matrix_row ^ row_cache; |
|
|
|
|
|
|
|
if (matrix_change) { |
|
|
|
#ifdef MATRIX_HAS_GHOST |
|
|
|
#ifdef MATRIX_HAS_GHOST |
|
|
|
if (has_ghost_in_row(r, matrix_row)) { |
|
|
|
//NOTE: The we support ghosting only for the main matrix, since it's only useful for old keyboards without diodes
|
|
|
|
/* Keep track of whether ghosted status has changed for
|
|
|
|
if (has_ghost_in_row(r, matrix_row)) { |
|
|
|
* debugging. But don't update matrix_prev until un-ghosted, or |
|
|
|
/* Keep track of whether ghosted status has changed for
|
|
|
|
* the last key would be lost. |
|
|
|
* debugging. But don't update matrix_prev until un-ghosted, or |
|
|
|
*/ |
|
|
|
* the last key would be lost. |
|
|
|
//if (debug_matrix && matrix_ghost[r] != matrix_row) {
|
|
|
|
*/ |
|
|
|
// matrix_print();
|
|
|
|
//if (debug_matrix && matrix_ghost[r] != matrix_row) {
|
|
|
|
//}
|
|
|
|
// matrix_print();
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//matrix_ghost[r] = matrix_row;
|
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
//matrix_ghost[r] = matrix_row;
|
|
|
|
//matrix_ghost[r] = matrix_row;
|
|
|
|
continue; |
|
|
|
#endif |
|
|
|
} |
|
|
|
if (debug_matrix) matrix_print(); |
|
|
|
//matrix_ghost[r] = matrix_row;
|
|
|
|
for (uint8_t c = 0; c < num_cols; c++) { |
|
|
|
#endif |
|
|
|
if (matrix_change & (uint32_t)(1u<<c)) { |
|
|
|
if (debug_matrix) matrix_print(); |
|
|
|
action_exec((keyevent_t){ |
|
|
|
for (uint8_t c = 0; c < MATRIX_COLS; c++) { |
|
|
|
// The main matrix is always 0
|
|
|
|
if (matrix_change & ((matrix_row_t)1<<c)) { |
|
|
|
.key = (keymatrix_t){.pos = (keypos_t){ .row = r, .col = c }, .matrix = m}, |
|
|
|
action_exec((keyevent_t){ |
|
|
|
.pressed = (matrix_row & ((uint32_t)1u<<c)), |
|
|
|
.key = (keypos_t){ .row = r, .col = c }, |
|
|
|
.time = (timer_read() | 1) /* time should not be 0 */ |
|
|
|
.pressed = (matrix_row & ((matrix_row_t)1<<c)), |
|
|
|
}); |
|
|
|
.time = (timer_read() | 1) /* time should not be 0 */ |
|
|
|
// record a processed key
|
|
|
|
}); |
|
|
|
row_cache ^= (uint32_t)(1u<<c); |
|
|
|
// record a processed key
|
|
|
|
set_row_cache(m, r, row_cache); |
|
|
|
matrix_prev[r] ^= ((matrix_row_t)1<<c); |
|
|
|
|
|
|
|
#ifdef QMK_KEYS_PER_SCAN |
|
|
|
#ifdef QMK_KEYS_PER_SCAN |
|
|
|
// only jump out if we have processed "enough" keys.
|
|
|
|
// only jump out if we have processed "enough" keys.
|
|
|
|
if (++keys_processed >= QMK_KEYS_PER_SCAN) |
|
|
|
if (++keys_processed >= QMK_KEYS_PER_SCAN) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
// process a key per task call
|
|
|
|
// process a key per task call
|
|
|
|
goto MATRIX_LOOP_END; |
|
|
|
goto MATRIX_LOOP_END; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|