]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Macro/PartialMap/kll.h
Splitting out structures and macros from the generated keymap.
[kiibohd-controller.git] / Macro / PartialMap / kll.h
1 /* Copyright (C) 2014 by Jacob Alexander
2  *
3  * This file is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This file is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this file.  If not, see <http://www.gnu.org/licenses/>.
15  */
16
17 #ifndef __kll_h
18 #define __kll_h
19
20 // ----- Includes -----
21
22 // Project Includes
23 #include <print.h>
24 #include <scan_loop.h>
25 #include <macro.h>
26 #include <output_com.h>
27
28 // USB HID Keymap list
29 #include <usb_hid.h>
30
31
32
33 // ----- Structs -----
34
35 // -- Result Macro
36 // Defines the sequence of combinations to as the Result of Trigger Macro
37 //
38 // Capability + args per USB send
39 // Default Args (always sent): key state/analog of last key
40 // Combo Length of 0 signifies end of sequence
41 //
42 // ResultMacro.guide     -> [<combo length>|<capability index>|<arg1>|<argn>|<capability index>|...|<combo length>|...|0]
43 // ResultMacro.pos       -> <current combo position>
44 // ResultMacro.state     -> <last key state>
45 // ResultMacro.stateType -> <last key state type>
46
47 // ResultMacro struct, one is created per ResultMacro, no duplicates
48 typedef struct ResultMacro {
49         const uint8_t *guide;
50         unsigned int pos;
51         uint8_t  state;
52         uint8_t  stateType;
53 } ResultMacro;
54
55 // Guide, key element
56 #define ResultGuideSize( guidePtr ) sizeof( ResultGuide ) - 1 + CapabilitiesList[ (guidePtr)->index ].argCount
57 typedef struct ResultGuide {
58         uint8_t index;
59         uint8_t args; // This is used as an array pointer (but for packing purposes, must be 8 bit)
60 } ResultGuide;
61
62
63
64 // -- Trigger Macro
65 // Defines the sequence of combinations to Trigger a Result Macro
66 // Key Types:
67 //   * 0x00 Normal (Press/Hold/Release)
68 //   * 0x01 LED State (On/Off)
69 //   * 0x02 Analog (Threshold)
70 //   * 0x03-0xFE Reserved
71 //   * 0xFF Debug State
72 //
73 // Key State:
74 //   * Off                - 0x00 (all flag states)
75 //   * On                 - 0x01
76 //   * Press/Hold/Release - 0x01/0x02/0x03
77 //   * Threshold (Range)  - 0x01 (Released), 0x10 (Light press), 0xFF (Max press)
78 //   * Debug              - 0xFF (Print capability name)
79 //
80 // Combo Length of 0 signifies end of sequence
81 //
82 // TriggerMacro.guide  -> [<combo length>|<key1 type>|<key1 state>|<key1>...<keyn type>|<keyn state>|<keyn>|<combo length>...|0]
83 // TriggerMacro.result -> <index to result macro>
84 // TriggerMacro.pos    -> <current combo position>
85 // TriggerMacro.state  -> <status of the macro pos>
86
87 // TriggerMacro states
88 typedef enum TriggerMacroState {
89         TriggerMacro_Press,   // Combo in sequence is passing
90         TriggerMacro_Release, // Move to next combo in sequence (or finish if at end of sequence)
91         TriggerMacro_Waiting, // Awaiting user input
92 } TriggerMacroState;
93
94 // TriggerMacro struct, one is created per TriggerMacro, no duplicates
95 typedef struct TriggerMacro {
96         const uint8_t *guide;
97         unsigned int result;
98         unsigned int pos;
99         TriggerMacroState state;
100 } TriggerMacro;
101
102 // Guide, key element
103 #define TriggerGuideSize sizeof( TriggerGuide )
104 typedef struct TriggerGuide {
105         uint8_t type;
106         uint8_t state;
107         uint8_t scanCode;
108 } TriggerGuide;
109
110
111
112 // ----- Capabilities -----
113
114 // Capability
115 typedef struct Capability {
116         void *func;
117         uint8_t argCount;
118 } Capability;
119
120 // Total Number of Capabilities
121 #define CapabilitiesNum sizeof( CapabilitiesList ) / sizeof( Capability )
122
123
124 // -- Result Macros
125
126 // Guide_RM / Define_RM Pair
127 // Guide_RM( index ) = result;
128 //  * index  - Result Macro index number
129 //  * result - Result Macro guide (see ResultMacro)
130 // Define_RM( index );
131 //  * index  - Result Macro index number
132 //  Must be used after Guide_RM
133 #define Guide_RM( index ) const uint8_t rm##index##_guide[]
134 #define Define_RM( index ) { rm##index##_guide, 0, 0, 0 }
135
136
137 // -- Result Macro List
138
139 // Total number of result macros (rm's)
140 // Used to create pending rm's table
141 #define ResultMacroNum sizeof( ResultMacroList ) / sizeof( ResultMacro )
142
143
144 // -- Trigger Macros
145
146 // Guide_TM / Define_TM Trigger Setup
147 // Guide_TM( index ) = trigger;
148 //  * index   - Trigger Macro index number
149 //  * trigger - Trigger Macro guide (see TriggerMacro)
150 // Define_TM( index, result );
151 //  * index   - Trigger Macro index number
152 //  * result  - Result Macro index number which is triggered by this Trigger Macro
153 #define Guide_TM( index ) const uint8_t tm##index##_guide[]
154 #define Define_TM( index, result ) { tm##index##_guide, result, 0, TriggerMacro_Waiting }
155
156
157 // -- Trigger Macro List
158
159 // Total number of trigger macros (tm's)
160 // Used to create pending tm's table
161 #define TriggerMacroNum sizeof( TriggerMacroList ) / sizeof( TriggerMacro )
162
163
164
165 // ----- Trigger Maps -----
166
167 // Define_TL( layer, scanCode ) = triggerList;
168 //  * layer       - basename of the layer
169 //  * scanCode    - Hex value of the scanCode
170 //  * triggerList - Trigger List (see Trigger Lists)
171 #define Define_TL( layer, scanCode ) const unsigned int layer##_tl_##scanCode[]
172
173
174
175 // ----- Layer Index -----
176
177 // Defines each map of trigger macro lists
178 // Layer 0 is always the default map
179 // Layer States:
180 //   * Off   - 0x00
181 //   * Shift - 0x01
182 //   * Latch - 0x02
183 //   * Lock  - 0x04
184 //
185 // Except for Off, all states an exist simultaneously for each layer
186 // For example:
187 // state -> 0x04 + 0x01 = 0x05 (Shift + Lock), which is effectively Off (0x00)
188 //
189 // Max defines the maximum number of keys in the map, maximum of 0xFF
190 //  - Compiler calculates this
191 //
192 // The name is defined for cli debugging purposes (Null terminated string)
193
194 typedef struct Layer {
195         const unsigned int **triggerMap;
196         const char *name;
197         const uint8_t max;
198         uint8_t state;
199 } Layer;
200
201
202 // Layer_IN( map, name );
203 //  * map  - Trigger map
204 //  * name - Name of the trigger map
205 #define Layer_IN( map, name ) { map, name, sizeof( map ) / 4 - 1, 0 }
206
207 // Total number of layers
208 #define LayerNum sizeof( LayerIndex ) / sizeof( Layer )
209
210
211
212 #endif // __kll_h
213