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.

93 lines
2.9 KiB

  1. /* Copyright 2016 Jack Humbert
  2. *
  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. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. /* Author: Wojciech Siewierski < wojciech dot siewierski at onet dot pl > */
  17. #pragma once
  18. #include "action.h"
  19. #include "action_layer.h"
  20. #ifndef DYNAMIC_MACRO_COUNT
  21. #define DYNAMIC_MACRO_COUNT 2
  22. #endif
  23. #ifndef DYNAMIC_MACRO_SIZE
  24. /* May be overridden with a custom value. Be aware that the effective
  25. * macro length is half of this value: each keypress is recorded twice
  26. * because of the down-event and up-event. This is not a bug, it's the
  27. * intended behavior.
  28. *
  29. * Usually it should be fine to set the macro size to at least 256 but
  30. * there have been reports of it being too much in some users' cases,
  31. * so 128 is considered a safe default.
  32. */
  33. #define DYNAMIC_MACRO_SIZE 64
  34. #endif
  35. #ifndef DYNAMIC_MACRO_EEPROM_STORAGE
  36. #define DYNAMIC_MACRO_EEPROM_STORAGE
  37. #endif
  38. /* DYNAMIC_MACRO_RANGE must be set as the last element of user's
  39. * "planck_keycodes" enum prior to including this header. This allows
  40. * us to 'extend' it.
  41. */
  42. enum dynamic_macro_keycodes {
  43. DYN_MACRO_PROG = DYNAMIC_MACRO_RANGE,
  44. /* Requirement: DYN_MACRO_KEYs are in sequence in the enum. */
  45. DYN_MACRO_KEY1,
  46. DYN_MACRO_KEY2,
  47. DYN_MACRO_KEY3,
  48. DYN_MACRO_KEY4,
  49. DYN_MACRO_KEY5,
  50. DYN_MACRO_KEY6,
  51. DYN_MACRO_KEY7,
  52. DYN_MACRO_KEY8,
  53. DYN_MACRO_KEY9,
  54. DYN_MACRO_KEY10,
  55. DYN_MACRO_KEY11,
  56. DYN_MACRO_KEY12
  57. };
  58. enum dynamic_macro_recording_state { STATE_NOT_RECORDING, STATE_RECORD_KEY_PRESSED, STATE_CURRENTLY_RECORDING };
  59. typedef struct {
  60. keyrecord_t events[DYNAMIC_MACRO_SIZE];
  61. uint8_t length;
  62. uint16_t checksum;
  63. } dynamic_macro_t;
  64. void dynamic_macro_init(void);
  65. void dynamic_macro_led_blink(void);
  66. void dynamic_macro_record_start(uint8_t macro_id);
  67. void dynamic_macro_play(uint8_t macro_id);
  68. void dynamic_macro_record_key(uint8_t macro_id, keyrecord_t* record);
  69. void dynamic_macro_record_end(uint8_t macro_id);
  70. bool process_record_dynamic_macro(uint16_t keycode, keyrecord_t* record);
  71. #define DYNAMIC_MACRO_CRC_LENGTH (sizeof(dynamic_macro_t) - sizeof(uint16_t))
  72. #ifdef DYNAMIC_MACRO_EEPROM_STORAGE
  73. #define DYNAMIC_MACRO_EEPROM_MAGIC (uint16_t)0xDEAD
  74. uint16_t dynamic_macro_calc_crc(dynamic_macro_t* macro);
  75. void dynamic_macro_load_eeprom_all(void);
  76. void dynamic_macro_load_eeprom(uint8_t macro_id);
  77. void dynamic_macro_save_eeprom(uint8_t macro_id);
  78. bool dynamic_macro_header_correct(void);
  79. #endif