diff options
| author | tmk <nobody@nowhere> | 2013-01-09 22:33:33 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-01-09 22:33:33 +0900 |
| commit | 411de9cc22e927313a5a768f3bf41f2f99bca126 (patch) | |
| tree | cff699c11ec293df8375566e7a3d186712e72e74 /common/action.h | |
| parent | 4324e163360db4c6ebd25cab74d09d42b3021278 (diff) | |
| download | qmk_firmware-411de9cc22e927313a5a768f3bf41f2f99bca126.tar.gz qmk_firmware-411de9cc22e927313a5a768f3bf41f2f99bca126.zip | |
Add new layer actions.
Diffstat (limited to 'common/action.h')
| -rw-r--r-- | common/action.h | 152 |
1 files changed, 91 insertions, 61 deletions
diff --git a/common/action.h b/common/action.h index 08f8c5608..942ce191a 100644 --- a/common/action.h +++ b/common/action.h | |||
| @@ -15,10 +15,6 @@ ACT_LMODS(0000) | |||
| 15 | 0 0 0 0| mods(4) | 0 0 0 0 0 0| 1 0 (reserved) | 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) | 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 | 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 | 18 | ||
| 23 | ACT_RMODS(0001) | 19 | ACT_RMODS(0001) |
| 24 | 0 0 0 1| 0 0 0 0| 0 0 0 0 0 0 0 0 No action(not used) | 20 | 0 0 0 1| 0 0 0 0| 0 0 0 0 0 0 0 0 No action(not used) |
| @@ -28,10 +24,6 @@ ACT_RMODS(0001) | |||
| 28 | 0 0 0 1| mods(4) | 0 0 0 0 0 0| 1 0 (reserved) | 24 | 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) | 25 | 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 | 26 | 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 | 27 | ||
| 36 | ACT_LMODS_TAP(0010) | 28 | ACT_LMODS_TAP(0010) |
| 37 | 0 0 1 0| 0 0 0 0| X X X X X X X X (reserved)[00-FF] | 29 | 0 0 1 0| 0 0 0 0| X X X X X X X X (reserved)[00-FF] |
| @@ -45,36 +37,47 @@ ACT_RMODS_TAP(0011) | |||
| 45 | 0 0 1 1| mods(4) | keycode(8) Rmods+tap Key | 37 | 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] | 38 | 0 0 1 1| mods(4) | 1 1 1 1| X X X X (reserved)[F0-FF] |
| 47 | 39 | ||
| 48 | ACT_LAYER(0100) | 40 | ACT_USAGE - other HID usage than keyboard |
| 49 | 0 1 0 0| layer(4) | 0 0 0 0 0 0| 0 0 Momentary | 41 | 0 1 0 0| 0 0| usage(10) System usage |
| 50 | 0 1 0 0| layer(4) | 0 0 0 0 0 0| 0 1 Oneshot | 42 | 0 1 0 0| 0 1| usage(10) Consumer usage |
| 51 | 0 1 0 0| layer(4) | 0 0 0 0 0 0| 1 0 (reserved) | 43 | 0 1 0 0| 1 0| usage(10) (reserved) |
| 52 | 0 1 0 0| layer(4) | 0 0 0 0 0 0| 1 1 (reserved) | 44 | 0 1 0 0| 1 1| usage(10) (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 | 45 | ||
| 63 | ACT_MOUSEKEY(0110) | 46 | ACT_MOUSEKEY(0110) |
| 64 | 0 1 1 0| X X X X| keycode(8) Mouse key | 47 | 0 1 0 1| X X X X| keycode(8) Mouse key |
| 65 | ??? TODO: refactor | 48 | ??? TODO: refactor |
| 66 | 0 1 1 0| 0 0 X X| accel(5) |cursor(3) Mouse key | 49 | 0 1 0 1| 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 | 50 | 0 1 0 1| 0 1 X X| accel(5) |wheel(3) Mouse key |
| 68 | 0 1 1 0| 1 0 X X| button(8) Mouse key | 51 | 0 1 0 1| 1 0 X X| button(8) Mouse key |
| 69 | 0 1 1 0| 1 1 X X| button(8) Mouse key | 52 | 0 1 0 1| 1 1 X X| button(8) Mouse key |
| 70 | ??? | 53 | ??? |
| 71 | 54 | ||
| 72 | 0 1 1 1| (reserved) | 55 | Layer Action |
| 73 | 1 0 0 0| (reserved) | 56 | ------------ |
| 74 | 1 0 0 1| (reserved) | 57 | 1000|LLLL|0000 0000 set layer L when pressed |
| 75 | 1 0 1 0| (reserved) | 58 | 1001|LLLL|0000 0000 set layer L when released |
| 76 | 1 0 1 1| (reserved) | 59 | 1010|BBBB|0000 0000 on/off bit B when pressed/released |
| 77 | 1 1 0 0| (reserved) | 60 | 1011|0000|0000 0000 set default layer when pressed |
| 61 | 1011|0001|0000 0000 set default layer when released | ||
| 62 | |||
| 63 | 1000|LLLL|1111 0000 set layer L when pressed + tap toggle | ||
| 64 | 1001|LLLL|1111 0000 set layer L when released[tap is ignored/not used] | ||
| 65 | 1010|BBBB|1111 0000 on/off bit B when pressed/released + tap toggle | ||
| 66 | 1011|0000|1111 0000 set default layer when pressed + tap toggle | ||
| 67 | 1011|0001|1111 0000 set default layer when released[tap is ignored/not used] | ||
| 68 | |||
| 69 | 1000|LLLL|1111 1111 set L to default layer when pressed | ||
| 70 | 1001|LLLL|1111 1111 set L to default layer when released | ||
| 71 | 1010|BBBB|1111 1111 on/off bit B of default layer when pressed/released | ||
| 72 | 1011|0000|1111 1111 set current to default layer when pressed | ||
| 73 | 1011|0001|1111 1111 set current to default layer when released | ||
| 74 | |||
| 75 | 1000|LLLL| keycode set layer L when pressed + tap key | ||
| 76 | 1001|LLLL| keyocde set layer L when released[tap is ignored/not used] | ||
| 77 | 1010|BBBB| keyocde on/off bit B when pressed/released + tap key | ||
| 78 | 1011|0000| keyocde set default layer when pressed + tap key | ||
| 79 | 1011|0001| keyocde set default layer when released[tap is ignored/not used] | ||
| 80 | |||
| 78 | 81 | ||
| 79 | ACT_MACRO(1100) | 82 | ACT_MACRO(1100) |
| 80 | 1 1 0 0| option(4) | macro-table id(8) Macro play(Flash) | 83 | 1 1 0 0| option(4) | macro-table id(8) Macro play(Flash) |
| @@ -88,25 +91,32 @@ ACT_FUNCTION(1111) | |||
| 88 | 1 1 1 1| function address(4K range) Function | 91 | 1 1 1 1| function address(4K range) Function |
| 89 | Macro record(dynamicly) | 92 | Macro record(dynamicly) |
| 90 | Macro play(dynamicly) | 93 | Macro play(dynamicly) |
| 94 | TODO: modifier + [tap key /w mod] | ||
| 95 | : layerkey + [tap key /w mod] | ||
| 96 | for example: LShift + '('[Shift+9] and RShift + ')'[Shift+0] | ||
| 97 | http://deskthority.net/workshop-f7/tmk-keyboard-firmware-collection-t4478.html#p90052 | ||
| 91 | */ | 98 | */ |
| 92 | 99 | ||
| 93 | enum action_id { | 100 | enum action_id { |
| 94 | ACT_LMODS = 0, | 101 | ACT_LMODS = 0b0000, |
| 95 | ACT_RMODS, | 102 | ACT_RMODS = 0b0001, |
| 96 | ACT_LMOD_TAP, | 103 | ACT_LMOD_TAP = 0b0010, |
| 97 | ACT_RMOD_TAP, | 104 | ACT_RMOD_TAP = 0b0011, |
| 98 | ACT_LAYER, | 105 | ACT_USAGE = 0b0100, |
| 99 | ACT_USAGE, | 106 | ACT_MOUSEKEY = 0b0101, |
| 100 | ACT_MOUSEKEY, | 107 | ACT_LAYER_PRESSED = 0b1000, |
| 101 | ACT_MACRO = 14, | 108 | ACT_LAYER_RELEASED = 0b1001, |
| 102 | ACT_COMMAND = 15, | 109 | ACT_LAYER_BIT = 0b1010, |
| 103 | ACT_FUNCTION = 16 | 110 | ACT_LAYER_EXT = 0b1011, |
| 111 | ACT_MACRO = 0b1100, | ||
| 112 | ACT_COMMAND = 0b1110, | ||
| 113 | ACT_FUNCTION = 0b1111 | ||
| 104 | }; | 114 | }; |
| 105 | 115 | ||
| 106 | // TODO: not portable across compiler/endianness? | 116 | // TODO: not portable across compiler/endianness? |
| 107 | /* | 117 | /* |
| 108 | In avr-gcc bit fields seems to be assigned from LSB(bit0) to MSB(bit15). | 118 | In avr-gcc bit fields seems to be assigned from LSB(bit0) to MSB(bit15). |
| 109 | AVR seems like little endian in avr-gcc. | 119 | AVR looks like a little endian in avr-gcc. |
| 110 | 120 | ||
| 111 | Byte order and bit order of 0x1234: | 121 | Byte order and bit order of 0x1234: |
| 112 | Big endian: 15 ... 8 7 ... 210 | 122 | Big endian: 15 ... 8 7 ... 210 |
| @@ -127,17 +137,11 @@ typedef union { | |||
| 127 | uint16_t mods :4; | 137 | uint16_t mods :4; |
| 128 | uint16_t kind :4; | 138 | uint16_t kind :4; |
| 129 | } key; | 139 | } key; |
| 130 | struct action_layer_key { | 140 | struct action_layer { |
| 131 | uint16_t code :8; | 141 | uint16_t code :8; |
| 132 | uint16_t layer :4; | 142 | uint16_t opt :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; | 143 | uint16_t kind :4; |
| 140 | } layer_tap; | 144 | } layer; |
| 141 | struct action_usage { | 145 | struct action_usage { |
| 142 | uint16_t code :10; | 146 | uint16_t code :10; |
| 143 | uint16_t page :2; | 147 | uint16_t page :2; |
| @@ -157,7 +161,14 @@ enum stroke_cmd { | |||
| 157 | STROKE_ALLUP, /* release all keys in reverse order */ | 161 | STROKE_ALLUP, /* release all keys in reverse order */ |
| 158 | }; | 162 | }; |
| 159 | 163 | ||
| 160 | void action_exec(action_t act, keyevent_t event); | 164 | typedef struct { |
| 165 | keyevent_t event; | ||
| 166 | action_t action; | ||
| 167 | uint8_t mods; | ||
| 168 | } keyrecord_t; | ||
| 169 | |||
| 170 | |||
| 171 | void action_exec(keyevent_t event); | ||
| 161 | /* | 172 | /* |
| 162 | void key_action(uint8_t code, keyevent_t event); | 173 | void key_action(uint8_t code, keyevent_t event); |
| 163 | void mod_action(uint8_t code, keyevent_t event); | 174 | void mod_action(uint8_t code, keyevent_t event); |
| @@ -166,9 +177,12 @@ void fn_action(uint8_t code, keyevent_t event); | |||
| 166 | 177 | ||
| 167 | 178 | ||
| 168 | /* action_t utility */ | 179 | /* action_t utility */ |
| 180 | /* | ||
| 181 | #define ACTION_NO { .code = 0 } | ||
| 169 | #define ACTION(kind, param) { .code = ((kind)<<12 | (param)) } | 182 | #define ACTION(kind, param) { .code = ((kind)<<12 | (param)) } |
| 170 | #define NO_ACTION ACTION(0, 0) | 183 | */ |
| 171 | #define LAYER_PARAM(layer, key) ((layer)<<8|(key)) | 184 | #define ACTION_NO 0 |
| 185 | #define ACTION(kind, param) ((kind)<<12 | (param)) | ||
| 172 | 186 | ||
| 173 | /* Key & Mods */ | 187 | /* Key & Mods */ |
| 174 | #define ACTION_KEY(key) ACTION(ACT_LMODS, key) | 188 | #define ACTION_KEY(key) ACTION(ACT_LMODS, key) |
| @@ -185,12 +199,28 @@ void fn_action(uint8_t code, keyevent_t event); | |||
| 185 | /* Mods + Tap key */ | 199 | /* Mods + Tap key */ |
| 186 | #define ACTION_LMODS_TAP(mods, key) ACTION(ACT_LMODS_TAP,(mods)<<8 | (key)) | 200 | #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)) | 201 | #define ACTION_RMODS_TAP(mods, key) ACTION(ACT_RMODS_TAP,(mods)<<8 | (key)) |
| 202 | |||
| 188 | /* Layer Switch */ | 203 | /* Layer Switch */ |
| 189 | #define ACTION_LAYER(layer) ACTION(ACT_LAYER, (layer)<<8 | 0x00) | 204 | #define ACTION_LAYER_SET_ON_PRESSED(layer) ACTION(ACT_LAYER_PRESSED, (layer)<<8 | 0x00) |
| 190 | #define ACTION_LAYER_ONESHOT(layer) ACTION(ACT_LAYER, (layer)<<8 | 0x01) | 205 | #define ACTION_LAYER_SET_ON_RELEASED(layer) ACTION(ACT_LAYER_RELEASED, (layer)<<8 | 0x00) |
| 191 | #define ACTION_LAYER_KEY(layer, key) ACTION(ACT_LAYER, (layer)<<8 | (key)) | 206 | #define ACTION_LAYER_BIT(bits) ACTION(ACT_LAYER_BIT, (layer)<<8 | 0x00) |
| 192 | #define ACTION_LAYER_SWITCH(layer, tap) ACTION(ACT_LAYER, (layer)<<8 | 0xF0 | (tap)) | 207 | #define ACTION_LAYER_TO_DEFAULT_ON_PRESSED ACTION(ACT_LAYER_EXT, 0x0<<8 | 0x00) |
| 193 | #define ACTION_LAYER_TOGGLE(layer, tap) ACTION(ACT_LAYER, (layer)<<8 | 0xF1 | (tap)) | 208 | #define ACTION_LAYER_TO_DEFAULT_ON_RELEASED ACTION(ACT_LAYER_EXT, 0x1<<8 | 0x00) |
| 209 | |||
| 210 | #define ACTION_LAYER_TAP_TOGGLE(layer) ACTION(ACT_LAYER_PRESSED, (layer)<<8 | 0xF0) | ||
| 211 | #define ACTION_LAYER_BIT_TAP_TOGGLE(layer) ACTION(ACT_LAYER_BIT, (layer)<<8 | 0xF0) | ||
| 212 | #define ACTION_LAYER_DEFAULT_TAP_TOGGLE ACTION(ACT_LAYER_EXT, 0x0<<8 | 0xF0) | ||
| 213 | |||
| 214 | #define ACTION_LAYER_DEFAULT_SET_ON_PRESSED(layer) ACTION(ACT_LAYER_PRESSED, (layer)<<8 | 0xFF) | ||
| 215 | #define ACTION_LAYER_DEFAULT_SET_ON_RELEASED(layer) ACTION(ACT_LAYER_RELEASED, (layer)<<8 | 0xFF) | ||
| 216 | #define ACTION_LAYER_DEFAULT_BIT(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | 0xFF) | ||
| 217 | #define ACTION_LAYER_DEFAULT_SET_CURRENT_ON_PRESSED ACTION(ACT_LAYER_EXT, 0x0<<8 | 0xFF) | ||
| 218 | #define ACTION_LAYER_DEFAULT_SET_CURRENT_ON_RELEASED ACTION(ACT_LAYER_EXT, 0x1<<8 | 0xFF) | ||
| 219 | |||
| 220 | #define ACTION_LAYER_SET_TAP_KEY(layer, key) ACTION(ACT_LAYER_PRESSED, (layer)<<8 | (key)) | ||
| 221 | #define ACTION_LAYER_BIT_TAP_KEY(bits, key) ACTION(ACT_LAYER_BIT, (layer)<<8 | (key)) | ||
| 222 | #define ACTION_LAYER_DEFAULT_SET_TAP_KEY(key) ACTION(ACT_LAYER_EXT, 0x0<<8 | (key)) | ||
| 223 | |||
| 194 | /* HID Usage */ | 224 | /* HID Usage */ |
| 195 | #define ACTION_USAGE_PAGE_SYSTEM 0 | 225 | #define ACTION_USAGE_PAGE_SYSTEM 0 |
| 196 | #define ACTION_USAGE_PAGE_CONSUMER 1 | 226 | #define ACTION_USAGE_PAGE_CONSUMER 1 |
