keymap.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. #include "preonic.h"
  2. #include "action_layer.h"
  3. #ifdef AUDIO_ENABLE
  4. #include "audio.h"
  5. #endif
  6. #include "eeconfig.h"
  7. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  8. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  9. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  10. // entirely and just use numbers.
  11. #define _QWERTY 0
  12. #define _COLEMAK 1
  13. #define _DVORAK 2
  14. #define _LOWER 3
  15. #define _RAISE 4
  16. #define _ADJUST 16
  17. enum preonic_keycodes {
  18. QWERTY = SAFE_RANGE,
  19. COLEMAK,
  20. DVORAK,
  21. LOWER,
  22. RAISE,
  23. BACKLIT
  24. };
  25. // Fillers to make layering more clear
  26. #define _______ KC_TRNS
  27. #define XXXXXXX KC_NO
  28. // Custom macros
  29. #define CTL_ESC CTL_T(KC_ESC) // Tap for Esc, hold for Ctrl
  30. #define SFT_ENT SFT_T(KC_ENT) // Tap for Enter, hold for Shift
  31. #define HPR_TAB ALL_T(KC_TAB) // Tap for Tab, hold for Hyper (Super+Ctrl+Alt+Shift)
  32. #define MEH_GRV MEH_T(KC_GRV) // Tap for Backtick, hold for Meh (Ctrl+Alt+Shift)
  33. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  34. /* Qwerty
  35. * ,-----------------------------------------------------------------------------------.
  36. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
  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. * | ` | Ctrl | Alt | GUI |Lower |Space |Space |Raise | Left | Down | Up |Right |
  45. * `-----------------------------------------------------------------------------------'
  46. */
  47. [_QWERTY] = {
  48. {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
  49. {HPR_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC},
  50. {CTL_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT},
  51. {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, SFT_ENT},
  52. {MEH_GRV, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
  53. },
  54. /* Colemak
  55. * ,-----------------------------------------------------------------------------------.
  56. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
  57. * |------+------+------+------+------+------+------+------+------+------+------+------|
  58. * | Tab | Q | W | F | P | G | J | L | U | Y | ; | Bksp |
  59. * |------+------+------+------+------+-------------+------+------+------+------+------|
  60. * | Esc | A | R | S | T | D | H | N | E | I | O | " |
  61. * |------+------+------+------+------+------|------+------+------+------+------+------|
  62. * | Shift| Z | X | C | V | B | K | M | , | . | / |Enter |
  63. * |------+------+------+------+------+------+------+------+------+------+------+------|
  64. * | ` | Ctrl | Alt | GUI |Lower |Space |Space |Raise | Left | Down | Up |Right |
  65. * `-----------------------------------------------------------------------------------'
  66. */
  67. [_COLEMAK] = {
  68. {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
  69. {HPR_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC},
  70. {CTL_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT},
  71. {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, SFT_ENT},
  72. {MEH_GRV, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
  73. },
  74. /* Dvorak
  75. * ,-----------------------------------------------------------------------------------.
  76. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
  77. * |------+------+------+------+------+------+------+------+------+------+------+------|
  78. * | Tab | " | , | . | P | Y | F | G | C | R | L | Bksp |
  79. * |------+------+------+------+------+-------------+------+------+------+------+------|
  80. * | Esc | A | O | E | U | I | D | H | T | N | S | - |
  81. * |------+------+------+------+------+------|------+------+------+------+------+------|
  82. * | Shift| ; | Q | J | K | X | B | M | W | V | Z |Enter |
  83. * |------+------+------+------+------+------+------+------+------+------+------+------|
  84. * | ` | Ctrl | Alt | GUI |Lower |Space |Space |Raise | Left | Down | Up |Right |
  85. * `-----------------------------------------------------------------------------------'
  86. */
  87. [_DVORAK] = {
  88. {KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC},
  89. {HPR_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC},
  90. {CTL_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_MINS},
  91. {KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, SFT_ENT},
  92. {MEH_GRV, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT}
  93. },
  94. /* Lower
  95. * ,-----------------------------------------------------------------------------------.
  96. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Del |
  97. * |------+------+------+------+------+------+------+------+------+------+------+------|
  98. * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Del |
  99. * |------+------+------+------+------+-------------+------+------+------+------+------|
  100. * | $ | F1 | F2 | F3 | F4 | F5 | F6 | 4 | 5 | 6 | | |
  101. * |------+------+------+------+------+------|------+------+------+------+------+------|
  102. * | | F7 | F8 | F9 | F10 | F11 | F12 | 1 | 2 | 3 | | |
  103. * |------+------+------+------+------+------+------+------+------+------+------+------|
  104. * | | | | | | | | Next | Vol- | Vol+ | Play |
  105. * `-----------------------------------------------------------------------------------'
  106. */
  107. [_LOWER] = {
  108. {ALL_T(KC_GRV), KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL},
  109. {ALL_T(KC_0), KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL},
  110. {CTL_T(KC_DLR), KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_4, KC_5, KC_6, _______, _______},
  111. {_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_1, KC_2, KC_3, _______, _______},
  112. {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
  113. },
  114. /* Raise
  115. * ,-----------------------------------------------------------------------------------.
  116. * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Del |
  117. * |------+------+------+------+------+-------------+------+------+------+------+------|
  118. * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Del |
  119. * |------+------+------+------+------+-------------+------+------+------+------+------|
  120. * | | | | | | | _ | ? | + | { | } | | |
  121. * |------+------+------+------+------+------|------+------+------+------+------+------|
  122. * | | | | | | | - | / | = | [ | ] | \ |
  123. * |------+------+------+------+------+------+------+------+------+------+------+------|
  124. * | | | | | | | | | Home |PageDn|PageUp| End |
  125. * `-----------------------------------------------------------------------------------'
  126. */
  127. [_RAISE] = {
  128. {ALL_T(KC_TILD), KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL},
  129. {ALL_T(KC_TILD), KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL},
  130. {_______, _______, _______, _______, _______, _______, KC_UNDS, KC_QUES, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE},
  131. {_______, _______, _______, _______, _______, _______, KC_MINS, KC_SLSH, KC_EQL, KC_LBRC, KC_RBRC, SFT_T(KC_BSLS)},
  132. {_______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END}
  133. },
  134. /* Adjust (Lower + Raise)
  135. * ,-----------------------------------------------------------------------------------.
  136. * | F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | F11 | F12 |
  137. * |------+------+------+------+------+------+------+------+------+------+------+------|
  138. * | | Reset| | | | | | | | | | Reset|
  139. * |------+------+------+------+------+-------------+------+------+------+------+------|
  140. * | | | |Aud on|AudOff|AGnorm|AGswap|Qwerty|Colemk|Dvorak| | |
  141. * |------+------+------+------+------+------|------+------+------+------+------+------|
  142. * | |Voice-|Voice+|Mus on|MusOff|MidiOn|MidOff| | | | | |
  143. * |------+------+------+------+------+------+------+------+------+------+------+------|
  144. * | | | | | | | | | | | |
  145. * `-----------------------------------------------------------------------------------'
  146. */
  147. [_ADJUST] = {
  148. {KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12},
  149. {_______, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, RESET},
  150. {_______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, _______, _______},
  151. {_______, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______},
  152. {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
  153. }
  154. };
  155. #ifdef AUDIO_ENABLE
  156. float tone_startup[][2] = {
  157. {NOTE_B5, 20},
  158. {NOTE_B6, 8},
  159. {NOTE_DS6, 20},
  160. {NOTE_B6, 8}
  161. };
  162. float tone_qwerty[][2] = SONG(QWERTY_SOUND);
  163. float tone_colemak[][2] = SONG(COLEMAK_SOUND);
  164. float tone_dvorak[][2] = SONG(DVORAK_SOUND);
  165. float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
  166. float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
  167. #endif
  168. void persistant_default_layer_set(uint16_t default_layer) {
  169. eeconfig_update_default_layer(default_layer);
  170. default_layer_set(default_layer);
  171. }
  172. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  173. switch (keycode) {
  174. case QWERTY:
  175. if (record->event.pressed) {
  176. #ifdef AUDIO_ENABLE
  177. PLAY_NOTE_ARRAY(tone_qwerty, false, 0);
  178. #endif
  179. persistant_default_layer_set(1UL<<_QWERTY);
  180. }
  181. return false;
  182. break;
  183. case COLEMAK:
  184. if (record->event.pressed) {
  185. #ifdef AUDIO_ENABLE
  186. PLAY_NOTE_ARRAY(tone_colemak, false, 0);
  187. #endif
  188. persistant_default_layer_set(1UL<<_COLEMAK);
  189. }
  190. return false;
  191. break;
  192. case DVORAK:
  193. if (record->event.pressed) {
  194. #ifdef AUDIO_ENABLE
  195. PLAY_NOTE_ARRAY(tone_dvorak, false, 0);
  196. #endif
  197. persistant_default_layer_set(1UL<<_DVORAK);
  198. }
  199. return false;
  200. break;
  201. case LOWER:
  202. if (record->event.pressed) {
  203. layer_on(_LOWER);
  204. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  205. } else {
  206. layer_off(_LOWER);
  207. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  208. }
  209. return false;
  210. break;
  211. case RAISE:
  212. if (record->event.pressed) {
  213. layer_on(_RAISE);
  214. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  215. } else {
  216. layer_off(_RAISE);
  217. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  218. }
  219. return false;
  220. break;
  221. case BACKLIT:
  222. if (record->event.pressed) {
  223. register_code(KC_RSFT);
  224. #ifdef BACKLIGHT_ENABLE
  225. backlight_step();
  226. #endif
  227. } else {
  228. unregister_code(KC_RSFT);
  229. }
  230. return false;
  231. break;
  232. }
  233. return true;
  234. };
  235. void matrix_init_user(void) {
  236. #ifdef AUDIO_ENABLE
  237. startup_user();
  238. #endif
  239. }
  240. #ifdef AUDIO_ENABLE
  241. void startup_user()
  242. {
  243. _delay_ms(20); // gets rid of tick
  244. PLAY_NOTE_ARRAY(tone_startup, false, 0);
  245. }
  246. void shutdown_user()
  247. {
  248. PLAY_NOTE_ARRAY(tone_goodbye, false, 0);
  249. _delay_ms(150);
  250. stop_all_notes();
  251. }
  252. void music_on_user(void)
  253. {
  254. music_scale_user();
  255. }
  256. void music_scale_user(void)
  257. {
  258. PLAY_NOTE_ARRAY(music_scale, false, 0);
  259. }
  260. #endif