keymap.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // This is the canonical layout file for the Quantum project. If you want to add another keyboard,
  2. // this is the style you want to emulate.
  3. #include "planck.h"
  4. #include "action_layer.h"
  5. #ifdef AUDIO_ENABLE
  6. #include "audio.h"
  7. #endif
  8. #include "eeconfig.h"
  9. extern keymap_config_t keymap_config;
  10. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  11. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  12. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  13. // entirely and just use numbers.
  14. enum planck_layers {
  15. _NERD,
  16. _LOWER,
  17. _RAISE,
  18. _ADJUST
  19. };
  20. enum planck_keycodes {
  21. NERD = SAFE_RANGE,
  22. LOWER,
  23. RAISE
  24. };
  25. // Fillers to make layering more clear
  26. #define _______ KC_TRNS
  27. #define XXXXXXX KC_NO
  28. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  29. /* NERD
  30. * ,-----------------------------------------------------------------------------------.
  31. * | Esc | Q | W | E | R | T | Y | U | I | O | P | Bksp |
  32. * |------+------+------+------+------+-------------+------+------+------+------+------|
  33. * | Tab | A | S | D | F | G | H | J | K | L | ; |Enter |
  34. * |------+------+------+------+------+------|------+------+------+------+------+------|
  35. * | Shift| Z | X | C | V | B | N | M | , | . | / |Shift |
  36. * |------+------+------+------+------+------+------+------+------+------+------+------|
  37. * | DEL | Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
  38. * `-----------------------------------------------------------------------------------'
  39. */
  40. [_NERD] = {
  41. {KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
  42. {KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_ENT },
  43. {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT},
  44. {KC_DEL, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
  45. },
  46. /* Lower
  47. * ,-----------------------------------------------------------------------------------.
  48. * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp |
  49. * |------+------+------+------+------+-------------+------+------+------+------+------|
  50. * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | \ |
  51. * |------+------+------+------+------+------|------+------+------+------+------+------|
  52. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | Home | End | |
  53. * |------+------+------+------+------+------+------+------+------+------+------+------|
  54. * | | | | | | | | Next | Vol- | Vol+ | Play |
  55. * `-----------------------------------------------------------------------------------'
  56. */
  57. [_LOWER] = {
  58. {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC},
  59. {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_BSLS},
  60. {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, S(KC_NUHS), S(KC_NUBS), KC_HOME, KC_END, _______},
  61. {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
  62. },
  63. /* Raise
  64. * ,-----------------------------------------------------------------------------------.
  65. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
  66. * |------+------+------+------+------+-------------+------+------+------+------+------|
  67. * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | ' |
  68. * |------+------+------+------+------+------|------+------+------+------+------+------|
  69. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / |Pg Up |Pg Dn | |
  70. * |------+------+------+------+------+------+------+------+------+------+------+------|
  71. * | | | | | | | | Next | Vol- | Vol+ | Play |
  72. * `-----------------------------------------------------------------------------------'
  73. */
  74. [_RAISE] = {
  75. {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
  76. {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_QUOT},
  77. {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, KC_PGUP, KC_PGDN, _______},
  78. {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
  79. },
  80. /* Adjust (Lower + Raise)
  81. * ,-----------------------------------------------------------------------------------.
  82. * | | Reset| | | | | | | | | | Del |
  83. * |------+------+------+------+------+-------------+------+------+------+------+------|
  84. * | | | |Aud on|Audoff|AGnorm|AGswap| NERD | | | | |
  85. * |------+------+------+------+------+------|------+------+------+------+------+------|
  86. * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | | |
  87. * |------+------+------+------+------+------+------+------+------+------+------+------|
  88. * | | | | | | | | | | | |
  89. * `-----------------------------------------------------------------------------------'
  90. */
  91. [_ADJUST] = {
  92. {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL },
  93. {_______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, NERD, _______, _______, _______, _______},
  94. {_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______},
  95. {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
  96. }
  97. };
  98. #ifdef AUDIO_ENABLE
  99. float tone_startup[][2] = SONG(STARTUP_SOUND);
  100. float tone_nerd[][2] = SONG(QWERTY_SOUND);
  101. float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
  102. float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
  103. #endif
  104. void persistent_default_layer_set(uint16_t default_layer) {
  105. eeconfig_update_default_layer(default_layer);
  106. default_layer_set(default_layer);
  107. }
  108. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  109. switch (keycode) {
  110. case NERD:
  111. if (record->event.pressed) {
  112. #ifdef AUDIO_ENABLE
  113. PLAY_SONG(tone_nerd);
  114. #endif
  115. persistent_default_layer_set(1UL<<_NERD);
  116. }
  117. return false;
  118. break;
  119. case LOWER:
  120. if (record->event.pressed) {
  121. layer_on(_LOWER);
  122. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  123. } else {
  124. layer_off(_LOWER);
  125. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  126. }
  127. return false;
  128. break;
  129. case RAISE:
  130. if (record->event.pressed) {
  131. layer_on(_RAISE);
  132. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  133. } else {
  134. layer_off(_RAISE);
  135. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  136. }
  137. return false;
  138. break;
  139. }
  140. return true;
  141. }
  142. void matrix_init_user(void) {
  143. #ifdef AUDIO_ENABLE
  144. startup_user();
  145. #endif
  146. }
  147. #ifdef AUDIO_ENABLE
  148. void startup_user()
  149. {
  150. _delay_ms(20); // gets rid of tick
  151. PLAY_SONG(tone_startup);
  152. }
  153. void shutdown_user()
  154. {
  155. PLAY_SONG(tone_goodbye);
  156. _delay_ms(150);
  157. stop_all_notes();
  158. }
  159. void music_on_user(void)
  160. {
  161. music_scale_user();
  162. }
  163. void music_scale_user(void)
  164. {
  165. PLAY_SONG(music_scale);
  166. }
  167. #endif