aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboards/ergodox_ez/matrix.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/keyboards/ergodox_ez/matrix.c b/keyboards/ergodox_ez/matrix.c
index 97f764113..6f604ae2b 100644
--- a/keyboards/ergodox_ez/matrix.c
+++ b/keyboards/ergodox_ez/matrix.c
@@ -123,6 +123,17 @@ void matrix_power_up(void) {
123#endif 123#endif
124} 124}
125 125
126// Reads and stores a row, returning
127// whether a change occurred.
128static inline bool store_raw_matrix_row(uint8_t index) {
129 matrix_row_t temp = read_cols(index);
130 if (raw_matrix[index] != temp) {
131 raw_matrix[index] = temp;
132 return true;
133 }
134 return false;
135}
136
126uint8_t matrix_scan(void) { 137uint8_t matrix_scan(void) {
127 if (mcp23018_status) { // if there was an error 138 if (mcp23018_status) { // if there was an error
128 if (++mcp23018_reset_loop == 0) { 139 if (++mcp23018_reset_loop == 0) {
@@ -157,22 +168,24 @@ uint8_t matrix_scan(void) {
157#ifdef LEFT_LEDS 168#ifdef LEFT_LEDS
158 mcp23018_status = ergodox_left_leds_update(); 169 mcp23018_status = ergodox_left_leds_update();
159#endif // LEFT_LEDS 170#endif // LEFT_LEDS
171 bool changed = false;
160 for (uint8_t i = 0; i < MATRIX_ROWS_PER_SIDE; i++) { 172 for (uint8_t i = 0; i < MATRIX_ROWS_PER_SIDE; i++) {
161 // select rows from left and right hands 173 // select rows from left and right hands
162 select_row(i); 174 uint8_t left_index = i;
163 select_row(i + MATRIX_ROWS_PER_SIDE); 175 uint8_t right_index = i + MATRIX_ROWS_PER_SIDE;
176 select_row(left_index);
177 select_row(right_index);
164 178
165 // we don't need a 30us delay anymore, because selecting a 179 // we don't need a 30us delay anymore, because selecting a
166 // left-hand row requires more than 30us for i2c. 180 // left-hand row requires more than 30us for i2c.
167
168 // grab left + right cols.
169 raw_matrix[i] = read_cols(i);
170 raw_matrix[i+MATRIX_ROWS_PER_SIDE] = read_cols(i+MATRIX_ROWS_PER_SIDE);
171 181
182 changed |= store_raw_matrix_row(left_index);
183 changed |= store_raw_matrix_row(right_index);
184
172 unselect_rows(); 185 unselect_rows();
173 } 186 }
174 187
175 debounce(raw_matrix, matrix, MATRIX_ROWS, true); 188 debounce(raw_matrix, matrix, MATRIX_ROWS, changed);
176 matrix_scan_quantum(); 189 matrix_scan_quantum();
177 190
178 return 1; 191 return 1;