]> git.gir.st - tmk_keyboard.git/blob - tmk_core/common/matrix.h
core: Change matrix_init and matrix_print
[tmk_keyboard.git] / tmk_core / common / matrix.h
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 #if (MATRIX_ROWS > 255)
36 #error "MATRIX_ROWS must not exceed 255"
37 #endif
38
39 #define MATRIX_IS_ON(row, col) (matrix_get_row(row) && (1<<col))
40
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /* number of matrix rows */
47 uint8_t matrix_rows(void);
48 /* number of matrix columns */
49 uint8_t matrix_cols(void);
50 /* should be called at early stage of startup before matrix_init.(optional) */
51 void matrix_setup(void);
52 /* intialize matrix for scaning. */
53 void matrix_init(void);
54 /* scan all key states on matrix */
55 uint8_t matrix_scan(void);
56 /* whether modified from previous scan. used after matrix_scan. */
57 bool matrix_is_modified(void) __attribute__ ((deprecated));
58 /* whether a swtich is on */
59 bool matrix_is_on(uint8_t row, uint8_t col);
60 /* matrix state on row */
61 matrix_row_t matrix_get_row(uint8_t row);
62 /* print matrix for debug */
63 void matrix_print(void);
64 /* clear matrix */
65 void matrix_clear(void);
66
67 #ifdef MATRIX_HAS_GHOST
68 bool matrix_has_ghost_in_row(uint8_t row);
69 #endif
70
71 /* power control */
72 void matrix_power_up(void);
73 void matrix_power_down(void);
74
75 #ifdef __cplusplus
76 }
77 #endif
78
79 #endif
Imprint / Impressum