aboutsummaryrefslogtreecommitdiff
path: root/keyboards/sixkeyboard/matrix.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/sixkeyboard/matrix.c')
-rw-r--r--keyboards/sixkeyboard/matrix.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/keyboards/sixkeyboard/matrix.c b/keyboards/sixkeyboard/matrix.c
index ed1b70e28..860452ebd 100644
--- a/keyboards/sixkeyboard/matrix.c
+++ b/keyboards/sixkeyboard/matrix.c
@@ -34,9 +34,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
34#include "util.h" 34#include "util.h"
35#include "matrix.h" 35#include "matrix.h"
36#include "sixkeyboard.h" 36#include "sixkeyboard.h"
37#include <string.h>
37 38
38/* matrix state(1:on, 0:off) */ 39/* matrix state(1:on, 0:off) */
39static matrix_row_t matrix[MATRIX_ROWS]; 40static matrix_row_t matrix[MATRIX_ROWS];
41static matrix_row_t matrix_stage[MATRIX_ROWS];
42static matrix_row_t matrix_debouncing[MATRIX_ROWS];
43
44static uint16_t debouncing_time;
45static bool debouncing = false;
40 46
41__attribute__ ((weak)) 47__attribute__ ((weak))
42void matrix_init_kb(void) { 48void matrix_init_kb(void) {
@@ -78,14 +84,35 @@ void matrix_init(void)
78 DDRD &= ~(1<<6 | 1<<4 | 1<<1); 84 DDRD &= ~(1<<6 | 1<<4 | 1<<1);
79 PORTD |= (1<<6 | 1<<4 | 1<<1); 85 PORTD |= (1<<6 | 1<<4 | 1<<1);
80 86
81 matrix_init_kb(); 87 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
88 matrix[i] = 0;
89 matrix_debouncing[i] = 0;
90 matrix_stage[i] = 0;
91 }
92
93 matrix_init_quantum();
82 94
83} 95}
84 96
85uint8_t matrix_scan(void) 97uint8_t matrix_scan(void)
86{ 98{
87 matrix[0] = (PINC&(1<<7) ? 0 : (1<<0)) | (PINB&(1<<7) ? 0 : (1<<1)) | (PINB&(1<<5) ? 0 : (1<<2)); 99 matrix_stage[0] = (PINC&(1<<7) ? 0 : (1<<0)) | (PINB&(1<<7) ? 0 : (1<<1)) | (PINB&(1<<5) ? 0 : (1<<2));
88 matrix[1] = (PIND&(1<<6) ? 0 : (1<<0)) | (PIND&(1<<1) ? 0 : (1<<1)) | (PIND&(1<<4) ? 0 : (1<<2)); 100 matrix_stage[1] = (PIND&(1<<6) ? 0 : (1<<0)) | (PIND&(1<<1) ? 0 : (1<<1)) | (PIND&(1<<4) ? 0 : (1<<2));
101
102 if (memcmp(matrix_debouncing, matrix_stage, sizeof(matrix)) != 0) {
103 debouncing = true;
104 debouncing_time = timer_read();
105 }
106
107 matrix_debouncing[0] = matrix_stage[0];
108 matrix_debouncing[1] = matrix_stage[1];
109
110 if (debouncing && (timer_elapsed(debouncing_time) > 20)) {
111 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
112 matrix[i] = matrix_debouncing[i];
113 }
114 debouncing = false;
115 }
89 116
90 matrix_scan_quantum(); 117 matrix_scan_quantum();
91 118
@@ -111,12 +138,6 @@ matrix_row_t matrix_get_row(uint8_t row)
111 138
112void matrix_print(void) 139void matrix_print(void)
113{ 140{
114 print("\nr/c 0123456789ABCDEF\n");
115 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
116 phex(row); print(": ");
117 pbin_reverse16(matrix_get_row(row));
118 print("\n");
119 }
120} 141}
121 142
122uint8_t matrix_key_count(void) 143uint8_t matrix_key_count(void)