diff options
| author | tmk <nobody@nowhere> | 2013-01-27 16:38:19 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-01-27 16:38:19 +0900 |
| commit | bfd7fe586297d70f824a402fd476c3daa889fa56 (patch) | |
| tree | c903d4a878aa7317ca3c2bb62ece03fdb745d51b /common/action.h | |
| parent | 66d5dd284271d85da4c161529e12526b50b0f71d (diff) | |
| download | qmk_firmware-bfd7fe586297d70f824a402fd476c3daa889fa56.tar.gz qmk_firmware-bfd7fe586297d70f824a402fd476c3daa889fa56.zip | |
Add oneshot modifier action.
Diffstat (limited to 'common/action.h')
| -rw-r--r-- | common/action.h | 198 |
1 files changed, 95 insertions, 103 deletions
diff --git a/common/action.h b/common/action.h index 327a009ef..1b5b30d86 100644 --- a/common/action.h +++ b/common/action.h | |||
| @@ -3,10 +3,79 @@ | |||
| 3 | 3 | ||
| 4 | #include "keyboard.h" | 4 | #include "keyboard.h" |
| 5 | 5 | ||
| 6 | |||
| 7 | /* Action struct. | ||
| 8 | * | ||
| 9 | * In avr-gcc bit field seems to be assigned from LSB(bit0) to MSB(bit15). | ||
| 10 | * AVR looks like a little endian in avr-gcc. | ||
| 11 | * | ||
| 12 | * TODO: not portable across compiler/endianness? | ||
| 13 | * Byte order and bit order of 0x1234: | ||
| 14 | * Big endian: 15 ... 8 7 ... 210 | ||
| 15 | * | 0x12 | 0x34 | | ||
| 16 | * 0001 0010 0011 0100 | ||
| 17 | * Little endian: 012 ... 7 8 ... 15 | ||
| 18 | * | 0x34 | 0x12 | | ||
| 19 | * 0010 1100 0100 1000 | ||
| 20 | */ | ||
| 21 | typedef union { | ||
| 22 | uint16_t code; | ||
| 23 | struct action_kind { | ||
| 24 | uint16_t param :12; | ||
| 25 | uint16_t id :4; | ||
| 26 | } kind; | ||
| 27 | struct action_key { | ||
| 28 | uint16_t code :8; | ||
| 29 | uint16_t mods :4; | ||
| 30 | uint16_t kind :4; | ||
| 31 | } key; | ||
| 32 | struct action_layer { | ||
| 33 | uint16_t code :8; | ||
| 34 | uint16_t opt :4; | ||
| 35 | uint16_t kind :4; | ||
| 36 | } layer; | ||
| 37 | struct action_usage { | ||
| 38 | uint16_t code :10; | ||
| 39 | uint16_t page :2; | ||
| 40 | uint16_t kind :4; | ||
| 41 | } usage; | ||
| 42 | struct action_command { | ||
| 43 | uint16_t id :8; | ||
| 44 | uint16_t option :4; | ||
| 45 | uint16_t kind :4; | ||
| 46 | } command; | ||
| 47 | struct action_function { | ||
| 48 | uint8_t id :8; | ||
| 49 | uint8_t opt :4; | ||
| 50 | uint8_t kind :4; | ||
| 51 | } func; | ||
| 52 | } action_t; | ||
| 53 | |||
| 54 | /* Action record. For internal use. */ | ||
| 55 | typedef struct { | ||
| 56 | keyevent_t event; | ||
| 57 | uint8_t tap_count; | ||
| 58 | } keyrecord_t; | ||
| 59 | |||
| 60 | |||
| 61 | /* Tap count: Tap is comprised of press and release within TAP_TERM. | ||
| 62 | * 0 means no tap. | ||
| 63 | * >1 means tap. | ||
| 64 | */ | ||
| 6 | extern uint8_t tap_count; | 65 | extern uint8_t tap_count; |
| 66 | |||
| 67 | /* current tap key event */ | ||
| 7 | extern keyevent_t tapping_event; | 68 | extern keyevent_t tapping_event; |
| 8 | 69 | ||
| 9 | 70 | ||
| 71 | /* action function */ | ||
| 72 | typedef void (*action_func_t)(keyevent_t event, uint8_t opt); | ||
| 73 | |||
| 74 | // TODO: legacy keymap support | ||
| 75 | void action_exec(keyevent_t event); | ||
| 76 | void action_call_function(keyevent_t event, uint8_t id); | ||
| 77 | |||
| 78 | |||
| 10 | /* | 79 | /* |
| 11 | * Utilities for actions. | 80 | * Utilities for actions. |
| 12 | */ | 81 | */ |
| @@ -25,33 +94,36 @@ bool is_tap_key(key_t key); | |||
| 25 | 94 | ||
| 26 | 95 | ||
| 27 | /* | 96 | /* |
| 28 | Action codes | 97 | * Action codes |
| 29 | 16bit code: action_kind(4bit) + action_parameter(12bit) | 98 | * ============ |
| 30 | 99 | * 16bit code: action_kind(4bit) + action_parameter(12bit) | |
| 100 | * | ||
| 31 | Keyboard Keys | 101 | Keyboard Keys |
| 32 | ------------- | 102 | ------------- |
| 33 | ACT_LMODS(0000): | 103 | ACT_LMODS(0000): |
| 34 | 0000|0000|000000|00 No action | 104 | 0000|0000|000000|00 No action |
| 35 | 0000|mods|000000|00 Left mods Momentary | ||
| 36 | 0000|mods|000000|01 Left mods OneShot | ||
| 37 | 0000|mods|000000|10 (reserved) | ||
| 38 | 0000|mods|000000|11 (reserved) | ||
| 39 | 0000|0000| keycode Key | 105 | 0000|0000| keycode Key |
| 106 | 0010|mods|000000|00 Left mods Momentary | ||
| 40 | 0000|mods| keycode Key+Left mods | 107 | 0000|mods| keycode Key+Left mods |
| 41 | 108 | ||
| 42 | ACT_RMODS(0001): | 109 | ACT_RMODS(0001): |
| 43 | 0001|0000|000000|00 No action | 110 | 0001|0000|000000|00 No action |
| 111 | 0001|0000| keycode Key(no used) | ||
| 44 | 0001|mods|000000|00 Right mods Momentary | 112 | 0001|mods|000000|00 Right mods Momentary |
| 45 | 0001|mods|000000|01 Right mods OneShot | ||
| 46 | 0001|mods|000000|10 (reserved) | ||
| 47 | 0001|mods|000000|11 (reserved) | ||
| 48 | 0001|0000| keycode Key | ||
| 49 | 0001|mods| keycode Key+Right mods | 113 | 0001|mods| keycode Key+Right mods |
| 50 | 114 | ||
| 51 | ACT_LMODS_TAP(0010): | 115 | ACT_LMODS_TAP(0010): |
| 116 | 0010|mods|000000|00 Left mods OneShot | ||
| 117 | 0010|mods|000000|01 (reserved) | ||
| 118 | 0010|mods|000000|10 (reserved) | ||
| 119 | 0010|mods|000000|11 (reserved) | ||
| 52 | 0010|mods| keycode Left mods+tap Key | 120 | 0010|mods| keycode Left mods+tap Key |
| 53 | 121 | ||
| 54 | ACT_RMODS_TAP(0011): | 122 | ACT_RMODS_TAP(0011): |
| 123 | 0011|mods|000000|00 Right mods OneShot | ||
| 124 | 0011|mods|000000|01 (reserved) | ||
| 125 | 0011|mods|000000|10 (reserved) | ||
| 126 | 0011|mods|000000|11 (reserved) | ||
| 55 | 0011|mods| keycode Right mods+tap Key | 127 | 0011|mods| keycode Right mods+tap Key |
| 56 | 128 | ||
| 57 | 129 | ||
| @@ -108,24 +180,22 @@ Extensions(11XX) | |||
| 108 | NOTE: NOT FIXED | 180 | NOTE: NOT FIXED |
| 109 | 181 | ||
| 110 | ACT_MACRO(1100): | 182 | ACT_MACRO(1100): |
| 111 | 1100|opt | id(8) Macro play | 183 | 1100|opt | id(8) Macro play? |
| 112 | 1100|1111| id(8) Macro record | 184 | 1100|1111| id(8) Macro record? |
| 113 | 185 | ||
| 114 | ACT_COMMAND(1110): | 186 | ACT_COMMAND(1110): |
| 115 | 1110|opt | id(8) Built-in Command exec | 187 | 1110|opt | id(8) Built-in Command exec |
| 116 | 188 | ||
| 117 | ACT_FUNCTION(1111): | 189 | ACT_FUNCTION(1111): |
| 118 | 1111| address(12) Function | 190 | 1111| address(12) Function? |
| 119 | 1111|opt | id(8) Function | 191 | 1111|opt | id(8) Function? |
| 120 | Macro record(dynamicly) | 192 | |
| 121 | Macro play(dynamicly) | 193 | TODO: modifier + function by tap? |
| 122 | TODO: modifier + [tap key /w mod] | ||
| 123 | : layerkey + [tap key /w mod] | ||
| 124 | for example: LShift + '('[Shift+9] and RShift + ')'[Shift+0] | 194 | for example: LShift + '('[Shift+9] and RShift + ')'[Shift+0] |
| 125 | http://deskthority.net/workshop-f7/tmk-keyboard-firmware-collection-t4478.html#p90052 | 195 | http://deskthority.net/workshop-f7/tmk-keyboard-firmware-collection-t4478.html#p90052 |
| 126 | */ | 196 | */ |
| 127 | 197 | ||
| 128 | enum action_id { | 198 | enum action_kind_id { |
| 129 | ACT_LMODS = 0b0000, | 199 | ACT_LMODS = 0b0000, |
| 130 | ACT_RMODS = 0b0001, | 200 | ACT_RMODS = 0b0001, |
| 131 | ACT_LMODS_TAP = 0b0010, | 201 | ACT_LMODS_TAP = 0b0010, |
| @@ -144,74 +214,11 @@ enum action_id { | |||
| 144 | ACT_FUNCTION = 0b1111 | 214 | ACT_FUNCTION = 0b1111 |
| 145 | }; | 215 | }; |
| 146 | 216 | ||
| 147 | // TODO: not portable across compiler/endianness? | 217 | enum acion_param { |
| 148 | /* | 218 | ONE_SHOT = 0x00, |
| 149 | In avr-gcc bit fields seems to be assigned from LSB(bit0) to MSB(bit15). | ||
| 150 | AVR looks like a little endian in avr-gcc. | ||
| 151 | |||
| 152 | Byte order and bit order of 0x1234: | ||
| 153 | Big endian: 15 ... 8 7 ... 210 | ||
| 154 | | 0x12 | 0x34 | | ||
| 155 | 0001 0010 0011 0100 | ||
| 156 | Little endian: 012 ... 7 8 ... 15 | ||
| 157 | | 0x34 | 0x12 | | ||
| 158 | 0010 1100 0100 1000 | ||
| 159 | */ | ||
| 160 | typedef union { | ||
| 161 | uint16_t code; | ||
| 162 | struct action_kind { | ||
| 163 | uint16_t param :12; | ||
| 164 | uint16_t id :4; | ||
| 165 | } kind; | ||
| 166 | struct action_key { | ||
| 167 | uint16_t code :8; | ||
| 168 | uint16_t mods :4; | ||
| 169 | uint16_t kind :4; | ||
| 170 | } key; | ||
| 171 | struct action_layer { | ||
| 172 | uint16_t code :8; | ||
| 173 | uint16_t opt :4; | ||
| 174 | uint16_t kind :4; | ||
| 175 | } layer; | ||
| 176 | struct action_usage { | ||
| 177 | uint16_t code :10; | ||
| 178 | uint16_t page :2; | ||
| 179 | uint16_t kind :4; | ||
| 180 | } usage; | ||
| 181 | struct action_command { | ||
| 182 | uint16_t id :8; | ||
| 183 | uint16_t option :4; | ||
| 184 | uint16_t kind :4; | ||
| 185 | } command; | ||
| 186 | struct action_function { | ||
| 187 | uint8_t id :8; | ||
| 188 | uint8_t opt :4; | ||
| 189 | uint8_t kind :4; | ||
| 190 | } func; | ||
| 191 | } action_t; | ||
| 192 | |||
| 193 | |||
| 194 | enum stroke_cmd { | ||
| 195 | STROKE_DOWN, | ||
| 196 | STROKE_UP, | ||
| 197 | STROKE_ALLUP, /* release all keys in reverse order */ | ||
| 198 | }; | 219 | }; |
| 199 | 220 | ||
| 200 | typedef struct { | ||
| 201 | keyevent_t event; | ||
| 202 | uint8_t tap_count; | ||
| 203 | } keyrecord_t; | ||
| 204 | |||
| 205 | /* action function */ | ||
| 206 | typedef void (*action_func_t)(keyevent_t event, uint8_t opt); | ||
| 207 | 221 | ||
| 208 | |||
| 209 | // TODO: legacy keymap support | ||
| 210 | void action_exec(keyevent_t event); | ||
| 211 | void action_call_function(keyevent_t event, uint8_t id); | ||
| 212 | |||
| 213 | |||
| 214 | // TODO: proper names | ||
| 215 | /* action_t utility */ | 222 | /* action_t utility */ |
| 216 | #define ACTION_NO 0 | 223 | #define ACTION_NO 0 |
| 217 | #define ACTION(kind, param) ((kind)<<12 | (param)) | 224 | #define ACTION(kind, param) ((kind)<<12 | (param)) |
| @@ -221,16 +228,12 @@ void action_call_function(keyevent_t event, uint8_t id); | |||
| 221 | #define ACTION_KEY(key) ACTION(ACT_LMODS, key) | 228 | #define ACTION_KEY(key) ACTION(ACT_LMODS, key) |
| 222 | #define ACTION_LMODS(mods) ACTION(ACT_LMODS, (mods)<<8 | 0x00) | 229 | #define ACTION_LMODS(mods) ACTION(ACT_LMODS, (mods)<<8 | 0x00) |
| 223 | #define ACTION_LMODS_KEY(mods, key) ACTION(ACT_LMODS, (mods)<<8 | (key)) | 230 | #define ACTION_LMODS_KEY(mods, key) ACTION(ACT_LMODS, (mods)<<8 | (key)) |
| 224 | #define ACTION_LMODS_ONESHOT(mods) ACTION(ACT_LMODS, (mods)<<8 | 0x01) | ||
| 225 | #define ACTION_LMODS_SWITCH(mods, tap) ACTION(ACT_LMODS, (mods)<<8 | 0xF0 | (tap)) | ||
| 226 | #define ACTION_LMODS_TOGGLE(mods, tap) ACTION(ACT_LMODS, (mods)<<8 | 0xF1 | (tap)) | ||
| 227 | #define ACTION_RMODS(mods) ACTION(ACT_RMODS, (mods)<<8 | 0x00) | 231 | #define ACTION_RMODS(mods) ACTION(ACT_RMODS, (mods)<<8 | 0x00) |
| 228 | #define ACTION_RMODS_KEY(mods, key) ACTION(ACT_RMODS, (mods)<<8 | (key)) | 232 | #define ACTION_RMODS_KEY(mods, key) ACTION(ACT_RMODS, (mods)<<8 | (key)) |
| 229 | #define ACTION_RMODS_ONESHOT(mods) ACTION(ACT_RMODS, (mods)<<8 | 0x01) | 233 | |
| 230 | #define ACTION_RMODS_SWITCH(mods, tap) ACTION(ACT_RMODS, (mods)<<8 | 0xF0 | (tap)) | ||
| 231 | #define ACTION_RMODS_TOGGLE(mods, tap) ACTION(ACT_RMODS, (mods)<<8 | 0xF1 | (tap)) | ||
| 232 | /* Mods + Tap key */ | 234 | /* Mods + Tap key */ |
| 233 | #define ACTION_LMODS_TAP(mods, key) ACTION(ACT_LMODS_TAP, MOD_BITS(mods)<<8 | (key)) | 235 | #define ACTION_LMODS_TAP(mods, key) ACTION(ACT_LMODS_TAP, MOD_BITS(mods)<<8 | (key)) |
| 236 | #define ACTION_LMODS_ONESHOT(mods) ACTION(ACT_LMODS_TAP, MOD_BITS(mods)<<8 | ONE_SHOT) | ||
| 234 | #define ACTION_RMODS_TAP(mods, key) ACTION(ACT_RMODS_TAP, MOD_BITS(mods)<<8 | (key)) | 237 | #define ACTION_RMODS_TAP(mods, key) ACTION(ACT_RMODS_TAP, MOD_BITS(mods)<<8 | (key)) |
| 235 | 238 | ||
| 236 | /* Layer Switch */ | 239 | /* Layer Switch */ |
| @@ -268,15 +271,4 @@ void action_call_function(keyevent_t event, uint8_t id); | |||
| 268 | /* Function */ | 271 | /* Function */ |
| 269 | #define ACTION_FUNCTION(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | id) | 272 | #define ACTION_FUNCTION(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | id) |
| 270 | 273 | ||
| 271 | |||
| 272 | /* helpers for readability */ | ||
| 273 | #define LAYER(layer) (layer) | ||
| 274 | #define TAP(tap) (tap) | ||
| 275 | #define DOUBLE_TAP 2 | ||
| 276 | #define TRIPLE_TAP 3 | ||
| 277 | #define QUADRUPLE_TAP 4 | ||
| 278 | #define QUINTUPLE_TAP 5 | ||
| 279 | #define DOWN(key) (key) | ||
| 280 | #define UP(key) STROKE_UP, (key) | ||
| 281 | |||
| 282 | #endif /* ACTION_H */ | 274 | #endif /* ACTION_H */ |
