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.

305 lines
12 KiB

  1. /* Copyright 2015-2017 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. #include QMK_KEYBOARD_H
  17. #include "action_layer.h"
  18. #include "muse.h"
  19. extern keymap_config_t keymap_config;
  20. enum planck_layers {
  21. _QWERTY,
  22. _LOWER,
  23. _RAISE,
  24. _ADJUST,
  25. _NAV,
  26. _DEV
  27. };
  28. enum planck_keycodes {
  29. QWERTY = SAFE_RANGE,
  30. BACKLIT,
  31. // my macros
  32. R_ASGN,
  33. R_PIPE,
  34. R_CMLN,
  35. };
  36. #define LOWER MO(_LOWER)
  37. #define RAISE MO(_RAISE)
  38. // my defs
  39. #define LT_ESC LT(_NAV, KC_ESC) //tap for esc, hold for mouse nav layer
  40. #define DEV MO(_DEV) // get to dev layer
  41. #define KC_CAD LALT(LCTL(KC_DEL)) // because awkwardness
  42. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  43. /* Qwerty
  44. * ,-----------------------------------------------------------------------------------.
  45. * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp |
  46. * |------+------+------+------+------+-------------+------+------+------+------+------|
  47. * | CTRL | A | S | D | F | G | H | J | K | L | ; | " |
  48. * |------+------+------+------+------+------|------+------+------+------+------+------|
  49. * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter |
  50. * |------+------+------+------+------+------+------+------+------+------+------+------|
  51. * | ESC | APP | GUI | ALT |Lower | Space |Raise | DEV | | | |
  52. * `-----------------------------------------------------------------------------------'
  53. */
  54. [_QWERTY] = LAYOUT_planck_grid(
  55. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  56. KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  57. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT ,
  58. LT_ESC, KC_APP, KC_LGUI, KC_LALT, LOWER, KC_SPC, KC_SPC, RAISE, DEV, _______, _______, _______
  59. ),
  60. /* Lower
  61. * ,-----------------------------------------------------------------------------------.
  62. * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp|
  63. * |------+------+------+------+------+-------------+------+------+------+------+------|
  64. * | | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | |
  65. * |------+------+------+------+------+------|------+------+------+------+------+------|
  66. * | | F7 | F8 | F9 | F10 | F11 | F12 | | Home | END | | |
  67. * |------+------+------+------+------+------+------+------+------+------+------+------|
  68. * | DEL | | | | | | | Next | Vol- | Vol+ | Play |
  69. * `-----------------------------------------------------------------------------------'
  70. */
  71. [_LOWER] = LAYOUT_planck_grid(
  72. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC,
  73. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE,
  74. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_HOME, KC_END, _______, _______,
  75. KC_DEL, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
  76. ),
  77. /* Raise
  78. * ,-----------------------------------------------------------------------------------.
  79. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
  80. * |------+------+------+------+------+-------------+------+------+------+------+------|
  81. * | | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ |
  82. * |------+------+------+------+------+------|------+------+------+------+------+------|
  83. * | | F7 | F8 | F9 | F10 | F11 | F12 | |Pg Up |Pg Dn | | |
  84. * |------+------+------+------+------+------+------+------+------+------+------+------|
  85. * | Del | | | | | | | Next | Vol- | Vol+ | Play
  86. * `-----------------------------------------------------------------------------------'
  87. */
  88. [_RAISE] = LAYOUT_planck_grid(
  89. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
  90. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS,
  91. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_PGUP, KC_PGDN, _______, _______,
  92. KC_DEL, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
  93. ),
  94. /* Adjust (Lower + Raise)
  95. * ,-----------------------------------------------------------------------------------.
  96. * | | Reset| | | | | | | | | | Del |
  97. * |------+------+------+------+------+-------------+------+------+------+------+------|
  98. * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty| | | | |
  99. * |------+------+------+------+------+------|------+------+------+------+------+------|
  100. * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | | |
  101. * |------+------+------+------+------+------+------+------+------+------+------+------|
  102. * | | | | | | | | | | | |
  103. * `-----------------------------------------------------------------------------------'
  104. */
  105. [_ADJUST] = LAYOUT_planck_grid(
  106. _______, RESET, DEBUG, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, KC_DEL ,
  107. _______, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, _______, _______, _______, _______,
  108. _______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, TERM_ON, TERM_OFF, _______, _______, _______,
  109. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  110. ),
  111. /* Nav Layer
  112. * ,-----------------------------------------------------------------------------------.
  113. * | | | | | | | | PGUP | UP | PGDN | |KC_CAD|
  114. * |------+------+------+------+------+-------------+------+------+------+------+------|
  115. * | | | | | | | HOME | LEFT | DOWN |RIGHT | | |
  116. * |------+------+------+------+------+------|------+------+------+------+------+------|
  117. * | | | | | | | END | | | | | |
  118. * |------+------+------+------+------+------+------+------+------+------+------+------|
  119. * | | | | | | | | | | | |
  120. * `-----------------------------------------------------------------------------------'
  121. */
  122. [_NAV] = LAYOUT_planck_grid(
  123. _______, _______, _______, _______, _______, _______, _______, KC_PGUP, KC_UP, KC_PGDN, _______, KC_CAD,
  124. _______, _______, _______, _______, _______, _______, KC_HOME, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______,
  125. _______, _______, _______, _______, _______, _______, KC_END, _______, _______, _______, _______, _______,
  126. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  127. ),
  128. /* DEV Layer
  129. * ,-----------------------------------------------------------------------------------.
  130. * | | | |R_CMLM| | | | | | | |KC_CAD|
  131. * |------+------+------+------+------+-------------+------+------+------+------+------|
  132. * | | | | | | | |R_ASGN|R_PIPE| | | |
  133. * |------+------+------+------+------+------|------+------+------+------+------+------|
  134. * | | | | | | | | | | | | |
  135. * |------+------+------+------+------+------+------+------+------+------+------+------|
  136. * | | | | | | | | | | | |
  137. * `-----------------------------------------------------------------------------------'
  138. */
  139. [_DEV] = LAYOUT_planck_grid(
  140. _______, _______, _______, R_CMLN, _______, _______, _______, _______, _______, _______, _______, KC_CAD,
  141. _______, _______, _______, _______, _______, _______, _______, R_ASGN, R_PIPE, _______, _______, _______,
  142. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  143. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  144. )
  145. };
  146. #ifdef AUDIO_ENABLE
  147. float plover_song[][2] = SONG(PLOVER_SOUND);
  148. float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
  149. #endif
  150. layer_state_t layer_state_set_user(layer_state_t state) {
  151. return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  152. }
  153. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  154. switch (keycode) {
  155. case QWERTY:
  156. if (record->event.pressed) {
  157. print("mode just switched to qwerty and this is a huge string\n");
  158. set_single_persistent_default_layer(_QWERTY);
  159. }
  160. return false;
  161. break;
  162. case BACKLIT:
  163. if (record->event.pressed) {
  164. register_code(KC_RSFT);
  165. #ifdef BACKLIGHT_ENABLE
  166. backlight_step();
  167. #endif
  168. #ifdef KEYBOARD_planck_rev5
  169. PORTE &= ~(1<<6);
  170. #endif
  171. } else {
  172. unregister_code(KC_RSFT);
  173. #ifdef KEYBOARD_planck_rev5
  174. PORTE |= (1<<6);
  175. #endif
  176. }
  177. return false;
  178. break;
  179. // my macros
  180. case R_ASGN:
  181. if (record->event.pressed) {
  182. SEND_STRING(" <- ");
  183. }
  184. return false;
  185. break;
  186. case R_PIPE:
  187. if (record->event.pressed) {
  188. SEND_STRING(" %>%\n");
  189. }
  190. return false;
  191. break;
  192. case R_CMLN:
  193. if (record->event.pressed) {
  194. SEND_STRING("################################################################################");
  195. }
  196. return false;
  197. break;
  198. }
  199. return true;
  200. }
  201. bool muse_mode = false;
  202. uint8_t last_muse_note = 0;
  203. uint16_t muse_counter = 0;
  204. uint8_t muse_offset = 70;
  205. uint16_t muse_tempo = 50;
  206. bool encoder_update_user(uint8_t index, bool clockwise) {
  207. if (muse_mode) {
  208. if (IS_LAYER_ON(_RAISE)) {
  209. if (clockwise) {
  210. muse_offset++;
  211. } else {
  212. muse_offset--;
  213. }
  214. } else {
  215. if (clockwise) {
  216. muse_tempo+=1;
  217. } else {
  218. muse_tempo-=1;
  219. }
  220. }
  221. } else {
  222. if (clockwise) {
  223. register_code(KC_PGDN);
  224. unregister_code(KC_PGDN);
  225. } else {
  226. register_code(KC_PGUP);
  227. unregister_code(KC_PGUP);
  228. }
  229. }
  230. return true;
  231. }
  232. bool dip_switch_update_user(uint8_t index, bool active) {
  233. switch (index) {
  234. case 0:
  235. if (active) {
  236. #ifdef AUDIO_ENABLE
  237. PLAY_SONG(plover_song);
  238. #endif
  239. layer_on(_ADJUST);
  240. } else {
  241. #ifdef AUDIO_ENABLE
  242. PLAY_SONG(plover_gb_song);
  243. #endif
  244. layer_off(_ADJUST);
  245. }
  246. break;
  247. case 1:
  248. if (active) {
  249. muse_mode = true;
  250. } else {
  251. muse_mode = false;
  252. #ifdef AUDIO_ENABLE
  253. stop_all_notes();
  254. #endif
  255. }
  256. }
  257. return true;
  258. }
  259. void matrix_scan_user(void) {
  260. #ifdef AUDIO_ENABLE
  261. if (muse_mode) {
  262. if (muse_counter == 0) {
  263. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  264. if (muse_note != last_muse_note) {
  265. stop_note(compute_freq_for_midi_note(last_muse_note));
  266. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  267. last_muse_note = muse_note;
  268. }
  269. }
  270. muse_counter = (muse_counter + 1) % muse_tempo;
  271. }
  272. #endif
  273. }
  274. bool music_mask_user(uint16_t keycode) {
  275. switch (keycode) {
  276. case RAISE:
  277. case LOWER:
  278. return false;
  279. default:
  280. return true;
  281. }
  282. }