aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboard/phantom/matrix.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/keyboard/phantom/matrix.c b/keyboard/phantom/matrix.c
index 7ea494a7e..7b2461dcc 100644
--- a/keyboard/phantom/matrix.c
+++ b/keyboard/phantom/matrix.c
@@ -24,10 +24,8 @@
24static uint8_t debouncing = DEBOUNCE; 24static uint8_t debouncing = DEBOUNCE;
25 25
26// bit array of key state(1:on, 0:off) 26// bit array of key state(1:on, 0:off)
27static matrix_row_t *matrix; 27static matrix_row_t matrix[MATRIX_ROWS];
28static matrix_row_t *matrix_debounced; 28static matrix_row_t matrix_debouncing[MATRIX_ROWS];
29static matrix_row_t matrix0[MATRIX_ROWS];
30static matrix_row_t matrix1[MATRIX_ROWS];
31 29
32 30
33#define _DDRA (uint8_t *const)&DDRA 31#define _DDRA (uint8_t *const)&DDRA
@@ -165,11 +163,9 @@ void matrix_init(void)
165 163
166 // initialize matrix state: all keys off 164 // initialize matrix state: all keys off
167 for (uint8_t i=0; i < MATRIX_ROWS; i++) { 165 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
168 matrix0[i] = 0; 166 matrix[i] = 0;
169 matrix1[i] = 0; 167 matrix_debouncing[i] = 0;
170 } 168 }
171 matrix = matrix0;
172 matrix_debounced = matrix1;
173} 169}
174 170
175uint8_t matrix_scan(void) 171uint8_t matrix_scan(void)
@@ -178,10 +174,10 @@ uint8_t matrix_scan(void)
178 pull_column(col); // output hi on theline 174 pull_column(col); // output hi on theline
179 _delay_us(3); // without this wait it won't read stable value. 175 _delay_us(3); // without this wait it won't read stable value.
180 for (uint8_t row = 0; row < MATRIX_ROWS; row++) { // 0-5 176 for (uint8_t row = 0; row < MATRIX_ROWS; row++) { // 0-5
181 bool prev_bit = matrix[row] & ((matrix_row_t)1<<col); 177 bool prev_bit = matrix_debouncing[row] & ((matrix_row_t)1<<col);
182 bool curr_bit = !(*row_pin[row] & row_bit[row]); 178 bool curr_bit = !(*row_pin[row] & row_bit[row]);
183 if (prev_bit != curr_bit) { 179 if (prev_bit != curr_bit) {
184 matrix[row] ^= ((matrix_row_t)1<<col); 180 matrix_debouncing[row] ^= ((matrix_row_t)1<<col);
185 if (debouncing) { 181 if (debouncing) {
186 debug("bounce!: "); debug_hex(debouncing); print("\n"); 182 debug("bounce!: "); debug_hex(debouncing); print("\n");
187 } 183 }
@@ -195,9 +191,9 @@ uint8_t matrix_scan(void)
195 if (--debouncing) { 191 if (--debouncing) {
196 _delay_ms(1); 192 _delay_ms(1);
197 } else { 193 } else {
198 matrix_row_t *tmp = matrix_debounced; 194 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
199 matrix_debounced = matrix; 195 matrix[i] = matrix_debouncing[i];
200 matrix = tmp; 196 }
201 } 197 }
202 } 198 }
203 199
@@ -213,13 +209,13 @@ bool matrix_is_modified(void)
213inline 209inline
214bool matrix_is_on(uint8_t row, uint8_t col) 210bool matrix_is_on(uint8_t row, uint8_t col)
215{ 211{
216 return (matrix_debounced[row] & ((matrix_row_t)1<<col)); 212 return (matrix[row] & ((matrix_row_t)1<<col));
217} 213}
218 214
219inline 215inline
220matrix_row_t matrix_get_row(uint8_t row) 216matrix_row_t matrix_get_row(uint8_t row)
221{ 217{
222 return matrix_debounced[row]; 218 return matrix[row];
223} 219}
224 220
225void matrix_print(void) 221void matrix_print(void)