diff options
author | Joel Challis <git@zvecr.com> | 2020-05-21 17:59:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-21 17:59:56 +0100 |
commit | 205321c37740caaffbca69e626a8432fd369d20c (patch) | |
tree | e0efcd82de1bd537368be7501684529e71a73dec /quantum/split_common/matrix.c | |
parent | 1816ad01d0efcc987b5aa7a833331b0f9d903d4f (diff) | |
download | qmk_firmware-205321c37740caaffbca69e626a8432fd369d20c.tar.gz qmk_firmware-205321c37740caaffbca69e626a8432fd369d20c.zip |
Slight speed increases for matrix scanning (#9150)
Diffstat (limited to 'quantum/split_common/matrix.c')
-rw-r--r-- | quantum/split_common/matrix.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/quantum/split_common/matrix.c b/quantum/split_common/matrix.c index 8b91f8ca8..27c37d4b0 100644 --- a/quantum/split_common/matrix.c +++ b/quantum/split_common/matrix.c | |||
@@ -65,17 +65,22 @@ static void init_pins(void) { | |||
65 | } | 65 | } |
66 | 66 | ||
67 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { | 67 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { |
68 | matrix_row_t last_row_value = current_matrix[current_row]; | 68 | // Start with a clear matrix row |
69 | current_matrix[current_row] = 0; | 69 | matrix_row_t current_row_value = 0; |
70 | 70 | ||
71 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { | 71 | for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) { |
72 | pin_t pin = direct_pins[current_row][col_index]; | 72 | pin_t pin = direct_pins[current_row][col_index]; |
73 | if (pin != NO_PIN) { | 73 | if (pin != NO_PIN) { |
74 | current_matrix[current_row] |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index); | 74 | current_row_value |= readPin(pin) ? 0 : (MATRIX_ROW_SHIFTER << col_index); |
75 | } | 75 | } |
76 | } | 76 | } |
77 | 77 | ||
78 | return (last_row_value != current_matrix[current_row]); | 78 | // If the row has changed, store the row and return the changed flag. |
79 | if (current_matrix[current_row] != current_row_value) { | ||
80 | current_matrix[current_row] = current_row_value; | ||
81 | return true; | ||
82 | } | ||
83 | return false; | ||
79 | } | 84 | } |
80 | 85 | ||
81 | #elif defined(DIODE_DIRECTION) | 86 | #elif defined(DIODE_DIRECTION) |
@@ -101,12 +106,9 @@ static void init_pins(void) { | |||
101 | } | 106 | } |
102 | } | 107 | } |
103 | 108 | ||
104 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { | 109 | static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { |
105 | // Store last value of row prior to reading | 110 | // Start with a clear matrix row |
106 | matrix_row_t last_row_value = current_matrix[current_row]; | 111 | matrix_row_t current_row_value = 0; |
107 | |||
108 | // Clear data in matrix row | ||
109 | current_matrix[current_row] = 0; | ||
110 | 112 | ||
111 | // Select row and wait for row selecton to stabilize | 113 | // Select row and wait for row selecton to stabilize |
112 | select_row(current_row); | 114 | select_row(current_row); |
@@ -118,13 +120,18 @@ static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
118 | uint8_t pin_state = readPin(col_pins[col_index]); | 120 | uint8_t pin_state = readPin(col_pins[col_index]); |
119 | 121 | ||
120 | // Populate the matrix row with the state of the col pin | 122 | // Populate the matrix row with the state of the col pin |
121 | current_matrix[current_row] |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); | 123 | current_row_value |= pin_state ? 0 : (MATRIX_ROW_SHIFTER << col_index); |
122 | } | 124 | } |
123 | 125 | ||
124 | // Unselect row | 126 | // Unselect row |
125 | unselect_row(current_row); | 127 | unselect_row(current_row); |
126 | 128 | ||
127 | return (last_row_value != current_matrix[current_row]); | 129 | // If the row has changed, store the row and return the changed flag. |
130 | if (current_matrix[current_row] != current_row_value) { | ||
131 | current_matrix[current_row] = current_row_value; | ||
132 | return true; | ||
133 | } | ||
134 | return false; | ||
128 | } | 135 | } |
129 | 136 | ||
130 | # elif (DIODE_DIRECTION == ROW2COL) | 137 | # elif (DIODE_DIRECTION == ROW2COL) |
@@ -160,19 +167,21 @@ static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col) | |||
160 | for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) { | 167 | for (uint8_t row_index = 0; row_index < ROWS_PER_HAND; row_index++) { |
161 | // Store last value of row prior to reading | 168 | // Store last value of row prior to reading |
162 | matrix_row_t last_row_value = current_matrix[row_index]; | 169 | matrix_row_t last_row_value = current_matrix[row_index]; |
170 | matrix_row_t current_row_value = last_row_value; | ||
163 | 171 | ||
164 | // Check row pin state | 172 | // Check row pin state |
165 | if (readPin(row_pins[row_index]) == 0) { | 173 | if (readPin(row_pins[row_index]) == 0) { |
166 | // Pin LO, set col bit | 174 | // Pin LO, set col bit |
167 | current_matrix[row_index] |= (MATRIX_ROW_SHIFTER << current_col); | 175 | current_row_value |= (MATRIX_ROW_SHIFTER << current_col); |
168 | } else { | 176 | } else { |
169 | // Pin HI, clear col bit | 177 | // Pin HI, clear col bit |
170 | current_matrix[row_index] &= ~(MATRIX_ROW_SHIFTER << current_col); | 178 | current_row_value &= ~(MATRIX_ROW_SHIFTER << current_col); |
171 | } | 179 | } |
172 | 180 | ||
173 | // Determine if the matrix changed state | 181 | // Determine if the matrix changed state |
174 | if ((last_row_value != current_matrix[row_index]) && !(matrix_changed)) { | 182 | if ((last_row_value != current_row_value)) { |
175 | matrix_changed = true; | 183 | matrix_changed |= true; |
184 | current_matrix[row_index] = current_row_value; | ||
176 | } | 185 | } |
177 | } | 186 | } |
178 | 187 | ||