aboutsummaryrefslogtreecommitdiff
path: root/keyboard
diff options
context:
space:
mode:
Diffstat (limited to 'keyboard')
-rw-r--r--keyboard/hhkb/config.h2
-rw-r--r--keyboard/hhkb/keymap.c8
-rw-r--r--keyboard/hhkb/matrix.c50
3 files changed, 10 insertions, 50 deletions
diff --git a/keyboard/hhkb/config.h b/keyboard/hhkb/config.h
index bf946ac01..17a449406 100644
--- a/keyboard/hhkb/config.h
+++ b/keyboard/hhkb/config.h
@@ -35,8 +35,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
35/* matrix size */ 35/* matrix size */
36#define MATRIX_ROWS 8 36#define MATRIX_ROWS 8
37#define MATRIX_COLS 8 37#define MATRIX_COLS 8
38/* define if matrix has ghost */
39//#define MATRIX_HAS_GHOST
40 38
41 39
42/* key combination for command */ 40/* key combination for command */
diff --git a/keyboard/hhkb/keymap.c b/keyboard/hhkb/keymap.c
index f05962aed..43f777c56 100644
--- a/keyboard/hhkb/keymap.c
+++ b/keyboard/hhkb/keymap.c
@@ -210,12 +210,12 @@ uint8_t keymap_get_keycode(uint8_t layer, uint8_t row, uint8_t col)
210 return KEYCODE(layer, row, col); 210 return KEYCODE(layer, row, col);
211} 211}
212 212
213uint8_t keymap_fn_layer(uint8_t fn_bits) 213uint8_t keymap_fn_layer(uint8_t index)
214{ 214{
215 return pgm_read_byte(&fn_layer[biton(fn_bits)]); 215 return pgm_read_byte(&fn_layer[index]);
216} 216}
217 217
218uint8_t keymap_fn_keycode(uint8_t fn_bits) 218uint8_t keymap_fn_keycode(uint8_t index)
219{ 219{
220 return pgm_read_byte(&fn_keycode[(biton(fn_bits))]); 220 return pgm_read_byte(&fn_keycode[index]);
221} 221}
diff --git a/keyboard/hhkb/matrix.c b/keyboard/hhkb/matrix.c
index 79d2d9873..3bd6e73b3 100644
--- a/keyboard/hhkb/matrix.c
+++ b/keyboard/hhkb/matrix.c
@@ -43,22 +43,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
43 43
44 44
45// matrix state buffer(1:on, 0:off) 45// matrix state buffer(1:on, 0:off)
46#if (MATRIX_COLS <= 8) 46static matrix_row_t *matrix;
47static uint8_t *matrix; 47static matrix_row_t *matrix_prev;
48static uint8_t *matrix_prev; 48static matrix_row_t _matrix0[MATRIX_ROWS];
49static uint8_t _matrix0[MATRIX_ROWS]; 49static matrix_row_t _matrix1[MATRIX_ROWS];
50static uint8_t _matrix1[MATRIX_ROWS];
51#else
52static uint16_t *matrix;
53static uint16_t *matrix_prev;
54static uint16_t _matrix0[MATRIX_ROWS];
55static uint16_t _matrix1[MATRIX_ROWS];
56#endif
57
58// HHKB has no ghost and no bounce.
59#ifdef MATRIX_HAS_GHOST
60static bool matrix_has_ghost_in_row(uint8_t row);
61#endif
62 50
63 51
64// Matrix I/O ports 52// Matrix I/O ports
@@ -192,6 +180,8 @@ uint8_t matrix_scan(void)
192 } 180 }
193 181
194 // Ignore if this code region execution time elapses more than 20us. 182 // Ignore if this code region execution time elapses more than 20us.
183 // MEMO: 20[us] * (TIMER_RAW_FREQ / 1000000)[count per us]
184 // MEMO: then change above using this rule: a/(b/c) = a*1/(b/c) = a*(c/b)
195 if (TIMER_DIFF_RAW(TIMER_RAW, last) > 20/(1000000/TIMER_RAW_FREQ)) { 185 if (TIMER_DIFF_RAW(TIMER_RAW, last) > 20/(1000000/TIMER_RAW_FREQ)) {
196 matrix[row] = matrix_prev[row]; 186 matrix[row] = matrix_prev[row];
197 } 187 }
@@ -219,12 +209,6 @@ bool matrix_is_modified(void)
219inline 209inline
220bool matrix_has_ghost(void) 210bool matrix_has_ghost(void)
221{ 211{
222#ifdef MATRIX_HAS_GHOST
223 for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
224 if (matrix_has_ghost_in_row(i))
225 return true;
226 }
227#endif
228 return false; 212 return false;
229} 213}
230 214
@@ -258,11 +242,6 @@ void matrix_print(void)
258#else 242#else
259 pbin_reverse16(matrix_get_row(row)); 243 pbin_reverse16(matrix_get_row(row));
260#endif 244#endif
261#ifdef MATRIX_HAS_GHOST
262 if (matrix_has_ghost_in_row(row)) {
263 print(" <ghost");
264 }
265#endif
266 print("\n"); 245 print("\n");
267 } 246 }
268} 247}
@@ -279,20 +258,3 @@ uint8_t matrix_key_count(void)
279 } 258 }
280 return count; 259 return count;
281} 260}
282
283#ifdef MATRIX_HAS_GHOST
284inline
285static bool matrix_has_ghost_in_row(uint8_t row)
286{
287 // no ghost exists in case less than 2 keys on
288 if (((matrix[row] - 1) & matrix[row]) == 0)
289 return false;
290
291 // ghost exists in case same state as other row
292 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
293 if (i != row && (matrix[i] & matrix[row]) == matrix[row])
294 return true;
295 }
296 return false;
297}
298#endif