Refine ACT_LAYER and ACT_LAYER_TAP
- Remove ACT_LAYER_BITOP
This commit is contained in:
parent
5e557f01e0
commit
8d8ee35fb0
199
common/action.c
199
common/action.c
@ -50,14 +50,19 @@ void action_exec(keyevent_t event)
|
|||||||
void process_action(keyrecord_t *record)
|
void process_action(keyrecord_t *record)
|
||||||
{
|
{
|
||||||
keyevent_t event = record->event;
|
keyevent_t event = record->event;
|
||||||
|
#ifndef NO_ACTION_TAPPING
|
||||||
uint8_t tap_count = record->tap.count;
|
uint8_t tap_count = record->tap.count;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (IS_NOEVENT(event)) { return; }
|
if (IS_NOEVENT(event)) { return; }
|
||||||
|
|
||||||
action_t action = layer_switch_get_action(event.key);
|
action_t action = layer_switch_get_action(event.key);
|
||||||
debug("ACTION: "); debug_action(action);
|
debug("ACTION: "); debug_action(action);
|
||||||
debug(" keymaps: "); keymap_debug();
|
#ifndef NO_ACTION_LAYER
|
||||||
debug(" default_layer: "); debug_dec(default_layer); debug("\n");
|
debug(" layer_state: "); layer_debug();
|
||||||
|
debug(" default_layer_state: "); default_layer_debug();
|
||||||
|
#endif
|
||||||
|
debug("\n");
|
||||||
|
|
||||||
switch (action.kind.id) {
|
switch (action.kind.id) {
|
||||||
/* Key and Mods */
|
/* Key and Mods */
|
||||||
@ -92,7 +97,7 @@ void process_action(keyrecord_t *record)
|
|||||||
{
|
{
|
||||||
uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods :
|
uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods :
|
||||||
action.key.mods<<4;
|
action.key.mods<<4;
|
||||||
switch (action.layer.code) {
|
switch (action.layer_tap.code) {
|
||||||
#ifndef NO_ACTION_ONESHOT
|
#ifndef NO_ACTION_ONESHOT
|
||||||
case 0x00:
|
case 0x00:
|
||||||
// Oneshot modifier
|
// Oneshot modifier
|
||||||
@ -200,163 +205,86 @@ void process_action(keyrecord_t *record)
|
|||||||
#endif
|
#endif
|
||||||
#ifndef NO_ACTION_LAYER
|
#ifndef NO_ACTION_LAYER
|
||||||
case ACT_LAYER:
|
case ACT_LAYER:
|
||||||
case ACT_LAYER1:
|
if (action.layer_bitop.on == 0) {
|
||||||
switch (action.layer.code) {
|
/* Default Layer Bitwise Operation */
|
||||||
/* Keymap clear */
|
|
||||||
case OP_RESET:
|
|
||||||
switch (action.layer.val & 0x03) {
|
|
||||||
case 0:
|
|
||||||
// NOTE: reserved
|
|
||||||
keymap_clear();
|
|
||||||
break;
|
|
||||||
case ON_PRESS:
|
|
||||||
if (event.pressed) {
|
|
||||||
keymap_clear();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ON_RELEASE:
|
|
||||||
if (!event.pressed) {
|
if (!event.pressed) {
|
||||||
keymap_clear();
|
uint8_t shift = action.layer_bitop.part*4;
|
||||||
|
uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift;
|
||||||
|
uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0;
|
||||||
|
switch (action.layer_bitop.op) {
|
||||||
|
case OP_BIT_AND: default_layer_and(bits | mask); break;
|
||||||
|
case OP_BIT_OR: default_layer_or(bits | mask); break;
|
||||||
|
case OP_BIT_XOR: default_layer_xor(bits | mask); break;
|
||||||
|
case OP_BIT_SET: default_layer_and(mask); default_layer_or(bits); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Layer Bitwise Operation */
|
||||||
|
if (event.pressed ? (action.layer_bitop.on & ON_PRESS) :
|
||||||
|
(action.layer_bitop.on & ON_RELEASE)) {
|
||||||
|
uint8_t shift = action.layer_bitop.part*4;
|
||||||
|
uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift;
|
||||||
|
uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0;
|
||||||
|
switch (action.layer_bitop.op) {
|
||||||
|
case OP_BIT_AND: layer_and(bits | mask); break;
|
||||||
|
case OP_BIT_OR: layer_or(bits | mask); break;
|
||||||
|
case OP_BIT_XOR: layer_xor(bits | mask); break;
|
||||||
|
case OP_BIT_SET: layer_and(mask); layer_or(bits); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ON_BOTH:
|
#ifndef NO_ACTION_TAPPING
|
||||||
keymap_clear();
|
case ACT_LAYER_TAP:
|
||||||
break;
|
case ACT_LAYER_TAP1:
|
||||||
/* NOTE: 4-7 rserved */
|
switch (action.layer_tap.code) {
|
||||||
}
|
case OP_TAP_TOGGLE:
|
||||||
break;
|
/* tap toggle */
|
||||||
/* Keymap Reset default layer */
|
|
||||||
case (OP_RESET | ON_PRESS):
|
|
||||||
if (event.pressed) {
|
|
||||||
default_layer_set(action.layer.val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case (OP_RESET | ON_RELEASE):
|
|
||||||
if (!event.pressed) {
|
|
||||||
default_layer_set(action.layer.val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case (OP_RESET | ON_BOTH):
|
|
||||||
default_layer_set(action.layer.val);
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Keymap Bit invert */
|
|
||||||
case OP_INV:
|
|
||||||
/* with tap toggle */
|
|
||||||
if (event.pressed) {
|
if (event.pressed) {
|
||||||
if (tap_count < TAPPING_TOGGLE) {
|
if (tap_count < TAPPING_TOGGLE) {
|
||||||
debug("KEYMAP_INV: tap toggle(press).\n");
|
layer_invert(action.layer_tap.val);
|
||||||
keymap_invert(action.layer.val);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tap_count <= TAPPING_TOGGLE) {
|
if (tap_count <= TAPPING_TOGGLE) {
|
||||||
debug("KEYMAP_INV: tap toggle(release).\n");
|
layer_invert(action.layer_tap.val);
|
||||||
keymap_invert(action.layer.val);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case (OP_INV | ON_PRESS):
|
case OP_ON_OFF:
|
||||||
if (event.pressed) {
|
event.pressed ? layer_on(action.layer_tap.val) :
|
||||||
keymap_invert(action.layer.val);
|
layer_off(action.layer_tap.val);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case (OP_INV | ON_RELEASE):
|
case OP_OFF_ON:
|
||||||
if (!event.pressed) {
|
event.pressed ? layer_off(action.layer_tap.val) :
|
||||||
keymap_invert(action.layer.val);
|
layer_on(action.layer_tap.val);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case (OP_INV | ON_BOTH):
|
case OP_SET_CLEAR:
|
||||||
keymap_invert(action.layer.val);
|
event.pressed ? layer_move(action.layer_tap.val) :
|
||||||
|
layer_clear();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Keymap Bit on */
|
|
||||||
case OP_ON:
|
|
||||||
if (event.pressed) {
|
|
||||||
keymap_on(action.layer.val);
|
|
||||||
} else {
|
|
||||||
keymap_off(action.layer.val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case (OP_ON | ON_PRESS):
|
|
||||||
if (event.pressed) {
|
|
||||||
keymap_on(action.layer.val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case (OP_ON | ON_RELEASE):
|
|
||||||
if (!event.pressed) {
|
|
||||||
keymap_on(action.layer.val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case (OP_ON | ON_BOTH):
|
|
||||||
keymap_on(action.layer.val);
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Keymap Bit off */
|
|
||||||
case OP_OFF:
|
|
||||||
if (event.pressed) {
|
|
||||||
keymap_off(action.layer.val);
|
|
||||||
} else {
|
|
||||||
keymap_on(action.layer.val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case (OP_OFF | ON_PRESS):
|
|
||||||
if (event.pressed) {
|
|
||||||
keymap_off(action.layer.val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case (OP_OFF | ON_RELEASE):
|
|
||||||
if (!event.pressed) {
|
|
||||||
keymap_off(action.layer.val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case (OP_OFF | ON_BOTH):
|
|
||||||
keymap_off(action.layer.val);
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Keymap Bit set */
|
|
||||||
case OP_SET:
|
|
||||||
if (event.pressed) {
|
|
||||||
keymap_set(action.layer.val);
|
|
||||||
} else {
|
|
||||||
keymap_clear();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case (OP_SET | ON_PRESS):
|
|
||||||
if (event.pressed) {
|
|
||||||
keymap_set(action.layer.val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case (OP_SET | ON_RELEASE):
|
|
||||||
if (!event.pressed) {
|
|
||||||
keymap_set(action.layer.val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case (OP_SET | ON_BOTH):
|
|
||||||
keymap_set(action.layer.val);
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Keymap Bit invert with tap key */
|
|
||||||
default:
|
default:
|
||||||
|
/* tap key */
|
||||||
if (event.pressed) {
|
if (event.pressed) {
|
||||||
if (tap_count > 0) {
|
if (tap_count > 0) {
|
||||||
debug("KEYMAP_TAP_KEY: Tap: register_code\n");
|
debug("KEYMAP_TAP_KEY: Tap: register_code\n");
|
||||||
register_code(action.layer.code);
|
register_code(action.layer_tap.code);
|
||||||
} else {
|
} else {
|
||||||
debug("KEYMAP_TAP_KEY: No tap: On on press\n");
|
debug("KEYMAP_TAP_KEY: No tap: On on press\n");
|
||||||
keymap_on(action.layer.val);
|
layer_on(action.layer_tap.val);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tap_count > 0) {
|
if (tap_count > 0) {
|
||||||
debug("KEYMAP_TAP_KEY: Tap: unregister_code\n");
|
debug("KEYMAP_TAP_KEY: Tap: unregister_code\n");
|
||||||
unregister_code(action.layer.code);
|
unregister_code(action.layer_tap.code);
|
||||||
} else {
|
} else {
|
||||||
debug("KEYMAP_TAP_KEY: No tap: Off on release\n");
|
debug("KEYMAP_TAP_KEY: No tap: Off on release\n");
|
||||||
keymap_off(action.layer.val);
|
layer_off(action.layer_tap.val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
/* Extentions */
|
/* Extentions */
|
||||||
#ifndef NO_ACTION_MACRO
|
#ifndef NO_ACTION_MACRO
|
||||||
@ -508,15 +436,9 @@ bool is_tap_key(key_t key)
|
|||||||
switch (action.kind.id) {
|
switch (action.kind.id) {
|
||||||
case ACT_LMODS_TAP:
|
case ACT_LMODS_TAP:
|
||||||
case ACT_RMODS_TAP:
|
case ACT_RMODS_TAP:
|
||||||
|
case ACT_LAYER_TAP:
|
||||||
|
case ACT_LAYER_TAP1:
|
||||||
return true;
|
return true;
|
||||||
case ACT_LAYER:
|
|
||||||
switch (action.layer.code) {
|
|
||||||
case 0x04 ... 0xEF: /* tap key */
|
|
||||||
case OP_INV:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
case ACT_MACRO:
|
case ACT_MACRO:
|
||||||
case ACT_FUNCTION:
|
case ACT_FUNCTION:
|
||||||
if (action.func.opt & FUNC_TAP) { return true; }
|
if (action.func.opt & FUNC_TAP) { return true; }
|
||||||
@ -555,7 +477,8 @@ void debug_action(action_t action)
|
|||||||
case ACT_USAGE: debug("ACT_USAGE"); break;
|
case ACT_USAGE: debug("ACT_USAGE"); break;
|
||||||
case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break;
|
case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break;
|
||||||
case ACT_LAYER: debug("ACT_LAYER"); break;
|
case ACT_LAYER: debug("ACT_LAYER"); break;
|
||||||
case ACT_LAYER_BITOP: debug("ACT_LAYER_BITOP"); break;
|
case ACT_LAYER_TAP: debug("ACT_LAYER_TAP"); break;
|
||||||
|
case ACT_LAYER_TAP1: debug("ACT_LAYER_TAP1"); break;
|
||||||
case ACT_MACRO: debug("ACT_MACRO"); break;
|
case ACT_MACRO: debug("ACT_MACRO"); break;
|
||||||
case ACT_COMMAND: debug("ACT_COMMAND"); break;
|
case ACT_COMMAND: debug("ACT_COMMAND"); break;
|
||||||
case ACT_FUNCTION: debug("ACT_FUNCTION"); break;
|
case ACT_FUNCTION: debug("ACT_FUNCTION"); break;
|
||||||
|
162
common/action.h
162
common/action.h
@ -63,11 +63,19 @@ typedef union {
|
|||||||
uint8_t mods :4;
|
uint8_t mods :4;
|
||||||
uint8_t kind :4;
|
uint8_t kind :4;
|
||||||
} key;
|
} key;
|
||||||
struct action_layer {
|
struct action_layer_bitop {
|
||||||
|
uint8_t bits :4;
|
||||||
|
uint8_t xbit :1;
|
||||||
|
uint8_t part :3;
|
||||||
|
uint8_t on :2;
|
||||||
|
uint8_t op :2;
|
||||||
|
uint8_t kind :4;
|
||||||
|
} layer_bitop;
|
||||||
|
struct action_layer_tap {
|
||||||
uint8_t code :8;
|
uint8_t code :8;
|
||||||
uint8_t val :5;
|
uint8_t val :5;
|
||||||
uint8_t kind :3;
|
uint8_t kind :3;
|
||||||
} layer;
|
} layer_tap;
|
||||||
struct action_usage {
|
struct action_usage {
|
||||||
uint16_t code :10;
|
uint16_t code :10;
|
||||||
uint8_t page :2;
|
uint8_t page :2;
|
||||||
@ -171,39 +179,26 @@ void debug_action(action_t action);
|
|||||||
* Layer Actions(10XX)
|
* Layer Actions(10XX)
|
||||||
* -------------------
|
* -------------------
|
||||||
* ACT_LAYER:
|
* ACT_LAYER:
|
||||||
* 1000|--xx|0000 0000 Clear keyamp
|
* 1000|oo00|pppx BBBB Default Layer Bitwise operation
|
||||||
* 100X|LLLL|0000 00xx Reset default layer and clear keymap
|
* oo: operation(00:AND, 01:OR, 10:XOR, 11:SET)
|
||||||
* 100X|LLLL| keycode Invert with tap key
|
* ppp: 4-bit chunk part(0-7)
|
||||||
* 100X|LLLL|1111 0000 Invert with tap toggle
|
* xBBBB: bits and extra bit
|
||||||
* 100X|LLLL|1111 00xx Invert[^= 1<<L]
|
* 1000|ooee|pppx BBBB Layer Bitwise Operation
|
||||||
* 100X|LLLL|1111 0100 On/Off
|
* oo: operation(00:AND, 01:OR, 10:XOR, 11:SET)
|
||||||
* 100X|LLLL|1111 01xx On[|= 1<<L]
|
* ppp: 4-bit chunk part(0-7)
|
||||||
* 100X|LLLL|1111 1000 Off/On
|
* xBBBB: bits and extra bit
|
||||||
* 100X|LLLL|1111 10xx Off[&= ~(1<<L)]
|
* ee: on event(00:default layer, 01:press, 10:release, 11:both)
|
||||||
* 100X|LLLL|1111 1100 Set/Clear
|
*
|
||||||
* 100X|LLLL|1111 11xx Set[= 1<<L]
|
* ACT_LAYER_TAP:
|
||||||
* XLLLL: Layer 0-31
|
* 101x|LLLL| keycode Invert with tap key
|
||||||
* xx: On {00:for special use, 01:press, 10:release, 11:both}
|
* 101x|LLLL|1110 xxxx Reserved(0xE0-EF)
|
||||||
|
* 101x|LLLL|1111 0000 Invert with tap toggle(0xF0)
|
||||||
|
* 101x|LLLL|1111 0001 On Off
|
||||||
|
* 101x|LLLL|1111 0010 Off On
|
||||||
|
* 101x|LLLL|1111 0011 Set Clear
|
||||||
|
* 101x|LLLL|1111 xxxx Reserved(0xF4-FF)
|
||||||
|
* xLLLL: layer(0-31)
|
||||||
*
|
*
|
||||||
* ACT_LAYER_BITOP:
|
|
||||||
* 101B|Booo|xxxx xxxx bit operation
|
|
||||||
* BB: operand. which part of layer state bits
|
|
||||||
* 00: 0-7th bit
|
|
||||||
* 01: 8-15th bit
|
|
||||||
* 10: 16-23th bit
|
|
||||||
* 11: 24-31th bit
|
|
||||||
* ooo: operation.
|
|
||||||
* 000: AND
|
|
||||||
* 001: OR
|
|
||||||
* 010: XOR
|
|
||||||
* 011:
|
|
||||||
* 100: LSHIFT
|
|
||||||
* 101: RSHIFT
|
|
||||||
* 110:
|
|
||||||
* 111:
|
|
||||||
* bbbb bbbb: bits
|
|
||||||
* layer_state |= (((layer_state>>(0bBB*8)) & 0xff) BITOP 0bxxxxxxxx)<<(0bBB*8)
|
|
||||||
* layer_state: 32-bit layer switch state
|
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
@ -234,9 +229,8 @@ enum action_kind_id {
|
|||||||
ACT_MOUSEKEY = 0b0101,
|
ACT_MOUSEKEY = 0b0101,
|
||||||
|
|
||||||
ACT_LAYER = 0b1000,
|
ACT_LAYER = 0b1000,
|
||||||
ACT_LAYER1 = 0b1001,
|
ACT_LAYER_TAP = 0b1010,
|
||||||
ACT_LAYER_BITOP = 0b1010,
|
ACT_LAYER_TAP1 = 0b1011,
|
||||||
ACT_LAYER1_BITOP = 0b1011,
|
|
||||||
|
|
||||||
ACT_MACRO = 0b1100,
|
ACT_MACRO = 0b1100,
|
||||||
ACT_COMMAND = 0b1110,
|
ACT_COMMAND = 0b1110,
|
||||||
@ -289,70 +283,60 @@ enum usage_pages {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Layer Actions:
|
/* Layer Actions */
|
||||||
* Invert layer ^= (1<<layer)
|
|
||||||
* On layer |= (1<<layer)
|
|
||||||
* Off layer &= ~(1<<layer)
|
|
||||||
* Set layer = (1<<layer)
|
|
||||||
* Clear layer = 0
|
|
||||||
*/
|
|
||||||
enum layer_param_on {
|
enum layer_param_on {
|
||||||
ON_PRESS = 1,
|
ON_PRESS = 1,
|
||||||
ON_RELEASE = 2,
|
ON_RELEASE = 2,
|
||||||
ON_BOTH = 3,
|
ON_BOTH = 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum layer_pram_op {
|
enum layer_param_op {
|
||||||
OP_RESET = 0x00,
|
OP_DEFAULT_LAYER = 0,
|
||||||
OP_INV4 = 0x00,
|
|
||||||
OP_INV = 0xF0,
|
|
||||||
OP_ON = 0xF4,
|
|
||||||
OP_OFF = 0xF8,
|
|
||||||
OP_SET = 0xFC,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum layer_pram_bitop {
|
enum layer_param_bit_op {
|
||||||
BITOP_AND,
|
OP_BIT_AND = 0,
|
||||||
BITOP_OR,
|
OP_BIT_OR,
|
||||||
BITOP_XOR,
|
OP_BIT_XOR,
|
||||||
BITOP_LSHIFT,
|
OP_BIT_SET,
|
||||||
BITOP_RSHIFT,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
enum layer_pram_tap_op {
|
||||||
* Default Layer
|
OP_TAP_TOGGLE = 0xF0,
|
||||||
*/
|
OP_ON_OFF,
|
||||||
#define ACTION_DEFAULT_LAYER ACTION(ACT_LAYER, ON_RELEASE<<8 | OP_RESET | 0)
|
OP_OFF_ON,
|
||||||
#define ACTION_DEFAULT_LAYER_SET(layer) ACTION_DEFAULT_LAYER_TO(layer, ON_RELEASE)
|
OP_SET_CLEAR,
|
||||||
#define ACTION_DEFAULT_LAYER_TO(layer, on) ACTION(ACT_LAYER, (layer)<<8 | OP_RESET | (on))
|
};
|
||||||
|
|
||||||
/*
|
/* Layer Operation 1000|ee00|ooov vvvv */
|
||||||
* Keymap Layer
|
#define ACTION_LAYER(op, val, on) (ACT_LAYER<<12 | (on)<<10 | (op)<<5 | val)
|
||||||
*/
|
/* Layer Bitwise Operation 1000|ooee|pppx BBBB */
|
||||||
|
#define ACTION_LAYER_BITOP(op, part, bits, on) (ACT_LAYER<<12 | (op)<<10 | (on)<<8 | (part)<<5 | (bits)&0x1f)
|
||||||
|
/* Layer with Tapping 101x|LLLL| keycode */
|
||||||
|
#define ACTION_LAYER_TAP(layer, key) (ACT_LAYER_TAP<<12 | (layer)<<8 | (key))
|
||||||
|
|
||||||
|
/* Default Layer Operation */
|
||||||
|
#define ACTION_DEFAULT_LAYER_SET(layer) ACTION_DEFAULT_LAYER(layer, ON_RELEASE)
|
||||||
|
#define ACTION_DEFAULT_LAYER(layer, on) ACTION_LAYER(OP_DEFAULT_LAYER, layer, on)
|
||||||
|
/* Layer Operation */
|
||||||
|
#define ACTION_LAYER_CLEAR(on) ACTION_LAYER_AND(0x1f, (on))
|
||||||
#define ACTION_LAYER_MOMENTARY(layer) ACTION_LAYER_ON_OFF(layer)
|
#define ACTION_LAYER_MOMENTARY(layer) ACTION_LAYER_ON_OFF(layer)
|
||||||
#define ACTION_LAYER_TOGGLE(layer) ACTION_LAYER_INV(layer, ON_RELEASE)
|
#define ACTION_LAYER_TOGGLE(layer) ACTION_LAYER_INVERT(layer, ON_RELEASE)
|
||||||
/* Keymap Invert */
|
#define ACTION_LAYER_INVERT(layer, on) ACTION_LAYER_BIT_XOR((layer)/4, 1<<((layer)%4), (on))
|
||||||
#define ACTION_LAYER_INV(layer, on) ACTION(ACT_LAYER, (layer)<<8 | OP_INV | (on))
|
#define ACTION_LAYER_ON(layer, on) ACTION_LAYER_BIT_OR((layer)/4, 1<<((layer)%4), (on))
|
||||||
#define ACTION_LAYER_TAP_TOGGLE(layer) ACTION(ACT_LAYER, (layer)<<8 | OP_INV | 0)
|
#define ACTION_LAYER_OFF(layer, on) ACTION_LAYER_BIT_AND((layer)/4, ~(1<<((layer)%4)), (on))
|
||||||
/* Keymap On */
|
#define ACTION_LAYER_SET(layer, on) ACTION_LAYER_BIT_SET((layer)/4, 1<<((layer)%4), (on))
|
||||||
#define ACTION_LAYER_ON(layer, on) ACTION(ACT_LAYER, (layer)<<8 | OP_ON | (on))
|
#define ACTION_LAYER_ON_OFF(layer) ACTION_LAYER_TAP((layer), OP_ON_OFF)
|
||||||
#define ACTION_LAYER_ON_OFF(layer) ACTION(ACT_LAYER, (layer)<<8 | OP_ON | 0)
|
#define ACTION_LAYER_OFF_ON(layer) ACTION_LAYER_TAP((layer), OP_OFF_ON)
|
||||||
/* Keymap Off */
|
#define ACTION_LAYER_SET_CLEAR(layer) ACTION_LAYER_TAP((layer), OP_SET_CLEAR)
|
||||||
#define ACTION_LAYER_OFF(layer, on) ACTION(ACT_LAYER, (layer)<<8 | OP_OFF | (on))
|
/* Bitwise Operation */
|
||||||
#define ACTION_LAYER_OFF_ON(layer) ACTION(ACT_LAYER, (layer)<<8 | OP_OFF | 0)
|
#define ACTION_LAYER_BIT_AND(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_AND, part, bits)
|
||||||
/* Keymap Set */
|
#define ACTION_LAYER_BIT_OR(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_OR, part, bits)
|
||||||
#define ACTION_LAYER_SET(layer, on) ACTION(ACT_LAYER, (layer)<<8 | OP_SET | (on))
|
#define ACTION_LAYER_BIT_XOR(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_XOR, part, bits)
|
||||||
#define ACTION_LAYER_SET_CLEAR(layer) ACTION(ACT_LAYER, (layer)<<8 | OP_SET | 0)
|
#define ACTION_LAYER_BIT_SET(part, bits, on) ACTION_LAYER_BITOP(OP_BIT_SET, part, bits)
|
||||||
/* Keymap Invert with tap key */
|
/* with Tapping */
|
||||||
#define ACTION_LAYER_TAP_KEY(layer, key) ACTION(ACT_LAYER, (layer)<<8 | (key))
|
#define ACTION_LAYER_TAP_KEY(layer, key) ACTION_LAYER_TAP((layer), (key))
|
||||||
|
#define ACTION_LAYER_TAP_TOGGLE(layer) ACTION_LAYER_TAP((layer), OP_TAP_TOGGLE)
|
||||||
/* Layer BitOp: 101|BB|ooo|xxxxxxxx */
|
|
||||||
#define ACTION_LAYER_BITOP(op, part, bits) (ACT_LAYER_BITOP<<12 | (part&0x3)<<11 | (op&0x7)<<8 | bits)
|
|
||||||
#define ACTION_LAYER_AND(part, bits) ACTION_LAYER_BITOP(BITOP_AND, part, bits)
|
|
||||||
#define ACTION_LAYER_OR(part, bits) ACTION_LAYER_BITOP(BITOP_OR, part, bits)
|
|
||||||
#define ACTION_LAYER_XOR(part, bits) ACTION_LAYER_BITOP(BITOP_XOR, part, bits)
|
|
||||||
#define ACTION_LAYER_LSHIFT(part, bits) ACTION_LAYER_BITOP(BITOP_LSHIFT, part, bits)
|
|
||||||
#define ACTION_LAYER_RSHIFT(part, bits) ACTION_LAYER_BITOP(BITOP_RSHIFT, part, bits)
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#define ACTION_TAPPING_H
|
#define ACTION_TAPPING_H
|
||||||
|
|
||||||
|
|
||||||
#ifndef NO_ACTION_TAPPING
|
|
||||||
|
|
||||||
/* period of tapping(ms) */
|
/* period of tapping(ms) */
|
||||||
#ifndef TAPPING_TERM
|
#ifndef TAPPING_TERM
|
||||||
@ -33,8 +32,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#define WAITING_BUFFER_SIZE 8
|
#define WAITING_BUFFER_SIZE 8
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef NO_ACTION_TAPPING
|
||||||
void action_tapping_process(keyrecord_t record);
|
void action_tapping_process(keyrecord_t record);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -573,7 +573,8 @@ static uint8_t numkey2num(uint8_t code)
|
|||||||
|
|
||||||
static void switch_default_layer(uint8_t layer)
|
static void switch_default_layer(uint8_t layer)
|
||||||
{
|
{
|
||||||
print("switch_default_layer: "); print_dec(default_layer); print(" to "); print_dec(layer); print("\n");
|
print("switch_default_layer: "); print_dec(biton32(default_layer_state));
|
||||||
default_layer_set(layer);
|
default_layer_set(layer);
|
||||||
|
print(" to "); print_dec(biton32(default_layer_state)); print("\n");
|
||||||
clear_keyboard();
|
clear_keyboard();
|
||||||
}
|
}
|
||||||
|
@ -7,94 +7,103 @@
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Default Layer (0-15)
|
* Default Layer State
|
||||||
*/
|
*/
|
||||||
uint8_t default_layer = 0;
|
uint32_t default_layer_state = 0;
|
||||||
|
|
||||||
|
static void default_layer_state_set(uint32_t state)
|
||||||
|
{
|
||||||
|
debug("default_layer_state: ");
|
||||||
|
default_layer_debug(); debug(" to ");
|
||||||
|
default_layer_state = state;
|
||||||
|
default_layer_debug(); debug("\n");
|
||||||
|
clear_keyboard_but_mods(); // To avoid stuck keys
|
||||||
|
}
|
||||||
|
|
||||||
|
void default_layer_debug(void)
|
||||||
|
{
|
||||||
|
debug_hex32(default_layer_state);
|
||||||
|
debug("("); debug_dec(biton32(default_layer_state)); debug(")");
|
||||||
|
}
|
||||||
|
|
||||||
void default_layer_set(uint8_t layer)
|
void default_layer_set(uint8_t layer)
|
||||||
{
|
{
|
||||||
debug("default_layer_set: ");
|
default_layer_state_set(1UL<<layer);
|
||||||
debug_dec(default_layer); debug(" to ");
|
|
||||||
|
|
||||||
default_layer = layer;
|
|
||||||
|
|
||||||
debug_dec(default_layer); debug("\n");
|
|
||||||
|
|
||||||
clear_keyboard_but_mods(); // To avoid stuck keys
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef NO_ACTION_LAYER
|
||||||
|
void default_layer_or(uint32_t state)
|
||||||
|
{
|
||||||
|
default_layer_state_set(default_layer_state | state);
|
||||||
|
}
|
||||||
|
void default_layer_and(uint32_t state)
|
||||||
|
{
|
||||||
|
default_layer_state_set(default_layer_state & state);
|
||||||
|
}
|
||||||
|
void default_layer_xor(uint32_t state)
|
||||||
|
{
|
||||||
|
default_layer_state_set(default_layer_state ^ state);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef NO_ACTION_LAYER
|
#ifndef NO_ACTION_LAYER
|
||||||
/*
|
/*
|
||||||
* Keymap Layer (0-15)
|
* Keymap Layer State
|
||||||
*/
|
*/
|
||||||
uint16_t keymap_stat = 0;
|
uint32_t layer_state = 0;
|
||||||
|
|
||||||
/* return highest layer whose state is on */
|
static void layer_state_set(uint32_t state)
|
||||||
uint8_t keymap_get_layer(void)
|
|
||||||
{
|
{
|
||||||
return biton16(keymap_stat);
|
debug("layer_state: ");
|
||||||
}
|
layer_debug(); debug(" to ");
|
||||||
|
layer_state = state;
|
||||||
static void keymap_stat_set(uint16_t stat)
|
layer_debug(); debug("\n");
|
||||||
{
|
|
||||||
debug("keymap: ");
|
|
||||||
keymap_debug(); debug(" to ");
|
|
||||||
|
|
||||||
keymap_stat = stat;
|
|
||||||
|
|
||||||
keymap_debug(); debug("\n");
|
|
||||||
|
|
||||||
clear_keyboard_but_mods(); // To avoid stuck keys
|
clear_keyboard_but_mods(); // To avoid stuck keys
|
||||||
}
|
}
|
||||||
|
|
||||||
void keymap_clear(void)
|
void layer_clear(void)
|
||||||
{
|
{
|
||||||
keymap_stat_set(0);
|
layer_state_set(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void layer_move(uint8_t layer)
|
||||||
void keymap_set(uint16_t stat)
|
|
||||||
{
|
{
|
||||||
keymap_stat_set(stat);
|
layer_state_set(1UL<<layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void keymap_move(uint8_t layer)
|
void layer_on(uint8_t layer)
|
||||||
{
|
{
|
||||||
keymap_stat_set(1<<layer);
|
layer_state_set(layer_state | (1UL<<layer));
|
||||||
}
|
}
|
||||||
|
|
||||||
void keymap_on(uint8_t layer)
|
void layer_off(uint8_t layer)
|
||||||
{
|
{
|
||||||
keymap_stat_set(keymap_stat | (1<<layer));
|
layer_state_set(layer_state & ~(1UL<<layer));
|
||||||
}
|
}
|
||||||
|
|
||||||
void keymap_off(uint8_t layer)
|
void layer_invert(uint8_t layer)
|
||||||
{
|
{
|
||||||
keymap_stat_set(keymap_stat & ~(1<<layer));
|
layer_state_set(layer_state ^ (1UL<<layer));
|
||||||
}
|
}
|
||||||
|
|
||||||
void keymap_invert(uint8_t layer)
|
void layer_or(uint32_t state)
|
||||||
{
|
{
|
||||||
keymap_stat_set(keymap_stat ^ (1<<layer));
|
layer_state_set(layer_state | state);
|
||||||
|
}
|
||||||
|
void layer_and(uint32_t state)
|
||||||
|
{
|
||||||
|
layer_state_set(layer_state & state);
|
||||||
|
}
|
||||||
|
void layer_xor(uint32_t state)
|
||||||
|
{
|
||||||
|
layer_state_set(layer_state ^ state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void keymap_or(uint16_t stat)
|
void layer_debug(void)
|
||||||
{
|
{
|
||||||
keymap_stat_set(keymap_stat | stat);
|
debug_hex32(layer_state);
|
||||||
}
|
debug("("); debug_dec(biton32(layer_state)); debug(")");
|
||||||
void keymap_and(uint16_t stat)
|
|
||||||
{
|
|
||||||
keymap_stat_set(keymap_stat & stat);
|
|
||||||
}
|
|
||||||
void keymap_xor(uint16_t stat)
|
|
||||||
{
|
|
||||||
keymap_stat_set(keymap_stat ^ stat);
|
|
||||||
}
|
|
||||||
|
|
||||||
void keymap_debug(void)
|
|
||||||
{
|
|
||||||
debug_hex16(keymap_stat); debug("("); debug_dec(keymap_get_layer()); debug(")");
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -106,18 +115,21 @@ action_t layer_switch_get_action(key_t key)
|
|||||||
action.code = ACTION_TRANSPARENT;
|
action.code = ACTION_TRANSPARENT;
|
||||||
|
|
||||||
#ifndef NO_ACTION_LAYER
|
#ifndef NO_ACTION_LAYER
|
||||||
/* keymap: top layer first */
|
uint32_t layers = layer_state | default_layer_state;
|
||||||
for (int8_t i = 15; i >= 0; i--) {
|
/* check top layer first */
|
||||||
if (keymap_stat & (1<<i)) {
|
for (int8_t i = 31; i >= 0; i--) {
|
||||||
|
if (layers & (1UL<<i)) {
|
||||||
action = action_for_key(i, key);
|
action = action_for_key(i, key);
|
||||||
if (action.code != ACTION_TRANSPARENT) {
|
if (action.code != ACTION_TRANSPARENT) {
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
/* fall back to layer 0 */
|
||||||
|
action = action_for_key(0, key);
|
||||||
/* default layer */
|
|
||||||
action = action_for_key(default_layer, key);
|
|
||||||
return action;
|
return action;
|
||||||
|
#else
|
||||||
|
action = action_for_key(biton32(default_layer_state), key);
|
||||||
|
return action;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -25,42 +25,49 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
/*
|
/*
|
||||||
* Default Layer
|
* Default Layer
|
||||||
*/
|
*/
|
||||||
/* base layer to fall back */
|
extern uint32_t default_layer_state;
|
||||||
extern uint8_t default_layer;
|
void default_layer_debug(void);
|
||||||
void default_layer_set(uint8_t layer);
|
void default_layer_set(uint8_t layer);
|
||||||
|
|
||||||
|
#ifndef NO_ACTION_LAYER
|
||||||
|
/* bitwise operation */
|
||||||
|
void default_layer_or(uint32_t state);
|
||||||
|
void default_layer_and(uint32_t state);
|
||||||
|
void default_layer_xor(uint32_t state);
|
||||||
|
#else
|
||||||
|
#define default_layer_or(state)
|
||||||
|
#define default_layer_and(state)
|
||||||
|
#define default_layer_xor(state)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Keymap Layer
|
* Keymap Layer
|
||||||
*/
|
*/
|
||||||
#ifndef NO_ACTION_LAYER
|
#ifndef NO_ACTION_LAYER
|
||||||
extern uint16_t keymap_stat;
|
extern uint32_t layer_state;
|
||||||
/* return current active layer */
|
void layer_debug(void);
|
||||||
uint8_t keymap_get_layer(void);
|
void layer_clear(void);
|
||||||
void keymap_clear(void);
|
void layer_move(uint8_t layer);
|
||||||
void keymap_set(uint16_t stat);
|
void layer_on(uint8_t layer);
|
||||||
void keymap_move(uint8_t layer);
|
void layer_off(uint8_t layer);
|
||||||
void keymap_on(uint8_t layer);
|
void layer_invert(uint8_t layer);
|
||||||
void keymap_off(uint8_t layer);
|
|
||||||
void keymap_invert(uint8_t layer);
|
|
||||||
/* bitwise operation */
|
/* bitwise operation */
|
||||||
void keymap_or(uint16_t stat);
|
void layer_or(uint32_t state);
|
||||||
void keymap_and(uint16_t stat);
|
void layer_and(uint32_t state);
|
||||||
void keymap_xor(uint16_t stat);
|
void layer_xor(uint32_t state);
|
||||||
void keymap_debug(void);
|
|
||||||
#else
|
#else
|
||||||
#define keymap_stat 0
|
#define layer_state 0
|
||||||
#define keymap_get_layer()
|
#define layer_clear()
|
||||||
#define keymap_clear()
|
#define layer_move(layer)
|
||||||
#define keymap_set(stat)
|
#define layer_on(layer)
|
||||||
#define keymap_move(layer)
|
#define layer_off(layer)
|
||||||
#define keymap_on(layer)
|
#define layer_invert(layer)
|
||||||
#define keymap_off(layer)
|
|
||||||
#define keymap_invert(layer)
|
#define layer_or(state)
|
||||||
#define keymap_or(stat)
|
#define layer_and(state)
|
||||||
#define keymap_and(stat)
|
#define layer_xor(state)
|
||||||
#define keymap_xor(stat)
|
#define layer_debug()
|
||||||
#define keymap_debug()
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,6 +38,14 @@ uint8_t bitpop16(uint16_t bits)
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t bitpop32(uint32_t bits)
|
||||||
|
{
|
||||||
|
uint8_t c;
|
||||||
|
for (c = 0; bits; c++)
|
||||||
|
bits &= bits - 1;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
// most significant on-bit - return highest location of on-bit
|
// most significant on-bit - return highest location of on-bit
|
||||||
// NOTE: return 0 when bit0 is on or all bits are off
|
// NOTE: return 0 when bit0 is on or all bits are off
|
||||||
uint8_t biton(uint8_t bits)
|
uint8_t biton(uint8_t bits)
|
||||||
@ -58,3 +66,14 @@ uint8_t biton16(uint16_t bits)
|
|||||||
if (bits >> 1) { bits >>= 1; n += 1;}
|
if (bits >> 1) { bits >>= 1; n += 1;}
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t biton32(uint32_t bits)
|
||||||
|
{
|
||||||
|
uint8_t n = 0;
|
||||||
|
if (bits >>16) { bits >>=16; n +=16;}
|
||||||
|
if (bits >> 8) { bits >>= 8; n += 8;}
|
||||||
|
if (bits >> 4) { bits >>= 4; n += 4;}
|
||||||
|
if (bits >> 2) { bits >>= 2; n += 2;}
|
||||||
|
if (bits >> 1) { bits >>= 1; n += 1;}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
@ -30,7 +30,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
uint8_t bitpop(uint8_t bits);
|
uint8_t bitpop(uint8_t bits);
|
||||||
uint8_t bitpop16(uint16_t bits);
|
uint8_t bitpop16(uint16_t bits);
|
||||||
|
uint8_t bitpop32(uint32_t bits);
|
||||||
|
|
||||||
uint8_t biton(uint8_t bits);
|
uint8_t biton(uint8_t bits);
|
||||||
uint8_t biton16(uint16_t bits);
|
uint8_t biton16(uint16_t bits);
|
||||||
|
uint8_t biton32(uint32_t bits);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user