diff options
| author | tmk <nobody@nowhere> | 2012-12-16 02:32:07 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2012-12-16 02:32:07 +0900 |
| commit | 8a709c2750eab09ec0f83450410a13640931d48e (patch) | |
| tree | 224bcea716521704d63993ed54917152a6bf046e /common/action.h | |
| parent | 77f157943f4e083fb9f1eaa0a55078b128842458 (diff) | |
| download | qmk_firmware-8a709c2750eab09ec0f83450410a13640931d48e.tar.gz qmk_firmware-8a709c2750eab09ec0f83450410a13640931d48e.zip | |
Add initial fix for new keymap.
Diffstat (limited to 'common/action.h')
| -rw-r--r-- | common/action.h | 219 |
1 files changed, 219 insertions, 0 deletions
diff --git a/common/action.h b/common/action.h new file mode 100644 index 000000000..08f8c5608 --- /dev/null +++ b/common/action.h | |||
| @@ -0,0 +1,219 @@ | |||
| 1 | #ifndef ACTION_H | ||
| 2 | #define ACTION_H | ||
| 3 | |||
| 4 | #include "keyboard.h" | ||
| 5 | |||
| 6 | |||
| 7 | /* Key Action(16bit code) | ||
| 8 | 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 | ||
| 9 | ------------------------------------------------ | ||
| 10 | ACT_LMODS(0000) | ||
| 11 | 0 0 0 0| 0 0 0 0| 0 0 0 0 0 0| 0 0 No action | ||
| 12 | 0 0 0 0| 0 0 0 0| keycode(8) Key | ||
| 13 | 0 0 0 0| mods(4) | 0 0 0 0 0 0| 0 0 Lmods Momentary | ||
| 14 | 0 0 0 0| mods(4) | 0 0 0 0 0 0| 0 1 Lmods OneShot | ||
| 15 | 0 0 0 0| mods(4) | 0 0 0 0 0 0| 1 0 (reserved) | ||
| 16 | 0 0 0 0| mods(4) | 0 0 0 0 0 0| 1 1 (reserved) | ||
| 17 | 0 0 0 0| mods(4) | keycode(8) Key+Lmods | ||
| 18 | ??? | ||
| 19 | 0 0 0 0| mods(4) | 1 1 1 1 0| tap(3) Lmods+tap Switch(enable/disable) | ||
| 20 | 0 0 0 0| mods(4) | 1 1 1 1 1| tap(3) Lmods+tap Toggle(on/off) | ||
| 21 | ??? | ||
| 22 | |||
| 23 | ACT_RMODS(0001) | ||
| 24 | 0 0 0 1| 0 0 0 0| 0 0 0 0 0 0 0 0 No action(not used) | ||
| 25 | 0 0 0 1| 0 0 0 0| keycode(8) Key(not used) | ||
| 26 | 0 0 0 1| mods(4) | 0 0 0 0 0 0| 0 0 Rmods Momentary | ||
| 27 | 0 0 0 1| mods(4) | 0 0 0 0 0 0| 0 1 Rmods OneShot | ||
| 28 | 0 0 0 1| mods(4) | 0 0 0 0 0 0| 1 0 (reserved) | ||
| 29 | 0 0 0 1| mods(4) | 0 0 0 0 0 0| 1 1 (reserved) | ||
| 30 | 0 0 0 1| mods(4) | keycode(8) Key+Rmod | ||
| 31 | ??? | ||
| 32 | 0 0 0 1| mods(4) | 1 1 1 1 0| tap(3) Rmods+tap Switch(enable/disable) | ||
| 33 | 0 0 0 1| mods(4) | 1 1 1 1 1| tap(3) Rmods+tap Toggle(on/off) | ||
| 34 | ??? | ||
| 35 | |||
| 36 | ACT_LMODS_TAP(0010) | ||
| 37 | 0 0 1 0| 0 0 0 0| X X X X X X X X (reserved)[00-FF] | ||
| 38 | 0 0 1 0| mods(4) | 0 0 0 0 0 0| X X (reserved) | ||
| 39 | 0 0 1 0| mods(4) | keycode(8) Lmods+tap Key | ||
| 40 | 0 0 1 0| mods(4) | 1 1 1 1| X X X X (reserved)[F0-FF] | ||
| 41 | |||
| 42 | ACT_RMODS_TAP(0011) | ||
| 43 | 0 0 1 1| 0 0 0 0| X X X X X X X X (reserved)[00-FF] | ||
| 44 | 0 0 1 1| mods(4) | 0 0 0 0 0 0| X X (reserved) | ||
| 45 | 0 0 1 1| mods(4) | keycode(8) Rmods+tap Key | ||
| 46 | 0 0 1 1| mods(4) | 1 1 1 1| X X X X (reserved)[F0-FF] | ||
| 47 | |||
| 48 | ACT_LAYER(0100) | ||
| 49 | 0 1 0 0| layer(4) | 0 0 0 0 0 0| 0 0 Momentary | ||
| 50 | 0 1 0 0| layer(4) | 0 0 0 0 0 0| 0 1 Oneshot | ||
| 51 | 0 1 0 0| layer(4) | 0 0 0 0 0 0| 1 0 (reserved) | ||
| 52 | 0 1 0 0| layer(4) | 0 0 0 0 0 0| 1 1 (reserved) | ||
| 53 | 0 1 0 0| layer(4) | keycode(8) Fn momentary + tap Key | ||
| 54 | 0 1 0 0| layer(4) | 1 1 1 1 0| tap(3) Fn+tap Switch(enable/disable) | ||
| 55 | 0 1 0 0| layer(4) | 1 1 1 1 1| tap(3) Fn+tap Toggle(on/off) | ||
| 56 | |||
| 57 | ACT_USAGE(0101) | ||
| 58 | 0 1 0 1| 0 0| usage(10) System usage | ||
| 59 | 0 1 0 1| 0 1| usage(10) Consumer usage | ||
| 60 | 0 1 0 1| 1 0| usage(10) (reserved) | ||
| 61 | 0 1 0 1| 1 1| usage(10) (reserved) | ||
| 62 | |||
| 63 | ACT_MOUSEKEY(0110) | ||
| 64 | 0 1 1 0| X X X X| keycode(8) Mouse key | ||
| 65 | ??? TODO: refactor | ||
| 66 | 0 1 1 0| 0 0 X X| accel(5) |cursor(3) Mouse key | ||
| 67 | 0 1 1 0| 0 1 X X| accel(5) |wheel(3) Mouse key | ||
| 68 | 0 1 1 0| 1 0 X X| button(8) Mouse key | ||
| 69 | 0 1 1 0| 1 1 X X| button(8) Mouse key | ||
| 70 | ??? | ||
| 71 | |||
| 72 | 0 1 1 1| (reserved) | ||
| 73 | 1 0 0 0| (reserved) | ||
| 74 | 1 0 0 1| (reserved) | ||
| 75 | 1 0 1 0| (reserved) | ||
| 76 | 1 0 1 1| (reserved) | ||
| 77 | 1 1 0 0| (reserved) | ||
| 78 | |||
| 79 | ACT_MACRO(1100) | ||
| 80 | 1 1 0 0| option(4) | macro-table id(8) Macro play(Flash) | ||
| 81 | 1 1 0 0| option(4) | macro-table id(8) Macro play(EEPROM) | ||
| 82 | 1 1 0 0| 1 1 1 1| macro-table id(8) Macro record | ||
| 83 | |||
| 84 | ACT_COMMAND(1110) | ||
| 85 | 1 1 1 0| option(4) | comamnd id(8) Built-in Command exec | ||
| 86 | |||
| 87 | ACT_FUNCTION(1111) | ||
| 88 | 1 1 1 1| function address(4K range) Function | ||
| 89 | Macro record(dynamicly) | ||
| 90 | Macro play(dynamicly) | ||
| 91 | */ | ||
| 92 | |||
| 93 | enum action_id { | ||
| 94 | ACT_LMODS = 0, | ||
| 95 | ACT_RMODS, | ||
| 96 | ACT_LMOD_TAP, | ||
| 97 | ACT_RMOD_TAP, | ||
| 98 | ACT_LAYER, | ||
| 99 | ACT_USAGE, | ||
| 100 | ACT_MOUSEKEY, | ||
| 101 | ACT_MACRO = 14, | ||
| 102 | ACT_COMMAND = 15, | ||
| 103 | ACT_FUNCTION = 16 | ||
| 104 | }; | ||
| 105 | |||
| 106 | // TODO: not portable across compiler/endianness? | ||
| 107 | /* | ||
| 108 | In avr-gcc bit fields seems to be assigned from LSB(bit0) to MSB(bit15). | ||
| 109 | AVR seems like little endian in avr-gcc. | ||
| 110 | |||
| 111 | Byte order and bit order of 0x1234: | ||
| 112 | Big endian: 15 ... 8 7 ... 210 | ||
| 113 | | 0x12 | 0x34 | | ||
| 114 | 0001 0010 0011 0100 | ||
| 115 | Little endian: 012 ... 7 8 ... 15 | ||
| 116 | | 0x34 | 0x12 | | ||
| 117 | 0010 1100 0100 1000 | ||
| 118 | */ | ||
| 119 | typedef union { | ||
| 120 | uint16_t code; | ||
| 121 | struct action_kind { | ||
| 122 | uint16_t param :12; | ||
| 123 | uint16_t id :4; | ||
| 124 | } kind; | ||
| 125 | struct action_key { | ||
| 126 | uint16_t code :8; | ||
| 127 | uint16_t mods :4; | ||
| 128 | uint16_t kind :4; | ||
| 129 | } key; | ||
| 130 | struct action_layer_key { | ||
| 131 | uint16_t code :8; | ||
| 132 | uint16_t layer :4; | ||
| 133 | uint16_t kind :4; | ||
| 134 | } layer_key; | ||
| 135 | struct action_layer_tap { | ||
| 136 | uint16_t count :3; | ||
| 137 | uint16_t rest :5; | ||
| 138 | uint16_t layer :4; | ||
| 139 | uint16_t kind :4; | ||
| 140 | } layer_tap; | ||
| 141 | struct action_usage { | ||
| 142 | uint16_t code :10; | ||
| 143 | uint16_t page :2; | ||
| 144 | uint16_t kind :4; | ||
| 145 | } usage; | ||
| 146 | struct action_command { | ||
| 147 | uint16_t id :8; | ||
| 148 | uint16_t option :4; | ||
| 149 | uint16_t kind :4; | ||
| 150 | } command; | ||
| 151 | } action_t; | ||
| 152 | |||
| 153 | |||
| 154 | enum stroke_cmd { | ||
| 155 | STROKE_DOWN, | ||
| 156 | STROKE_UP, | ||
| 157 | STROKE_ALLUP, /* release all keys in reverse order */ | ||
| 158 | }; | ||
| 159 | |||
| 160 | void action_exec(action_t act, keyevent_t event); | ||
| 161 | /* | ||
| 162 | void key_action(uint8_t code, keyevent_t event); | ||
| 163 | void mod_action(uint8_t code, keyevent_t event); | ||
| 164 | void fn_action(uint8_t code, keyevent_t event); | ||
| 165 | */ | ||
| 166 | |||
| 167 | |||
| 168 | /* action_t utility */ | ||
| 169 | #define ACTION(kind, param) { .code = ((kind)<<12 | (param)) } | ||
| 170 | #define NO_ACTION ACTION(0, 0) | ||
| 171 | #define LAYER_PARAM(layer, key) ((layer)<<8|(key)) | ||
| 172 | |||
| 173 | /* Key & Mods */ | ||
| 174 | #define ACTION_KEY(key) ACTION(ACT_LMODS, key) | ||
| 175 | #define ACTION_LMODS(mods) ACTION(ACT_LMODS, (mods)<<8 | 0x00) | ||
| 176 | #define ACTION_LMODS_KEY(mods, key) ACTION(ACT_LMODS, (mods)<<8 | (key)) | ||
| 177 | #define ACTION_LMODS_ONESHOT(mods) ACTION(ACT_LMODS, (mods)<<8 | 0x01) | ||
| 178 | #define ACTION_LMODS_SWITCH(mods, tap) ACTION(ACT_LMODS, (mods)<<8 | 0xF0 | (tap)) | ||
| 179 | #define ACTION_LMODS_TOGGLE(mods, tap) ACTION(ACT_LMODS, (mods)<<8 | 0xF1 | (tap)) | ||
| 180 | #define ACTION_RMODS(mods) ACTION(ACT_RMODS, (mods)<<8 | 0x00) | ||
| 181 | #define ACTION_RMODS_KEY(mods, key) ACTION(ACT_RMODS, (mods)<<8 | (key)) | ||
| 182 | #define ACTION_RMODS_ONESHOT(mods) ACTION(ACT_RMODS, (mods)<<8 | 0x01) | ||
| 183 | #define ACTION_RMODS_SWITCH(mods, tap) ACTION(ACT_RMODS, (mods)<<8 | 0xF0 | (tap)) | ||
| 184 | #define ACTION_RMODS_TOGGLE(mods, tap) ACTION(ACT_RMODS, (mods)<<8 | 0xF1 | (tap)) | ||
| 185 | /* Mods + Tap key */ | ||
| 186 | #define ACTION_LMODS_TAP(mods, key) ACTION(ACT_LMODS_TAP,(mods)<<8 | (key)) | ||
| 187 | #define ACTION_RMODS_TAP(mods, key) ACTION(ACT_RMODS_TAP,(mods)<<8 | (key)) | ||
| 188 | /* Layer Switch */ | ||
| 189 | #define ACTION_LAYER(layer) ACTION(ACT_LAYER, (layer)<<8 | 0x00) | ||
| 190 | #define ACTION_LAYER_ONESHOT(layer) ACTION(ACT_LAYER, (layer)<<8 | 0x01) | ||
| 191 | #define ACTION_LAYER_KEY(layer, key) ACTION(ACT_LAYER, (layer)<<8 | (key)) | ||
| 192 | #define ACTION_LAYER_SWITCH(layer, tap) ACTION(ACT_LAYER, (layer)<<8 | 0xF0 | (tap)) | ||
| 193 | #define ACTION_LAYER_TOGGLE(layer, tap) ACTION(ACT_LAYER, (layer)<<8 | 0xF1 | (tap)) | ||
| 194 | /* HID Usage */ | ||
| 195 | #define ACTION_USAGE_PAGE_SYSTEM 0 | ||
| 196 | #define ACTION_USAGE_PAGE_CONSUMER 1 | ||
| 197 | #define ACTION_USAGE_SYSTEM(id) ACTION(ACT_USAGE, ACTION_USAGE_PAGE_SYSTEM<<10 | (id)) | ||
| 198 | #define ACTION_USAGE_CONSUMER(id) ACTION(ACT_USAGE, ACTION_USAGE_PAGE_CONSUMER<<10 | (id)) | ||
| 199 | /* Mousekey */ | ||
| 200 | #define ACTION_MOUSEKEY(key) ACTION(ACT_MOUSEKEY, key) | ||
| 201 | /* Macro */ | ||
| 202 | #define ACTION_MACRO(opt, id) ACTION(ACT_FUNCTION, (opt)<<8 | (addr)) | ||
| 203 | /* Command */ | ||
| 204 | #define ACTION_COMMAND(opt, id) ACTION(ACT_COMMAND, (opt)<<8 | (addr)) | ||
| 205 | /* Function */ | ||
| 206 | #define ACTION_FUNCTION(addr) ACTION(ACT_FUNCTION, addr) | ||
| 207 | |||
| 208 | |||
| 209 | /* helpers for readability */ | ||
| 210 | #define LAYER(layer) (layer) | ||
| 211 | #define TAP(tap) (tap) | ||
| 212 | #define DOUBLE_TAP 2 | ||
| 213 | #define TRIPLE_TAP 3 | ||
| 214 | #define QUADRUPLE_TAP 4 | ||
| 215 | #define QUINTUPLE_TAP 5 | ||
| 216 | #define DOWN(key) (key) | ||
| 217 | #define UP(key) STROKE_UP, (key) | ||
| 218 | |||
| 219 | #endif /* ACTION_H */ | ||
