]> git.gir.st - tmk_keyboard.git/blob - common/action_macro.h
Documentation: small mistake
[tmk_keyboard.git] / 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 <avr/pgmspace.h>
21
22
23 #define MACRO_NONE 0
24 #define MACRO(...) ({ static const macro_t __m[] PROGMEM = { __VA_ARGS__ }; &__m[0]; })
25
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
68 /* 0x84 - 0xf3 (reserved for keycode up) */
69
70 /* 0xf4 - 0xff */
71 };
72
73
74 /* TODO: keycode:0x04-0x73 can be handled by 1byte command else 2bytes are needed
75 * if keycode between 0x04 and 0x73
76 * keycode / (keycode|0x80)
77 * else
78 * {KEY_DOWN, keycode} / {KEY_UP, keycode}
79 */
80 #define DOWN(key) KEY_DOWN, (key)
81 #define UP(key) KEY_UP, (key)
82 #define TYPE(key) DOWN(key), UP(key)
83 #define WAIT(ms) WAIT, (ms)
84 #define INTERVAL(ms) INTERVAL, (ms)
85
86 /* key down */
87 #define D(key) DOWN(KC_##key)
88 /* key up */
89 #define U(key) UP(KC_##key)
90 /* key type */
91 #define T(key) TYPE(KC_##key)
92 /* wait */
93 #define W(ms) WAIT(ms)
94 /* interval */
95 #define I(ms) INTERVAL(ms)
96
97 /* for backward comaptibility */
98 #define MD(key) DOWN(KC_##key)
99 #define MU(key) UP(KC_##key)
100
101
102 #endif /* ACTION_MACRO_H */
Imprint / Impressum