summaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2017-02-07 13:18:47 -0500
committerGitHub <noreply@github.com>2017-02-07 13:18:47 -0500
commit3c7fa0acc10305a573bc3bb29243a7a3d601579b (patch)
tree49aa463e861b30c3fa0bd454679e1aefebcb7c9c /tmk_core
parent0c2b6951a6ad80649798c0eca36a9999ebae0b13 (diff)
parent77e54e34e129a03e58c128171a7188978ec908b4 (diff)
Merge pull request #1046 from LukeSilva/master
Add Tapping Macros to QMK
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/common/action_code.h10
-rw-r--r--tmk_core/common/action_macro.h26
2 files changed, 31 insertions, 5 deletions
diff --git a/tmk_core/common/action_code.h b/tmk_core/common/action_code.h
index 33da35f35f..b15aaa0eb3 100644
--- a/tmk_core/common/action_code.h
+++ b/tmk_core/common/action_code.h
@@ -47,10 +47,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* 0100|10| usage(10) (reserved)
* 0100|11| usage(10) (reserved)
*
- * ACT_MOUSEKEY(0110): TODO: Not needed?
+ *
+ * ACT_MOUSEKEY(0101): TODO: Merge these two actions to conserve space?
* 0101|xxxx| keycode Mouse key
*
- * 011x|xxxx xxxx xxxx (reseved)
+ * ACT_SWAP_HANDS(0110):
+ * 0110|xxxx| keycode Swap hands (keycode on tap, or options)
+ *
+ *
+ * 0111|xxxx xxxx xxxx (reserved)
*
*
* Layer Actions(10xx)
@@ -67,7 +72,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* ee: on event(01:press, 10:release, 11:both)
*
* 1001|xxxx|xxxx xxxx (reserved)
- * 1001|oopp|BBBB BBBB 8-bit Bitwise Operation???
*
* ACT_LAYER_TAP(101x):
* 101E|LLLL| keycode On/Off with tap key (0x00-DF)[TAP]
diff --git a/tmk_core/common/action_macro.h b/tmk_core/common/action_macro.h
index aedc32ec6b..f373f5068e 100644
--- a/tmk_core/common/action_macro.h
+++ b/tmk_core/common/action_macro.h
@@ -20,11 +20,33 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "progmem.h"
-#define MACRO_NONE 0
+
+typedef uint8_t macro_t;
+
+#define MACRO_NONE (macro_t*)0
#define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; })
#define MACRO_GET(p) pgm_read_byte(p)
-typedef uint8_t macro_t;
+// Sends press when the macro key is pressed, release when release, or tap_macro when the key has been tapped
+#define MACRO_TAP_HOLD(record, press, release, tap_macro) ( ((record)->event.pressed) ? \
+ ( ((record)->tap.count <= 0 || (record)->tap.interrupted) ? (press) : MACRO_NONE ) : \
+ ( ((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (tap_macro) : (release) ) )
+
+// Holds down the modifier mod when the macro key is held, or sends macro instead when tapped
+#define MACRO_TAP_HOLD_MOD(record, macro, mod) MACRO_TAP_HOLD(record, (MACRO(D(mod), END)), MACRO(U(mod), END), macro)
+
+// Holds down the modifier mod when the macro key is held, or pressed a shifted key when tapped (eg: shift+3 for #)
+#define MACRO_TAP_SHFT_KEY_HOLD_MOD(record, key, mod) MACRO_TAP_HOLD_MOD(record, (MACRO(I(10), D(LSFT), T(key), U(LSFT), END)), mod)
+
+
+// Momentary switch layer when held, sends macro if tapped
+#define MACRO_TAP_HOLD_LAYER(record, macro, layer) ( ((record)->event.pressed) ? \
+ ( ((record)->tap.count <= 0 || (record)->tap.interrupted) ? ({layer_on((layer)); MACRO_NONE; }) : MACRO_NONE ) : \
+ ( ((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (macro) : ({layer_off((layer)); MACRO_NONE; }) ) )
+
+// Momentary switch layer when held, presses a shifted key when tapped (eg: shift+3 for #)
+#define MACRO_TAP_SHFT_KEY_HOLD_LAYER(record, key, layer) MACRO_TAP_HOLD_LAYER(record, MACRO(I(10), D(LSFT), T(key), U(LSFT), END), layer)
+
#ifndef NO_ACTION_MACRO