aboutsummaryrefslogtreecommitdiff
path: root/keyboard/macway/matrix.c
diff options
context:
space:
mode:
authorErez Zukerman <ezuk@madmimi.com>2016-05-24 23:55:29 -0400
committerErez Zukerman <ezuk@madmimi.com>2016-05-24 23:55:29 -0400
commitd06e940a179b2e81563cf6123461cfcad35f9045 (patch)
tree58f4bbc22f51cba0c22a6a1ab09a499681f1f89e /keyboard/macway/matrix.c
parent8bc69afc633d3e199e3ac0a5bf39e4d255f2ce4a (diff)
downloadqmk_firmware-d06e940a179b2e81563cf6123461cfcad35f9045.tar.gz
qmk_firmware-d06e940a179b2e81563cf6123461cfcad35f9045.zip
[Erez & Jack] Removes keyboards which are not active on qmk
Diffstat (limited to 'keyboard/macway/matrix.c')
-rw-r--r--keyboard/macway/matrix.c217
1 files changed, 0 insertions, 217 deletions
diff --git a/keyboard/macway/matrix.c b/keyboard/macway/matrix.c
deleted file mode 100644
index 3d10b304d..000000000
--- a/keyboard/macway/matrix.c
+++ /dev/null
@@ -1,217 +0,0 @@
1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18/*
19 * scan matrix
20 */
21#include <stdint.h>
22#include <stdbool.h>
23#include <avr/io.h>
24#include <util/delay.h>
25#include "print.h"
26#include "debug.h"
27#include "util.h"
28#include "matrix.h"
29
30
31#ifndef DEBOUNCE
32# define DEBOUNCE 5
33#endif
34static uint8_t debouncing = DEBOUNCE;
35
36/* matrix state(1:on, 0:off) */
37static matrix_row_t matrix[MATRIX_ROWS];
38static matrix_row_t matrix_debouncing[MATRIX_ROWS];
39
40#ifdef MATRIX_HAS_GHOST
41static bool matrix_has_ghost_in_row(uint8_t row);
42#endif
43static matrix_row_t read_cols(void);
44static void unselect_rows(void);
45static void select_row(uint8_t row);
46
47
48inline
49uint8_t matrix_rows(void)
50{
51 return MATRIX_ROWS;
52}
53
54inline
55uint8_t matrix_cols(void)
56{
57 return MATRIX_COLS;
58}
59
60void matrix_init(void)
61{
62 // initialize row and col
63 unselect_rows();
64 // Input with pull-up(DDR:0, PORT:1)
65 DDRB = 0x00;
66 PORTB = 0xFF;
67
68 // initialize matrix state: all keys off
69 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
70 matrix[i] = 0;
71 matrix_debouncing[i] = 0;
72 }
73}
74
75uint8_t matrix_scan(void)
76{
77 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
78 select_row(i);
79 _delay_us(30); // without this wait read unstable value.
80 matrix_row_t cols = read_cols();
81 if (matrix_debouncing[i] != cols) {
82 matrix_debouncing[i] = cols;
83 if (debouncing) {
84 debug("bounce!: "); debug_hex(debouncing); debug("\n");
85 }
86 debouncing = DEBOUNCE;
87 }
88 unselect_rows();
89 }
90
91 if (debouncing) {
92 if (--debouncing) {
93 _delay_ms(1);
94 } else {
95 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
96 matrix[i] = matrix_debouncing[i];
97 }
98 }
99
100 }
101
102 return 1;
103}
104
105bool matrix_is_modified(void)
106{
107 if (debouncing) return false;
108 return true;
109}
110
111inline
112bool matrix_is_on(uint8_t row, uint8_t col)
113{
114 return (matrix[row] & ((matrix_row_t)1<<col));
115}
116
117inline
118matrix_row_t matrix_get_row(uint8_t row)
119{
120 return matrix[row];
121}
122
123void matrix_print(void)
124{
125 print("\nr/c 01234567\n");
126 for (uint8_t row = 0; row < matrix_rows(); row++) {
127 phex(row); print(": ");
128 pbin_reverse(matrix_get_row(row));
129#ifdef MATRIX_HAS_GHOST
130 if (matrix_has_ghost_in_row(row)) {
131 print(" <ghost");
132 }
133#endif
134 print("\n");
135 }
136}
137
138#ifdef MATRIX_HAS_GHOST
139inline
140static bool matrix_has_ghost_in_row(uint8_t row)
141{
142 // no ghost exists in case less than 2 keys on
143 if (((matrix[row] - 1) & matrix[row]) == 0)
144 return false;
145
146 // ghost exists in case same state as other row
147 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
148 if (i != row && (matrix[i] & matrix[row]))
149 return true;
150 }
151 return false;
152}
153#endif
154
155inline
156static matrix_row_t read_cols(void)
157{
158 return ~PINB;
159}
160
161inline
162static void unselect_rows(void)
163{
164 // Hi-Z(DDR:0, PORT:0) to unselect
165 DDRC &= ~0b01000000; // PC: 6
166 PORTC &= ~0b01000000;
167 DDRD &= ~0b11100111; // PD: 7,6,5,2,1,0
168 PORTD &= ~0b11100111;
169 DDRF &= ~0b11000000; // PF: 7,6
170 PORTF &= ~0b11000000;
171}
172
173inline
174static void select_row(uint8_t row)
175{
176 // Output low(DDR:1, PORT:0) to select
177 // row: 0 1 2 3 4 5 6 7 8
178 // pin: PD0, PD5, PD7, PF6, PD6, PD1, PD2, PC6, PF7
179 switch (row) {
180 case 0:
181 DDRD |= (1<<0);
182 PORTD &= ~(1<<0);
183 break;
184 case 1:
185 DDRD |= (1<<5);
186 PORTD &= ~(1<<5);
187 break;
188 case 2:
189 DDRD |= (1<<7);
190 PORTD &= ~(1<<7);
191 break;
192 case 3:
193 DDRF |= (1<<6);
194 PORTF &= ~(1<<6);
195 break;
196 case 4:
197 DDRD |= (1<<6);
198 PORTD &= ~(1<<6);
199 break;
200 case 5:
201 DDRD |= (1<<1);
202 PORTD &= ~(1<<1);
203 break;
204 case 6:
205 DDRD |= (1<<2);
206 PORTD &= ~(1<<2);
207 break;
208 case 7:
209 DDRC |= (1<<6);
210 PORTC &= ~(1<<6);
211 break;
212 case 8:
213 DDRF |= (1<<7);
214 PORTF &= ~(1<<7);
215 break;
216 }
217}