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.

160 lines
4.1 KiB

  1. #include "quantum.h"
  2. #include "yet-another-developer.h"
  3. userspace_config_t userspace_config;
  4. #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
  5. #define YAD_UNICODE_MODE UC_WIN
  6. #else
  7. // set to 2 for UC_WIN, set to 4 for UC_WINC
  8. #define YAD_UNICODE_MODE 2
  9. #endif
  10. bool mod_key_press_timer(uint16_t code, uint16_t mod_code, bool pressed) {
  11. static uint16_t this_timer;
  12. if (pressed) {
  13. this_timer = timer_read();
  14. } else {
  15. if (timer_elapsed(this_timer) < TAPPING_TERM) {
  16. tap_code(code);
  17. } else {
  18. register_code(mod_code);
  19. tap_code(code);
  20. unregister_code(mod_code);
  21. }
  22. }
  23. return false;
  24. }
  25. bool mod_key_press(uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
  26. if (pressed) {
  27. this_timer = timer_read();
  28. } else {
  29. if (timer_elapsed(this_timer) < TAPPING_TERM) {
  30. tap_code(code);
  31. } else {
  32. register_code(mod_code);
  33. tap_code(code);
  34. unregister_code(mod_code);
  35. }
  36. }
  37. return false;
  38. }
  39. // Add reconfigurable functions here, for keymap customization
  40. // This allows for a global, userspace functions, and continued
  41. // customization of the keymap. Use _keymap instead of _user
  42. // functions in the keymaps
  43. __attribute__ ((weak))
  44. void matrix_init_keymap(void) {}
  45. // Call user matrix init, set default RGB colors and then
  46. // call the keymap's init function
  47. void matrix_init_user(void) {
  48. userspace_config.raw = eeconfig_read_user();
  49. #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
  50. set_unicode_input_mode(YAD_UNICODE_MODE);
  51. get_unicode_input_mode();
  52. #endif //UNICODE_ENABLE
  53. matrix_init_keymap();
  54. }
  55. __attribute__((weak))
  56. void keyboard_post_init_keymap(void) {}
  57. void keyboard_post_init_user(void) {
  58. #ifdef RGBLIGHT_ENABLE
  59. keyboard_post_init_rgb();
  60. #endif
  61. keyboard_post_init_keymap();
  62. }
  63. __attribute__((weak))
  64. void suspend_power_down_keymap(void) {}
  65. void suspend_power_down_user(void) {
  66. suspend_power_down_keymap();
  67. }
  68. __attribute__((weak))
  69. void suspend_wakeup_init_keymap(void) {}
  70. void suspend_wakeup_init_user(void) {
  71. suspend_wakeup_init_keymap();
  72. }
  73. __attribute__((weak))
  74. void matrix_scan_keymap(void) {}
  75. __attribute__ ((weak))
  76. void matrix_scan_user(void){
  77. #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
  78. // run_diablo_macro_check();
  79. #endif // TAP_DANCE_ENABLE
  80. #ifdef RGBLIGHT_ENABLE
  81. matrix_scan_rgb();
  82. #endif // RGBLIGHT_ENABLE
  83. matrix_scan_keymap();
  84. }
  85. __attribute__((weak))
  86. layer_state_t layer_state_set_keymap(layer_state_t state) {
  87. return state;
  88. }
  89. // on layer change, no matter where the change was initiated
  90. // Then runs keymap's layer change check
  91. layer_state_t layer_state_set_user(layer_state_t state) {
  92. state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
  93. #ifdef RGBLIGHT_ENABLE
  94. state = layer_state_set_rgb(state);
  95. #endif // RGBLIGHT_ENABLE
  96. return layer_state_set_keymap(state);
  97. }
  98. __attribute__((weak))
  99. layer_state_t default_layer_state_set_keymap(layer_state_t state) {
  100. return state;
  101. }
  102. // Runs state check and changes underglow color and animation
  103. layer_state_t default_layer_state_set_user(layer_state_t state) {
  104. state = default_layer_state_set_keymap(state);
  105. #if 0
  106. #ifdef RGBLIGHT_ENABLE
  107. state = default_layer_state_set_rgb(state);
  108. #endif // RGBLIGHT_ENABLE
  109. #endif
  110. return state;
  111. }
  112. __attribute__ ((weak))
  113. void led_set_keymap(uint8_t usb_led) {}
  114. // Any custom LED code goes here.
  115. // So far, I only have keyboard specific code,
  116. // So nothing goes here.
  117. void led_set_user(uint8_t usb_led) {
  118. led_set_keymap(usb_led);
  119. }
  120. __attribute__ ((weak))
  121. void eeconfig_init_keymap(void) {}
  122. void eeconfig_init_user(void) {
  123. userspace_config.raw = 0;
  124. userspace_config.rgb_layer_change = true;
  125. eeconfig_update_user(userspace_config.raw);
  126. #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
  127. set_unicode_input_mode(YAD_UNICODE_MODE);
  128. get_unicode_input_mode();
  129. #else
  130. eeprom_update_byte(EECONFIG_UNICODEMODE, YAD_UNICODE_MODE);
  131. #endif
  132. }