bocaj.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. Copyright 2020 Jacob Jerrell <jacob.jerrell@gmail.com> @JacobJerrell
  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 "bocaj.h"
  15. #ifdef KEYBOARD_planck_ez
  16. userspace_config_t userspace_config;
  17. #endif
  18. bool mod_key_press_timer(uint16_t code, uint16_t mod_code, bool pressed) {
  19. static uint16_t this_timer;
  20. if (pressed) {
  21. this_timer = timer_read();
  22. } else {
  23. if (timer_elapsed(this_timer) < TAPPING_TERM) {
  24. tap_code(code);
  25. } else {
  26. register_code(mod_code);
  27. tap_code(code);
  28. unregister_code(mod_code);
  29. }
  30. }
  31. return false;
  32. }
  33. bool mod_key_press(uint16_t code, uint16_t mod_code, bool pressed, uint16_t this_timer) {
  34. if (pressed) {
  35. this_timer = timer_read();
  36. } else {
  37. if (timer_elapsed(this_timer) < TAPPING_TERM) {
  38. tap_code(code);
  39. } else {
  40. register_code(mod_code);
  41. tap_code(code);
  42. unregister_code(mod_code);
  43. }
  44. }
  45. return false;
  46. }
  47. void bootmagic_lite(void) {
  48. matrix_scan();
  49. #if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0
  50. wait_ms(DEBOUNCING_DELAY * 2);
  51. #elif defined(DEBOUNCE) && DEBOUNCE > 0
  52. wait_ms(DEBOUNCE * 2);
  53. #else
  54. wait_ms(30);
  55. #endif
  56. matrix_scan();
  57. if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
  58. bootloader_jump();
  59. }
  60. }
  61. __attribute__((weak)) void keyboard_pre_init_keymap(void) {}
  62. void keyboard_pre_init_user(void) {
  63. #ifdef KEYBOARD_planck_ez
  64. userspace_config.raw = eeconfig_read_user();
  65. #endif
  66. keyboard_pre_init_keymap();
  67. }
  68. // Add reconfigurable functions here, for keymap customization
  69. // This allows for a global, userspace functions, and continued
  70. // customization of the keymap. Use _keymap instead of _user
  71. // functions in the keymaps
  72. __attribute__((weak)) void matrix_init_keymap(void) {}
  73. // Call user matrix init, set default RGB colors and then
  74. // call the keymap's init function
  75. void matrix_init_user(void) {
  76. matrix_init_keymap();
  77. }
  78. __attribute__((weak)) void keyboard_post_init_keymap(void) {}
  79. void keyboard_post_init_user(void) {
  80. #if defined(RGB_MATRIX_ENABLE)
  81. keyboard_post_init_rgb_matrix();
  82. #endif
  83. keyboard_post_init_keymap();
  84. }
  85. __attribute__((weak)) void shutdown_keymap(void) {}
  86. void rgb_matrix_update_pwm_buffers(void);
  87. void shutdown_user(void) {
  88. #ifdef RGB_MATRIX_ENABLE
  89. rgb_matrix_set_color_all(0xFF, 0x00, 0x00);
  90. rgb_matrix_update_pwm_buffers();
  91. #endif // RGB_MATRIX_ENABLE
  92. shutdown_keymap();
  93. }
  94. __attribute__((weak)) void suspend_power_down_keymap(void) {}
  95. void suspend_power_down_user(void) { suspend_power_down_keymap(); }
  96. __attribute__((weak)) void suspend_wakeup_init_keymap(void) {}
  97. void suspend_wakeup_init_user(void) { suspend_wakeup_init_keymap(); }
  98. __attribute__((weak)) void matrix_scan_secrets(void) {}
  99. __attribute__((weak)) void matrix_scan_keymap(void) {}
  100. LEADER_EXTERNS();
  101. // No global matrix scan code, so just run keymap's matrix
  102. // scan function
  103. void matrix_scan_user(void) {
  104. static bool has_ran_yet;
  105. if (!has_ran_yet) {
  106. has_ran_yet = true;
  107. startup_user();
  108. }
  109. LEADER_DICTIONARY() {
  110. leading = false;
  111. leader_end();
  112. // Website Refresh / XCode "Run"
  113. SEQ_ONE_KEY(KC_R) {
  114. SEND_STRING(SS_LGUI("r"));
  115. }
  116. SEQ_TWO_KEYS(KC_B, KC_D) {
  117. SEND_STRING (QMK_KEYBOARD "/" QMK_KEYMAP " @ " QMK_VERSION " Built at: " QMK_BUILDDATE);
  118. }
  119. #ifndef NO_SECRETS
  120. matrix_scan_secrets();
  121. #endif // !NO_SECRETS
  122. }
  123. #if defined(RGB_MATRIX_ENABLE)
  124. matrix_scan_rgb_matrix();
  125. #endif
  126. matrix_scan_keymap();
  127. }
  128. __attribute__((weak)) layer_state_t layer_state_set_keymap(layer_state_t state) { return state; }
  129. // on layer change, no matter where the change was initiated
  130. // Then runs keymap's layer change check
  131. layer_state_t layer_state_set_user(layer_state_t state) {
  132. state = update_tri_layer_state(state, _RAISE, _LOWER, _ADJUST);
  133. #if defined(RGBLIGHT_ENABLE)
  134. state = layer_state_set_rgb_light(state);
  135. #endif // RGBLIGHT_ENABLE
  136. return layer_state_set_keymap(state);
  137. }
  138. __attribute__((weak)) layer_state_t default_layer_state_set_keymap(layer_state_t state) { return state; }
  139. // Runs state check and changes underglow color and animation
  140. layer_state_t default_layer_state_set_user(layer_state_t state) {
  141. state = default_layer_state_set_keymap(state);
  142. #if 0
  143. # if defined(RGB_MATRIX_ENABLE)
  144. state = default_layer_state_set_rgb(state);
  145. # endif // RGB_MATRIX_ENABLE
  146. #endif
  147. return state;
  148. }
  149. __attribute__((weak)) void led_set_keymap(uint8_t usb_led) {}
  150. // Any custom LED code goes here.
  151. // So far, I only have keyboard specific code,
  152. // So nothing goes here.
  153. void led_set_user(uint8_t usb_led) { led_set_keymap(usb_led); }
  154. __attribute__((weak)) void eeconfig_init_keymap(void) {}
  155. void eeconfig_init_user(void) {
  156. #ifdef KEYBOARD_planck_ez
  157. userspace_config.raw = 0;
  158. # if defined(RGB_MATRIX_ENABLE)
  159. userspace_config.rgb_layer_change = true;
  160. # endif
  161. eeconfig_update_user(userspace_config.raw);
  162. #endif
  163. eeconfig_init_keymap();
  164. keyboard_init();
  165. }
  166. bool hasAllBitsInMask(uint8_t value, uint8_t mask) {
  167. value &= 0xF;
  168. mask &= 0xF;
  169. return (value & mask) == mask;
  170. }