]> git.gir.st - tmk_keyboard.git/blob - tmk_core/common/action_macro.h
core: Fix suspend/wake for converters #386
[tmk_keyboard.git] / tmk_core / common / action_macro.h
1 /*
2 Copyright 2013 Jun Wako <wakojun@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 #ifndef ACTION_MACRO_H
18 #define ACTION_MACRO_H
19 #include <stdint.h>
20 #include "progmem.h"
21
22
23 #define MACRO_NONE 0
24 #define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; })
25 #define MACRO_GET(p) pgm_read_byte(p)
26
27 typedef uint8_t macro_t;
28
29
30 #ifndef NO_ACTION_MACRO
31 void action_macro_play(const macro_t *macro_p);
32 #else
33 #define action_macro_play(macro)
34 #endif
35
36
37
38 /* Macro commands
39 * code(0x04-73) // key down(1byte)
40 * code(0x04-73) | 0x80 // key up(1byte)
41 * { KEY_DOWN, code(0x04-0xff) } // key down(2bytes)
42 * { KEY_UP, code(0x04-0xff) } // key up(2bytes)
43 * WAIT // wait milli-seconds
44 * INTERVAL // set interval between macro commands
45 * END // stop macro execution
46 *
47 * Ideas(Not implemented):
48 * modifiers
49 * system usage
50 * consumer usage
51 * unicode usage
52 * function call
53 * conditionals
54 * loop
55 */
56 enum macro_command_id{
57 /* 0x00 - 0x03 */
58 END = 0x00,
59 KEY_DOWN,
60 KEY_UP,
61
62 /* 0x04 - 0x73 (reserved for keycode down) */
63
64 /* 0x74 - 0x83 */
65 WAIT = 0x74,
66 INTERVAL,
67 MOD_STORE,
68 MOD_RESTORE,
69 MOD_CLEAR,
70
71 /* 0x84 - 0xf3 (reserved for keycode up) */
72
73 /* 0xf4 - 0xff */
74 };
75
76
77 /* TODO: keycode:0x04-0x73 can be handled by 1byte command else 2bytes are needed
78 * if keycode between 0x04 and 0x73
79 * keycode / (keycode|0x80)
80 * else
81 * {KEY_DOWN, keycode} / {KEY_UP, keycode}
82 */
83 #define DOWN(key) KEY_DOWN, (key)
84 #define UP(key) KEY_UP, (key)
85 #define TYPE(key) DOWN(key), UP(key)
86 #define WAIT(ms) WAIT, (ms)
87 #define INTERVAL(ms) INTERVAL, (ms)
88 #define STORE() MOD_STORE
89 #define RESTORE() MOD_RESTORE
90 #define CLEAR() MOD_CLEAR
91
92 /* key down */
93 #define D(key) DOWN(KC_##key)
94 /* key up */
95 #define U(key) UP(KC_##key)
96 /* key type */
97 #define T(key) TYPE(KC_##key)
98 /* wait */
99 #define W(ms) WAIT(ms)
100 /* interval */
101 #define I(ms) INTERVAL(ms)
102 /* store modifier(s) */
103 #define SM() STORE()
104 /* restore modifier(s) */
105 #define RM() RESTORE()
106 /* clear modifier(s) */
107 #define CM() CLEAR()
108
109 /* for backward comaptibility */
110 #define MD(key) DOWN(KC_##key)
111 #define MU(key) UP(KC_##key)
112
113
114 #endif /* ACTION_MACRO_H */
Imprint / Impressum