]> git.donarmstrong.com Git - tmk_firmware.git/blobdiff - common/action_macro.h
Fix rn42.h API
[tmk_firmware.git] / common / action_macro.h
index db657795904f6d3ec3ccf598ca28f4ec6a73d989..aedc32ec6b2c428e53cd24d3d5c105eb1f1143eb 100644 (file)
@@ -17,95 +17,86 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #ifndef ACTION_MACRO_H
 #define ACTION_MACRO_H
 #include <stdint.h>
-#include <avr/pgmspace.h>
+#include "progmem.h"
 
 
-#define MACRO_NONE  0
-#define MACRO(...) ({ static prog_macro_t _m[] PROGMEM = { __VA_ARGS__ }; _m; })
-
+#define MACRO_NONE      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;
-typedef macro_t prog_macro_t PROGMEM;
-
-
-void action_macro_play(const prog_macro_t *macro);
-
-
-
-/* TODO: NOT FINISHED 
-normal mode command:
-    key(down):      0x04-7f/73(F24)
-    key(up):        0x84-ff
-command:        0x00-03, 0x80-83(0x74-7f, 0xf4-ff)
-    mods down   0x00
-    mods up     0x01
-    wait        0x02
-    interval    0x03
-    extkey down 0x80
-    extkey up   0x81
-    ext commad  0x82
-    ext mode    0x83
-    end         0xff
-
-extension mode command: NOT IMPLEMENTED
-    key down            0x00
-    key up              0x01
-    key down + wait
-    key up   + wait
-    mods push
-    mods pop
-    wait
-    interval
-    if
-    loop
-    push
-    pop
-    all up
-    end
-*/
+
+
+#ifndef NO_ACTION_MACRO
+void action_macro_play(const macro_t *macro_p);
+#else
+#define action_macro_play(macro)
+#endif
+
+
+
+/* Macro commands
+ *   code(0x04-73)                      // key down(1byte)
+ *   code(0x04-73) | 0x80               // key up(1byte)
+ *   { KEY_DOWN, code(0x04-0xff) }      // key down(2bytes)
+ *   { KEY_UP,   code(0x04-0xff) }      // key up(2bytes)
+ *   WAIT                               // wait milli-seconds
+ *   INTERVAL                           // set interval between macro commands
+ *   END                                // stop macro execution
+ *
+ * Ideas(Not implemented):
+ *   modifiers
+ *   system usage
+ *   consumer usage
+ *   unicode usage
+ *   function call
+ *   conditionals
+ *   loop
+ */
 enum macro_command_id{
     /* 0x00 - 0x03 */
     END                 = 0x00,
-    MODS_DOWN           = 0x01,
-    MODS_UP             = 0x02,
-    MODS_SET,
-    MODS_PUSH,
-    MODS_POP,
+    KEY_DOWN,
+    KEY_UP,
 
+    /* 0x04 - 0x73 (reserved for keycode down) */
+
+    /* 0x74 - 0x83 */
     WAIT                = 0x74,
     INTERVAL,
-    /* 0x74 - 0x7f */
-    /* 0x80 - 0x84 */
 
-    EXT_DOWN,
-    EXT_UP,
-    EXT_WAIT,
-    EXT_INTERVAL,
-    COMPRESSION_MODE,
+    /* 0x84 - 0xf3 (reserved for keycode up) */
 
-    EXTENSION_MODE      = 0xff,
+    /* 0xf4 - 0xff */
 };
 
 
-/* normal mode */
-#define DOWN(key)       (key)
-#define UP(key)         ((key) | 0x80)
-#define TYPE(key)       (key), (key | 0x80)
-#define MODS_DOWN(mods) MODS_DOWN, (mods)
-#define MODS_UP(mods)   MODS_UP, (mods)
+/* TODO: keycode:0x04-0x73 can be handled by 1byte command  else 2bytes are needed
+ * if keycode between 0x04 and 0x73
+ *      keycode / (keycode|0x80)
+ * else
+ *      {KEY_DOWN, keycode} / {KEY_UP, keycode}
+*/
+#define DOWN(key)       KEY_DOWN, (key)
+#define UP(key)         KEY_UP, (key)
+#define TYPE(key)       DOWN(key), UP(key)
 #define WAIT(ms)        WAIT, (ms)
 #define INTERVAL(ms)    INTERVAL, (ms)
 
+/* key down */
 #define D(key)          DOWN(KC_##key)
+/* key up */
 #define U(key)          UP(KC_##key)
+/* key type */
 #define T(key)          TYPE(KC_##key)
-#define MD(key)         MODS_DOWN(MOD_BIT(KC_##key))
-#define MU(key)         MODS_UP(MOD_BIT(KC_##key))
+/* wait */
 #define W(ms)           WAIT(ms)
+/* interval */
 #define I(ms)           INTERVAL(ms)
 
-
-/* extension mode */
+/* for backward comaptibility */
+#define MD(key)         DOWN(KC_##key)
+#define MU(key)         UP(KC_##key)
 
 
 #endif /* ACTION_MACRO_H */