diff options
Diffstat (limited to 'tmk_core/common/matrix.h')
-rw-r--r-- | tmk_core/common/matrix.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tmk_core/common/matrix.h b/tmk_core/common/matrix.h new file mode 100644 index 000000000..107ee7265 --- /dev/null +++ b/tmk_core/common/matrix.h | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | Copyright 2011 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 | |||
18 | #ifndef MATRIX_H | ||
19 | #define MATRIX_H | ||
20 | |||
21 | #include <stdint.h> | ||
22 | #include <stdbool.h> | ||
23 | |||
24 | |||
25 | #if (MATRIX_COLS <= 8) | ||
26 | typedef uint8_t matrix_row_t; | ||
27 | #elif (MATRIX_COLS <= 16) | ||
28 | typedef uint16_t matrix_row_t; | ||
29 | #elif (MATRIX_COLS <= 32) | ||
30 | typedef uint32_t matrix_row_t; | ||
31 | #else | ||
32 | #error "MATRIX_COLS: invalid value" | ||
33 | #endif | ||
34 | |||
35 | #define MATRIX_IS_ON(row, col) (matrix_get_row(row) && (1<<col)) | ||
36 | |||
37 | |||
38 | #ifdef __cplusplus | ||
39 | extern "C" { | ||
40 | #endif | ||
41 | |||
42 | /* number of matrix rows */ | ||
43 | uint8_t matrix_rows(void); | ||
44 | /* number of matrix columns */ | ||
45 | uint8_t matrix_cols(void); | ||
46 | /* intialize matrix for scaning. should be called once. */ | ||
47 | void matrix_init(void); | ||
48 | /* scan all key states on matrix */ | ||
49 | uint8_t matrix_scan(void); | ||
50 | /* whether modified from previous scan. used after matrix_scan. */ | ||
51 | bool matrix_is_modified(void) __attribute__ ((deprecated)); | ||
52 | /* whether a swtich is on */ | ||
53 | bool matrix_is_on(uint8_t row, uint8_t col); | ||
54 | /* matrix state on row */ | ||
55 | matrix_row_t matrix_get_row(uint8_t row); | ||
56 | /* print matrix for debug */ | ||
57 | void matrix_print(void); | ||
58 | |||
59 | |||
60 | /* power control */ | ||
61 | void matrix_power_up(void); | ||
62 | void matrix_power_down(void); | ||
63 | |||
64 | #ifdef __cplusplus | ||
65 | } | ||
66 | #endif | ||
67 | |||
68 | #endif | ||