aboutsummaryrefslogtreecommitdiff
path: root/keyboard/planck/matrix_steno.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboard/planck/matrix_steno.c')
-rw-r--r--keyboard/planck/matrix_steno.c234
1 files changed, 0 insertions, 234 deletions
diff --git a/keyboard/planck/matrix_steno.c b/keyboard/planck/matrix_steno.c
deleted file mode 100644
index 98ef55ed6..000000000
--- a/keyboard/planck/matrix_steno.c
+++ /dev/null
@@ -1,234 +0,0 @@
1/*
2Copyright 2012 Jun Wako
3Generated by planckkeyboard.com (2014 Jack Humbert)
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 2 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/*
20 * scan matrix
21 */
22#include <stdint.h>
23#include <stdbool.h>
24#include <avr/io.h>
25#include <util/delay.h>
26#include "print.h"
27#include "debug.h"
28#include "util.h"
29#include "matrix.h"
30
31#ifndef DEBOUNCE
32# define DEBOUNCE 10
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
40static matrix_row_t read_cols(void);
41static void init_cols(void);
42static void unselect_rows(void);
43static void select_row(uint8_t row);
44
45inline
46uint8_t matrix_rows(void)
47{
48 return MATRIX_ROWS;
49}
50
51inline
52uint8_t matrix_cols(void)
53{
54 return MATRIX_COLS;
55}
56
57void matrix_init(void)
58{
59 // To use PORTF disable JTAG with writing JTD bit twice within four cycles.
60 MCUCR |= (1<<JTD);
61 MCUCR |= (1<<JTD);
62
63 backlight_init_ports();
64
65 // Turn status LED on
66 DDRE |= (1<<6);
67 PORTE |= (1<<6);
68
69 // initialize row and col
70 unselect_rows();
71 init_cols();
72
73 // initialize matrix state: all keys off
74 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
75 matrix[i] = 0;
76 matrix_debouncing[i] = 0;
77 }
78}
79
80
81uint8_t matrix_scan(void)
82{
83 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
84 select_row(i);
85 _delay_us(30); // without this wait read unstable value.
86 matrix_row_t cols = read_cols();
87 if (matrix_debouncing[i] != cols) {
88 matrix_debouncing[i] = cols;
89 if (debouncing) {
90 debug("bounce!: "); debug_hex(debouncing); debug("\n");
91 }
92 debouncing = DEBOUNCE;
93 }
94 unselect_rows();
95 }
96
97 if (debouncing) {
98 if (--debouncing) {
99 _delay_ms(1);
100 } else {
101 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
102 matrix[i] = matrix_debouncing[i];
103 }
104 }
105 }
106
107 return 1;
108}
109
110bool matrix_is_modified(void)
111{
112 if (debouncing) return false;
113 return true;
114}
115
116inline
117bool matrix_is_on(uint8_t row, uint8_t col)
118{
119 return (matrix[row] & ((matrix_row_t)1<col));
120}
121
122inline
123matrix_row_t matrix_get_row(uint8_t row)
124{
125 return matrix[row];
126}
127
128void matrix_print(void)
129{
130 print("\nr/c 0123456789ABCDEF\n");
131 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
132 phex(row); print(": ");
133 pbin_reverse16(matrix_get_row(row));
134 print("\n");
135 }
136}
137
138uint8_t matrix_key_count(void)
139{
140 uint8_t count = 0;
141 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
142 count += bitpop16(matrix[i]);
143 }
144 return count;
145}
146
147static void init_cols(void)
148{
149 int B = 0, C = 0, D = 0, E = 0, F = 0;
150 for(int x = 0; x < MATRIX_COLS; x++) {
151 int col = COLS[x];
152 if ((col & 0xF0) == 0x20) {
153 B |= (1<<(col & 0x0F));
154 } else if ((col & 0xF0) == 0x30) {
155 C |= (1<<(col & 0x0F));
156 } else if ((col & 0xF0) == 0x40) {
157 D |= (1<<(col & 0x0F));
158 } else if ((col & 0xF0) == 0x50) {
159 E |= (1<<(col & 0x0F));
160 } else if ((col & 0xF0) == 0x60) {
161 F |= (1<<(col & 0x0F));
162 }
163 }
164 DDRB &= ~(B); PORTB |= (B);
165 DDRC &= ~(C); PORTC |= (C);
166 DDRD &= ~(D); PORTD |= (D);
167 DDRE &= ~(E); PORTE |= (E);
168 DDRF &= ~(F); PORTF |= (F);
169}
170
171static matrix_row_t read_cols(void)
172{
173 matrix_row_t result = 0;
174 for(int x = 0; x < MATRIX_COLS; x++) {
175 int col = COLS[x];
176 if ((col & 0xF0) == 0x20) {
177 result |= (PINB&(1<<(col & 0x0F)) ? 0 : (1<<x));
178 } else if ((col & 0xF0) == 0x30) {
179 result |= (PINC&(1<<(col & 0x0F)) ? 0 : (1<<x));
180 } else if ((col & 0xF0) == 0x40) {
181 result |= (PIND&(1<<(col & 0x0F)) ? 0 : (1<<x));
182 } else if ((col & 0xF0) == 0x50) {
183 result |= (PINE&(1<<(col & 0x0F)) ? 0 : (1<<x));
184 } else if ((col & 0xF0) == 0x60) {
185 result |= (PINF&(1<<(col & 0x0F)) ? 0 : (1<<x));
186 }
187 }
188 return result;
189}
190
191static void unselect_rows(void)
192{
193 int B = 0, C = 0, D = 0, E = 0, F = 0;
194 for(int x = 0; x < MATRIX_ROWS; x++) {
195 int row = ROWS[x];
196 if ((row & 0xF0) == 0x20) {
197 B |= (1<<(row & 0x0F));
198 } else if ((row & 0xF0) == 0x30) {
199 C |= (1<<(row & 0x0F));
200 } else if ((row & 0xF0) == 0x40) {
201 D |= (1<<(row & 0x0F));
202 } else if ((row & 0xF0) == 0x50) {
203 E |= (1<<(row & 0x0F));
204 } else if ((row & 0xF0) == 0x60) {
205 F |= (1<<(row & 0x0F));
206 }
207 }
208 DDRB &= ~(B); PORTB |= (B);
209 DDRC &= ~(C); PORTC |= (C);
210 DDRD &= ~(D); PORTD |= (D);
211 DDRE &= ~(E); PORTE |= (E);
212 DDRF &= ~(F); PORTF |= (F);
213}
214
215static void select_row(uint8_t row)
216{
217 int row_pin = ROWS[row];
218 if ((row_pin & 0xF0) == 0x20) {
219 DDRB |= (1<<(row_pin & 0x0F));
220 PORTB &= ~(1<<(row_pin & 0x0F));
221 } else if ((row_pin & 0xF0) == 0x30) {
222 DDRC |= (1<<(row_pin & 0x0F));
223 PORTC &= ~(1<<(row_pin & 0x0F));
224 } else if ((row_pin & 0xF0) == 0x40) {
225 DDRD |= (1<<(row_pin & 0x0F));
226 PORTD &= ~(1<<(row_pin & 0x0F));
227 } else if ((row_pin & 0xF0) == 0x50) {
228 DDRE |= (1<<(row_pin & 0x0F));
229 PORTE &= ~(1<<(row_pin & 0x0F));
230 } else if ((row_pin & 0xF0) == 0x60) {
231 DDRF |= (1<<(row_pin & 0x0F));
232 PORTF &= ~(1<<(row_pin & 0x0F));
233 }
234} \ No newline at end of file