Parent directory

matrix.h

2376 bytes
 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#pragma once
19
20#include <stdint.h>
21#include <stdbool.h>
22#include "gpio.h"
23
24/* diode directions */
25#define COL2ROW 0
26#define ROW2COL 1
27
28#if (MATRIX_COLS <= 8)
29typedef uint8_t matrix_row_t;
30#elif (MATRIX_COLS <= 16)
31typedef uint16_t matrix_row_t;
32#elif (MATRIX_COLS <= 32)
33typedef uint32_t matrix_row_t;
34#else
35#    error "MATRIX_COLS: invalid value"
36#endif
37
38#define MATRIX_ROW_SHIFTER ((matrix_row_t)1)
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/* number of matrix rows */
45uint8_t matrix_rows(void);
46/* number of matrix columns */
47uint8_t matrix_cols(void);
48/* should be called at early stage of startup before matrix_init.(optional) */
49void matrix_setup(void);
50/* intialize matrix for scaning. */
51void matrix_init(void);
52/* scan all key states on matrix */
53uint8_t matrix_scan(void);
54/* whether matrix scanning operations should be executed */
55bool matrix_can_read(void);
56/* whether a switch is on */
57bool matrix_is_on(uint8_t row, uint8_t col);
58/* matrix state on row */
59matrix_row_t matrix_get_row(uint8_t row);
60/* print matrix for debug */
61void matrix_print(void);
62/* delay between changing matrix pin state and reading values */
63void matrix_output_select_delay(void);
64void matrix_output_unselect_delay(uint8_t line, bool key_pressed);
65/* only for backwards compatibility. delay between changing matrix pin state and reading values */
66void matrix_io_delay(void);
67
68/* power control */
69void matrix_power_up(void);
70void matrix_power_down(void);
71
72void matrix_init_kb(void);
73void matrix_scan_kb(void);
74
75void matrix_init_user(void);
76void matrix_scan_user(void);
77
78#ifdef SPLIT_KEYBOARD
79bool matrix_post_scan(void);
80void matrix_slave_scan_kb(void);
81void matrix_slave_scan_user(void);
82#endif
83
84#ifdef __cplusplus
85}
86#endif