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.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/keyboards/sixkeyboard/matrix.c b/keyboards/sixkeyboard/matrix.c
index ed1b70e28..37cc68a21 100644
--- a/keyboards/sixkeyboard/matrix.c
+++ b/keyboards/sixkeyboard/matrix.c
@@ -37,6 +37,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
37 37
38/* matrix state(1:on, 0:off) */ 38/* matrix state(1:on, 0:off) */
39static matrix_row_t matrix[MATRIX_ROWS]; 39static matrix_row_t matrix[MATRIX_ROWS];
40static matrix_row_t matrix_stage[MATRIX_ROWS];
41static matrix_row_t matrix_debouncing[MATRIX_ROWS];
42
43static uint16_t debouncing_time;
44static bool debouncing = false;
40 45
41__attribute__ ((weak)) 46__attribute__ ((weak))
42void matrix_init_kb(void) { 47void matrix_init_kb(void) {
@@ -78,14 +83,35 @@ void matrix_init(void)
78 DDRD &= ~(1<<6 | 1<<4 | 1<<1); 83 DDRD &= ~(1<<6 | 1<<4 | 1<<1);
79 PORTD |= (1<<6 | 1<<4 | 1<<1); 84 PORTD |= (1<<6 | 1<<4 | 1<<1);
80 85
81 matrix_init_kb(); 86 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
87 matrix[i] = 0;
88 matrix_debouncing[i] = 0;
89 matrix_stage[i] = 0;
90 }
91
92 matrix_init_quantum();
82 93
83} 94}
84 95
85uint8_t matrix_scan(void) 96uint8_t matrix_scan(void)
86{ 97{
87 matrix[0] = (PINC&(1<<7) ? 0 : (1<<0)) | (PINB&(1<<7) ? 0 : (1<<1)) | (PINB&(1<<5) ? 0 : (1<<2)); 98 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)); 99 matrix_stage[1] = (PIND&(1<<6) ? 0 : (1<<0)) | (PIND&(1<<1) ? 0 : (1<<1)) | (PIND&(1<<4) ? 0 : (1<<2));
100
101 if (memcmp(matrix_debouncing, matrix_stage, sizeof(matrix)) != 0) {
102 debouncing = true;
103 debouncing_time = timer_read();
104 }
105
106 matrix_debouncing[0] = matrix_stage[0];
107 matrix_debouncing[1] = matrix_stage[1];
108
109 if (debouncing && (timer_elapsed(debouncing_time) > 20)) {
110 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
111 matrix[i] = matrix_debouncing[i];
112 }
113 debouncing = false;
114 }
89 115
90 matrix_scan_quantum(); 116 matrix_scan_quantum();
91 117
@@ -111,12 +137,6 @@ matrix_row_t matrix_get_row(uint8_t row)
111 137
112void matrix_print(void) 138void matrix_print(void)
113{ 139{
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} 140}
121 141
122uint8_t matrix_key_count(void) 142uint8_t matrix_key_count(void)