]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/common/matrix.h
Merge branch 'master' of https://github.com/jackhumbert/qmk_firmware
[qmk_firmware.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 #ifndef MATRIX_H
18 #define MATRIX_H
19
20 #include <stdint.h>
21 #include <stdbool.h>
22
23 #if MATRIX_COLS <= 8
24 typedef uint8_t matrix_row_t;
25 #elif MATRIX_COLS <= 16
26 typedef uint16_t matrix_row_t;
27 #elif MATRIX_COLS <= 32
28 typedef uint32_t matrix_row_t;
29 #else
30 #   error "There are too many columns."
31 #endif
32
33 #if DIODE_DIRECTION == ROW2COL
34 #   if MATRIX_ROWS <= 8
35 typedef uint8_t matrix_col_t;
36 #   elif MATRIX_ROWS <= 16
37 typedef uint16_t matrix_col_t;
38 #   elif MATRIX_ROWS <= 32
39 typedef uint32_t matrix_col_t;
40 #   else
41 #       error "There are too many rows."
42 #   endif
43 #endif
44
45 typedef struct {
46     uint8_t input_addr:4;
47     uint8_t bit:4;
48 } io_pin_t;
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 /* counts the number of rows in the matrix */
54 uint8_t matrix_rows(void);
55 /* counts the number of columns in the matrix */
56 uint8_t matrix_cols(void);
57 /* sets up the matrix before matrix_init */
58 void matrix_setup(void);
59 /* intializes the matrix */
60 void matrix_init(void);
61 /* scans the entire matrix */
62 uint8_t matrix_scan(void);
63 /* checks if the matrix has been modified */
64 bool matrix_is_modified(void) __attribute__ ((deprecated));
65 /* checks if a key is pressed */
66 bool matrix_is_on(uint8_t row, uint8_t col);
67 /* inspects the state of a row in the matrix */
68 matrix_row_t matrix_get_row(uint8_t row);
69 /* prints the matrix for debugging */
70 void matrix_print(void);
71 /* counts the total number of keys pressed */
72 uint8_t matrix_key_count(void);
73 /* controls power to the matrix */
74 void matrix_power_up(void);
75 void matrix_power_down(void);
76 /* executes code for Quantum */
77 void matrix_init_quantum(void);
78 void matrix_scan_quantum(void);
79
80 void matrix_init_kb(void);
81 void matrix_scan_kb(void);
82
83 void matrix_init_user(void);
84 void matrix_scan_user(void);
85
86 #ifdef __cplusplus
87 }
88 #endif
89
90 #endif