keymap.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #include "preonic.h"
  2. #include "action_layer.h"
  3. #include "eeconfig.h"
  4. #ifdef AUDIO_ENABLE
  5. #include "audio.h"
  6. #endif
  7. // Layer names
  8. #define _COLEMAK 0
  9. #define _GAME 1
  10. #define _RAISE 2
  11. enum preonic_keycodes {
  12. COLEMAK = SAFE_RANGE,
  13. GAME,
  14. RAISE
  15. };
  16. // Fillers to make layering more clear
  17. #define _______ KC_TRNS
  18. #define XXXXXXX KC_NO
  19. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  20. /* Colemak
  21. * ,-----------------------------------------------------------------------------------.
  22. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | \ |
  23. * |------+------+------+------+------+------+------+------+------+------+------+------|
  24. * | = | Q | W | F | P | G | J | L | U | Y | [ | ] |
  25. * |------+------+------+------+------+------+------+------+------+------+------+------|
  26. * | - | A | R | S | T | D | H | N | E | I | O | ' |
  27. * |------+------+------+------+------+------+------+------+------+------+------+------|
  28. * | ; | Z | X | C | V | B | K | M | , | . | / | ENTER|
  29. * |------+------+------+------+------+------+------+------+------+------+------+------|
  30. * | ESC | ALT | GUI | SHIFT| CTRL | BKSP | SPACE| RAISE| SHIFT| | DEL | TAB |
  31. * `-----------------------------------------------------------------------------------'
  32. */
  33. [_COLEMAK] = {
  34. {KC_GRV ,KC_1 ,KC_2 ,KC_3 ,KC_4 ,KC_5 ,KC_6 ,KC_7 ,KC_8 ,KC_9 ,KC_0 ,KC_BSLS},
  35. {KC_EQL ,KC_Q ,KC_W ,KC_F ,KC_P ,KC_G ,KC_J ,KC_L ,KC_U ,KC_Y ,KC_LBRC,KC_RBRC},
  36. {KC_MINS,KC_A ,KC_R ,KC_S ,KC_T ,KC_D ,KC_H ,KC_N ,KC_E ,KC_I ,KC_O ,KC_QUOT},
  37. {KC_SCLN,KC_Z ,KC_X ,KC_C ,KC_V ,KC_B ,KC_K ,KC_M ,KC_COMM,KC_DOT ,KC_SLSH,KC_ENT },
  38. {KC_ESC ,KC_LALT,KC_LGUI,KC_LSFT,KC_LCTL,KC_BSPC,KC_SPC ,RAISE ,KC_RSFT,_______,KC_DEL ,KC_TAB }
  39. },
  40. /* Game
  41. * ,-----------------------------------------------------------------------------------.
  42. * | ESC | 1 | 2 | 3 | 4 | 5 | 6 | 7 |NUM LK| ÷ | × | - |
  43. * |------+------+------+------+------+------+------+------+------+------+------+------+
  44. * | TAB | Q | W | E | R | T | Y | U | 1 | 2 | 3 | + |
  45. * |------+------+------+------+------+------+------+------+------+------+------+------+
  46. * | CTRL | A | S | D | F | G | H | J | 4 | 5 | 6 | = |
  47. * |------+------+------+------+------+------+------+------+------+------+------+------+
  48. * | SHIFT| Z | X | C | V | B | N | M | 7 | 8 | 9 | ENTER|
  49. * |------+------+------+------+------+------+------+------+------+------+------+------+
  50. * | | ALT | GUI | SPACE| CTRL | BKSP | SPACE| RAISE| , | 0 | . | TAB |
  51. * `-----------------------------------------------------------------------------------'
  52. */
  53. [_GAME] = {
  54. {KC_ESC ,KC_1 ,KC_2 ,KC_3 ,KC_4 ,KC_5 ,KC_6 ,KC_7 ,KC_NLCK,KC_PSLS,KC_PAST,KC_PMNS},
  55. {KC_TAB ,KC_Q ,KC_W ,KC_E ,KC_R ,KC_T ,KC_Y ,KC_U ,KC_P1 ,KC_P2 ,KC_P3 ,KC_PPLS},
  56. {KC_LCTL,KC_A ,KC_S ,KC_D ,KC_F ,KC_G ,KC_H ,KC_J ,KC_P4 ,KC_P5 ,KC_P6 ,KC_PEQL},
  57. {KC_LSFT,KC_Z ,KC_X ,KC_C ,KC_V ,KC_B ,KC_N ,KC_M ,KC_P7 ,KC_P8 ,KC_P9 ,KC_PENT},
  58. {XXXXXXX,KC_LALT,KC_LGUI,KC_SPC ,KC_LCTL,KC_BSPC,KC_SPC ,RAISE ,KC_PCMM,KC_P0 ,KC_PDOT,KC_TAB }
  59. },
  60. /* Raise
  61. * ,-----------------------------------------------------------------------------------.
  62. * | SLEEP| F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 |PRTSCR|
  63. * |------+------+------+------+------+------+------+------+------+------+------+------|
  64. * | SYM | F11 | F12 | |AU TOG| VOL+ |BL INC|COLMAK| GAME | MUSIC| MENU |SCRLCK|
  65. * |------+------+------+------+------+------+------+------+------+------+------+------|
  66. * | CAPS | PREV | STOP | PLAY | NEXT | VOL- |BL DEC| LEFT | DOWN | UP | RIGHT| PAUSE|
  67. * |------+------+------+------+------+------+------+------+------+------+------+------|
  68. * | | BACK | STOP | RFRSH| FRWRD| MUTE |BL TOG| HOME | PGDN | PGUP | END |INSERT|
  69. * |------+------+------+------+------+------+------+------+------+------+------+------|
  70. * | RESET| | | | | DEL | | | | | | |
  71. * `-----------------------------------------------------------------------------------'
  72. */
  73. [_RAISE] = {
  74. {KC_SLEP,KC_F1 ,KC_F2 ,KC_F3 ,KC_F4 ,KC_F5 ,KC_F6 ,KC_F7 ,KC_F8 ,KC_F9 ,KC_F10 ,KC_PSCR},
  75. {XXXXXXX,KC_F11 ,KC_F12 ,XXXXXXX,AU_TOG ,KC_VOLU,BL_INC ,COLEMAK,GAME ,MU_TOG ,KC_MENU,KC_SLCK},
  76. {KC_CAPS,KC_MPRV,KC_MSTP,KC_MPLY,KC_MNXT,KC_VOLD,BL_DEC ,KC_LEFT,KC_DOWN,KC_UP ,KC_RGHT,KC_PAUS},
  77. {XXXXXXX,KC_WBAK,KC_WSTP,KC_WREF,KC_WFWD,KC_MUTE,BL_TOGG,KC_HOME,KC_PGDN,KC_PGUP,KC_END ,KC_INS },
  78. {RESET ,_______,_______,_______,_______,KC_DEL ,_______,_______,_______,_______,_______,_______}
  79. }
  80. };
  81. #ifdef AUDIO_ENABLE
  82. float tone_startup[][2] = {
  83. {NOTE_B5, 20},
  84. {NOTE_B6, 8},
  85. {NOTE_DS6, 20},
  86. {NOTE_B6, 8}
  87. };
  88. float tone_colemak[][2] = SONG(COLEMAK_SOUND);
  89. float tone_game[][2] = {
  90. {NOTE_E6, 10} ,{NOTE_E6, 10} ,{NOTE_REST, 10} ,{NOTE_E6, 10} ,
  91. {NOTE_REST, 10} ,{NOTE_C6, 10} ,{NOTE_E6, 10} ,{NOTE_REST, 10} ,
  92. {NOTE_G6, 10} ,{NOTE_REST, 30},
  93. {NOTE_G5, 10} ,{NOTE_REST, 30}
  94. };
  95. float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
  96. float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
  97. void startup_user() {
  98. _delay_ms(20); // gets rid of tick
  99. PLAY_NOTE_ARRAY(tone_startup, false, 0);
  100. }
  101. void shutdown_user() {
  102. PLAY_NOTE_ARRAY(tone_goodbye, false, 0);
  103. _delay_ms(150);
  104. stop_all_notes();
  105. }
  106. void music_on_user(void) {
  107. music_scale_user();
  108. }
  109. void music_scale_user(void) {
  110. PLAY_NOTE_ARRAY(music_scale, false, 0);
  111. }
  112. #endif
  113. void matrix_init_user(void) {
  114. #ifdef AUDIO_ENABLE
  115. startup_user();
  116. #endif
  117. }
  118. void persistant_default_layer_set(uint16_t default_layer) {
  119. eeconfig_update_default_layer(default_layer);
  120. default_layer_set(default_layer);
  121. }
  122. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  123. switch (keycode) {
  124. case COLEMAK:
  125. if (record->event.pressed) {
  126. #ifdef AUDIO_ENABLE
  127. PLAY_NOTE_ARRAY(tone_colemak, false, 0);
  128. #endif
  129. persistant_default_layer_set(1UL<<_COLEMAK);
  130. }
  131. break;
  132. case GAME:
  133. if (record->event.pressed) {
  134. #ifdef AUDIO_ENABLE
  135. PLAY_NOTE_ARRAY(tone_game, false, STACCATO);
  136. #endif
  137. persistant_default_layer_set(1UL<<_GAME);
  138. }
  139. break;
  140. case RAISE:
  141. if (record->event.pressed) {
  142. layer_on(_RAISE);
  143. } else {
  144. layer_off(_RAISE);
  145. }
  146. break;
  147. default:
  148. return true;
  149. break;
  150. }
  151. return false;
  152. };