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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. /* 0x84 - 0xf3 (reserved for keycode up) */
  55. /* 0xf4 - 0xff */
  56. };
  57. /* TODO: keycode:0x04-0x73 can be handled by 1byte command else 2bytes are needed
  58. * if keycode between 0x04 and 0x73
  59. * keycode / (keycode|0x80)
  60. * else
  61. * {KEY_DOWN, keycode} / {KEY_UP, keycode}
  62. */
  63. #define DOWN(key) KEY_DOWN, (key)
  64. #define UP(key) KEY_UP, (key)
  65. #define TYPE(key) DOWN(key), UP(key)
  66. #define WAIT(ms) WAIT, (ms)
  67. #define INTERVAL(ms) INTERVAL, (ms)
  68. /* key down */
  69. #define D(key) DOWN(KC_##key)
  70. /* key up */
  71. #define U(key) UP(KC_##key)
  72. /* key type */
  73. #define T(key) TYPE(KC_##key)
  74. /* wait */
  75. #define W(ms) WAIT(ms)
  76. /* interval */
  77. #define I(ms) INTERVAL(ms)
  78. /* for backward comaptibility */
  79. #define MD(key) DOWN(KC_##key)
  80. #define MU(key) UP(KC_##key)
  81. #endif /* ACTION_MACRO_H */