You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.9 KiB

  1. /* 2019, g Heavy Industries
  2. Blessed mother of Christ, please keep this readable
  3. and protect us from segfaults. For thine is the clock,
  4. the slave and the master. Until we return from main.
  5. Amen.
  6. This is a stripped down version of the Georgi engine meant for use with
  7. . As such serial-Steno features are disabled, chords are 16bits and
  8. crap is removed where possible
  9. */
  10. #pragma once
  11. #include "quantum.h"
  12. #include <string.h>
  13. #include <stdio.h>
  14. #include "config_engine.h"
  15. // Set defaults
  16. #ifndef IN_CHORD_MASK
  17. # define IN_CHORD_MASK 0xFFFFFFFFFFFFFFFF
  18. #endif
  19. #ifndef COMBO_END
  20. # define COMBO_END 0x00
  21. #endif
  22. // In memory chord datatypes
  23. enum specialActions {
  24. SPEC_STICKY,
  25. SPEC_REPEAT,
  26. SPEC_CLICK,
  27. SPEC_SWITCH,
  28. };
  29. struct funcEntry {
  30. C_SIZE chord;
  31. void (*act)(void);
  32. } funcEntry_t;
  33. struct stringEntry {
  34. C_SIZE chord;
  35. PGM_P str;
  36. } stringEntry_t;
  37. struct comboEntry {
  38. C_SIZE chord;
  39. PGM_P keys;
  40. } comboEntry_t;
  41. struct keyEntry {
  42. C_SIZE chord;
  43. uint8_t key;
  44. } keyEntry_t;
  45. struct specialEntry {
  46. C_SIZE chord;
  47. enum specialActions action;
  48. uint16_t arg;
  49. } specialEntry_t;
  50. // Chord Temps
  51. extern C_SIZE cChord;
  52. extern C_SIZE test;
  53. extern size_t keymapsCount; // Total keymaps (exported from keymap.c)
  54. // Function defs
  55. void processKeysUp(void);
  56. void processChord(void);
  57. C_SIZE processQwerty(bool lookup);
  58. C_SIZE processFakeSteno(bool lookup);
  59. void saveState(C_SIZE cChord);
  60. void restoreState(void);
  61. uint8_t bitpop_v(C_SIZE val);
  62. // Macros for use in keymap.c
  63. void SEND(uint8_t kc);
  64. void REPEAT(void);
  65. void SET_STICKY(C_SIZE);
  66. void SWITCH_LAYER(int);
  67. void CLICK_MOUSE(uint8_t);
  68. C_SIZE process_chord_getnext(C_SIZE cur_chord);
  69. // Run before hitting the engine. Return false to skip engine processing
  70. C_SIZE process_engine_pre(C_SIZE cur_chord, uint16_t keycode, keyrecord_t *record);
  71. // Run after reading a chord.
  72. C_SIZE process_engine_post(C_SIZE cur_chord, uint16_t keycode, keyrecord_t *record);
  73. // Keymap helpers
  74. // New Approach, multiple structures
  75. #define P_KEYMAP(chord, keycode) {chord, keycode},
  76. #define K_KEYMAP(chord, name, ...) {chord, (PGM_P)&name},
  77. #define K_ACTION(chord, name, ...) const uint8_t name[] PROGMEM = __VA_ARGS__;
  78. #define S_KEYMAP(chord, name, string) {chord, (PGM_P)&name},
  79. #define S_ACTION(chord, name, string) const char name[] PROGMEM = string;
  80. #define X_KEYMAP(chord, name, func) {chord, name},
  81. #define X_ACTION(chord, name, func) \
  82. void name(void) { func }
  83. #define Z_KEYMAP(chord, act, arg) {chord, act, arg},
  84. #define TEST_COLLISION(chord, ...) \
  85. case chord: \
  86. break;
  87. #define BLANK(...)
  88. // Shift to internal representation
  89. // i.e) S(teno)R(ight)F
  90. #define STN(n) ((C_SIZE)1 << n)
  91. #define ENGINE_HOOK(keycode, chord) \
  92. case keycode: \
  93. pr ? (pressed |= (chord)) : (pressed &= ~(chord)); \
  94. break;