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.

233 lines
9.6 KiB

  1. #pragma message "You may need to add LAYOUT_planck_grid to your keymap layers - see default for an example"
  2. #include "planck.h"
  3. #include "action_layer.h"
  4. #ifdef AUDIO_ENABLE
  5. #include "audio.h"
  6. #endif
  7. #include "eeconfig.h"
  8. extern keymap_config_t keymap_config;
  9. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  10. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  11. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  12. // entirely and just use numbers.
  13. #define _QWERTY 0
  14. #define _LOWER 1
  15. #define _RAISE 2
  16. #define _MULTIMEDIA 3
  17. #define _ADJUST 4
  18. enum planck_keycodes {
  19. QWERTY = SAFE_RANGE,
  20. LOWER,
  21. RAISE,
  22. BACKLIT
  23. };
  24. // Fillers to make layering more clear
  25. #define _______ KC_TRNS
  26. #define XXXXXXX KC_NO
  27. // Func macro definitions.
  28. #define SFT_TAB FUNC(0) // Tap for Enter, hold for Shift
  29. // Enable these functions using FUNC(n) macro.
  30. const uint16_t PROGMEM fn_actions[] = {
  31. [0] = ACTION_LAYER_TAP_KEY(_MULTIMEDIA, KC_TAB)
  32. };
  33. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  34. /* Qwerty
  35. * ,-----------------------------------------------------------------------------------.
  36. * | Esc | Q | W | E | R | T | Y | U | I | O | P | Bksp |
  37. * |------+------+------+------+------+------+------+------+------+------+------+------|
  38. * | Tab | A | S | D | F | G | H | J | K | L | ; | " |
  39. * |------+------+------+------+------+------+------+------+------+------+------+------|
  40. * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter |
  41. * |------+------+------+------+------+------+------+------+------+------+------+------|
  42. * | Ctrl | GUI | AltGr| Alt | Lower| Space | Raise| Left | Down | Up |Right |
  43. * `-----------------------------------------------------------------------------------'
  44. */
  45. [_QWERTY] = {
  46. {KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
  47. {SFT_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
  48. {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
  49. {KC_LCTL, KC_LGUI, KC_RALT, KC_LALT, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT}
  50. },
  51. /* Lower
  52. * ,-----------------------------------------------------------------------------------.
  53. * | | | | | | | | | | | ( | ) |
  54. * |------+------+------+------+------+------+------+------+------+------+------+------|
  55. * | Brite| | | | | | | | | | { | } |
  56. * |------+------+------+------+------+------+------+------+------+------+------+------|
  57. * | | | | | | | | | | | [ | ] |
  58. * |------+------+------+------+------+------+------+------+------+------+------+------|
  59. * | | | | | | | | Home | PgDwn| PgUp | End |
  60. * `-----------------------------------------------------------------------------------'
  61. */
  62. [_LOWER] = {
  63. {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_LPRN, KC_RPRN},
  64. {BACKLIT, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_LCBR, KC_RCBR},
  65. {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_LBRC, KC_RBRC},
  66. {_______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END}
  67. },
  68. /* Raise
  69. * ,-----------------------------------------------------------------------------------.
  70. * | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | - | = |
  71. * |------+------+------+------+------+------+------+------+------+------+------+------|
  72. * | | | | | | | | | | | | ` |
  73. * |------+------+------+------+------+------+------+------+------+------+------+------|
  74. * | | | | | | | | | | | \ | |
  75. * |------+------+------+------+------+------+------+------+------+------+------+------|
  76. * | | | | | | | | | | | |
  77. * `-----------------------------------------------------------------------------------'
  78. */
  79. [_RAISE] = {
  80. {KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL},
  81. {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_GRV},
  82. {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_BSLS, _______},
  83. {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
  84. },
  85. /* _MULTIMEDIA
  86. * ,-----------------------------------------------------------------------------------.
  87. * | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 |
  88. * |------+------+------+------+------+------+------+------+------+------+------+------|
  89. * | | | | | | | | Psc | | | | |
  90. * |------+------+------+------+------+------+------+------+------+------+------+------|
  91. * | | | | | | Mute | Vol+ | Vol- | | | |Insert|
  92. * |------+------+------+------+------+------+------+------+------+------+------+------|
  93. * | | | | | | | | Prev | Play | Next | Del |
  94. * `-----------------------------------------------------------------------------------'
  95. */
  96. [_MULTIMEDIA] = {
  97. {KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12},
  98. {_______, _______, _______, _______, _______, _______, _______, KC_PSCR, _______, _______, _______, _______},
  99. {_______, _______, _______, _______, _______, KC_MUTE, KC_VOLU, KC_VOLD, _______, _______, _______, KC_INS},
  100. {_______, _______, _______, _______, _______, _______, _______, _______, KC_MPRV, KC_MPLY, KC_MNXT, KC_DEL}
  101. },
  102. /* Adjust (Lower + Raise)
  103. * ,-----------------------------------------------------------------------------------.
  104. * | | Reset| | | | | | | | | | Del |
  105. * |------+------+------+------+------+------+------+------+------+------+------+------|
  106. * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty| | | | |
  107. * |------+------+------+------+------+------+------+------+------+------+------+------|
  108. * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | | |
  109. * |------+------+------+------+------+------+------+------+------+------+------+------|
  110. * | | | | | | | | | | | |
  111. * `-----------------------------------------------------------------------------------'
  112. */
  113. [_ADJUST] = {
  114. {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL},
  115. {_______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, _______, _______, _______, _______},
  116. {_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______},
  117. {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
  118. }
  119. };
  120. #ifdef AUDIO_ENABLE
  121. float tone_startup[][2] = SONG(STARTUP_SOUND);
  122. float tone_qwerty[][2] = SONG(QWERTY_SOUND);
  123. float tone_dvorak[][2] = SONG(DVORAK_SOUND);
  124. float tone_colemak[][2] = SONG(COLEMAK_SOUND);
  125. float tone_plover[][2] = SONG(PLOVER_SOUND);
  126. float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND);
  127. float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
  128. float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
  129. #endif
  130. void persistent_default_layer_set(uint16_t default_layer) {
  131. eeconfig_update_default_layer(default_layer);
  132. default_layer_set(default_layer);
  133. }
  134. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  135. switch (keycode) {
  136. case QWERTY:
  137. if (record->event.pressed) {
  138. #ifdef AUDIO_ENABLE
  139. PLAY_SONG(tone_qwerty);
  140. #endif
  141. persistent_default_layer_set(1UL<<_QWERTY);
  142. }
  143. return false;
  144. break;
  145. case LOWER:
  146. if (record->event.pressed) {
  147. layer_on(_LOWER);
  148. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  149. } else {
  150. layer_off(_LOWER);
  151. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  152. }
  153. return false;
  154. break;
  155. case RAISE:
  156. if (record->event.pressed) {
  157. layer_on(_RAISE);
  158. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  159. } else {
  160. layer_off(_RAISE);
  161. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  162. }
  163. return false;
  164. break;
  165. case BACKLIT:
  166. if (record->event.pressed) {
  167. register_code(KC_RSFT);
  168. #ifdef BACKLIGHT_ENABLE
  169. backlight_step();
  170. #endif
  171. } else {
  172. unregister_code(KC_RSFT);
  173. }
  174. return false;
  175. break;
  176. }
  177. return true;
  178. }
  179. void matrix_init_user(void) {
  180. #ifdef AUDIO_ENABLE
  181. startup_user();
  182. #endif
  183. }
  184. #ifdef AUDIO_ENABLE
  185. void startup_user()
  186. {
  187. _delay_ms(20); // gets rid of tick
  188. PLAY_SONG(tone_startup);
  189. }
  190. void shutdown_user()
  191. {
  192. PLAY_SONG(tone_goodbye);
  193. _delay_ms(150);
  194. stop_all_notes();
  195. }
  196. void music_on_user(void)
  197. {
  198. music_scale_user();
  199. }
  200. void music_scale_user(void)
  201. {
  202. PLAY_SONG(music_scale);
  203. }
  204. #endif