aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common/matrix.h
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common/matrix.h')
-rw-r--r--tmk_core/common/matrix.h68
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/*
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#ifndef MATRIX_H
19#define MATRIX_H
20
21#include <stdint.h>
22#include <stdbool.h>
23
24
25#if (MATRIX_COLS <= 8)
26typedef uint8_t matrix_row_t;
27#elif (MATRIX_COLS <= 16)
28typedef uint16_t matrix_row_t;
29#elif (MATRIX_COLS <= 32)
30typedef 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
39extern "C" {
40#endif
41
42/* number of matrix rows */
43uint8_t matrix_rows(void);
44/* number of matrix columns */
45uint8_t matrix_cols(void);
46/* intialize matrix for scaning. should be called once. */
47void matrix_init(void);
48/* scan all key states on matrix */
49uint8_t matrix_scan(void);
50/* whether modified from previous scan. used after matrix_scan. */
51bool matrix_is_modified(void) __attribute__ ((deprecated));
52/* whether a swtich is on */
53bool matrix_is_on(uint8_t row, uint8_t col);
54/* matrix state on row */
55matrix_row_t matrix_get_row(uint8_t row);
56/* print matrix for debug */
57void matrix_print(void);
58
59
60/* power control */
61void matrix_power_up(void);
62void matrix_power_down(void);
63
64#ifdef __cplusplus
65}
66#endif
67
68#endif