qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

keymap_engine.h (2555B)


      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 // Clear all X Macros
     13 #define PRES BLANK
     14 #define KEYS BLANK
     15 #define SUBS BLANK
     16 #define EXEC BLANK
     17 #define SPEC BLANK
     18 
     19 // Process single key pushes
     20 #undef PRES
     21 #define PRES P_KEYMAP
     22 const struct keyEntry keyDict[] = {
     23 #include "dicts.def"
     24 };
     25 #undef PRES
     26 #define PRES BLANK
     27 
     28 // Process Combos
     29 #undef KEYS
     30 #define KEYS K_ACTION
     31 #include "dicts.def"
     32 #undef KEYS
     33 #define KEYS BLANK
     34 
     35 #undef KEYS
     36 #define KEYS K_KEYMAP
     37 const struct comboEntry PROGMEM cmbDict[] = {
     38 #include "dicts.def"
     39 };
     40 #undef KEYS
     41 #define KEYS BLANK
     42 
     43 // Process String stubs
     44 #undef SUBS
     45 #define SUBS S_ACTION
     46 #include "dicts.def"
     47 #undef SUBS
     48 #define SUBS BLANK
     49 
     50 // Generate dict for strings
     51 #undef SUBS
     52 #define SUBS S_KEYMAP
     53 const struct stringEntry PROGMEM strDict[] = {
     54 #include "dicts.def"
     55 };
     56 #undef SUBS
     57 #define SUBS BLANK
     58 
     59 // Generate function stubs
     60 #undef EXEC
     61 #define EXEC X_ACTION
     62 #include "dicts.def"
     63 #undef EXEC
     64 #define EXEC BLANK
     65 
     66 // Process the function structure
     67 #undef EXEC
     68 #define EXEC X_KEYMAP
     69 const struct funcEntry funDict[] = {
     70 #include "dicts.def"
     71 };
     72 #undef EXEC
     73 #define EXEC BLANK
     74 
     75 // Handle Special calls
     76 #undef SPEC
     77 #define SPEC Z_KEYMAP
     78 const struct specialEntry spcDict[] = {
     79 #include "dicts.def"
     80 };
     81 #undef SPEC
     82 #define SPEC BLANK
     83 
     84 // Test for collisions!
     85 // Switch statement will explode on duplicate
     86 // chords. This will be optimized out
     87 #undef PRES
     88 #undef KEYS
     89 #undef SUBS
     90 #undef EXEC
     91 #undef SPEC
     92 #define PRES TEST_COLLISION
     93 #define KEYS TEST_COLLISION
     94 #define SUBS TEST_COLLISION
     95 #define EXEC TEST_COLLISION
     96 #define SPEC TEST_COLLISION
     97 void testCollisions(void) {
     98     C_SIZE bomb = 0;
     99     switch (bomb) {
    100 #include "dicts.def"
    101     }
    102 }
    103 
    104 // Test for unexpected input
    105 // Should return blank lines for all valid input
    106 #undef PRES
    107 #undef KEYS
    108 #undef SUBS
    109 #undef EXEC
    110 #undef SPEC
    111 #define PRES BLANK
    112 #define KEYS BLANK
    113 #define SUBS BLANK
    114 #define EXEC BLANK
    115 #define SPEC BLANK
    116 #include "dicts.def"
    117 
    118 // Get size data back into the engine
    119 size_t funcsLen   = ARRAY_SIZE(funDict);
    120 size_t stringLen  = ARRAY_SIZE(strDict);
    121 size_t keyLen     = ARRAY_SIZE(keyDict);
    122 size_t comboLen   = ARRAY_SIZE(cmbDict);
    123 size_t specialLen = ARRAY_SIZE(spcDict);