keymap.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. #define _QWERTY 0
  15. #define _COLEMAK 1
  16. #define _DVORAK 2
  17. #define _LOWER 3
  18. #define _RAISE 4
  19. #define _PLOVER 5
  20. #define _ADJUST 16
  21. enum planck_keycodes {
  22. QWERTY = SAFE_RANGE,
  23. COLEMAK,
  24. DVORAK,
  25. PLOVER,
  26. LOWER,
  27. RAISE,
  28. BACKLIT,
  29. EXT_PLV,
  30. TOG_OUT
  31. };
  32. // Fillers to make layering more clear
  33. #define _______ KC_TRNS
  34. #define XXXXXXX KC_NO
  35. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  36. /* Qwerty
  37. * ,-----------------------------------------------------------------------------------.
  38. * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp |
  39. * |------+------+------+------+------+-------------+------+------+------+------+------|
  40. * | Esc | A | S | D | F | G | H | J | K | L | ; | " |
  41. * |------+------+------+------+------+------|------+------+------+------+------+------|
  42. * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter |
  43. * |------+------+------+------+------+------+------+------+------+------+------+------|
  44. * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
  45. * `-----------------------------------------------------------------------------------'
  46. */
  47. [_QWERTY] = {
  48. {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
  49. {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
  50. {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
  51. {BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
  52. },
  53. /* Colemak
  54. * ,-----------------------------------------------------------------------------------.
  55. * | Tab | Q | W | F | P | G | J | L | U | Y | ; | Bksp |
  56. * |------+------+------+------+------+-------------+------+------+------+------+------|
  57. * | Esc | A | R | S | T | D | H | N | E | I | O | " |
  58. * |------+------+------+------+------+------|------+------+------+------+------+------|
  59. * | Shift| Z | X | C | V | B | K | M | , | . | / |Enter |
  60. * |------+------+------+------+------+------+------+------+------+------+------+------|
  61. * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
  62. * `-----------------------------------------------------------------------------------'
  63. */
  64. [_COLEMAK] = {
  65. {KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC},
  66. {KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT},
  67. {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT },
  68. {BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
  69. },
  70. /* Dvorak
  71. * ,-----------------------------------------------------------------------------------.
  72. * | Tab | " | , | . | P | Y | F | G | C | R | L | Bksp |
  73. * |------+------+------+------+------+-------------+------+------+------+------+------|
  74. * | Esc | A | O | E | U | I | D | H | T | N | S | / |
  75. * |------+------+------+------+------+------|------+------+------+------+------+------|
  76. * | Shift| ; | Q | J | K | X | B | M | W | V | Z |Enter |
  77. * |------+------+------+------+------+------+------+------+------+------+------+------|
  78. * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
  79. * `-----------------------------------------------------------------------------------'
  80. */
  81. [_DVORAK] = {
  82. {KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC},
  83. {KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH},
  84. {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT },
  85. {BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
  86. },
  87. /* Lower
  88. * ,-----------------------------------------------------------------------------------.
  89. * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp |
  90. * |------+------+------+------+------+-------------+------+------+------+------+------|
  91. * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | |
  92. * |------+------+------+------+------+------|------+------+------+------+------+------|
  93. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | | |Enter |
  94. * |------+------+------+------+------+------+------+------+------+------+------+------|
  95. * | | | | | | | | Next | Vol- | Vol+ | Play |
  96. * `-----------------------------------------------------------------------------------'
  97. */
  98. [_LOWER] = {
  99. {KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC},
  100. {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE},
  101. {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,S(KC_NUHS),S(KC_NUBS),_______, _______, _______},
  102. {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
  103. },
  104. /* Raise
  105. * ,-----------------------------------------------------------------------------------.
  106. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
  107. * |------+------+------+------+------+-------------+------+------+------+------+------|
  108. * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ |
  109. * |------+------+------+------+------+------|------+------+------+------+------+------|
  110. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / | | |Enter |
  111. * |------+------+------+------+------+------+------+------+------+------+------+------|
  112. * | | | | | | | | Next | Vol- | Vol+ | Play |
  113. * `-----------------------------------------------------------------------------------'
  114. */
  115. [_RAISE] = {
  116. {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
  117. {KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS},
  118. {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, _______, _______, _______},
  119. {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
  120. },
  121. /* Plover layer (http://opensteno.org)
  122. * ,-----------------------------------------------------------------------------------.
  123. * | # | # | # | # | # | # | # | # | # | # | # | # |
  124. * |------+------+------+------+------+-------------+------+------+------+------+------|
  125. * | | S | T | P | H | * | * | F | P | L | T | D |
  126. * |------+------+------+------+------+------|------+------+------+------+------+------|
  127. * |TogOut| S | K | W | R | * | * | R | B | G | S | Z |
  128. * |------+------+------+------+------+------+------+------+------+------+------+------|
  129. * | Exit | | | A | O | | E | U | | | |
  130. * `-----------------------------------------------------------------------------------'
  131. */
  132. [_PLOVER] = {
  133. {KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1 },
  134. {XXXXXXX, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC},
  135. {TOG_OUT, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
  136. {EXT_PLV, XXXXXXX, XXXXXXX, KC_C, KC_V, XXXXXXX, XXXXXXX, KC_N, KC_M, XXXXXXX, XXXXXXX, XXXXXXX}
  137. },
  138. /* Adjust (Lower + Raise)
  139. * ,-----------------------------------------------------------------------------------.
  140. * | | Reset| | | | | | | | | | Del |
  141. * |------+------+------+------+------+-------------+------+------+------+------+------|
  142. * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty|Colemk|Dvorak|Plover| |
  143. * |------+------+------+------+------+------|------+------+------+------+------+------|
  144. * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | | |
  145. * |------+------+------+------+------+------+------+------+------+------+------+------|
  146. * | | | | | | | | | | | |
  147. * `-----------------------------------------------------------------------------------'
  148. */
  149. [_ADJUST] = {
  150. {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL},
  151. {_______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, PLOVER, _______},
  152. {_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______},
  153. {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
  154. }
  155. };
  156. #ifdef AUDIO_ENABLE
  157. float tone_startup[][2] = SONG(STARTUP_SOUND);
  158. float tone_qwerty[][2] = SONG(QWERTY_SOUND);
  159. float tone_dvorak[][2] = SONG(DVORAK_SOUND);
  160. float tone_colemak[][2] = SONG(COLEMAK_SOUND);
  161. float tone_plover[][2] = SONG(PLOVER_SOUND);
  162. float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND);
  163. float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
  164. float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
  165. #endif
  166. void persistant_default_layer_set(uint16_t default_layer) {
  167. eeconfig_update_default_layer(default_layer);
  168. default_layer_set(default_layer);
  169. }
  170. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  171. switch (keycode) {
  172. case QWERTY:
  173. if (record->event.pressed) {
  174. #ifdef AUDIO_ENABLE
  175. PLAY_NOTE_ARRAY(tone_qwerty, false, 0);
  176. #endif
  177. persistant_default_layer_set(1UL<<_QWERTY);
  178. }
  179. break;
  180. case COLEMAK:
  181. if (record->event.pressed) {
  182. #ifdef AUDIO_ENABLE
  183. PLAY_NOTE_ARRAY(tone_colemak, false, 0);
  184. #endif
  185. persistant_default_layer_set(1UL<<_COLEMAK);
  186. }
  187. break;
  188. case DVORAK:
  189. if (record->event.pressed) {
  190. #ifdef AUDIO_ENABLE
  191. PLAY_NOTE_ARRAY(tone_dvorak, false, 0);
  192. #endif
  193. persistant_default_layer_set(1UL<<_DVORAK);
  194. }
  195. break;
  196. case LOWER:
  197. if (record->event.pressed) {
  198. layer_on(_LOWER);
  199. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  200. } else {
  201. layer_off(_LOWER);
  202. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  203. }
  204. break;
  205. case RAISE:
  206. if (record->event.pressed) {
  207. layer_on(_RAISE);
  208. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  209. } else {
  210. layer_off(_RAISE);
  211. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  212. }
  213. break;
  214. case BACKLIT:
  215. if (record->event.pressed) {
  216. register_code(KC_RSFT);
  217. #ifdef BACKLIGHT_ENABLE
  218. backlight_step();
  219. #endif
  220. } else {
  221. unregister_code(KC_RSFT);
  222. }
  223. break;
  224. case PLOVER:
  225. if (record->event.pressed) {
  226. #ifdef AUDIO_ENABLE
  227. stop_all_notes();
  228. PLAY_NOTE_ARRAY(tone_plover, false, 0);
  229. #endif
  230. layer_off(_RAISE);
  231. layer_off(_LOWER);
  232. layer_off(_ADJUST);
  233. layer_on(_PLOVER);
  234. if (!eeconfig_is_enabled()) {
  235. eeconfig_init();
  236. }
  237. keymap_config.raw = eeconfig_read_keymap();
  238. keymap_config.nkro = 1;
  239. eeconfig_update_keymap(keymap_config.raw);
  240. }
  241. break;
  242. case EXT_PLV:
  243. if (record->event.pressed) {
  244. #ifdef AUDIO_ENABLE
  245. PLAY_NOTE_ARRAY(tone_plover_gb, false, 0);
  246. #endif
  247. layer_off(_PLOVER);
  248. }
  249. break;
  250. case TOG_OUT:
  251. if (record->event.pressed) {
  252. return MACRO( D(E), D(R), D(F), D(V), D(O), D(L), U(E), U(R), U(F), U(V), U(O), U(L), END );
  253. }
  254. break;
  255. }
  256. return true;
  257. }
  258. void matrix_init_user(void) {
  259. #ifdef AUDIO_ENABLE
  260. startup_user();
  261. #endif
  262. }
  263. #ifdef AUDIO_ENABLE
  264. void startup_user()
  265. {
  266. _delay_ms(20); // gets rid of tick
  267. PLAY_NOTE_ARRAY(tone_startup, false, 0);
  268. }
  269. void shutdown_user()
  270. {
  271. PLAY_NOTE_ARRAY(tone_goodbye, false, 0);
  272. _delay_ms(150);
  273. stop_all_notes();
  274. }
  275. void music_on_user(void)
  276. {
  277. music_scale_user();
  278. }
  279. void music_scale_user(void)
  280. {
  281. PLAY_NOTE_ARRAY(music_scale, false, 0);
  282. }
  283. #endif