]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Scan/MatrixARM/matrix_scan.h
Matrix scanning for ARM now functional.
[kiibohd-controller.git] / Scan / MatrixARM / matrix_scan.h
1 /* Copyright (C) 2014 by Jacob Alexander
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19  * THE SOFTWARE.
20  */
21
22 #ifndef __MATRIX_SCAN_H
23 #define __MATRIX_SCAN_H
24
25 // ----- Includes -----
26
27
28
29 // ----- Enums -----
30
31 // Freescale MK20s have GPIO ports A...E
32 typedef enum Port {
33         Port_A = 0,
34         Port_B = 1,
35         Port_C = 2,
36         Port_D = 3,
37         Port_E = 4,
38 } Port;
39
40 // Each port has a possible 32 pins
41 typedef enum Pin {
42         Pin_0  = 0,
43         Pin_1  = 1,
44         Pin_2  = 2,
45         Pin_3  = 3,
46         Pin_4  = 4,
47         Pin_5  = 5,
48         Pin_6  = 6,
49         Pin_7  = 7,
50         Pin_8  = 8,
51         Pin_9  = 9,
52         Pin_10 = 10,
53         Pin_11 = 11,
54         Pin_12 = 12,
55         Pin_13 = 13,
56         Pin_14 = 14,
57         Pin_15 = 15,
58         Pin_16 = 16,
59         Pin_17 = 17,
60         Pin_18 = 18,
61         Pin_19 = 19,
62         Pin_20 = 20,
63         Pin_21 = 21,
64         Pin_22 = 22,
65         Pin_23 = 23,
66         Pin_24 = 24,
67         Pin_25 = 25,
68         Pin_26 = 26,
69         Pin_27 = 27,
70         Pin_28 = 28,
71         Pin_29 = 29,
72         Pin_30 = 30,
73         Pin_31 = 31,
74 } Pin;
75
76 // Type of pin
77 typedef enum Type {
78         Type_StrobeOn,
79         Type_StrobeOff,
80         Type_StrobeSetup,
81         Type_Sense,
82         Type_SenseSetup,
83 } Type;
84
85 // Sense/Strobe configuration
86 typedef enum Config {
87         Config_Pullup,    // Internal pull-up
88         Config_Pulldown,  // Internal pull-down
89         Config_Opendrain, // External pull resistor
90 } Config;
91
92 // Keypress States
93 typedef enum KeyPosition {
94         KeyState_Off     = 0,
95         KeyState_Press   = 1,
96         KeyState_Hold    = 2,
97         KeyState_Release = 3,
98         KeyState_Invalid,
99 } KeyPosition;
100
101
102
103 // ----- Structs -----
104
105 // Struct container for defining Rows (Sense) and Columns (Strobes)
106 typedef struct GPIO_Pin {
107         Port port;
108         Pin  pin;
109 } GPIO_Pin;
110
111 // Debounce Element
112 typedef struct KeyState {
113         KeyPosition prevState;
114         KeyPosition curState;
115         uint16_t activeCount;
116         uint16_t inactiveCount;
117 } KeyState;
118
119
120
121 // ----- Functions -----
122
123 void Matrix_setup();
124 void Matrix_scan( uint16_t scanNum );
125
126
127 #endif // __MATRIX_SCAN_H
128