Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

action_macro.h 3.0KB

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