keymap.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /* Copyright 2018 MakotoKurauchi
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include QMK_KEYBOARD_H
  17. #ifdef RGBLIGHT_ENABLE
  18. //Following line allows macro to read current RGB settings
  19. extern rgblight_config_t rgblight_config;
  20. #endif
  21. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  22. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  23. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  24. // entirely and just use numbers.
  25. enum layer_number {
  26. _QWERTY = 0,
  27. _COLEMAK,
  28. _DVORAK,
  29. _LOWER,
  30. _RAISE,
  31. _ADJUST
  32. };
  33. enum custom_keycodes {
  34. QWERTY = SAFE_RANGE,
  35. COLEMAK,
  36. DVORAK,
  37. LOWER,
  38. RAISE,
  39. ADJUST,
  40. BACKLIT,
  41. EISU,
  42. KANA,
  43. RGBRST
  44. };
  45. enum macro_keycodes {
  46. KC_SAMPLEMACRO,
  47. };
  48. //Macros
  49. #define M_SAMPLE M(KC_SAMPLEMACRO)
  50. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  51. /* Qwerty
  52. * ,-----------------------------------------. ,-----------------------------------------.
  53. * | Tab | Q | W | E | R | T | | Y | U | I | O | P | Bksp |
  54. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  55. * | Ctrl | A | S | D | F | G | | H | J | K | L | ; | ' |
  56. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  57. * | Shift| Z | X | C | V | B | | N | M | , | . | / |Enter |
  58. * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
  59. * |Adjust| Esc | Alt | GUI | EISU |Lower |Space |Space |Raise | KANA | Left | Down | Up |Right |
  60. * `-------------------------------------------------------------------------------------------------'
  61. */
  62. [_QWERTY] = LAYOUT(
  63. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  64. KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  65. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT ,
  66. ADJUST, KC_ESC, KC_LALT, KC_LGUI, EISU, LOWER, KC_SPC, KC_SPC, RAISE, KANA, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  67. ),
  68. /* Colemak
  69. * ,-----------------------------------------. ,-----------------------------------------.
  70. * | Tab | Q | W | F | P | G | | J | L | U | Y | ; | Bksp |
  71. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  72. * | Ctrl | A | R | S | T | D | | H | N | E | I | O | ' |
  73. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  74. * | Shift| Z | X | C | V | B | | K | M | , | . | / |Enter |
  75. * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
  76. * |Adjust| Esc | Alt | GUI | EISU |Lower |Space |Space |Raise | KANA | Left | Down | Up |Right |
  77. * `-------------------------------------------------------------------------------------------------'
  78. */
  79. [_COLEMAK] = LAYOUT(
  80. KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC,
  81. KC_LCTL, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT,
  82. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT ,
  83. ADJUST, KC_ESC, KC_LALT, KC_LGUI, EISU, LOWER, KC_SPC, KC_SPC, RAISE, KANA, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  84. ),
  85. /* Dvorak
  86. * ,-----------------------------------------. ,-----------------------------------------.
  87. * | Tab | ' | , | . | P | Y | | F | G | C | R | L | Bksp |
  88. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  89. * | Ctrl | A | O | E | U | I | | D | H | T | N | S | / |
  90. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  91. * | Shift| ; | Q | J | K | X | | B | M | W | V | Z |Enter |
  92. * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
  93. * |Adjust| Esc | Alt | GUI | EISU |Lower |Space |Space |Raise | KANA | Left | Down | Up |Right |
  94. * `-------------------------------------------------------------------------------------------------'
  95. */
  96. [_DVORAK] = LAYOUT(
  97. KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC,
  98. KC_LCTL, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH,
  99. KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT ,
  100. ADJUST, KC_ESC, KC_LALT, KC_LGUI, EISU, LOWER, KC_SPC, KC_SPC, RAISE, KANA, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  101. ),
  102. /* Lower
  103. * ,-----------------------------------------. ,-----------------------------------------.
  104. * | ~ | ! | @ | # | $ | % | | ^ | & | * | ( | ) | Del |
  105. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  106. * | | F1 | F2 | F3 | F4 | F5 | | F6 | _ | + | { | } | | |
  107. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  108. * | | F7 | F8 | F9 | F10 | F11 | | F12 | | PrSc | Home | End | |
  109. * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
  110. * | | | | | | | | | | | Next | Vol- | Vol+ | Play |
  111. * `-------------------------------------------------------------------------------------------------'
  112. */
  113. [_LOWER] = LAYOUT(
  114. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL,
  115. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE,
  116. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_PSCR, KC_HOME, KC_END, _______,
  117. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
  118. ),
  119. /* Raise
  120. * ,-----------------------------------------. ,-----------------------------------------.
  121. * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | Del |
  122. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  123. * | | F1 | F2 | F3 | F4 | F5 | | F6 | - | = | [ | ] | \ |
  124. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  125. * | | F7 | F8 | F9 | F10 | F11 | | F12 | | PrSc |PageDn|PageUp| |
  126. * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
  127. * | | | | | | | | | | | Next | Vol- | Vol+ | Play |
  128. * `-------------------------------------------------------------------------------------------------'
  129. */
  130. [_RAISE] = LAYOUT(
  131. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL,
  132. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS,
  133. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_PSCR, KC_PGDN, KC_PGUP, _______,
  134. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
  135. ),
  136. /* Adjust (Lower + Raise)
  137. * ,-----------------------------------------. ,-----------------------------------------.
  138. * | | Reset|RGBRST| | | | | | | | | | |
  139. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  140. * | |Aud on|Audoff|MU TOG|MU MOD| Mac | | Win |Qwerty|Colemk|Dvorak| | |
  141. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  142. * | |CK TOG|CK RST| CK UP|CK DWN| | | | |RGB ON| HUE+ | SAT+ | VAL+ |
  143. * |------+------+------+------+------+------+-------------+------+------+------+------+------+------|
  144. * | | | | | | | | | | | MODE | HUE- | SAT- | VAL- |
  145. * `-------------------------------------------------------------------------------------------------'
  146. */
  147. [_ADJUST] = LAYOUT(
  148. _______, QK_BOOT, RGBRST, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  149. _______, AU_ON, AU_OFF, MU_TOGG, MU_NEXT, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, _______, _______,
  150. _______, CK_TOGG, CK_RST, CK_UP, CK_DOWN, _______, _______, _______, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI,
  151. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD
  152. )
  153. };
  154. #ifdef AUDIO_ENABLE
  155. float tone_qwerty[][2] = SONG(QWERTY_SOUND);
  156. float tone_dvorak[][2] = SONG(DVORAK_SOUND);
  157. float tone_colemak[][2] = SONG(COLEMAK_SOUND);
  158. float tone_plover[][2] = SONG(PLOVER_SOUND);
  159. float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND);
  160. float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
  161. #endif
  162. // define variables for reactive RGB
  163. bool TOG_STATUS = false;
  164. int RGB_current_mode;
  165. void persistent_default_layer_set(uint16_t default_layer) {
  166. eeconfig_update_default_layer(default_layer);
  167. default_layer_set(default_layer);
  168. }
  169. // Setting ADJUST layer RGB back to default
  170. void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  171. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  172. #ifdef RGBLIGHT_ENABLE
  173. //rgblight_mode(RGB_current_mode);
  174. #endif
  175. layer_on(layer3);
  176. } else {
  177. layer_off(layer3);
  178. }
  179. }
  180. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  181. switch (keycode) {
  182. case QWERTY:
  183. if (record->event.pressed) {
  184. #ifdef AUDIO_ENABLE
  185. PLAY_SONG(tone_qwerty);
  186. #endif
  187. persistent_default_layer_set(1UL<<_QWERTY);
  188. }
  189. return false;
  190. break;
  191. case COLEMAK:
  192. if (record->event.pressed) {
  193. #ifdef AUDIO_ENABLE
  194. PLAY_SONG(tone_colemak);
  195. #endif
  196. persistent_default_layer_set(1UL<<_COLEMAK);
  197. }
  198. return false;
  199. break;
  200. case DVORAK:
  201. if (record->event.pressed) {
  202. #ifdef AUDIO_ENABLE
  203. PLAY_SONG(tone_dvorak);
  204. #endif
  205. persistent_default_layer_set(1UL<<_DVORAK);
  206. }
  207. return false;
  208. break;
  209. case LOWER:
  210. if (record->event.pressed) {
  211. //not sure how to have keyboard check mode and set it to a variable, so my work around
  212. //uses another variable that would be set to true after the first time a reactive key is pressed.
  213. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  214. } else {
  215. TOG_STATUS = !TOG_STATUS;
  216. #ifdef RGBLIGHT_ENABLE
  217. //rgblight_mode(RGBLIGHT_MODE_SNAKE + 1);
  218. #endif
  219. }
  220. layer_on(_LOWER);
  221. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  222. } else {
  223. #ifdef RGBLIGHT_ENABLE
  224. //rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  225. #endif
  226. TOG_STATUS = false;
  227. layer_off(_LOWER);
  228. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  229. }
  230. return false;
  231. break;
  232. case RAISE:
  233. if (record->event.pressed) {
  234. //not sure how to have keyboard check mode and set it to a variable, so my work around
  235. //uses another variable that would be set to true after the first time a reactive key is pressed.
  236. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  237. } else {
  238. TOG_STATUS = !TOG_STATUS;
  239. #ifdef RGBLIGHT_ENABLE
  240. //rgblight_mode(RGBLIGHT_MODE_SNAKE);
  241. #endif
  242. }
  243. layer_on(_RAISE);
  244. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  245. } else {
  246. #ifdef RGBLIGHT_ENABLE
  247. //rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  248. #endif
  249. layer_off(_RAISE);
  250. TOG_STATUS = false;
  251. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  252. }
  253. return false;
  254. break;
  255. case ADJUST:
  256. if (record->event.pressed) {
  257. layer_on(_ADJUST);
  258. } else {
  259. layer_off(_ADJUST);
  260. }
  261. return false;
  262. break;
  263. //led operations - RGB mode change now updates the RGB_current_mode to allow the right RGB mode to be set after reactive keys are released
  264. case RGB_MOD:
  265. #ifdef RGBLIGHT_ENABLE
  266. if (record->event.pressed) {
  267. rgblight_mode(RGB_current_mode);
  268. rgblight_step();
  269. RGB_current_mode = rgblight_config.mode;
  270. }
  271. #endif
  272. return false;
  273. break;
  274. case EISU:
  275. if (record->event.pressed) {
  276. if(keymap_config.swap_lalt_lgui==false){
  277. register_code(KC_LNG2);
  278. }else{
  279. SEND_STRING(SS_LALT("`"));
  280. }
  281. } else {
  282. unregister_code(KC_LNG2);
  283. }
  284. return false;
  285. break;
  286. case KANA:
  287. if (record->event.pressed) {
  288. if(keymap_config.swap_lalt_lgui==false){
  289. register_code(KC_LNG1);
  290. }else{
  291. SEND_STRING(SS_LALT("`"));
  292. }
  293. } else {
  294. unregister_code(KC_LNG1);
  295. }
  296. return false;
  297. break;
  298. case RGBRST:
  299. #ifdef RGBLIGHT_ENABLE
  300. if (record->event.pressed) {
  301. eeconfig_update_rgblight_default();
  302. rgblight_enable();
  303. RGB_current_mode = rgblight_config.mode;
  304. }
  305. #endif
  306. break;
  307. }
  308. return true;
  309. }
  310. void matrix_init_user(void) {
  311. #ifdef AUDIO_ENABLE
  312. startup_user();
  313. #endif
  314. #ifdef RGBLIGHT_ENABLE
  315. RGB_current_mode = rgblight_config.mode;
  316. #endif
  317. }
  318. #ifdef AUDIO_ENABLE
  319. void startup_user(void)
  320. {
  321. _delay_ms(50); // gets rid of tick
  322. }
  323. void shutdown_user(void)
  324. {
  325. _delay_ms(150);
  326. stop_all_notes();
  327. }
  328. void music_on_user(void)
  329. {
  330. music_scale_user();
  331. }
  332. void music_scale_user(void)
  333. {
  334. PLAY_SONG(music_scale);
  335. }
  336. #endif