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.

197 lines
5.0 KiB

  1. /*
  2. Copyright 2019 Andre Poley <andre.poley@mailbox.org>
  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. #include "quantum.h"
  15. #include "kuchosauronad0.h"
  16. userspace_config_t userspace_config;
  17. #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
  18. # define KUCHOSAURONAD0_UNICODE_MODE UC_WINC
  19. #else
  20. # define KUCHOSAURONAD0_UNICODE_MODE 2 // set to 2 for UC_WIN, set to 4 for UC_WINC
  21. #endif
  22. // Add reconfigurable functions here, for keymap customization
  23. // This allows for a global, userspace functions, and continued
  24. // customization of the keymap. Use _keymap instead of _user
  25. // functions in the keymaps
  26. __attribute__ ((weak))
  27. void matrix_init_keymap(void) {}
  28. // Call user matrix init, set default RGB colors and then
  29. // call the keymap's init function
  30. void matrix_init_user(void) {
  31. userspace_config.raw = eeconfig_read_user();
  32. #ifdef BOOTLOADER_CATERINA
  33. DDRD &= ~(1<<5);
  34. PORTD &= ~(1<<5);
  35. DDRB &= ~(1<<0);
  36. PORTB &= ~(1<<0);
  37. #endif
  38. #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
  39. set_unicode_input_mode(KUCHOSAURONAD0_UNICODE_MODE);
  40. get_unicode_input_mode();
  41. #endif //UNICODE_ENABLE
  42. matrix_init_keymap();
  43. }
  44. __attribute__((weak))
  45. void keyboard_post_init_keymap(void){ }
  46. void keyboard_post_init_user(void){
  47. #ifdef RGBLIGHT_ENABLE
  48. keyboard_post_init_rgb();
  49. #endif
  50. keyboard_post_init_keymap();
  51. }
  52. __attribute__ ((weak))
  53. void shutdown_keymap(void) {}
  54. void shutdown_user (void) {
  55. #ifdef RGBLIGHT_ENABLE
  56. rgblight_enable_noeeprom();
  57. rgblight_mode_noeeprom(1);
  58. rgblight_setrgb_teal();
  59. #endif // RGBLIGHT_ENABLE
  60. #ifdef RGB_MATRIX_ENABLE
  61. // uint16_t timer_start = timer_read();
  62. // rgb_matrix_set_color_all( 0xFF, 0x00, 0x00 );
  63. // while(timer_elapsed(timer_start) < 250) { wait_ms(1); }
  64. #endif //RGB_MATRIX_ENABLE
  65. shutdown_keymap();
  66. }
  67. __attribute__ ((weak))
  68. void suspend_power_down_keymap(void) {}
  69. void suspend_power_down_user(void) {
  70. suspend_power_down_keymap();
  71. }
  72. __attribute__ ((weak))
  73. void suspend_wakeup_init_keymap(void) {}
  74. void suspend_wakeup_init_user(void) {
  75. suspend_wakeup_init_keymap();
  76. }
  77. __attribute__ ((weak))
  78. void matrix_scan_keymap(void) {}
  79. __attribute__ ((weak))
  80. void matrix_scan_user(void){
  81. static bool has_ran_yet;
  82. if (!has_ran_yet) {
  83. has_ran_yet = true;
  84. startup_user();
  85. }
  86. #ifdef TAP_DANCE_ENABLE // Run Diablo 3 macro checking code.
  87. // run_diablo_macro_check();
  88. #endif // !TAP_DANCE_ENABLE
  89. #ifdef RGBLIGHT_ENABLE
  90. matrix_scan_rgb();
  91. #endif // !RGBLIGHT_ENABLE
  92. matrix_scan_keymap();
  93. }
  94. __attribute__ ((weak))
  95. uint32_t layer_state_set_keymap (uint32_t state) {
  96. return state;
  97. }
  98. // on layer change, no matter where the change was initiated
  99. // Then runs keymap's layer change check
  100. layer_state_t layer_state_set_user(layer_state_t state) {
  101. state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
  102. #ifdef RGBLIGHT_ENABLE
  103. state = layer_state_set_rgb(state);
  104. #endif // RGBLIGHT_ENABLE
  105. return layer_state_set_keymap (state);
  106. }
  107. __attribute__ ((weak))
  108. uint32_t default_layer_state_set_keymap (uint32_t state) {
  109. return state;
  110. }
  111. // Runs state check and changes underglow color and animation
  112. uint32_t default_layer_state_set_user(uint32_t state) {
  113. state = default_layer_state_set_keymap(state);
  114. #if 0
  115. #ifdef RGBLIGHT_ENABLE
  116. state = default_layer_state_set_rgb(state);
  117. #endif // RGBLIGHT_ENABLE
  118. #endif
  119. return state;
  120. }
  121. __attribute__ ((weak))
  122. void led_set_keymap(uint8_t usb_led) {}
  123. // Any custom LED code goes here.
  124. // So far, I only have keyboard specific code,
  125. // So nothing goes here.
  126. void led_set_user(uint8_t usb_led) {
  127. led_set_keymap(usb_led);
  128. }
  129. __attribute__ ((weak))
  130. void eeconfig_init_keymap(void) {}
  131. void eeconfig_init_user(void) {
  132. userspace_config.raw = 0;
  133. userspace_config.rgb_layer_change = true;
  134. eeconfig_update_user(userspace_config.raw);
  135. #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
  136. set_unicode_input_mode(KUCHOSAURONAD0_UNICODE_MODE);
  137. get_unicode_input_mode();
  138. #else
  139. eeprom_update_byte(EECONFIG_UNICODEMODE, KUCHOSAURONAD0_UNICODE_MODE);
  140. #endif
  141. eeconfig_init_keymap();
  142. keyboard_init();
  143. }
  144. // TMUX stuff
  145. void tmux_prefix(void) {
  146. register_code(KC_LCTL);
  147. tap_code(KC_B);
  148. unregister_code(KC_LCTL);
  149. }
  150. void tmux_pane_last(void) {
  151. tmux_prefix();
  152. tap_code(KC_SCLN);
  153. }
  154. void tmux_pane_switch_repeat(void) {
  155. tmux_pane_last();
  156. tap_code(KC_UP);
  157. tap_code(KC_ENT);
  158. tmux_pane_last();
  159. }
  160. /* vi: ft=c:tw=80:sw=2:ts=2:sts=2:et */