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 | |
| parent | 10f33a3e484e24065ed5eaab1c56c35156bace89 (diff) | |
| download | qmk_firmware-cc8e66754b1a5d0c11985cb0feb51ead49668744.tar.gz qmk_firmware-cc8e66754b1a5d0c11985cb0feb51ead49668744.zip | |
Refine ACT_LAYER and ACT_LAYER_TAP
- Remove ACT_LAYER_BITOP
| -rw-r--r-- | common/action.c | 201 | ||||
| -rw-r--r-- | common/action.h | 166 | ||||
| -rw-r--r-- | common/action_tapping.h | 3 | ||||
| -rw-r--r-- | common/command.c | 3 | ||||
| -rw-r--r-- | common/layer_switch.c | 122 | ||||
| -rw-r--r-- | common/layer_switch.h | 61 | ||||
| -rw-r--r-- | common/util.c | 19 | ||||
| -rw-r--r-- | common/util.h | 3 |
8 files changed, 263 insertions, 315 deletions
diff --git a/common/action.c b/common/action.c index ef04851b1..596831d4d 100644 --- a/common/action.c +++ b/common/action.c | |||
| @@ -50,14 +50,19 @@ void action_exec(keyevent_t event) | |||
| 50 | void process_action(keyrecord_t *record) | 50 | void process_action(keyrecord_t *record) |
| 51 | { | 51 | { |
| 52 | keyevent_t event = record->event; | 52 | keyevent_t event = record->event; |
| 53 | #ifndef NO_ACTION_TAPPING | ||
| 53 | uint8_t tap_count = record->tap.count; | 54 | uint8_t tap_count = record->tap.count; |
| 55 | #endif | ||
| 54 | 56 | ||
| 55 | if (IS_NOEVENT(event)) { return; } | 57 | if (IS_NOEVENT(event)) { return; } |
| 56 | 58 | ||
| 57 | action_t action = layer_switch_get_action(event.key); | 59 | action_t action = layer_switch_get_action(event.key); |
| 58 | debug("ACTION: "); debug_action(action); | 60 | debug("ACTION: "); debug_action(action); |
| 59 | debug(" keymaps: "); keymap_debug(); | 61 | #ifndef NO_ACTION_LAYER |
| 60 | debug(" default_layer: "); debug_dec(default_layer); debug("\n"); | 62 | debug(" layer_state: "); layer_debug(); |
| 63 | debug(" default_layer_state: "); default_layer_debug(); | ||
| 64 | #endif | ||
| 65 | debug("\n"); | ||
| 61 | 66 | ||
| 62 | switch (action.kind.id) { | 67 | switch (action.kind.id) { |
| 63 | /* Key and Mods */ | 68 | /* Key and Mods */ |
| @@ -92,7 +97,7 @@ void process_action(keyrecord_t *record) | |||
| 92 | { | 97 | { |
| 93 | uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods : | 98 | uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods : |
| 94 | action.key.mods<<4; | 99 | action.key.mods<<4; |
| 95 | switch (action.layer.code) { | 100 | switch (action.layer_tap.code) { |
| 96 | #ifndef NO_ACTION_ONESHOT | 101 | #ifndef NO_ACTION_ONESHOT |
| 97 | case 0x00: | 102 | case 0x00: |
| 98 | // Oneshot modifier | 103 | // Oneshot modifier |
| @@ -200,163 +205,86 @@ void process_action(keyrecord_t *record) | |||
| 200 | #endif | 205 | #endif |
| 201 | #ifndef NO_ACTION_LAYER | 206 | #ifndef NO_ACTION_LAYER |
| 202 | case ACT_LAYER: | 207 | case ACT_LAYER: |
| 203 | case ACT_LAYER1: | 208 | if (action.layer_bitop.on == 0) { |
| 204 | switch (action.layer.code) { | 209 | /* Default Layer Bitwise Operation */ |
| 205 | /* Keymap clear */ | 210 | if (!event.pressed) { |
| 206 | case OP_RESET: | 211 | uint8_t shift = action.layer_bitop.part*4; |
| 207 | switch (action.layer.val & 0x03) { | 212 | uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift; |
| 208 | case 0: | 213 | uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0; |
| 209 | // NOTE: reserved | 214 | switch (action.layer_bitop.op) { |
| 210 | keymap_clear(); | 215 | case OP_BIT_AND: default_layer_and(bits | mask); break; |
| 211 | break; | 216 | case OP_BIT_OR: default_layer_or(bits | mask); break; |
| 212 | case ON_PRESS: | 217 | case OP_BIT_XOR: default_layer_xor(bits | mask); break; |
| 213 | if (event.pressed) { | 218 | case OP_BIT_SET: default_layer_and(mask); default_layer_or(bits); break; |
| 214 | keymap_clear(); | ||
| 215 | } | ||
| 216 | break; | ||
| 217 | case ON_RELEASE: | ||
| 218 | if (!event.pressed) { | ||
| 219 | keymap_clear(); | ||
| 220 | } | ||
| 221 | break; | ||
| 222 | case ON_BOTH: | ||
| 223 | keymap_clear(); | ||
| 224 | break; | ||
| 225 | /* NOTE: 4-7 rserved */ | ||
| 226 | } | 219 | } |
| 227 | break; | 220 | } |
| 228 | /* Keymap Reset default layer */ | 221 | } else { |
| 229 | case (OP_RESET | ON_PRESS): | 222 | /* Layer Bitwise Operation */ |
| 230 | if (event.pressed) { | 223 | if (event.pressed ? (action.layer_bitop.on & ON_PRESS) : |
| 231 | default_layer_set(action.layer.val); | 224 | (action.layer_bitop.on & ON_RELEASE)) { |
| 232 | } | 225 | uint8_t shift = action.layer_bitop.part*4; |
| 233 | break; | 226 | uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift; |
| 234 | case (OP_RESET | ON_RELEASE): | 227 | uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0; |
| 235 | if (!event.pressed) { | 228 | switch (action.layer_bitop.op) { |
| 236 | default_layer_set(action.layer.val); | 229 | case OP_BIT_AND: layer_and(bits | mask); break; |
| 230 | case OP_BIT_OR: layer_or(bits | mask); break; | ||
| 231 | case OP_BIT_XOR: layer_xor(bits | mask); break; | ||
| 232 | case OP_BIT_SET: layer_and(mask); layer_or(bits); break; | ||
| 237 | } | 233 | } |
| 238 | break; | 234 | } |
| 239 | case (OP_RESET | ON_BOTH): | 235 | } |
| 240 | default_layer_set(action.layer.val); | 236 | break; |
| 241 | break; | 237 | #ifndef NO_ACTION_TAPPING |
| 242 | 238 | case ACT_LAYER_TAP: | |
| 243 | /* Keymap Bit invert */ | 239 | case ACT_LAYER_TAP1: |
| 244 | case OP_INV: | 240 | switch (action.layer_tap.code) { |
| 245 | /* with tap toggle */ | 241 | case OP_TAP_TOGGLE: |
| 242 | /* tap toggle */ | ||
| 246 | if (event.pressed) { | 243 | if (event.pressed) { |
| 247 | if (tap_count < TAPPING_TOGGLE) { | 244 | if (tap_count < TAPPING_TOGGLE) { |
| 248 | debug("KEYMAP_INV: tap toggle(press).\n"); | 245 | layer_invert(action.layer_tap.val); |
| 249 | keymap_invert(action.layer.val); | ||
| 250 | } | 246 | } |
| 251 | } else { | 247 | } else { |
| 252 | if (tap_count <= TAPPING_TOGGLE) { | 248 | if (tap_count <= TAPPING_TOGGLE) { |
| 253 | debug("KEYMAP_INV: tap toggle(release).\n"); | 249 | layer_invert(action.layer_tap.val); |
| 254 | keymap_invert(action.layer.val); | ||
| 255 | } | 250 | } |
| 256 | } | 251 | } |
| 257 | break; | 252 | break; |
| 258 | case (OP_INV | ON_PRESS): | 253 | case OP_ON_OFF: |
| 259 | if (event.pressed) { | 254 | event.pressed ? layer_on(action.layer_tap.val) : |
| 260 | keymap_invert(action.layer.val); | 255 | layer_off(action.layer_tap.val); |
| 261 | } | ||
| 262 | break; | 256 | break; |
| 263 | case (OP_INV | ON_RELEASE): | 257 | case OP_OFF_ON: |
| 264 | if (!event.pressed) { | 258 | event.pressed ? layer_off(action.layer_tap.val) : |
| 265 | keymap_invert(action.layer.val); | 259 | layer_on(action.layer_tap.val); |
| 266 | } | ||
| 267 | break; | 260 | break; |
| 268 | case (OP_INV | ON_BOTH): | 261 | case OP_SET_CLEAR: |
| 269 | keymap_invert(action.layer.val); | 262 | event.pressed ? layer_move(action.layer_tap.val) : |
| 263 | layer_clear(); | ||
| 270 | break; | 264 | break; |
| 271 | |||
| 272 | /* Keymap Bit on */ | ||
| 273 | case OP_ON: | ||
| 274 | if (event.pressed) { | ||
| 275 | keymap_on(action.layer.val); | ||
| 276 | } else { | ||
| 277 | keymap_off(action.layer.val); | ||
| 278 | } | ||
| 279 | break; | ||
| 280 | case (OP_ON | ON_PRESS): | ||
| 281 | if (event.pressed) { | ||
| 282 | keymap_on(action.layer.val); | ||
| 283 | } | ||
| 284 | break; | ||
| 285 | case (OP_ON | ON_RELEASE): | ||
| 286 | if (!event.pressed) { | ||
| 287 | keymap_on(action.layer.val); | ||
| 288 | } | ||
| 289 | break; | ||
| 290 | case (OP_ON | ON_BOTH): | ||
| 291 | keymap_on(action.layer.val); | ||
| 292 | break; | ||
| 293 | |||
| 294 | /* Keymap Bit off */ | ||
| 295 | case OP_OFF: | ||
| 296 | if (event.pressed) { | ||
| 297 | keymap_off(action.layer.val); | ||
| 298 | } else { | ||
| 299 | keymap_on(action.layer.val); | ||
| 300 | } | ||
| 301 | break; | ||
| 302 | case (OP_OFF | ON_PRESS): | ||
| 303 | if (event.pressed) { | ||
| 304 | keymap_off(action.layer.val); | ||
| 305 | } | ||
| 306 | break; | ||
| 307 | case (OP_OFF | ON_RELEASE): | ||
| 308 | if (!event.pressed) { | ||
| 309 | keymap_off(action.layer.val); | ||
| 310 | } | ||
| 311 | break; | ||
| 312 | case (OP_OFF | ON_BOTH): | ||
| 313 | keymap_off(action.layer.val); | ||
| 314 | break; | ||
| 315 | |||
| 316 | /* Keymap Bit set */ | ||
| 317 | case OP_SET: | ||
| 318 | if (event.pressed) { | ||
| 319 | keymap_set(action.layer.val); | ||
| 320 | } else { | ||
| 321 | keymap_clear(); | ||
| 322 | } | ||
| 323 | break; | ||
| 324 | case (OP_SET | ON_PRESS): | ||
| 325 | if (event.pressed) { | ||
| 326 | keymap_set(action.layer.val); | ||
| 327 | } | ||
| 328 | break; | ||
| 329 | case (OP_SET | ON_RELEASE): | ||
| 330 | if (!event.pressed) { | ||
| 331 | keymap_set(action.layer.val); | ||
| 332 | } | ||
| 333 | break; | ||
| 334 | case (OP_SET | ON_BOTH): | ||
| 335 | keymap_set(action.layer.val); | ||
| 336 | break; | ||
| 337 | |||
| 338 | /* Keymap Bit invert with tap key */ | ||
| 339 | default: | 265 | default: |
| 266 | /* tap key */ | ||
| 340 | if (event.pressed) { | 267 | if (event.pressed) { |
| 341 | if (tap_count > 0) { | 268 | if (tap_count > 0) { |
| 342 | debug("KEYMAP_TAP_KEY: Tap: register_code\n"); | 269 | debug("KEYMAP_TAP_KEY: Tap: register_code\n"); |
| 343 | register_code(action.layer.code); | 270 | register_code(action.layer_tap.code); |
| 344 | } else { | 271 | } else { |
| 345 | debug("KEYMAP_TAP_KEY: No tap: On on press\n"); | 272 | debug("KEYMAP_TAP_KEY: No tap: On on press\n"); |
| 346 | keymap_on(action.layer.val); | 273 | layer_on(action.layer_tap.val); |
| 347 | } | 274 | } |
| 348 | } else { | 275 | } else { |
| 349 | if (tap_count > 0) { | 276 | if (tap_count > 0) { |
| 350 | debug("KEYMAP_TAP_KEY: Tap: unregister_code\n"); | 277 | debug("KEYMAP_TAP_KEY: Tap: unregister_code\n"); |
| 351 | unregister_code(action.layer.code); | 278 | unregister_code(action.layer_tap.code); |
| 352 | } else { | 279 | } else { |
| 353 | debug("KEYMAP_TAP_KEY: No tap: Off on release\n"); | 280 | debug("KEYMAP_TAP_KEY: No tap: Off on release\n"); |
| 354 | keymap_off(action.layer.val); | 281 | layer_off(action.layer_tap.val); |
| 355 | } | 282 | } |
| 356 | } | 283 | } |
| 357 | break; | 284 | break; |
| 358 | } | 285 | } |
| 359 | break; | 286 | break; |
| 287 | #endif | ||
| 360 | #endif | 288 | #endif |
| 361 | /* Extentions */ | 289 | /* Extentions */ |
| 362 | #ifndef NO_ACTION_MACRO | 290 | #ifndef NO_ACTION_MACRO |
| @@ -508,15 +436,9 @@ bool is_tap_key(key_t key) | |||
| 508 | switch (action.kind.id) { | 436 | switch (action.kind.id) { |
| 509 | case ACT_LMODS_TAP: | 437 | case ACT_LMODS_TAP: |
| 510 | case ACT_RMODS_TAP: | 438 | case ACT_RMODS_TAP: |
| 439 | case ACT_LAYER_TAP: | ||
| 440 | case ACT_LAYER_TAP1: | ||
| 511 | return true; | 441 | return true; |
| 512 | case ACT_LAYER: | ||
| 513 | switch (action.layer.code) { | ||
| 514 | case 0x04 ... 0xEF: /* tap key */ | ||
| 515 | case OP_INV: | ||
| 516 | return true; | ||
| 517 | default: | ||
| 518 | return false; | ||
| 519 | } | ||
| 520 | case ACT_MACRO: | 442 | case ACT_MACRO: |
| 521 | case ACT_FUNCTION: | 443 | case ACT_FUNCTION: |
| 522 | if (action.func.opt & FUNC_TAP) { return true; } | 444 | if (action.func.opt & FUNC_TAP) { return true; } |
| @@ -555,7 +477,8 @@ void debug_action(action_t action) | |||
| 555 | case ACT_USAGE: debug("ACT_USAGE"); break; | 477 | case ACT_USAGE: debug("ACT_USAGE"); break; |
| 556 | case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; | 478 | case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; |
| 557 | case ACT_LAYER: debug("ACT_LAYER"); break; | 479 | case ACT_LAYER: debug("ACT_LAYER"); break; |
| 558 | case ACT_LAYER_BITOP: debug("ACT_LAYER_BITOP"); break; | 480 | case ACT_LAYER_TAP: debug("ACT_LAYER_TAP"); break; |
| 481 | case ACT_LAYER_TAP1: debug("ACT_LAYER_TAP1"); break; | ||
| 559 | case ACT_MACRO: debug("ACT_MACRO"); break; | 482 | case ACT_MACRO: debug("ACT_MACRO"); break; |
| 560 | case ACT_COMMAND: debug("ACT_COMMAND"); break; | 483 | case ACT_COMMAND: debug("ACT_COMMAND"); break; |
| 561 | case ACT_FUNCTION: debug("ACT_FUNCTION"); break; | 484 | case ACT_FUNCTION: debug("ACT_FUNCTION"); break; |
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 |
diff --git a/common/action_tapping.h b/common/action_tapping.h index c9f09f576..9b42d50dc 100644 --- a/common/action_tapping.h +++ b/common/action_tapping.h | |||
| @@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 18 | #define ACTION_TAPPING_H | 18 | #define ACTION_TAPPING_H |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | #ifndef NO_ACTION_TAPPING | ||
| 22 | 21 | ||
| 23 | /* period of tapping(ms) */ | 22 | /* period of tapping(ms) */ |
| 24 | #ifndef TAPPING_TERM | 23 | #ifndef TAPPING_TERM |
| @@ -33,8 +32,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 33 | #define WAITING_BUFFER_SIZE 8 | 32 | #define WAITING_BUFFER_SIZE 8 |
| 34 | 33 | ||
| 35 | 34 | ||
| 35 | #ifndef NO_ACTION_TAPPING | ||
| 36 | void action_tapping_process(keyrecord_t record); | 36 | void action_tapping_process(keyrecord_t record); |
| 37 | |||
| 38 | #endif | 37 | #endif |
| 39 | 38 | ||
| 40 | #endif | 39 | #endif |
diff --git a/common/command.c b/common/command.c index e197a8f80..c954ff02f 100644 --- a/common/command.c +++ b/common/command.c | |||
| @@ -573,7 +573,8 @@ static uint8_t numkey2num(uint8_t code) | |||
| 573 | 573 | ||
| 574 | static void switch_default_layer(uint8_t layer) | 574 | static void switch_default_layer(uint8_t layer) |
| 575 | { | 575 | { |
| 576 | print("switch_default_layer: "); print_dec(default_layer); print(" to "); print_dec(layer); print("\n"); | 576 | print("switch_default_layer: "); print_dec(biton32(default_layer_state)); |
| 577 | default_layer_set(layer); | 577 | default_layer_set(layer); |
| 578 | print(" to "); print_dec(biton32(default_layer_state)); print("\n"); | ||
| 578 | clear_keyboard(); | 579 | clear_keyboard(); |
| 579 | } | 580 | } |
diff --git a/common/layer_switch.c b/common/layer_switch.c index 359e6b9d8..9905741f4 100644 --- a/common/layer_switch.c +++ b/common/layer_switch.c | |||
| @@ -7,94 +7,103 @@ | |||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | /* | 9 | /* |
| 10 | * Default Layer (0-15) | 10 | * Default Layer State |
| 11 | */ | 11 | */ |
| 12 | uint8_t default_layer = 0; | 12 | uint32_t default_layer_state = 0; |
| 13 | 13 | ||
| 14 | void default_layer_set(uint8_t layer) | 14 | static void default_layer_state_set(uint32_t state) |
| 15 | { | 15 | { |
| 16 | debug("default_layer_set: "); | 16 | debug("default_layer_state: "); |
| 17 | debug_dec(default_layer); debug(" to "); | 17 | default_layer_debug(); debug(" to "); |
| 18 | 18 | default_layer_state = state; | |
| 19 | default_layer = layer; | 19 | default_layer_debug(); debug("\n"); |
| 20 | |||
| 21 | debug_dec(default_layer); debug("\n"); | ||
| 22 | |||
| 23 | clear_keyboard_but_mods(); // To avoid stuck keys | 20 | clear_keyboard_but_mods(); // To avoid stuck keys |
| 24 | } | 21 | } |
| 25 | 22 | ||
| 26 | 23 | void default_layer_debug(void) | |
| 27 | #ifndef NO_ACTION_LAYER | ||
| 28 | /* | ||
| 29 | * Keymap Layer (0-15) | ||
| 30 | */ | ||
| 31 | uint16_t keymap_stat = 0; | ||
| 32 | |||
| 33 | /* return highest layer whose state is on */ | ||
| 34 | uint8_t keymap_get_layer(void) | ||
| 35 | { | 24 | { |
| 36 | return biton16(keymap_stat); | 25 | debug_hex32(default_layer_state); |
| 26 | debug("("); debug_dec(biton32(default_layer_state)); debug(")"); | ||
| 37 | } | 27 | } |
| 38 | 28 | ||
| 39 | static void keymap_stat_set(uint16_t stat) | 29 | void default_layer_set(uint8_t layer) |
| 40 | { | 30 | { |
| 41 | debug("keymap: "); | 31 | default_layer_state_set(1UL<<layer); |
| 42 | keymap_debug(); debug(" to "); | 32 | } |
| 43 | 33 | ||
| 44 | keymap_stat = stat; | 34 | #ifndef NO_ACTION_LAYER |
| 35 | void default_layer_or(uint32_t state) | ||
| 36 | { | ||
| 37 | default_layer_state_set(default_layer_state | state); | ||
| 38 | } | ||
| 39 | void default_layer_and(uint32_t state) | ||
| 40 | { | ||
| 41 | default_layer_state_set(default_layer_state & state); | ||
| 42 | } | ||
| 43 | void default_layer_xor(uint32_t state) | ||
| 44 | { | ||
| 45 | default_layer_state_set(default_layer_state ^ state); | ||
| 46 | } | ||
| 47 | #endif | ||
| 45 | 48 | ||
| 46 | keymap_debug(); debug("\n"); | ||
| 47 | 49 | ||
| 48 | clear_keyboard_but_mods(); // To avoid stuck keys | 50 | #ifndef NO_ACTION_LAYER |
| 49 | } | 51 | /* |
| 52 | * Keymap Layer State | ||
| 53 | */ | ||
| 54 | uint32_t layer_state = 0; | ||
| 50 | 55 | ||
| 51 | void keymap_clear(void) | 56 | static void layer_state_set(uint32_t state) |
| 52 | { | 57 | { |
| 53 | keymap_stat_set(0); | 58 | debug("layer_state: "); |
| 59 | layer_debug(); debug(" to "); | ||
| 60 | layer_state = state; | ||
| 61 | layer_debug(); debug("\n"); | ||
| 62 | clear_keyboard_but_mods(); // To avoid stuck keys | ||
| 54 | } | 63 | } |
| 55 | 64 | ||
| 56 | 65 | void layer_clear(void) | |
| 57 | void keymap_set(uint16_t stat) | ||
| 58 | { | 66 | { |
| 59 | keymap_stat_set(stat); | 67 | layer_state_set(0); |
| 60 | } | 68 | } |
| 61 | 69 | ||
| 62 | void keymap_move(uint8_t layer) | 70 | void layer_move(uint8_t layer) |
| 63 | { | 71 | { |
| 64 | keymap_stat_set(1<<layer); | 72 | layer_state_set(1UL<<layer); |
| 65 | } | 73 | } |
| 66 | 74 | ||
| 67 | void keymap_on(uint8_t layer) | 75 | void layer_on(uint8_t layer) |
| 68 | { | 76 | { |
| 69 | keymap_stat_set(keymap_stat | (1<<layer)); | 77 | layer_state_set(layer_state | (1UL<<layer)); |
| 70 | } | 78 | } |
| 71 | 79 | ||
| 72 | void keymap_off(uint8_t layer) | 80 | void layer_off(uint8_t layer) |
| 73 | { | 81 | { |
| 74 | keymap_stat_set(keymap_stat & ~(1<<layer)); | 82 | layer_state_set(layer_state & ~(1UL<<layer)); |
| 75 | } | 83 | } |
| 76 | 84 | ||
| 77 | void keymap_invert(uint8_t layer) | 85 | void layer_invert(uint8_t layer) |
| 78 | { | 86 | { |
| 79 | keymap_stat_set(keymap_stat ^ (1<<layer)); | 87 | layer_state_set(layer_state ^ (1UL<<layer)); |
| 80 | } | 88 | } |
| 81 | 89 | ||
| 82 | void keymap_or(uint16_t stat) | 90 | void layer_or(uint32_t state) |
| 83 | { | 91 | { |
| 84 | keymap_stat_set(keymap_stat | stat); | 92 | layer_state_set(layer_state | state); |
| 85 | } | 93 | } |
| 86 | void keymap_and(uint16_t stat) | 94 | void layer_and(uint32_t state) |
| 87 | { | 95 | { |
| 88 | keymap_stat_set(keymap_stat & stat); | 96 | layer_state_set(layer_state & state); |
| 89 | } | 97 | } |
| 90 | void keymap_xor(uint16_t stat) | 98 | void layer_xor(uint32_t state) |
| 91 | { | 99 | { |
| 92 | keymap_stat_set(keymap_stat ^ stat); | 100 | layer_state_set(layer_state ^ state); |
| 93 | } | 101 | } |
| 94 | 102 | ||
| 95 | void keymap_debug(void) | 103 | void layer_debug(void) |
| 96 | { | 104 | { |
| 97 | debug_hex16(keymap_stat); debug("("); debug_dec(keymap_get_layer()); debug(")"); | 105 | debug_hex32(layer_state); |
| 106 | debug("("); debug_dec(biton32(layer_state)); debug(")"); | ||
| 98 | } | 107 | } |
| 99 | #endif | 108 | #endif |
| 100 | 109 | ||
| @@ -106,18 +115,21 @@ action_t layer_switch_get_action(key_t key) | |||
| 106 | action.code = ACTION_TRANSPARENT; | 115 | action.code = ACTION_TRANSPARENT; |
| 107 | 116 | ||
| 108 | #ifndef NO_ACTION_LAYER | 117 | #ifndef NO_ACTION_LAYER |
| 109 | /* keymap: top layer first */ | 118 | uint32_t layers = layer_state | default_layer_state; |
| 110 | for (int8_t i = 15; i >= 0; i--) { | 119 | /* check top layer first */ |
| 111 | if (keymap_stat & (1<<i)) { | 120 | for (int8_t i = 31; i >= 0; i--) { |
| 121 | if (layers & (1UL<<i)) { | ||
| 112 | action = action_for_key(i, key); | 122 | action = action_for_key(i, key); |
| 113 | if (action.code != ACTION_TRANSPARENT) { | 123 | if (action.code != ACTION_TRANSPARENT) { |
| 114 | return action; | 124 | return action; |
| 115 | } | 125 | } |
| 116 | } | 126 | } |
| 117 | } | 127 | } |
| 118 | #endif | 128 | /* fall back to layer 0 */ |
| 119 | 129 | action = action_for_key(0, key); | |
| 120 | /* default layer */ | 130 | return action; |
| 121 | action = action_for_key(default_layer, key); | 131 | #else |
| 132 | action = action_for_key(biton32(default_layer_state), key); | ||
| 122 | return action; | 133 | return action; |
| 134 | #endif | ||
| 123 | } | 135 | } |
diff --git a/common/layer_switch.h b/common/layer_switch.h index 423dafb5b..ed8dfb502 100644 --- a/common/layer_switch.h +++ b/common/layer_switch.h | |||
| @@ -25,42 +25,49 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 25 | /* | 25 | /* |
| 26 | * Default Layer | 26 | * Default Layer |
| 27 | */ | 27 | */ |
| 28 | /* base layer to fall back */ | 28 | extern uint32_t default_layer_state; |
| 29 | extern uint8_t default_layer; | 29 | void default_layer_debug(void); |
| 30 | void default_layer_set(uint8_t layer); | 30 | void default_layer_set(uint8_t layer); |
| 31 | 31 | ||
| 32 | #ifndef NO_ACTION_LAYER | ||
| 33 | /* bitwise operation */ | ||
| 34 | void default_layer_or(uint32_t state); | ||
| 35 | void default_layer_and(uint32_t state); | ||
| 36 | void default_layer_xor(uint32_t state); | ||
| 37 | #else | ||
| 38 | #define default_layer_or(state) | ||
| 39 | #define default_layer_and(state) | ||
| 40 | #define default_layer_xor(state) | ||
| 41 | #endif | ||
| 42 | |||
| 32 | 43 | ||
| 33 | /* | 44 | /* |
| 34 | * Keymap Layer | 45 | * Keymap Layer |
| 35 | */ | 46 | */ |
| 36 | #ifndef NO_ACTION_LAYER | 47 | #ifndef NO_ACTION_LAYER |
| 37 | extern uint16_t keymap_stat; | 48 | extern uint32_t layer_state; |
| 38 | /* return current active layer */ | 49 | void layer_debug(void); |
| 39 | uint8_t keymap_get_layer(void); | 50 | void layer_clear(void); |
| 40 | void keymap_clear(void); | 51 | void layer_move(uint8_t layer); |
| 41 | void keymap_set(uint16_t stat); | 52 | void layer_on(uint8_t layer); |
| 42 | void keymap_move(uint8_t layer); | 53 | void layer_off(uint8_t layer); |
| 43 | void keymap_on(uint8_t layer); | 54 | void layer_invert(uint8_t layer); |
| 44 | void keymap_off(uint8_t layer); | ||
| 45 | void keymap_invert(uint8_t layer); | ||
| 46 | /* bitwise operation */ | 55 | /* bitwise operation */ |
| 47 | void keymap_or(uint16_t stat); | 56 | void layer_or(uint32_t state); |
| 48 | void keymap_and(uint16_t stat); | 57 | void layer_and(uint32_t state); |
| 49 | void keymap_xor(uint16_t stat); | 58 | void layer_xor(uint32_t state); |
| 50 | void keymap_debug(void); | ||
| 51 | #else | 59 | #else |
| 52 | #define keymap_stat 0 | 60 | #define layer_state 0 |
| 53 | #define keymap_get_layer() | 61 | #define layer_clear() |
| 54 | #define keymap_clear() | 62 | #define layer_move(layer) |
| 55 | #define keymap_set(stat) | 63 | #define layer_on(layer) |
| 56 | #define keymap_move(layer) | 64 | #define layer_off(layer) |
| 57 | #define keymap_on(layer) | 65 | #define layer_invert(layer) |
| 58 | #define keymap_off(layer) | 66 | |
| 59 | #define keymap_invert(layer) | 67 | #define layer_or(state) |
| 60 | #define keymap_or(stat) | 68 | #define layer_and(state) |
| 61 | #define keymap_and(stat) | 69 | #define layer_xor(state) |
| 62 | #define keymap_xor(stat) | 70 | #define layer_debug() |
| 63 | #define keymap_debug() | ||
| 64 | #endif | 71 | #endif |
| 65 | 72 | ||
| 66 | 73 | ||
diff --git a/common/util.c b/common/util.c index ff1926d7d..6d4d6bfda 100644 --- a/common/util.c +++ b/common/util.c | |||
| @@ -38,6 +38,14 @@ uint8_t bitpop16(uint16_t bits) | |||
| 38 | return c; | 38 | return c; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | uint8_t bitpop32(uint32_t bits) | ||
| 42 | { | ||
| 43 | uint8_t c; | ||
| 44 | for (c = 0; bits; c++) | ||
| 45 | bits &= bits - 1; | ||
| 46 | return c; | ||
| 47 | } | ||
| 48 | |||
| 41 | // most significant on-bit - return highest location of on-bit | 49 | // most significant on-bit - return highest location of on-bit |
| 42 | // NOTE: return 0 when bit0 is on or all bits are off | 50 | // NOTE: return 0 when bit0 is on or all bits are off |
| 43 | uint8_t biton(uint8_t bits) | 51 | uint8_t biton(uint8_t bits) |
| @@ -58,3 +66,14 @@ uint8_t biton16(uint16_t bits) | |||
| 58 | if (bits >> 1) { bits >>= 1; n += 1;} | 66 | if (bits >> 1) { bits >>= 1; n += 1;} |
| 59 | return n; | 67 | return n; |
| 60 | } | 68 | } |
| 69 | |||
| 70 | uint8_t biton32(uint32_t bits) | ||
| 71 | { | ||
| 72 | uint8_t n = 0; | ||
| 73 | if (bits >>16) { bits >>=16; n +=16;} | ||
| 74 | if (bits >> 8) { bits >>= 8; n += 8;} | ||
| 75 | if (bits >> 4) { bits >>= 4; n += 4;} | ||
| 76 | if (bits >> 2) { bits >>= 2; n += 2;} | ||
| 77 | if (bits >> 1) { bits >>= 1; n += 1;} | ||
| 78 | return n; | ||
| 79 | } | ||
diff --git a/common/util.h b/common/util.h index 58b7fdf14..4b8b5ca3a 100644 --- a/common/util.h +++ b/common/util.h | |||
| @@ -30,7 +30,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 30 | 30 | ||
| 31 | uint8_t bitpop(uint8_t bits); | 31 | uint8_t bitpop(uint8_t bits); |
| 32 | uint8_t bitpop16(uint16_t bits); | 32 | uint8_t bitpop16(uint16_t bits); |
| 33 | uint8_t bitpop32(uint32_t bits); | ||
| 34 | |||
| 33 | uint8_t biton(uint8_t bits); | 35 | uint8_t biton(uint8_t bits); |
| 34 | uint8_t biton16(uint16_t bits); | 36 | uint8_t biton16(uint16_t bits); |
| 37 | uint8_t biton32(uint32_t bits); | ||
| 35 | 38 | ||
| 36 | #endif | 39 | #endif |
