diff options
Diffstat (limited to 'quantum/matrix.c')
| -rw-r--r-- | quantum/matrix.c | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/quantum/matrix.c b/quantum/matrix.c index 33586c431..483d518ec 100644 --- a/quantum/matrix.c +++ b/quantum/matrix.c | |||
| @@ -69,7 +69,7 @@ uint8_t thisHand, thatHand; | |||
| 69 | // user-defined overridable functions | 69 | // user-defined overridable functions |
| 70 | __attribute__((weak)) void matrix_init_pins(void); | 70 | __attribute__((weak)) void matrix_init_pins(void); |
| 71 | __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row); | 71 | __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row); |
| 72 | __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col); | 72 | __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col, matrix_row_t row_shifter); |
| 73 | #ifdef SPLIT_KEYBOARD | 73 | #ifdef SPLIT_KEYBOARD |
| 74 | __attribute__((weak)) void matrix_slave_scan_kb(void) { matrix_slave_scan_user(); } | 74 | __attribute__((weak)) void matrix_slave_scan_kb(void) { matrix_slave_scan_user(); } |
| 75 | __attribute__((weak)) void matrix_slave_scan_user(void) {} | 75 | __attribute__((weak)) void matrix_slave_scan_user(void) {} |
| @@ -113,10 +113,11 @@ __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[] | |||
| 113 | // Start with a clear matrix row | 113 | // Start with a clear matrix row |
| 114 | matrix_row_t current_row_value = 0; | 114 | matrix_row_t current_row_value = 0; |
| 115 | 115 | ||
| 116 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { | 116 | matrix_row_t row_shifter = MATRIX_ROW_SHIFTER; |
| 117 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++, row_shifter <<= 1) { | ||
| 117 | pin_t pin = direct_pins[current_row][col_index]; | 118 | pin_t pin = direct_pins[current_row][col_index]; |
| 118 | if (pin != NO_PIN) { | 119 | if (pin != NO_PIN) { |
| 119 | current_row_value |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index); | 120 | current_row_value |= readPin(pin) ? 0 : row_shifter; |
| 120 | } | 121 | } |
| 121 | } | 122 | } |
| 122 | 123 | ||
| @@ -169,11 +170,12 @@ __attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[] | |||
| 169 | matrix_output_select_delay(); | 170 | matrix_output_select_delay(); |
| 170 | 171 | ||
| 171 | // For each col... | 172 | // For each col... |
| 172 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { | 173 | matrix_row_t row_shifter = MATRIX_ROW_SHIFTER; |
| 174 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++, row_shifter <<= 1) { | ||
| 173 | uint8_t pin_state = readMatrixPin(col_pins[col_index]); | 175 | uint8_t pin_state = readMatrixPin(col_pins[col_index]); |
| 174 | 176 | ||
| 175 | // Populate the matrix row with the state of the col pin | 177 | // Populate the matrix row with the state of the col pin |
| 176 | current_row_value |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); | 178 | current_row_value |= pin_state ? 0 : row_shifter; |
| 177 | } | 179 | } |
| 178 | 180 | ||
| 179 | // Unselect row | 181 | // Unselect row |
| @@ -217,7 +219,7 @@ __attribute__((weak)) void matrix_init_pins(void) { | |||
| 217 | } | 219 | } |
| 218 | } | 220 | } |
| 219 | 221 | ||
| 220 | __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) { | 222 | __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col, matrix_row_t row_shifter) { |
| 221 | bool key_pressed = false; | 223 | bool key_pressed = false; |
| 222 | 224 | ||
| 223 | // Select col | 225 | // Select col |
| @@ -231,11 +233,11 @@ __attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[] | |||
| 231 | // Check row pin state | 233 | // Check row pin state |
| 232 | if (readMatrixPin(row_pins[row_index]) == 0) { | 234 | if (readMatrixPin(row_pins[row_index]) == 0) { |
| 233 | // Pin LO, set col bit | 235 | // Pin LO, set col bit |
| 234 | current_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col); | 236 | current_matrix[row_index] |= row_shifter; |
| 235 | key_pressed = true; | 237 | key_pressed = true; |
| 236 | } else { | 238 | } else { |
| 237 | // Pin HI, clear col bit | 239 | // Pin HI, clear col bit |
| 238 | current_matrix[row_index] &= ~(MATRIX_ROW_SHIFTER << current_col); | 240 | current_matrix[row_index] &= ~row_shifter; |
| 239 | } | 241 | } |
| 240 | } | 242 | } |
| 241 | 243 | ||
| @@ -288,10 +290,8 @@ void matrix_init(void) { | |||
| 288 | matrix_init_pins(); | 290 | matrix_init_pins(); |
| 289 | 291 | ||
| 290 | // initialize matrix state: all keys off | 292 | // initialize matrix state: all keys off |
| 291 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | 293 | memset(matrix, 0, sizeof(matrix)); |
| 292 | raw_matrix[i] = 0; | 294 | memset(raw_matrix, 0, sizeof(raw_matrix)); |
| 293 | matrix[i] = 0; | ||
| 294 | } | ||
| 295 | 295 | ||
| 296 | debounce_init(ROWS_PER_HAND); | 296 | debounce_init(ROWS_PER_HAND); |
| 297 | 297 | ||
| @@ -312,24 +312,22 @@ __attribute__((weak)) bool transport_master_if_connected(matrix_row_t master_mat | |||
| 312 | bool matrix_post_scan(void) { | 312 | bool matrix_post_scan(void) { |
| 313 | bool changed = false; | 313 | bool changed = false; |
| 314 | if (is_keyboard_master()) { | 314 | if (is_keyboard_master()) { |
| 315 | static bool last_connected = false; | ||
| 315 | matrix_row_t slave_matrix[ROWS_PER_HAND] = {0}; | 316 | matrix_row_t slave_matrix[ROWS_PER_HAND] = {0}; |
| 316 | if (transport_master_if_connected(matrix + thisHand, slave_matrix)) { | 317 | if (transport_master_if_connected(matrix + thisHand, slave_matrix)) { |
| 317 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | 318 | changed = memcmp(matrix + thatHand, slave_matrix, sizeof(slave_matrix)) != 0; |
| 318 | if (matrix[thatHand + i] != slave_matrix[i]) { | ||
| 319 | matrix[thatHand + i] = slave_matrix[i]; | ||
| 320 | changed = true; | ||
| 321 | } | ||
| 322 | } | ||
| 323 | } else { | ||
| 324 | // reset other half if disconnected | ||
| 325 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 326 | matrix[thatHand + i] = 0; | ||
| 327 | slave_matrix[i] = 0; | ||
| 328 | } | ||
| 329 | 319 | ||
| 320 | last_connected = true; | ||
| 321 | } else if (last_connected) { | ||
| 322 | // reset other half when disconnected | ||
| 323 | memset(slave_matrix, 0, sizeof(slave_matrix)); | ||
| 330 | changed = true; | 324 | changed = true; |
| 325 | |||
| 326 | last_connected = false; | ||
| 331 | } | 327 | } |
| 332 | 328 | ||
| 329 | if (changed) memcpy(matrix + thatHand, slave_matrix, sizeof(slave_matrix)); | ||
| 330 | |||
| 333 | matrix_scan_quantum(); | 331 | matrix_scan_quantum(); |
| 334 | } else { | 332 | } else { |
| 335 | transport_slave(matrix + thatHand, matrix + thisHand); | 333 | transport_slave(matrix + thatHand, matrix + thisHand); |
| @@ -351,8 +349,9 @@ uint8_t matrix_scan(void) { | |||
| 351 | } | 349 | } |
| 352 | #elif (DIODE_DIRECTION == ROW2COL) | 350 | #elif (DIODE_DIRECTION == ROW2COL) |
| 353 | // Set col, read rows | 351 | // Set col, read rows |
| 354 | for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { | 352 | matrix_row_t row_shifter = MATRIX_ROW_SHIFTER; |
| 355 | matrix_read_rows_on_col(curr_matrix, current_col); | 353 | for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++, row_shifter <<= 1) { |
| 354 | matrix_read_rows_on_col(curr_matrix, current_col, row_shifter); | ||
| 356 | } | 355 | } |
| 357 | #endif | 356 | #endif |
| 358 | 357 | ||
