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.

220 lines
14 KiB

  1. /* Copyright 2019 Brandon Schlack
  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. #include QMK_KEYBOARD_H
  17. #ifdef KEYBOARD_planck_rev6
  18. #include "muse.h"
  19. #endif
  20. #include "brandonschlack.h"
  21. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  22. /* Qwerty */
  23. [_BASE] = LAYOUT_ortho_4x12( \
  24. // ┌────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐
  25. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, \
  26. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  27. HY_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, \
  28. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  29. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, SFT_ENT, \
  30. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  31. MCO_LYR, KC_LCTL, KC_LOPT, KC_LCMD, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \
  32. // └────────┴────────┴────────┴────────┴────────┴─────────────────┴────────┴────────┴────────┴────────┴────────┘
  33. ),
  34. /* Lower */
  35. [_LOWER] = LAYOUT_ortho_4x12( \
  36. // ┌────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐
  37. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC, \
  38. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  39. KC_DELT, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, \
  40. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  41. SF_CAPS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_HOME, KC_PGUP, KC_PGDN, KC_END, _______, \
  42. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  43. _______, _______, _______, _______, _______, KC_MUTE, KC_MUTE, _______, KC_MPRV, KC_VOLD, KC_VOLU, KC_MNXT \
  44. // └────────┴────────┴────────┴────────┴────────┴─────────────────┴────────┴────────┴────────┴────────┴────────┘
  45. ),
  46. /* Raise */
  47. [_RAISE] = LAYOUT_ortho_4x12( \
  48. // ┌────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐
  49. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, \
  50. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  51. KC_DELT, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, \
  52. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  53. SF_CAPS, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_HOME, KC_PGUP, KC_PGDN, KC_END, _______, \
  54. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  55. _______, _______, _______, _______, _______, KC_MPLY, KC_MPLY, _______, KC_MPRV, KC_VOLD, KC_VOLU, KC_MNXT \
  56. // └────────┴────────┴────────┴────────┴────────┴─────────────────┴────────┴────────┴────────┴────────┴────────┘
  57. ),
  58. /* Macros */
  59. [_MACRO] = LAYOUT_ortho_4x12( \
  60. // ┌────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐
  61. _______, _______, _______, _______, _______, _______, _______, KC_BRMD, KC_BRMU, MC_MSSN, MC_LHPD, MC_SLPD, \
  62. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  63. _______, _______, _______, _______, _______, _______, _______, MC_BACK, MC_FWRD, PRV_TAB, NXT_TAB, NXT_WIN, \
  64. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  65. _______, _______, _______, _______, _______, _______, PX_AFLL, OP_AFLL, _______, _______, _______, _______, \
  66. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  67. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
  68. // └────────┴────────┴────────┴────────┴────────┴─────────────────┴────────┴────────┴────────┴────────┴────────┘
  69. ),
  70. /* Adjust (Lower + Raise) */
  71. [_ADJUST] = LAYOUT_ortho_4x12( \
  72. // ┌────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┬────────┐
  73. QM_MAKE, RESET, DEBUG, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, MC_SLPD, \
  74. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  75. QM_FLSH, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, _______, _______, _______, _______, _______, \
  76. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  77. _______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, RGB_RTHM,RGB_THM, _______, _______, _______, \
  78. // ├────────┼────────┼────────┼────────┼────────┼────────┴────────┼────────┼────────┼────────┼────────┼────────┤
  79. EEP_RST, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
  80. // └────────┴────────┴────────┴────────┴────────┴─────────────────┴────────┴────────┴────────┴────────┴────────┘
  81. )
  82. };
  83. layer_state_t layer_state_set_keymap(layer_state_t state) {
  84. state = update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  85. return state;
  86. }
  87. #ifdef KEYBOARD_plaid
  88. // Turn on Red LED when initialized
  89. void keyboard_post_init_keymap(void) {
  90. writePinHigh(LED_RED);
  91. }
  92. // Use Green LED for Caps Lock
  93. void led_set_user(uint8_t usb_led) {
  94. if (IS_LED_OFF(usb_led, USB_LED_CAPS_LOCK)) {
  95. writePinLow(LED_GREEN);
  96. } else {
  97. writePinHigh(LED_GREEN);
  98. }
  99. }
  100. #endif
  101. #ifdef KEYBOARD_planck_rev6
  102. #ifdef AUDIO_ENABLE
  103. float plover_song[][2] = SONG(PLOVER_SOUND);
  104. float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
  105. #endif
  106. bool muse_mode = false;
  107. uint8_t last_muse_note = 0;
  108. uint16_t muse_counter = 0;
  109. uint8_t muse_offset = 70;
  110. uint16_t muse_tempo = 50;
  111. bool encoder_update_keymap(uint8_t index, bool clockwise) {
  112. if (muse_mode) {
  113. if (IS_LAYER_ON(_RAISE)) {
  114. if (clockwise) {
  115. muse_offset++;
  116. } else {
  117. muse_offset--;
  118. }
  119. } else {
  120. if (clockwise) {
  121. muse_tempo+=1;
  122. } else {
  123. muse_tempo-=1;
  124. }
  125. }
  126. } else {
  127. if (clockwise) {
  128. #ifdef MOUSEKEY_ENABLE
  129. tap_code(MC_WH_U);
  130. #else
  131. tap_code(KC_VOLU);
  132. #endif
  133. } else {
  134. #ifdef MOUSEKEY_ENABLE
  135. tap_code(MC_WH_D);
  136. #else
  137. tap_code(KC_VOLD);
  138. #endif
  139. }
  140. }
  141. return true;
  142. }
  143. bool dip_switch_update_user(uint8_t index, bool active) {
  144. switch (index) {
  145. case 0: {
  146. #ifdef AUDIO_ENABLE
  147. static bool play_sound = false;
  148. #endif
  149. if (active) {
  150. #ifdef AUDIO_ENABLE
  151. if (play_sound) { PLAY_SONG(plover_song); }
  152. #endif
  153. layer_on(_ADJUST);
  154. } else {
  155. #ifdef AUDIO_ENABLE
  156. if (play_sound) { PLAY_SONG(plover_gb_song); }
  157. #endif
  158. layer_off(_ADJUST);
  159. }
  160. #ifdef AUDIO_ENABLE
  161. play_sound = true;
  162. #endif
  163. break;
  164. }
  165. case 1:
  166. if (active) {
  167. muse_mode = true;
  168. } else {
  169. muse_mode = false;
  170. }
  171. }
  172. return true;
  173. }
  174. void matrix_scan_keymap(void) {
  175. #ifdef AUDIO_ENABLE
  176. if (muse_mode) {
  177. if (muse_counter == 0) {
  178. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  179. if (muse_note != last_muse_note) {
  180. stop_note(compute_freq_for_midi_note(last_muse_note));
  181. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  182. last_muse_note = muse_note;
  183. }
  184. }
  185. muse_counter = (muse_counter + 1) % muse_tempo;
  186. } else {
  187. if (muse_counter) {
  188. stop_all_notes();
  189. muse_counter = 0;
  190. }
  191. }
  192. #endif
  193. }
  194. bool music_mask_user(uint16_t keycode) {
  195. switch (keycode) {
  196. case RAISE:
  197. case LOWER:
  198. case MCO_LYR:
  199. return false;
  200. default:
  201. return true;
  202. }
  203. }
  204. #endif