aboutsummaryrefslogtreecommitdiff
path: root/quantum/matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/matrix.c')
-rw-r--r--quantum/matrix.c79
1 files changed, 3 insertions, 76 deletions
diff --git a/quantum/matrix.c b/quantum/matrix.c
index 9b5ce33d2..292171490 100644
--- a/quantum/matrix.c
+++ b/quantum/matrix.c
@@ -25,17 +25,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
25#include "quantum.h" 25#include "quantum.h"
26 26
27 27
28/* Set 0 if debouncing isn't needed */
29
30#ifndef DEBOUNCING_DELAY
31# define DEBOUNCING_DELAY 5
32#endif
33
34#if (DEBOUNCING_DELAY > 0)
35 static uint16_t debouncing_time;
36 static bool debouncing = false;
37#endif
38
39#if (MATRIX_COLS <= 8) 28#if (MATRIX_COLS <= 8)
40# define print_matrix_header() print("\nr/c 01234567\n") 29# define print_matrix_header() print("\nr/c 01234567\n")
41# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row)) 30# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
@@ -65,8 +54,6 @@ static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
65/* matrix state(1:on, 0:off) */ 54/* matrix state(1:on, 0:off) */
66static matrix_row_t matrix[MATRIX_ROWS]; 55static matrix_row_t matrix[MATRIX_ROWS];
67 56
68static matrix_row_t matrix_debouncing[MATRIX_ROWS];
69
70 57
71#if (DIODE_DIRECTION == COL2ROW) 58#if (DIODE_DIRECTION == COL2ROW)
72 static void init_cols(void); 59 static void init_cols(void);
@@ -120,30 +107,6 @@ uint8_t matrix_cols(void) {
120 return MATRIX_COLS; 107 return MATRIX_COLS;
121} 108}
122 109
123// void matrix_power_up(void) {
124// #if (DIODE_DIRECTION == COL2ROW)
125// for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
126// /* DDRxn */
127// _SFR_IO8((row_pins[r] >> 4) + 1) |= _BV(row_pins[r] & 0xF);
128// toggle_row(r);
129// }
130// for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
131// /* PORTxn */
132// _SFR_IO8((col_pins[c] >> 4) + 2) |= _BV(col_pins[c] & 0xF);
133// }
134// #elif (DIODE_DIRECTION == ROW2COL)
135// for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
136// /* DDRxn */
137// _SFR_IO8((col_pins[c] >> 4) + 1) |= _BV(col_pins[c] & 0xF);
138// toggle_col(c);
139// }
140// for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
141// /* PORTxn */
142// _SFR_IO8((row_pins[r] >> 4) + 2) |= _BV(row_pins[r] & 0xF);
143// }
144// #endif
145// }
146
147void matrix_init(void) { 110void matrix_init(void) {
148 111
149 // initialize row and col 112 // initialize row and col
@@ -158,7 +121,6 @@ void matrix_init(void) {
158 // initialize matrix state: all keys off 121 // initialize matrix state: all keys off
159 for (uint8_t i=0; i < MATRIX_ROWS; i++) { 122 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
160 matrix[i] = 0; 123 matrix[i] = 0;
161 matrix_debouncing[i] = 0;
162 } 124 }
163 125
164 matrix_init_quantum(); 126 matrix_init_quantum();
@@ -168,59 +130,24 @@ uint8_t matrix_scan(void)
168{ 130{
169 131
170#if (DIODE_DIRECTION == COL2ROW) 132#if (DIODE_DIRECTION == COL2ROW)
171
172 // Set row, read cols 133 // Set row, read cols
173 for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { 134 for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
174# if (DEBOUNCING_DELAY > 0) 135 read_cols_on_row(matrix, current_row);
175 bool matrix_changed = read_cols_on_row(matrix_debouncing, current_row);
176
177 if (matrix_changed) {
178 debouncing = true;
179 debouncing_time = timer_read();
180 }
181
182# else
183 read_cols_on_row(matrix, current_row);
184# endif
185
186 } 136 }
187
188#elif (DIODE_DIRECTION == ROW2COL) 137#elif (DIODE_DIRECTION == ROW2COL)
189
190 // Set col, read rows 138 // Set col, read rows
191 for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { 139 for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
192# if (DEBOUNCING_DELAY > 0) 140 read_rows_on_col(matrix, current_col);
193 bool matrix_changed = read_rows_on_col(matrix_debouncing, current_col);
194 if (matrix_changed) {
195 debouncing = true;
196 debouncing_time = timer_read();
197 }
198# else
199 read_rows_on_col(matrix, current_col);
200# endif
201
202 } 141 }
203
204#endif 142#endif
205 143
206# if (DEBOUNCING_DELAY > 0)
207 if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) {
208 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
209 matrix[i] = matrix_debouncing[i];
210 }
211 debouncing = false;
212 }
213# endif
214
215 matrix_scan_quantum(); 144 matrix_scan_quantum();
216 return 1; 145 return 1;
217} 146}
218 147
148//Deprecated.
219bool matrix_is_modified(void) 149bool matrix_is_modified(void)
220{ 150{
221#if (DEBOUNCING_DELAY > 0)
222 if (debouncing) return false;
223#endif
224 return true; 151 return true;
225} 152}
226 153