aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common/action_macro.h
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common/action_macro.h')
-rw-r--r--tmk_core/common/action_macro.h70
1 files changed, 35 insertions, 35 deletions
diff --git a/tmk_core/common/action_macro.h b/tmk_core/common/action_macro.h
index f373f5068..21004ead6 100644
--- a/tmk_core/common/action_macro.h
+++ b/tmk_core/common/action_macro.h
@@ -19,18 +19,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19#include <stdint.h> 19#include <stdint.h>
20#include "progmem.h" 20#include "progmem.h"
21 21
22
23
24typedef uint8_t macro_t; 22typedef uint8_t macro_t;
25 23
26#define MACRO_NONE (macro_t*)0 24#define MACRO_NONE (macro_t *)0
27#define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; }) 25#define MACRO(...) \
28#define MACRO_GET(p) pgm_read_byte(p) 26 ({ \
27 static const macro_t __m[] PROGMEM = {__VA_ARGS__}; \
28 &__m[0]; \
29 })
30#define MACRO_GET(p) pgm_read_byte(p)
29 31
30// Sends press when the macro key is pressed, release when release, or tap_macro when the key has been tapped 32// Sends press when the macro key is pressed, release when release, or tap_macro when the key has been tapped
31#define MACRO_TAP_HOLD(record, press, release, tap_macro) ( ((record)->event.pressed) ? \ 33#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)))
32 ( ((record)->tap.count <= 0 || (record)->tap.interrupted) ? (press) : MACRO_NONE ) : \
33 ( ((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (tap_macro) : (release) ) )
34 34
35// Holds down the modifier mod when the macro key is held, or sends macro instead when tapped 35// Holds down the modifier mod when the macro key is held, or sends macro instead when tapped
36#define MACRO_TAP_HOLD_MOD(record, macro, mod) MACRO_TAP_HOLD(record, (MACRO(D(mod), END)), MACRO(U(mod), END), macro) 36#define MACRO_TAP_HOLD_MOD(record, macro, mod) MACRO_TAP_HOLD(record, (MACRO(D(mod), END)), MACRO(U(mod), END), macro)
@@ -38,25 +38,27 @@ typedef uint8_t macro_t;
38// Holds down the modifier mod when the macro key is held, or pressed a shifted key when tapped (eg: shift+3 for #) 38// Holds down the modifier mod when the macro key is held, or pressed a shifted key when tapped (eg: shift+3 for #)
39#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) 39#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)
40 40
41
42// Momentary switch layer when held, sends macro if tapped 41// Momentary switch layer when held, sends macro if tapped
43#define MACRO_TAP_HOLD_LAYER(record, macro, layer) ( ((record)->event.pressed) ? \ 42#define MACRO_TAP_HOLD_LAYER(record, macro, layer) \
44 ( ((record)->tap.count <= 0 || (record)->tap.interrupted) ? ({layer_on((layer)); MACRO_NONE; }) : MACRO_NONE ) : \ 43 (((record)->event.pressed) ? (((record)->tap.count <= 0 || (record)->tap.interrupted) ? ({ \
45 ( ((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (macro) : ({layer_off((layer)); MACRO_NONE; }) ) ) 44 layer_on((layer)); \
45 MACRO_NONE; \
46 }) \
47 : MACRO_NONE) \
48 : (((record)->tap.count > 0 && !((record)->tap.interrupted)) ? (macro) : ({ \
49 layer_off((layer)); \
50 MACRO_NONE; \
51 })))
46 52
47// Momentary switch layer when held, presses a shifted key when tapped (eg: shift+3 for #) 53// Momentary switch layer when held, presses a shifted key when tapped (eg: shift+3 for #)
48#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) 54#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)
49
50
51 55
52#ifndef NO_ACTION_MACRO 56#ifndef NO_ACTION_MACRO
53void action_macro_play(const macro_t *macro_p); 57void action_macro_play(const macro_t *macro_p);
54#else 58#else
55#define action_macro_play(macro) 59# define action_macro_play(macro)
56#endif 60#endif
57 61
58
59
60/* Macro commands 62/* Macro commands
61 * code(0x04-73) // key down(1byte) 63 * code(0x04-73) // key down(1byte)
62 * code(0x04-73) | 0x80 // key up(1byte) 64 * code(0x04-73) | 0x80 // key up(1byte)
@@ -75,16 +77,16 @@ void action_macro_play(const macro_t *macro_p);
75 * conditionals 77 * conditionals
76 * loop 78 * loop
77 */ 79 */
78enum macro_command_id{ 80enum macro_command_id {
79 /* 0x00 - 0x03 */ 81 /* 0x00 - 0x03 */
80 END = 0x00, 82 END = 0x00,
81 KEY_DOWN, 83 KEY_DOWN,
82 KEY_UP, 84 KEY_UP,
83 85
84 /* 0x04 - 0x73 (reserved for keycode down) */ 86 /* 0x04 - 0x73 (reserved for keycode down) */
85 87
86 /* 0x74 - 0x83 */ 88 /* 0x74 - 0x83 */
87 WAIT = 0x74, 89 WAIT = 0x74,
88 INTERVAL, 90 INTERVAL,
89 91
90 /* 0x84 - 0xf3 (reserved for keycode up) */ 92 /* 0x84 - 0xf3 (reserved for keycode up) */
@@ -92,33 +94,31 @@ enum macro_command_id{
92 /* 0xf4 - 0xff */ 94 /* 0xf4 - 0xff */
93}; 95};
94 96
95
96/* TODO: keycode:0x04-0x73 can be handled by 1byte command else 2bytes are needed 97/* TODO: keycode:0x04-0x73 can be handled by 1byte command else 2bytes are needed
97 * if keycode between 0x04 and 0x73 98 * if keycode between 0x04 and 0x73
98 * keycode / (keycode|0x80) 99 * keycode / (keycode|0x80)
99 * else 100 * else
100 * {KEY_DOWN, keycode} / {KEY_UP, keycode} 101 * {KEY_DOWN, keycode} / {KEY_UP, keycode}
101*/ 102 */
102#define DOWN(key) KEY_DOWN, (key) 103#define DOWN(key) KEY_DOWN, (key)
103#define UP(key) KEY_UP, (key) 104#define UP(key) KEY_UP, (key)
104#define TYPE(key) DOWN(key), UP(key) 105#define TYPE(key) DOWN(key), UP(key)
105#define WAIT(ms) WAIT, (ms) 106#define WAIT(ms) WAIT, (ms)
106#define INTERVAL(ms) INTERVAL, (ms) 107#define INTERVAL(ms) INTERVAL, (ms)
107 108
108/* key down */ 109/* key down */
109#define D(key) DOWN(KC_##key) 110#define D(key) DOWN(KC_##key)
110/* key up */ 111/* key up */
111#define U(key) UP(KC_##key) 112#define U(key) UP(KC_##key)
112/* key type */ 113/* key type */
113#define T(key) TYPE(KC_##key) 114#define T(key) TYPE(KC_##key)
114/* wait */ 115/* wait */
115#define W(ms) WAIT(ms) 116#define W(ms) WAIT(ms)
116/* interval */ 117/* interval */
117#define I(ms) INTERVAL(ms) 118#define I(ms) INTERVAL(ms)
118 119
119/* for backward comaptibility */ 120/* for backward comaptibility */
120#define MD(key) DOWN(KC_##key) 121#define MD(key) DOWN(KC_##key)
121#define MU(key) UP(KC_##key) 122#define MU(key) UP(KC_##key)
122
123 123
124#endif /* ACTION_MACRO_H */ 124#endif /* ACTION_MACRO_H */