diff options
| author | tmk <nobody@nowhere> | 2013-04-02 16:09:43 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2013-04-02 16:09:43 +0900 |
| commit | cc8e66754b1a5d0c11985cb0feb51ead49668744 (patch) | |
| tree | b2c7aa7bf5a2ed20650febc6b25fbbd3d773fe10 /common/action.h | |
| parent | 10f33a3e484e24065ed5eaab1c56c35156bace89 (diff) | |
| download | qmk_firmware-cc8e66754b1a5d0c11985cb0feb51ead49668744.tar.gz qmk_firmware-cc8e66754b1a5d0c11985cb0feb51ead49668744.zip | |
Refine ACT_LAYER and ACT_LAYER_TAP
- Remove ACT_LAYER_BITOP
Diffstat (limited to 'common/action.h')
| -rw-r--r-- | common/action.h | 166 |
1 files changed, 75 insertions, 91 deletions
diff --git a/common/action.h b/common/action.h index 2c4f306a4..4daae1d04 100644 --- a/common/action.h +++ b/common/action.h | |||
| @@ -63,11 +63,19 @@ typedef union { | |||
| 63 | uint8_t mods :4; | 63 | uint8_t mods :4; |
| 64 | uint8_t kind :4; | 64 | uint8_t kind :4; |
| 65 | } key; | 65 | } key; |
| 66 | struct action_layer { | 66 | struct action_layer_bitop { |
| 67 | uint8_t bits :4; | ||
| 68 | uint8_t xbit :1; | ||
| 69 | uint8_t part :3; | ||
| 70 | uint8_t on :2; | ||
| 71 | uint8_t op :2; | ||
| 72 | uint8_t kind :4; | ||
| 73 | } layer_bitop; | ||
| 74 | struct action_layer_tap { | ||
| 67 | uint8_t code :8; | 75 | uint8_t code :8; |
| 68 | uint8_t val :5; | 76 | uint8_t val :5; |
| 69 | uint8_t kind :3; | 77 | uint8_t kind :3; |
| 70 | } layer; | 78 | } layer_tap; |
| 71 | struct action_usage { | 79 | struct action_usage { |
| 72 | uint16_t code :10; | 80 | uint16_t code :10; |
| 73 | uint8_t page :2; | 81 | uint8_t page :2; |
| @@ -170,40 +178,27 @@ void debug_action(action_t action); | |||
| 170 | * | 178 | * |
| 171 | * Layer Actions(10XX) | 179 | * Layer Actions(10XX) |
| 172 | * ------------------- | 180 | * ------------------- |
| 173 | * ACT_LAYER: | 181 | * ACT_LAYER: |
| 174 | * 1000|--xx|0000 0000 Clear keyamp | 182 | * 1000|oo00|pppx BBBB Default Layer Bitwise operation |
| 175 | * 100X|LLLL|0000 00xx Reset default layer and clear keymap | 183 | * oo: operation(00:AND, 01:OR, 10:XOR, 11:SET) |
| 176 | * 100X|LLLL| keycode Invert with tap key | 184 | * ppp: 4-bit chunk part(0-7) |
| 177 | * 100X|LLLL|1111 0000 Invert with tap toggle | 185 | * xBBBB: bits and extra bit |
| 178 | * 100X|LLLL|1111 00xx Invert[^= 1<<L] | 186 | * 1000|ooee|pppx BBBB Layer Bitwise Operation |
| 179 | * 100X|LLLL|1111 0100 On/Off | 187 | * oo: operation(00:AND, 01:OR, 10:XOR, 11:SET) |
| 180 | * 100X|LLLL|1111 01xx On[|= 1<<L] | 188 | * ppp: 4-bit chunk part(0-7) |
| 181 | * 100X|LLLL|1111 1000 Off/On | 189 | * xBBBB: bits and extra bit |
| 182 | * 100X|LLLL|1111 10xx Off[&= ~(1<<L)] | 190 | * ee: on event(00:default layer, 01:press, 10:release, 11:both) |
| 183 | * 100X|LLLL|1111 1100 Set/Clear | 191 | * |
| 184 | * 100X|LLLL|1111 11xx Set[= 1<<L] | 192 | * ACT_LAYER_TAP: |
| 185 | * XLLLL: Layer 0-31 | 193 | * 101x|LLLL| keycode Invert with tap key |
| 186 | * xx: On {00:for special use, 01:press, 10:release, 11:both} | 194 | * 101x|LLLL|1110 xxxx Reserved(0xE0-EF) |
| 195 | * 101x|LLLL|1111 0000 Invert with tap toggle(0xF0) | ||
| 196 | * 101x|LLLL|1111 0001 On Off | ||
| 197 | * 101x|LLLL|1111 0010 Off On | ||
| 198 | * 101x|LLLL|1111 0011 Set Clear | ||
| 199 | * 101x|LLLL|1111 xxxx Reserved(0xF4-FF) | ||
| 200 | * xLLLL: layer(0-31) | ||
| 187 | * | 201 | * |
| 188 | * ACT_LAYER_BITOP: | ||
| 189 | * 101B|Booo|xxxx xxxx bit operation | ||
| 190 | * BB: operand. which part of layer state bits | ||
| 191 | * 00: 0-7th bit | ||
| 192 | * 01: 8-15th bit | ||
| 193 | * 10: 16-23th bit | ||
| 194 | * 11: 24-31th bit | ||
| 195 | * ooo: operation. | ||
| 196 | * 000: AND | ||
| 197 | * 001: OR | ||
| 198 | * 010: XOR | ||
| 199 | * 011: | ||
| 200 | * 100: LSHIFT | ||
| 201 | * 101: RSHIFT | ||
| 202 | * 110: | ||
| 203 | * 111: | ||
| 204 | * bbbb bbbb: bits | ||
| 205 | * layer_state |= (((layer_state>>(0bBB*8)) & 0xff) BITOP 0bxxxxxxxx)<<(0bBB*8) | ||
| 206 | * layer_state: 32-bit layer switch state | ||
| 207 | * | 202 | * |
| 208 | * | 203 | * |
| 209 | * | 204 | * |
| @@ -234,9 +229,8 @@ enum action_kind_id { | |||
| 234 | ACT_MOUSEKEY = 0b0101, | 229 | ACT_MOUSEKEY = 0b0101, |
| 235 | 230 | ||
| 236 | ACT_LAYER = 0b1000, | 231 | ACT_LAYER = 0b1000, |
| 237 | ACT_LAYER1 = 0b1001, | 232 | ACT_LAYER_TAP = 0b1010, |
| 238 | ACT_LAYER_BITOP = 0b1010, | 233 | ACT_LAYER_TAP1 = 0b1011, |
| 239 | ACT_LAYER1_BITOP = 0b1011, | ||
| 240 | 234 | ||
| 241 | ACT_MACRO = 0b1100, | 235 | ACT_MACRO = 0b1100, |
| 242 | ACT_COMMAND = 0b1110, | 236 | ACT_COMMAND = 0b1110, |
| @@ -289,71 +283,61 @@ enum usage_pages { | |||
| 289 | 283 | ||
| 290 | 284 | ||
| 291 | 285 | ||
| 292 | /* Layer Actions: | 286 | /* Layer Actions */ |
| 293 | * Invert layer ^= (1<<layer) | ||
| 294 | * On layer |= (1<<layer) | ||
| 295 | * Off layer &= ~(1<<layer) | ||
| 296 | * Set layer = (1<<layer) | ||
| 297 | * Clear layer = 0 | ||
| 298 | */ | ||
| 299 | enum layer_param_on { | 287 | enum layer_param_on { |
| 300 | ON_PRESS = 1, | 288 | ON_PRESS = 1, |
| 301 | ON_RELEASE = 2, | 289 | ON_RELEASE = 2, |
| 302 | ON_BOTH = 3, | 290 | ON_BOTH = 3, |
| 303 | }; | 291 | }; |
| 304 | 292 | ||
| 305 | enum layer_pram_op { | 293 | enum layer_param_op { |
| 306 | OP_RESET = 0x00, | 294 | OP_DEFAULT_LAYER = 0, |
| 307 | OP_INV4 = 0x00, | ||
| 308 | OP_INV = 0xF0, | ||
| 309 | OP_ON = 0xF4, | ||
| 310 | OP_OFF = 0xF8, | ||
| 311 | OP_SET = 0xFC, | ||
| 312 | }; | 295 | }; |
| 313 | 296 | ||
| 314 | enum layer_pram_bitop { | 297 | enum layer_param_bit_op { |
| 315 | BITOP_AND, | 298 | OP_BIT_AND = 0, |
| 316 | BITOP_OR, | 299 | OP_BIT_OR, |
| 317 | BITOP_XOR, | 300 | OP_BIT_XOR, |
| 318 | BITOP_LSHIFT, | 301 | OP_BIT_SET, |
| 319 | BITOP_RSHIFT, | ||
| 320 | }; | 302 | }; |
| 321 | 303 | ||
| 322 | /* | 304 | enum layer_pram_tap_op { |
| 323 | * Default Layer | 305 | OP_TAP_TOGGLE = 0xF0, |
| 324 | */ | 306 | OP_ON_OFF, |
| 325 | #define ACTION_DEFAULT_LAYER ACTION(ACT_LAYER, ON_RELEASE<<8 | OP_RESET | 0) | 307 | OP_OFF_ON, |
| 326 | #define ACTION_DEFAULT_LAYER_SET(layer) ACTION_DEFAULT_LAYER_TO(layer, ON_RELEASE) | 308 | OP_SET_CLEAR, |
| 327 | #define ACTION_DEFAULT_LAYER_TO(layer, on) ACTION(ACT_LAYER, (layer)<<8 | OP_RESET | (on)) | 309 | }; |
| 328 | 310 | ||
| 329 | /* | 311 | /* Layer Operation 1000|ee00|ooov vvvv */ |
| 330 | * Keymap Layer | 312 | #define ACTION_LAYER(op, val, on) (ACT_LAYER<<12 | (on)<<10 | (op)<<5 | val) |
| 331 | */ | 313 | /* Layer Bitwise Operation 1000|ooee|pppx BBBB */ |
| 314 | #define ACTION_LAYER_BITOP(op, part, bits, on) (ACT_LAYER<<12 | (op)<<10 | (on)<<8 | (part)<<5 | (bits)&0x1f) | ||
| 315 | /* Layer with Tapping 101x|LLLL| keycode */ | ||
| 316 | #define ACTION_LAYER_TAP(layer, key) (ACT_LAYER_TAP<<12 | (layer)<<8 | (key)) | ||
| 317 | |||
| 318 | /* Default Layer Operation */ | ||
| 319 | #define ACTION_DEFAULT_LAYER_SET(layer) ACTION_DEFAULT_LAYER(layer, ON_RELEASE) | ||
| 320 | #define ACTION_DEFAULT_LAYER(layer, on) ACTION_LAYER(OP_DEFAULT_LAYER, layer, on) | ||
| 321 | /* Layer Operation */ | ||
| 322 | #define ACTION_LAYER_CLEAR(on) ACTION_LAYER_AND(0x1f, (on)) | ||
| 332 | #define ACTION_LAYER_MOMENTARY(layer) ACTION_LAYER_ON_OFF(layer) | 323 | #define ACTION_LAYER_MOMENTARY(layer) ACTION_LAYER_ON_OFF(layer) |
| 333 | #define ACTION_LAYER_TOGGLE(layer) ACTION_LAYER_INV(layer, ON_RELEASE) | 324 | #define ACTION_LAYER_TOGGLE(layer) ACTION_LAYER_INVERT(layer, ON_RELEASE) |
| 334 | /* Keymap Invert */ | 325 | #define ACTION_LAYER_INVERT(layer, on) ACTION_LAYER_BIT_XOR((layer)/4, 1<<((layer)%4), (on)) |
| 335 | #define ACTION_LAYER_INV(layer, on) ACTION(ACT_LAYER, (layer)<<8 | OP_INV | (on)) | 326 | #define ACTION_LAYER_ON(layer, on) ACTION_LAYER_BIT_OR((layer)/4, 1<<((layer)%4), (on)) |
| 336 | #define ACTION_LAYER_TAP_TOGGLE(layer) ACTION(ACT_LAYER, (layer)<<8 | OP_INV | 0) | 327 | #define ACTION_LAYER_OFF(layer, on) ACTION_LAYER_BIT_AND((layer)/4, ~(1<<((layer)%4)), (on)) |
| 337 | /* Keymap On */ | 328 | #define ACTION_LAYER_SET(layer, on) ACTION_LAYER_BIT_SET((layer)/4, 1<<((layer)%4), (on)) |
| 338 | #define ACTION_LAYER_ON(layer, on) ACTION(ACT_LAYER, (layer)<<8 | OP_ON | (on)) | 329 | #define ACTION_LAYER_ON_OFF(layer) ACTION_LAYER_TAP((layer), OP_ON_OFF) |
| 339 | #define ACTION_LAYER_ON_OFF(layer) ACTION(ACT_LAYER, (layer)<<8 | OP_ON | 0) | 330 | #define ACTION_LAYER_OFF_ON(layer) ACTION_LAYER_TAP((layer), OP_OFF_ON) |
| 340 | /* Keymap Off */ | 331 | #define ACTION_LAYER_SET_CLEAR(layer) ACTION_LAYER_TAP((layer), OP_SET_CLEAR) |
| 341 | #define ACTION_LAYER_OFF(layer, on) ACTION(ACT_LAYER, (layer)<<8 | OP_OFF | (on)) | 332 | /* Bitwise Operation */ |
| 342 | #define ACTION_LAYER_OFF_ON(layer) ACTION(ACT_LAYER, (layer)<<8 | OP_OFF | 0) | 333 | #define ACTION_LAYER_BIT_AND(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_AND, part, bits) |
| 343 | /* Keymap Set */ | 334 | #define ACTION_LAYER_BIT_OR(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_OR, part, bits) |
| 344 | #define ACTION_LAYER_SET(layer, on) ACTION(ACT_LAYER, (layer)<<8 | OP_SET | (on)) | 335 | #define ACTION_LAYER_BIT_XOR(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_XOR, part, bits) |
| 345 | #define ACTION_LAYER_SET_CLEAR(layer) ACTION(ACT_LAYER, (layer)<<8 | OP_SET | 0) | 336 | #define ACTION_LAYER_BIT_SET(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_SET, part, bits) |
| 346 | /* Keymap Invert with tap key */ | 337 | /* with Tapping */ |
| 347 | #define ACTION_LAYER_TAP_KEY(layer, key) ACTION(ACT_LAYER, (layer)<<8 | (key)) | 338 | #define ACTION_LAYER_TAP_KEY(layer, key) ACTION_LAYER_TAP((layer), (key)) |
| 348 | 339 | #define ACTION_LAYER_TAP_TOGGLE(layer) ACTION_LAYER_TAP((layer), OP_TAP_TOGGLE) | |
| 349 | /* Layer BitOp: 101|BB|ooo|xxxxxxxx */ | 340 | |
| 350 | #define ACTION_LAYER_BITOP(op, part, bits) (ACT_LAYER_BITOP<<12 | (part&0x3)<<11 | (op&0x7)<<8 | bits) | ||
| 351 | #define ACTION_LAYER_AND(part, bits) ACTION_LAYER_BITOP(BITOP_AND, part, bits) | ||
| 352 | #define ACTION_LAYER_OR(part, bits) ACTION_LAYER_BITOP(BITOP_OR, part, bits) | ||
| 353 | #define ACTION_LAYER_XOR(part, bits) ACTION_LAYER_BITOP(BITOP_XOR, part, bits) | ||
| 354 | #define ACTION_LAYER_LSHIFT(part, bits) ACTION_LAYER_BITOP(BITOP_LSHIFT, part, bits) | ||
| 355 | #define ACTION_LAYER_RSHIFT(part, bits) ACTION_LAYER_BITOP(BITOP_RSHIFT, part, bits) | ||
| 356 | |||
| 357 | 341 | ||
| 358 | /* | 342 | /* |
| 359 | * Extensions | 343 | * Extensions |
