summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/action.c213
-rw-r--r--common/action.h190
2 files changed, 152 insertions, 251 deletions
diff --git a/common/action.c b/common/action.c
index 301a9b6a0a..f6e50032eb 100644
--- a/common/action.c
+++ b/common/action.c
@@ -319,14 +319,14 @@ static void process_action(keyrecord_t *record)
case ACT_USAGE:
#ifdef EXTRAKEY_ENABLE
switch (action.usage.page) {
- case ACTION_USAGE_PAGE_SYSTEM:
+ case PAGE_SYSTEM:
if (event.pressed) {
host_system_send(action.usage.code);
} else {
host_system_send(0);
}
break;
- case ACTION_USAGE_PAGE_CONSUMER:
+ case PAGE_CONSUMER:
if (event.pressed) {
host_consumer_send(action.usage.code);
} else {
@@ -351,20 +351,44 @@ static void process_action(keyrecord_t *record)
break;
/* Layer key */
- case ACT_LAYER_PRESSED:
- // layer action when pressed
+ case ACT_LAYER:
switch (action.layer.code) {
- case 0x00:
+ case LAYER_MOMENTARY: /* momentary */
if (event.pressed) {
layer_switch(action.layer.val);
}
-//TODO: this is ok?
else {
layer_switch(default_layer);
}
break;
- case 0xF0:
- // tap toggle
+ case LAYER_ON_PRESS:
+ if (event.pressed) {
+ layer_switch(action.layer.val);
+ }
+ break;
+ case LAYER_ON_RELEASE:
+ if (!event.pressed) {
+ layer_switch(action.layer.val);
+ }
+ break;
+ case LAYER_DEFAULT: /* default layer */
+ switch (action.layer.val) {
+ case DEFAULT_ON_BOTH:
+ layer_switch(default_layer);
+ break;
+ case DEFAULT_ON_PRESS:
+ if (event.pressed) {
+ layer_switch(default_layer);
+ }
+ break;
+ case DEFAULT_ON_RELEASE:
+ if (!event.pressed) {
+ layer_switch(default_layer);
+ }
+ break;
+ }
+ break;
+ case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */
if (event.pressed) {
if (tap_count < TAPPING_TOGGLE) {
layer_switch(action.layer.val);
@@ -376,15 +400,13 @@ static void process_action(keyrecord_t *record)
}
}
break;
- case 0xFF:
- // change default layer
+ case LAYER_CHANGE_DEFAULT: /* change default layer */
if (event.pressed) {
default_layer = action.layer.val;
layer_switch(default_layer);
}
break;
- default:
- // with tap key
+ default: /* switch layer on hold and key on tap*/
if (event.pressed) {
if (tap_count > 0) {
debug("LAYER_PRESSED: Tap: register_code\n");
@@ -407,65 +429,26 @@ static void process_action(keyrecord_t *record)
break;
}
break;
- case ACT_LAYER_RELEASED:
+ case ACT_LAYER_BIT:
switch (action.layer.code) {
- case 0x00:
- if (!event.pressed) {
- layer_switch(action.layer.val);
- }
- break;
- case 0xF0:
- // tap toggle
+ case LAYER_MOMENTARY: /* momentary */
if (event.pressed) {
- if (tap_count >= TAPPING_TOGGLE) {
- debug("LAYER_RELEASED: tap toggle.\n");
- layer_switch(action.layer.val);
- }
+ layer_switch(current_layer ^ action.layer.val);
} else {
- if (tap_count < TAPPING_TOGGLE) {
- layer_switch(action.layer.val);
- }
- }
- break;
- case 0xFF:
- // change default layer
- if (!event.pressed) {
- default_layer = action.layer.val;
- layer_switch(default_layer);
+ layer_switch(current_layer ^ action.layer.val);
}
break;
- default:
- // with tap key
+ case LAYER_ON_PRESS:
if (event.pressed) {
- if (tap_count > 0) {
- debug("LAYER_RELEASED: Tap: register_code\n");
- register_code(action.layer.code);
- } else {
- debug("LAYER_RELEASED: No tap: NO ACTION\n");
- }
- } else {
- if (tap_count > 0) {
- debug("LAYER_RELEASED: Tap: unregister_code\n");
- unregister_code(action.layer.code);
- } else {
- debug("LAYER_RELEASED: No tap: layer_switch\n");
- layer_switch(action.layer.val);
- }
+ layer_switch(current_layer ^ action.layer.val);
}
break;
- }
- break;
- case ACT_LAYER_BIT:
- switch (action.layer.code) {
- case 0x00:
- if (event.pressed) {
- layer_switch(current_layer ^ action.layer.val);
- } else {
+ case LAYER_ON_RELEASE:
+ if (!event.pressed) {
layer_switch(current_layer ^ action.layer.val);
}
break;
- case 0xF0:
- // tap toggle
+ case LAYER_TAP_TOGGLE: /* switch on hold and toggle on several taps */
if (event.pressed) {
if (tap_count < TAPPING_TOGGLE) {
debug("LAYER_BIT: tap toggle(press).\n");
@@ -510,108 +493,6 @@ static void process_action(keyrecord_t *record)
break;
}
break;
- case ACT_LAYER_EXT:
- switch (action.layer.val) {
- case 0x00:
- // set default layer when pressed
- switch (action.layer.code) {
- case 0x00:
- if (event.pressed) {
- layer_switch(default_layer);
- }
- break;
- case 0xF0:
- // tap toggle
- if (event.pressed) {
- if (tap_count < TAPPING_TOGGLE) {
- layer_switch(default_layer);
- }
- } else {
- if (tap_count >= TAPPING_TOGGLE) {
- debug("LAYER_EXT_PRESSED: tap toggle.\n");
- layer_switch(default_layer);
- }
- }
- break;
- case 0xFF:
- // change default layer
- if (event.pressed) {
- default_layer = current_layer;
- layer_switch(default_layer);
- }
- break;
- default:
- // with tap key
- if (event.pressed) {
- if (tap_count > 0) {
- debug("LAYER_EXT_PRESSED: Tap: register_code\n");
- register_code(action.layer.code);
- } else {
- debug("LAYER_EXT_PRESSED: No tap: layer_switch\n");
- layer_switch(default_layer);
- }
- } else {
- if (tap_count > 0) {
- debug("LAYER_EXT_PRESSED: Tap: unregister_code\n");
- unregister_code(action.layer.code);
- } else {
- debug("LAYER_EXT_PRESSED: No tap: NO ACTION\n");
- }
- }
- break;
- }
- break;
- case 0x01:
- // set default layer when released
- switch (action.layer.code) {
- case 0x00:
- if (!event.pressed) {
- layer_switch(default_layer);
- }
- break;
- case 0xF0:
- // tap toggle
- if (event.pressed) {
- if (tap_count >= TAPPING_TOGGLE) {
- debug("LAYER_EXT_RELEASED: tap toggle.\n");
- layer_switch(default_layer);
- }
- } else {
- if (tap_count < TAPPING_TOGGLE) {
- layer_switch(default_layer);
- }
- }
- break;
- case 0xFF:
- // change default layer
- if (!event.pressed) {
- default_layer = current_layer;
- layer_switch(default_layer);
- }
- break;
- default:
- // with tap key
- if (event.pressed) {
- if (tap_count > 0) {
- debug("LAYER_EXT_RELEASED: Tap: register_code\n");
- register_code(action.layer.code);
- } else {
- debug("LAYER_EXT_RELEASED: No tap: NO ACTION\n");
- }
- } else {
- if (tap_count > 0) {
- debug("LAYER_EXT_RELEASED: Tap: unregister_code\n");
- unregister_code(action.layer.code);
- } else {
- debug("LAYER_EXT_RELEASED: No tap: layer_switch\n");
- layer_switch(default_layer);
- }
- }
- break;
- }
- break;
- }
- break;
/* Extentions */
case ACT_MACRO:
@@ -932,7 +813,7 @@ bool is_tap_key(key_t key)
case ACT_LMODS_TAP:
case ACT_RMODS_TAP:
return true;
- case ACT_LAYER_PRESSED:
+ case ACT_LAYER:
case ACT_LAYER_BIT:
switch (action.layer.code) {
case 0x00:
@@ -944,7 +825,7 @@ bool is_tap_key(key_t key)
}
return false;
case ACT_FUNCTION:
- if (action.func.opt & O_TAP) {
+ if (action.func.opt & FUNC_TAP) {
return true;
}
return false;
@@ -975,10 +856,8 @@ static void debug_action(action_t action)
case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break;
case ACT_USAGE: debug("ACT_USAGE"); break;
case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break;
- case ACT_LAYER_PRESSED: debug("ACT_LAYER_PRESSED"); break;
- case ACT_LAYER_RELEASED: debug("ACT_LAYER_RELEASED"); break;
+ case ACT_LAYER: debug("ACT_LAYER"); break;
case ACT_LAYER_BIT: debug("ACT_LAYER_BIT"); break;
- case ACT_LAYER_EXT: debug("ACT_LAYER_EXT"); break;
case ACT_MACRO: debug("ACT_MACRO"); break;
case ACT_COMMAND: debug("ACT_COMMAND"); break;
case ACT_FUNCTION: debug("ACT_FUNCTION"); break;
diff --git a/common/action.h b/common/action.h
index b1e958a266..800554eb8f 100644
--- a/common/action.h
+++ b/common/action.h
@@ -150,42 +150,26 @@ ACT_MOUSEKEY(0110):
Layer Actions
-------------
-TODO: reconsider layer methods.
-1 momemtary + tap key up: L, down: default
-1 bitwise + tap key up: xor B, down: xor B
-3 momemtary go + tap key? up: X, down:
-3 toggle(mementary back) + tap key? up: down: Y
-3 no tap up: X, down: Y
-
-ACT_LAYER_PRESSED(1000): Set layer on key pressed
-ACT_LAYER_RELEASED(1001): Set layer on key released
-ACT_LAYER_BIT(1010): On/Off layer bit
-ACT_LAYER_EXT(1011): Extentions
-
-1000|LLLL|0000 0000 set layer L when pressed
-1001|LLLL|0000 0000 set layer L when released
-1010|BBBB|0000 0000 on/off bit B when pressed/released
-1011|0000|0000 0000 set default layer when pressed
-1011|0001|0000 0000 set default layer when released
-
-1000|LLLL|1111 0000 set layer L when pressed + tap toggle
-1001|LLLL|1111 0000 set layer L when released + tap toggle
-1010|BBBB|1111 0000 on/off bit B when pressed/released + tap toggle
-1011|0000|1111 0000 set default layer when pressed + tap toggle
-1011|0001|1111 0000 set default layer when released + tap toggle
-
-1000|LLLL|1111 1111 set L to default layer when pressed
-1001|LLLL|1111 1111 set L to default layer when released
-1010|BBBB|1111 1111 on/off bit B of default layer when pressed/released
-1011|0000|1111 1111 set current to default layer when pressed
-1011|0001|1111 1111 set current to default layer when released
-
-1000|LLLL| keycode set layer L when pressed + tap key
-1001|LLLL| keyocde set layer L when released + tap key
-1010|BBBB| keyocde on/off bit B when pressed/released + tap key
-1011|0000| keyocde set default layer when pressed + tap key
-1011|0001| keyocde set default layer when released + tap key
-
+ACT_LAYER(1000): Set layer
+ACT_LAYER_BIT(1001): Bit-op layer
+
+1000|LLLL|0000 0000 set L to layer on press and set default on release(momentary)
+1000|LLLL|0000 0001 set L to layer on press
+1000|LLLL|0000 0010 set L to layer on release
+1000|----|0000 0011 set default to layer on both(return to default layer)
+1000|LLLL|xxxx xxxx set L to layer while hold and send key on tap
+1000|LLLL|1111 0000 set L to layer while hold and toggle on several taps
+1000|LLLL|1111 1111 set L to default and layer(on press)
+
+1001|BBBB|0000 0000 (not used)
+1001|BBBB|0000 0001 bit-xor layer with B on press
+1001|BBBB|0000 0010 bit-xor layer with B on release
+1001|BBBB|0000 0011 bit-xor layer with B on both(momentary)
+1001|BBBB|xxxx xxxx bit-xor layer with B while hold and send key on tap
+1001|BBBB|1111 0000 bit-xor layer with B while hold and toggle on several taps
+1001|BBBB|1111 1111 bit-xor default with B and set layer(on press)
+
+
Extensions(11XX)
----------------
@@ -212,24 +196,14 @@ enum action_kind_id {
ACT_USAGE = 0b0100,
ACT_MOUSEKEY = 0b0101,
- ACT_LAYER_PRESSED = 0b1000,
- ACT_LAYER_RELEASED = 0b1001,
- ACT_LAYER_BIT = 0b1010,
- ACT_LAYER_EXT = 0b1011,
+ ACT_LAYER = 0b1000,
+ ACT_LAYER_BIT = 0b1001,
ACT_MACRO = 0b1100,
ACT_COMMAND = 0b1110,
ACT_FUNCTION = 0b1111
};
-enum params {
- P_ONESHOT = 0x00,
-};
-
-enum options {
- O_TAP = 0x8,
-};
-
/* action utility */
#define ACTION_NO 0
@@ -250,48 +224,93 @@ enum options {
#define ACTION_RMOD_KEY(mod, key) ACTION(ACT_RMODS, MODS4(MOD_BIT(mod))<<8 | (key))
/* Mods + Tap key */
+enum mods_codes {
+ MODS_ONESHOT = 0x00,
+};
#define ACTION_LMODS_TAP_KEY(mods, key) ACTION(ACT_LMODS_TAP, MODS4(mods)<<8 | (key))
-#define ACTION_LMODS_ONESHOT(mods) ACTION(ACT_LMODS_TAP, MODS4(mods)<<8 | P_ONESHOT)
+#define ACTION_LMODS_ONESHOT(mods) ACTION(ACT_LMODS_TAP, MODS4(mods)<<8 | MODS_ONESHOT)
#define ACTION_RMODS_TAP_KEY(mods, key) ACTION(ACT_RMODS_TAP, MODS4(mods)<<8 | (key))
-#define ACTION_RMODS_ONESHOT(mods) ACTION(ACT_RMODS_TAP, MODS4(mods)<<8 | P_ONESHOT)
+#define ACTION_RMODS_ONESHOT(mods) ACTION(ACT_RMODS_TAP, MODS4(mods)<<8 | MODS_ONESHOT)
/* Mod + Tap key */
#define ACTION_LMOD_TAP_KEY(mod, key) ACTION(ACT_LMODS_TAP, MODS4(MOD_BIT(mod))<<8 | (key))
-#define ACTION_LMOD_ONESHOT(mod) ACTION(ACT_LMODS_TAP, MODS4(MOD_BIT(mod))<<8 | P_ONESHOT)
+#define ACTION_LMOD_ONESHOT(mod) ACTION(ACT_LMODS_TAP, MODS4(MOD_BIT(mod))<<8 | MODS_ONESHOT)
#define ACTION_RMOD_TAP_KEY(mod, key) ACTION(ACT_RMODS_TAP, MODS4(MOD_BIT(mod))<<8 | (key))
-#define ACTION_RMOD_ONESHOT(mod) ACTION(ACT_RMODS_TAP, MODS4(MOD_BIT(mod))<<8 | P_ONESHOT)
-
-// TODO: contemplate about layer action
-/* Switch current layer */
-#define ACTION_LAYER_SET(layer) ACTION(ACT_LAYER_PRESSED, (layer)<<8 | 0x00)
-#define ACTION_LAYER_SET_ON_PRESSED(layer) ACTION(ACT_LAYER_PRESSED, (layer)<<8 | 0x00)
-#define ACTION_LAYER_SET_ON_RELEASED(layer) ACTION(ACT_LAYER_RELEASED, (layer)<<8 | 0x00)
-#define ACTION_LAYER_BIT(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | 0x00)
-#define ACTION_LAYER_SET_DEFAULT ACTION(ACT_LAYER_EXT, 0x0<<8 | 0x00)
-#define ACTION_LAYER_RETURN_DEFAULT ACTION(ACT_LAYER_EXT, 0x1<<8 | 0x00)
-#define ACTION_LAYER_SET_DEFAULT_ON_PRESSED ACTION(ACT_LAYER_EXT, 0x0<<8 | 0x00)
-#define ACTION_LAYER_SET_DEFAULT_ON_RELEASED ACTION(ACT_LAYER_EXT, 0x1<<8 | 0x00)
-/* Switch default layer */
-#define ACTION_LAYER_DEFAULT_SET(layer) ACTION(ACT_LAYER_PRESSED, (layer)<<8 | 0xFF)
-#define ACTION_LAYER_DEFAULT_SET_ON_PRESSED(layer) ACTION(ACT_LAYER_PRESSED, (layer)<<8 | 0xFF)
-#define ACTION_LAYER_DEFAULT_SET_ON_RELEASED(layer) ACTION(ACT_LAYER_RELEASED, (layer)<<8 | 0xFF)
-#define ACTION_LAYER_DEFAULT_BIT(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | 0xFF)
-#define ACTION_LAYER_DEFAULT_SET_CURRENT_ON_PRESSED ACTION(ACT_LAYER_EXT, 0x0<<8 | 0xFF)
-#define ACTION_LAYER_DEFAULT_SET_CURRENT_ON_RELEASED ACTION(ACT_LAYER_EXT, 0x1<<8 | 0xFF)
-/* Layer switch with tap key */
-#define ACTION_LAYER_SET_TAP_KEY(layer, key) ACTION(ACT_LAYER_PRESSED, (layer)<<8 | (key))
-#define ACTION_LAYER_BIT_TAP_KEY(bits, key) ACTION(ACT_LAYER_BIT, (bits)<<8 | (key))
-#define ACTION_LAYER_DEFAULT_SET_TAP_KEY(key) ACTION(ACT_LAYER_EXT, 0x0<<8 | (key))
-/* Layer switch with tap toggle */
-#define ACTION_LAYER_SET_ON_PRESSED_TAP_TOGGLE(layer) ACTION(ACT_LAYER_PRESSED, (layer)<<8 | 0xF0)
-#define ACTION_LAYER_SET_ON_RELEASED_TAP_TOGGLE(layer) ACTION(ACT_LAYER_RELEASED, (layer)<<8 | 0xF0)
-#define ACTION_LAYER_BIT_TAP_TOGGLE(layer) ACTION(ACT_LAYER_BIT, (layer)<<8 | 0xF0)
-#define ACTION_LAYER_DEFAULT_TAP_TOGGLE ACTION(ACT_LAYER_EXT, 0x0<<8 | 0xF0)
+#define ACTION_RMOD_ONESHOT(mod) ACTION(ACT_RMODS_TAP, MODS4(MOD_BIT(mod))<<8 | MODS_ONESHOT)
+
+
+/*
+ * Switch layer
+ */
+enum layer_codes {
+ LAYER_MOMENTARY = 0,
+ LAYER_ON_PRESS = 1,
+ LAYER_ON_RELEASE = 2,
+ LAYER_DEFAULT =3,
+ LAYER_TAP_TOGGLE = 0xF0,
+ LAYER_CHANGE_DEFAULT = 0xFF
+};
+enum layer_vals_default {
+ DEFAULT_ON_PRESS = 1,
+ DEFAULT_ON_RELEASE = 2,
+ DEFAULT_ON_BOTH = 3,
+};
+
+/*
+ * return to default layer
+ */
+#define ACTION_LAYER_DEFAULT ACTION_LAYER_DEFAULT_R
+/* set default layer on press */
+#define ACTION_LAYER_DEFAULT_P ACTION(ACT_LAYER, DEFAULT_ON_PRESS<<8 | LAYER_DEFAULT)
+/* set default layer on release */
+#define ACTION_LAYER_DEFAULT_R ACTION(ACT_LAYER, DEFAULT_ON_RELEASE<<8 | LAYER_DEFAULT)
+/* change default layer and set layer */
+
+/*
+ * Set layer
+ */
+/* set layer on press and set default on release */
+#define ACTION_LAYER_SET(layer) ACTION_LAYER_SET_MOMENTARY(layer)
+#define ACTION_LAYER_SET_MOMENTARY(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_MOMENTARY)
+/* set layer on press and none on release */
+#define ACTION_LAYER_SET_TOGGLE(layer) ACTION_LAYER_SET_R(layer)
+/* set layer while hold and send key on tap */
+#define ACTION_LAYER_SET_TAP_KEY(layer, key) ACTION(ACT_LAYER, (layer)<<8 | (key))
+/* set layer on press */
+#define ACTION_LAYER_SET_P(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_ON_PRESS)
+/* set layer on release */
+#define ACTION_LAYER_SET_R(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_ON_RELEASE)
+/* set layer on hold and toggle on several taps */
+#define ACTION_LAYER_SET_TAP_TOGGLE(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_TAP_TOGGLE)
+/* set default layer on both press and release */
+#define ACTION_LAYER_SET_DEFAULT(layer) ACTION(ACT_LAYER, (layer)<<8 | LAYER_CHANGE_DEFAULT)
+
+/*
+ * Bit-op layer
+ */
+/* bit-xor on both press and release */
+#define ACTION_LAYER_BIT(bits) ACTION_LAYER_BIT_MOMENTARY(bits)
+#define ACTION_LAYER_BIT_MOMENTARY(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_MOMENTARY)
+/* bit-xor on press */
+#define ACTION_LAYER_BIT_TOGGLE(bits) ACTION_LAYER_BIT_R(bits)
+/* bit-xor while hold and send key on tap */
+#define ACTION_LAYER_BIT_TAP_KEY(bits, key) ACTION(ACT_LAYER_BIT, (bits)<<8 | (key))
+/* bit-xor on press */
+#define ACTION_LAYER_BIT_P(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_ON_PRESS)
+/* bit-xor on release */
+#define ACTION_LAYER_BIT_R(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_ON_RELEASE)
+/* bit-xor while hold and toggle on several taps */
+#define ACTION_LAYER_BIT_TAP_TOGGLE(bits) ACTION(ACT_LAYER_BIT, (bits)<<8 | LAYER_TAP_TOGGLE)
+/* bit-xor default layer and set layer */
+#define ACTION_LAYER_BIT_DEFAULT(bits) ACTION(ACT_LAYER, (bits)<<8 | LAYER_CHANGE_DEFAULT)
+
/* HID Usage */
-#define ACTION_USAGE_PAGE_SYSTEM 0
-#define ACTION_USAGE_PAGE_CONSUMER 1
-#define ACTION_USAGE_SYSTEM(id) ACTION(ACT_USAGE, ACTION_USAGE_PAGE_SYSTEM<<10 | (id))
-#define ACTION_USAGE_CONSUMER(id) ACTION(ACT_USAGE, ACTION_USAGE_PAGE_CONSUMER<<10 | (id))
+enum usage_pages {
+ PAGE_SYSTEM,
+ PAGE_CONSUMER
+};
+#define ACTION_USAGE_SYSTEM(id) ACTION(ACT_USAGE, PAGE_SYSTEM<<10 | (id))
+#define ACTION_USAGE_CONSUMER(id) ACTION(ACT_USAGE, PAGE_CONSUMER<<10 | (id))
/* Mousekey */
#define ACTION_MOUSEKEY(key) ACTION(ACT_MOUSEKEY, key)
@@ -303,7 +322,10 @@ enum options {
#define ACTION_COMMAND(opt, id) ACTION(ACT_COMMAND, (opt)<<8 | (addr))
/* Function */
+enum function_opts {
+ FUNC_TAP = 0x8,
+};
#define ACTION_FUNCTION(id, opt) ACTION(ACT_FUNCTION, (opt)<<8 | id)
-#define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, O_TAP<<8 | id)
+#define ACTION_FUNCTION_TAP(id) ACTION(ACT_FUNCTION, FUNC_TAP<<8 | id)
#endif /* ACTION_H */