keymap_engine.h 2.6 KB

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