]> git.gir.st - tmk_keyboard.git/blob - tmk_core/common/matrix.c
Merge branch 'matrix-fix'
[tmk_keyboard.git] / tmk_core / common / matrix.c
1 /*
2 Copyright 2016 Jun Wako <wakojun@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "print.h"
18 #include "matrix.h"
19
20
21 __attribute__ ((weak))
22 uint8_t matrix_rows(void)
23 {
24 return MATRIX_ROWS;
25 }
26
27 __attribute__ ((weak))
28 uint8_t matrix_cols(void)
29 {
30 return MATRIX_COLS;
31 }
32
33 __attribute__ ((weak))
34 void matrix_clear(void)
35 {
36 }
37
38 __attribute__ ((weak))
39 void matrix_setup(void) {}
40
41 __attribute__ ((weak))
42 bool matrix_is_on(uint8_t row, uint8_t col)
43 {
44 return (matrix_get_row(row) & (1<<col));
45 }
46
47 __attribute__ ((weak))
48 void matrix_print(void)
49 {
50 #if (MATRIX_COLS <= 8)
51 print("r/c 01234567\n");
52 #elif (MATRIX_COLS <= 16)
53 print("r/c 0123456789ABCDEF\n");
54 #elif (MATRIX_COLS <= 32)
55 print("r/c 0123456789ABCDEF0123456789ABCDEF\n");
56 #endif
57
58 for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
59
60 #if (MATRIX_COLS <= 8)
61 xprintf("%02X: %08b%s\n", row, bitrev(matrix_get_row(row)),
62 #elif (MATRIX_COLS <= 16)
63 xprintf("%02X: %016b%s\n", row, bitrev16(matrix_get_row(row)),
64 #elif (MATRIX_COLS <= 32)
65 xprintf("%02X: %032b%s\n", row, bitrev32(matrix_get_row(row)),
66 #endif
67 #ifdef MATRIX_HAS_GHOST
68 matrix_has_ghost_in_row(row) ? " <ghost" : ""
69 #else
70 ""
71 #endif
72 );
73 }
74 }
75
76 #ifdef MATRIX_HAS_GHOST
77 __attribute__ ((weak))
78 bool matrix_has_ghost_in_row(uint8_t row)
79 {
80 matrix_row_t matrix_row = matrix_get_row(row);
81 // No ghost exists when less than 2 keys are down on the row
82 if (((matrix_row - 1) & matrix_row) == 0)
83 return false;
84
85 // Ghost occurs when the row shares column line with other row
86 for (uint8_t i=0; i < MATRIX_ROWS; i++) {
87 if (i != row && (matrix_get_row(i) & matrix_row))
88 return true;
89 }
90 return false;
91 }
92 #endif
93
94 __attribute__ ((weak)) void matrix_power_up(void) {}
95 __attribute__ ((weak)) void matrix_power_down(void) {}
Imprint / Impressum