]> git.gir.st - tmk_keyboard.git/blob - tmk_core/common/matrix.h
ec6f8cd431895d19c957d4b28c069779eae5f05b
[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 #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 /* should be called at early stage of startup before matrix_init.(optional) */
47 void matrix_setup(void);
48 /* intialize matrix for scaning. */
49 void matrix_init(void);
50 /* scan all key states on matrix */
51 uint8_t matrix_scan(void);
52 /* whether modified from previous scan. used after matrix_scan. */
53 bool matrix_is_modified(void) __attribute__ ((deprecated));
54 /* whether a swtich is on */
55 bool matrix_is_on(uint8_t row, uint8_t col);
56 /* matrix state on row */
57 matrix_row_t matrix_get_row(uint8_t row);
58 /* print matrix for debug */
59 void matrix_print(void);
60
61
62 /* power control */
63 void matrix_power_up(void);
64 void matrix_power_down(void);
65
66 #ifdef __cplusplus
67 }
68 #endif
69
70 #endif
Imprint / Impressum