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