diff options
Diffstat (limited to 'common/action.h')
| -rw-r--r-- | common/action.h | 200 |
1 files changed, 105 insertions, 95 deletions
diff --git a/common/action.h b/common/action.h index bb44049ad..b9a6cb5b4 100644 --- a/common/action.h +++ b/common/action.h | |||
| @@ -21,10 +21,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 21 | #include "keycode.h" | 21 | #include "keycode.h" |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | /* Execute action per keyevent */ | ||
| 25 | void action_exec(keyevent_t event); | ||
| 26 | |||
| 27 | |||
| 28 | /* Struct to record event and tap count */ | 24 | /* Struct to record event and tap count */ |
| 29 | typedef struct { | 25 | typedef struct { |
| 30 | keyevent_t event; | 26 | keyevent_t event; |
| @@ -33,7 +29,7 @@ typedef struct { | |||
| 33 | 29 | ||
| 34 | /* Action struct. | 30 | /* Action struct. |
| 35 | * | 31 | * |
| 36 | * In avr-gcc bit field seems to be assigned from LSB(bit0) to MSB(bit15). | 32 | * In avr-gcc bit field seems to be assigned from LSB(bit0) to MSB(bit15). |
| 37 | * AVR looks like a little endian in avr-gcc. | 33 | * AVR looks like a little endian in avr-gcc. |
| 38 | * | 34 | * |
| 39 | * NOTE: not portable across compiler/endianness? | 35 | * NOTE: not portable across compiler/endianness? |
| @@ -79,6 +75,21 @@ typedef union { | |||
| 79 | } action_t; | 75 | } action_t; |
| 80 | 76 | ||
| 81 | 77 | ||
| 78 | |||
| 79 | /* layer used currently */ | ||
| 80 | extern uint8_t current_layer; | ||
| 81 | /* layer to return or start with */ | ||
| 82 | extern uint8_t default_layer; | ||
| 83 | |||
| 84 | /* Execute action per keyevent */ | ||
| 85 | void action_exec(keyevent_t event); | ||
| 86 | |||
| 87 | /* action for key */ | ||
| 88 | action_t action_for_key(uint8_t layer, key_t key); | ||
| 89 | |||
| 90 | /* user defined special function */ | ||
| 91 | void action_function(keyrecord_t *record, uint8_t id, uint8_t opt); | ||
| 92 | |||
| 82 | /* | 93 | /* |
| 83 | * Utilities for actions. | 94 | * Utilities for actions. |
| 84 | */ | 95 | */ |
| @@ -96,98 +107,97 @@ bool waiting_buffer_has_anykey_pressed(void); | |||
| 96 | 107 | ||
| 97 | 108 | ||
| 98 | 109 | ||
| 99 | |||
| 100 | /* | 110 | /* |
| 101 | * Action codes | 111 | * Action codes |
| 102 | * ============ | 112 | * ============ |
| 103 | * 16bit code: action_kind(4bit) + action_parameter(12bit) | 113 | * 16bit code: action_kind(4bit) + action_parameter(12bit) |
| 104 | * | 114 | * |
| 105 | Keyboard Keys | 115 | * Keyboard Keys |
| 106 | ------------- | 116 | * ------------- |
| 107 | ACT_LMODS(0000): | 117 | * ACT_LMODS(0000): |
| 108 | 0000|0000|000000|00 No action | 118 | * 0000|0000|000000|00 No action |
| 109 | 0000|0000|000000|01 Transparent | 119 | * 0000|0000|000000|01 Transparent |
| 110 | 0000|0000| keycode Key | 120 | * 0000|0000| keycode Key |
| 111 | 0000|mods|000000|00 Left mods | 121 | * 0000|mods|000000|00 Left mods |
| 112 | 0000|mods| keycode Key & Left mods | 122 | * 0000|mods| keycode Key & Left mods |
| 113 | 123 | * | |
| 114 | ACT_RMODS(0001): | 124 | * ACT_RMODS(0001): |
| 115 | 0001|0000|000000|00 No action(not used) | 125 | * 0001|0000|000000|00 No action(not used) |
| 116 | 0001|0000|000000|01 Transparent(not used) | 126 | * 0001|0000|000000|01 Transparent(not used) |
| 117 | 0001|0000| keycode Key(no used) | 127 | * 0001|0000| keycode Key(no used) |
| 118 | 0001|mods|000000|00 Right mods | 128 | * 0001|mods|000000|00 Right mods |
| 119 | 0001|mods| keycode Key & Right mods | 129 | * 0001|mods| keycode Key & Right mods |
| 120 | 130 | * | |
| 121 | ACT_LMODS_TAP(0010): | 131 | * ACT_LMODS_TAP(0010): |
| 122 | 0010|mods|000000|00 Left mods OneShot | 132 | * 0010|mods|000000|00 Left mods OneShot |
| 123 | 0010|mods|000000|01 (reserved) | 133 | * 0010|mods|000000|01 (reserved) |
| 124 | 0010|mods|000000|10 (reserved) | 134 | * 0010|mods|000000|10 (reserved) |
| 125 | 0010|mods|000000|11 (reserved) | 135 | * 0010|mods|000000|11 (reserved) |
| 126 | 0010|mods| keycode Left mods + tap Key | 136 | * 0010|mods| keycode Left mods + tap Key |
| 127 | 137 | * | |
| 128 | ACT_RMODS_TAP(0011): | 138 | * ACT_RMODS_TAP(0011): |
| 129 | 0011|mods|000000|00 Right mods OneShot | 139 | * 0011|mods|000000|00 Right mods OneShot |
| 130 | 0011|mods|000000|01 (reserved) | 140 | * 0011|mods|000000|01 (reserved) |
| 131 | 0011|mods|000000|10 (reserved) | 141 | * 0011|mods|000000|10 (reserved) |
| 132 | 0011|mods|000000|11 (reserved) | 142 | * 0011|mods|000000|11 (reserved) |
| 133 | 0011|mods| keycode Right mods + tap Key | 143 | * 0011|mods| keycode Right mods + tap Key |
| 134 | 144 | * | |
| 135 | 145 | * | |
| 136 | Other HID Usage | 146 | * Other HID Usage |
| 137 | --------------- | 147 | * --------------- |
| 138 | This action handles other usages than keyboard. | 148 | * This action handles other usages than keyboard. |
| 139 | ACT_USAGE(0100): | 149 | * ACT_USAGE(0100): |
| 140 | 0100|00| usage(10) System control(0x80) - General Desktop page(0x01) | 150 | * 0100|00| usage(10) System control(0x80) - General Desktop page(0x01) |
| 141 | 0100|01| usage(10) Consumer control(0x01) - Consumer page(0x0C) | 151 | * 0100|01| usage(10) Consumer control(0x01) - Consumer page(0x0C) |
| 142 | 0100|10| usage(10) (reserved) | 152 | * 0100|10| usage(10) (reserved) |
| 143 | 0100|11| usage(10) (reserved) | 153 | * 0100|11| usage(10) (reserved) |
| 144 | 154 | * | |
| 145 | 155 | * | |
| 146 | Mouse Keys | 156 | * Mouse Keys |
| 147 | ---------- | 157 | * ---------- |
| 148 | TODO: can be combined with 'Other HID Usage'? to save action kind id. | 158 | * TODO: can be combined with 'Other HID Usage'? to save action kind id. |
| 149 | ACT_MOUSEKEY(0110): | 159 | * ACT_MOUSEKEY(0110): |
| 150 | 0101|XXXX| keycode Mouse key | 160 | * 0101|XXXX| keycode Mouse key |
| 151 | 161 | * | |
| 152 | 162 | * | |
| 153 | Layer Actions | 163 | * Layer Actions |
| 154 | ------------- | 164 | * ------------- |
| 155 | ACT_LAYER(1000): Set layer | 165 | * ACT_LAYER(1000): Set layer |
| 156 | ACT_LAYER_BIT(1001): Bit-op layer | 166 | * ACT_LAYER_BIT(1001): Bit-op layer |
| 157 | 167 | * | |
| 158 | 1000|LLLL|0000 0000 set L to layer on press and set default on release(momentary) | 168 | * 1000|LLLL|0000 0000 set L to layer on press and set default on release(momentary) |
| 159 | 1000|LLLL|0000 0001 set L to layer on press | 169 | * 1000|LLLL|0000 0001 set L to layer on press |
| 160 | 1000|LLLL|0000 0010 set L to layer on release | 170 | * 1000|LLLL|0000 0010 set L to layer on release |
| 161 | 1000|----|0000 0011 set default to layer on both(return to default layer) | 171 | * 1000|----|0000 0011 set default to layer on both(return to default layer) |
| 162 | 1000|LLLL| keycode set L to layer while hold and send key on tap | 172 | * 1000|LLLL| keycode set L to layer while hold and send key on tap |
| 163 | 1000|LLLL|1111 0000 set L to layer while hold and toggle on several taps | 173 | * 1000|LLLL|1111 0000 set L to layer while hold and toggle on several taps |
| 164 | 1000|LLLL|1111 1111 set L to default and layer(on press) | 174 | * 1000|LLLL|1111 1111 set L to default and layer(on press) |
| 165 | 175 | * | |
| 166 | 1001|BBBB|0000 0000 (not used) | 176 | * 1001|BBBB|0000 0000 (not used) |
| 167 | 1001|BBBB|0000 0001 bit-xor layer with B on press | 177 | * 1001|BBBB|0000 0001 bit-xor layer with B on press |
| 168 | 1001|BBBB|0000 0010 bit-xor layer with B on release | 178 | * 1001|BBBB|0000 0010 bit-xor layer with B on release |
| 169 | 1001|BBBB|0000 0011 bit-xor layer with B on both(momentary) | 179 | * 1001|BBBB|0000 0011 bit-xor layer with B on both(momentary) |
| 170 | 1001|BBBB| keycode bit-xor layer with B while hold and send key on tap | 180 | * 1001|BBBB| keycode bit-xor layer with B while hold and send key on tap |
| 171 | 1001|BBBB|1111 0000 bit-xor layer with B while hold and toggle on several taps | 181 | * 1001|BBBB|1111 0000 bit-xor layer with B while hold and toggle on several taps |
| 172 | 1001|BBBB|1111 1111 bit-xor default with B and set layer(on press) | 182 | * 1001|BBBB|1111 1111 bit-xor default with B and set layer(on press) |
| 173 | 183 | * | |
| 174 | 184 | * | |
| 175 | 185 | * | |
| 176 | Extensions(11XX) | 186 | * Extensions(11XX) |
| 177 | ---------------- | 187 | * ---------------- |
| 178 | NOTE: NOT FIXED | 188 | * NOTE: NOT FIXED |
| 179 | 189 | * | |
| 180 | ACT_MACRO(1100): | 190 | * ACT_MACRO(1100): |
| 181 | 1100|opt | id(8) Macro play? | 191 | * 1100|opt | id(8) Macro play? |
| 182 | 1100|1111| id(8) Macro record? | 192 | * 1100|1111| id(8) Macro record? |
| 183 | 193 | * | |
| 184 | ACT_COMMAND(1110): | 194 | * ACT_COMMAND(1110): |
| 185 | 1110|opt | id(8) Built-in Command exec | 195 | * 1110|opt | id(8) Built-in Command exec |
| 186 | 196 | * | |
| 187 | ACT_FUNCTION(1111): | 197 | * ACT_FUNCTION(1111): |
| 188 | 1111| address(12) Function? | 198 | * 1111| address(12) Function? |
| 189 | 1111|opt | id(8) Function? | 199 | * 1111|opt | id(8) Function? |
| 190 | 200 | * | |
| 191 | */ | 201 | */ |
| 192 | enum action_kind_id { | 202 | enum action_kind_id { |
| 193 | ACT_LMODS = 0b0000, | 203 | ACT_LMODS = 0b0000, |
| @@ -241,7 +251,7 @@ enum mods_codes { | |||
| 241 | #define ACTION_RMOD_ONESHOT(mod) ACTION(ACT_RMODS_TAP, MODS4(MOD_BIT(mod))<<8 | MODS_ONESHOT) | 251 | #define ACTION_RMOD_ONESHOT(mod) ACTION(ACT_RMODS_TAP, MODS4(MOD_BIT(mod))<<8 | MODS_ONESHOT) |
| 242 | 252 | ||
| 243 | 253 | ||
| 244 | /* | 254 | /* |
| 245 | * Switch layer | 255 | * Switch layer |
| 246 | */ | 256 | */ |
| 247 | enum layer_codes { | 257 | enum layer_codes { |
| @@ -258,7 +268,7 @@ enum layer_vals_default { | |||
| 258 | DEFAULT_ON_BOTH = 3, | 268 | DEFAULT_ON_BOTH = 3, |
| 259 | }; | 269 | }; |
| 260 | 270 | ||
| 261 | /* | 271 | /* |
| 262 | * return to default layer | 272 | * return to default layer |
| 263 | */ | 273 | */ |
| 264 | #define ACTION_LAYER_DEFAULT ACTION_LAYER_DEFAULT_R | 274 | #define ACTION_LAYER_DEFAULT ACTION_LAYER_DEFAULT_R |
| @@ -288,7 +298,7 @@ enum layer_vals_default { | |||
| 288 | /* set default layer on both press and release */ | 298 | /* set default layer on both press and release */ |
| 289 | #define ACTION_LAYER_SET_DEFAULT(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_CHANGE_DEFAULT) | 299 | #define ACTION_LAYER_SET_DEFAULT(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_CHANGE_DEFAULT) |
| 290 | 300 | ||
| 291 | /* | 301 | /* |
| 292 | * Bit-op layer | 302 | * Bit-op layer |
| 293 | */ | 303 | */ |
| 294 | /* bit-xor on both press and release */ | 304 | /* bit-xor on both press and release */ |
