1 /* Copyright (C) 2014 by Jacob Alexander
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.
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.
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/>.
20 // ----- Includes -----
24 #include <scan_loop.h>
26 #include <output_com.h>
28 // USB HID Keymap list
33 // ----- Structs -----
36 // Defines the sequence of combinations to as the Result of Trigger Macro
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
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>
47 // ResultMacro struct, one is created per ResultMacro, no duplicates
48 typedef struct ResultMacro {
56 #define ResultGuideSize( guidePtr ) sizeof( ResultGuide ) - 1 + CapabilitiesList[ (guidePtr)->index ].argCount
57 typedef struct ResultGuide {
59 uint8_t args; // This is used as an array pointer (but for packing purposes, must be 8 bit)
65 // Defines the sequence of combinations to Trigger a Result Macro
67 // * 0x00 Normal (Press/Hold/Release)
68 // * 0x01 LED State (On/Off)
69 // * 0x02 Analog (Threshold)
70 // * 0x03-0xFE Reserved
74 // * Off - 0x00 (all flag states)
76 // * Press/Hold/Release - 0x01/0x02/0x03
77 // * Threshold (Range) - 0x01 (Released), 0x10 (Light press), 0xFF (Max press)
78 // * Debug - 0xFF (Print capability name)
80 // Combo Length of 0 signifies end of sequence
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>
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
94 // TriggerMacro struct, one is created per TriggerMacro, no duplicates
95 typedef struct TriggerMacro {
99 TriggerMacroState state;
102 // Guide, key element
103 #define TriggerGuideSize sizeof( TriggerGuide )
104 typedef struct TriggerGuide {
112 // ----- Capabilities -----
115 typedef struct Capability {
120 // Total Number of Capabilities
121 #define CapabilitiesNum sizeof( CapabilitiesList ) / sizeof( Capability )
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 }
137 // -- Result Macro List
139 // Total number of result macros (rm's)
140 // Used to create pending rm's table
141 #define ResultMacroNum sizeof( ResultMacroList ) / sizeof( ResultMacro )
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 }
157 // -- Trigger Macro List
159 // Total number of trigger macros (tm's)
160 // Used to create pending tm's table
161 #define TriggerMacroNum sizeof( TriggerMacroList ) / sizeof( TriggerMacro )
165 // ----- Trigger Maps -----
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[]
175 // ----- Layer Index -----
177 // Defines each map of trigger macro lists
178 // Layer 0 is always the default map
185 // Except for Off, all states an exist simultaneously for each layer
187 // state -> 0x04 + 0x01 = 0x05 (Shift + Lock), which is effectively Off (0x00)
189 // Max defines the maximum number of keys in the map, maximum of 0xFF
190 // - Compiler calculates this
192 // The name is defined for cli debugging purposes (Null terminated string)
194 typedef struct Layer {
195 const unsigned int **triggerMap;
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 }
207 // Total number of layers
208 #define LayerNum sizeof( LayerIndex ) / sizeof( Layer )