summaryrefslogtreecommitdiffstats
path: root/quantum/split_common
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2020-05-21 17:59:56 +0100
committerGitHub <noreply@github.com>2020-05-21 17:59:56 +0100
commit205321c37740caaffbca69e626a8432fd369d20c (patch)
treee0efcd82de1bd537368be7501684529e71a73dec /quantum/split_common
parent1816ad01d0efcc987b5aa7a833331b0f9d903d4f (diff)
Slight speed increases for matrix scanning (#9150)
Diffstat (limited to 'quantum/split_common')
-rw-r--r--quantum/split_common/matrix.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c
index 8b91f8ca83..27c37d4b00 100644
--- a/quantum/split_common/matrix.c
+++ b/quantum/split_common/matrix.c
@@ -65,17 +65,22 @@ static void init_pins(void) {
}
static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
- matrix_row_t last_row_value = current_matrix[current_row];
- current_matrix[current_row] = 0;
+ // Start with a clear matrix row
+ matrix_row_t current_row_value = 0;
for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
pin_t pin = direct_pins[current_row][col_index];
if (pin != NO_PIN) {
- current_matrix[current_row] |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index);
+ current_row_value |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index);
}
}
- return (last_row_value != current_matrix[current_row]);
+ // If the row has changed, store the row and return the changed flag.
+ if (current_matrix[current_row] != current_row_value) {
+ current_matrix[current_row] = current_row_value;
+ return true;
+ }
+ return false;
}
#elif defined(DIODE_DIRECTION)
@@ -101,12 +106,9 @@ static void init_pins(void) {
}
}
-static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
- // Store last value of row prior to reading
- matrix_row_t last_row_value = current_matrix[current_row];
-
- // Clear data in matrix row
- current_matrix[current_row] = 0;
+static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
+ // Start with a clear matrix row
+ matrix_row_t current_row_value = 0;
// Select row and wait for row selecton to stabilize
select_row(current_row);
@@ -118,13 +120,18 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
uint8_t pin_state = readPin(col_pins[col_index]);
// Populate the matrix row with the state of the col pin
- current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index);
+ current_row_value |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index);
}
// Unselect row
unselect_row(current_row);
- return (last_row_value != current_matrix[current_row]);
+ // If the row has changed, store the row and return the changed flag.
+ if (current_matrix[current_row] != current_row_value) {
+ current_matrix[current_row] = current_row_value;
+ return true;
+ }
+ return false;
}
# elif (DIODE_DIRECTION == ROW2COL)
@@ -160,19 +167,21 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) {
// Store last value of row prior to reading
matrix_row_t last_row_value = current_matrix[row_index];
+ matrix_row_t current_row_value = last_row_value;
// Check row pin state
if (readPin(row_pins[row_index]) == 0) {
// Pin LO, set col bit
- current_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col);
+ current_row_value |= (MATRIX_ROW_SHIFTER << current_col);
} else {
// Pin HI, clear col bit
- current_matrix[row_index] &= ~(MATRIX_ROW_SHIFTER << current_col);
+ current_row_value &= ~(MATRIX_ROW_SHIFTER << current_col);
}
// Determine if the matrix changed state
- if ((last_row_value != current_matrix[row_index]) && !(matrix_changed)) {
- matrix_changed = true;
+ if ((last_row_value != current_row_value)) {
+ matrix_changed |= true;
+ current_matrix[row_index] = current_row_value;
}
}