keymap_engine.h (2578B)
1 /* If for some reason you're still here, maybe due to horror, shock or 2 * some other godforsaken reason. Meet X Macros. 3 * 4 * The we abuse the include system to generate data structures that are 5 * used by the internal chording engine. The alternative to this is 6 * using a external generator (Like is done for the ASETNIOP base keymaps) 7 * With this disgusting bodge, you can just edit your .defs and compile! 8 */ 9 10 #pragma once 11 12 #include "g/engine.h" 13 14 // Clear all X Macros 15 #define PRES BLANK 16 #define KEYS BLANK 17 #define SUBS BLANK 18 #define EXEC BLANK 19 #define SPEC BLANK 20 21 // Process single key pushes 22 #undef PRES 23 #define PRES P_KEYMAP 24 const struct keyEntry keyDict[] = { 25 #include "dicts.def" 26 }; 27 #undef PRES 28 #define PRES BLANK 29 30 // Process Combos 31 #undef KEYS 32 #define KEYS K_ACTION 33 #include "dicts.def" 34 #undef KEYS 35 #define KEYS BLANK 36 37 #undef KEYS 38 #define KEYS K_KEYMAP 39 const struct comboEntry PROGMEM cmbDict[] = { 40 #include "dicts.def" 41 }; 42 #undef KEYS 43 #define KEYS BLANK 44 45 // Process String stubs 46 #undef SUBS 47 #define SUBS S_ACTION 48 #include "dicts.def" 49 #undef SUBS 50 #define SUBS BLANK 51 52 // Generate dict for strings 53 #undef SUBS 54 #define SUBS S_KEYMAP 55 const struct stringEntry PROGMEM strDict[] = { 56 #include "dicts.def" 57 }; 58 #undef SUBS 59 #define SUBS BLANK 60 61 // Generate function stubs 62 #undef EXEC 63 #define EXEC X_ACTION 64 #include "dicts.def" 65 #undef EXEC 66 #define EXEC BLANK 67 68 // Process the function structure 69 #undef EXEC 70 #define EXEC X_KEYMAP 71 const struct funcEntry funDict[] = { 72 #include "dicts.def" 73 }; 74 #undef EXEC 75 #define EXEC BLANK 76 77 // Handle Special calls 78 #undef SPEC 79 #define SPEC Z_KEYMAP 80 const struct specialEntry spcDict[] = { 81 #include "dicts.def" 82 }; 83 #undef SPEC 84 #define SPEC BLANK 85 86 // Test for collisions! 87 // Switch statement will explode on duplicate 88 // chords. This will be optimized out 89 #undef PRES 90 #undef KEYS 91 #undef SUBS 92 #undef EXEC 93 #undef SPEC 94 #define PRES TEST_COLLISION 95 #define KEYS TEST_COLLISION 96 #define SUBS TEST_COLLISION 97 #define EXEC TEST_COLLISION 98 #define SPEC TEST_COLLISION 99 void testCollisions(void) { 100 C_SIZE bomb = 0; 101 switch (bomb) { 102 #include "dicts.def" 103 } 104 } 105 106 // Test for unexpected input 107 // Should return blank lines for all valid input 108 #undef PRES 109 #undef KEYS 110 #undef SUBS 111 #undef EXEC 112 #undef SPEC 113 #define PRES BLANK 114 #define KEYS BLANK 115 #define SUBS BLANK 116 #define EXEC BLANK 117 #define SPEC BLANK 118 #include "dicts.def" 119 120 // Get size data back into the engine 121 size_t funcsLen = ARRAY_SIZE(funDict); 122 size_t stringLen = ARRAY_SIZE(strDict); 123 size_t keyLen = ARRAY_SIZE(keyDict); 124 size_t comboLen = ARRAY_SIZE(cmbDict); 125 size_t specialLen = ARRAY_SIZE(spcDict);