keymap.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. #include QMK_KEYBOARD_H
  2. #ifdef RGBLIGHT_ENABLE
  3. //Following line allows macro to read current RGB settings
  4. extern rgblight_config_t rgblight_config;
  5. rgblight_config_t RGB_current_config;
  6. #endif
  7. extern uint8_t is_master;
  8. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  9. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  10. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  11. // entirely and just use numbers.
  12. enum layer_number {
  13. _QWERTY = 0,
  14. _COLEMAK,
  15. _DVORAK,
  16. _LOWER,
  17. _RAISE,
  18. _ADJUST
  19. };
  20. enum custom_keycodes {
  21. QWERTY = SAFE_RANGE,
  22. COLEMAK,
  23. DVORAK,
  24. LOWER,
  25. RAISE,
  26. ADJUST,
  27. BACKLIT,
  28. KANA,
  29. EISU,
  30. RGBRST
  31. };
  32. enum macro_keycodes {
  33. KC_SAMPLEMACRO,
  34. };
  35. //Macros
  36. #define M_SAMPLE M(KC_SAMPLEMACRO)
  37. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  38. /* Qwerty
  39. * ,-----------------------------------------. ,-----------------------------------------.
  40. * | Tab | Q | W | E | R | T | | Y | U | I | O | P | Bksp |
  41. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  42. * | Ctrl | A | S | D | F | G | | H | J | K | L | ; | ' |
  43. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  44. * | Shift| Z | X | C | V | B | | N | M | , | . | / |Enter |
  45. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  46. * | Esc |ADJUST| Win | Alt |LOWER |Space | | Space| RAISE| Left | Down | Up | Right|
  47. * `-----------------------------------------' `-----------------------------------------'
  48. */
  49. [_QWERTY] = LAYOUT_ortho_4x12(
  50. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  51. KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  52. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT ,
  53. KC_ESC, ADJUST, KC_LGUI, KC_LALT, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  54. ),
  55. /* Colemak
  56. * ,-----------------------------------------. ,-----------------------------------------.
  57. * | Tab | Q | W | F | P | G | | J | L | U | Y | ; | Bksp |
  58. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  59. * | Ctrl | A | R | S | T | D | | H | N | E | I | O | ' |
  60. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  61. * | Shift| Z | X | C | V | B | | K | M | , | . | / |Enter |
  62. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  63. * | Esc |ADJUST| Alt | Win |LOWER |Space | | Space| RAISE| Left | Down | Up | Right|
  64. * `-----------------------------------------' `-----------------------------------------'
  65. */
  66. [_COLEMAK] = LAYOUT_ortho_4x12(
  67. KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC,
  68. KC_LCTL, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT,
  69. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT ,
  70. KC_ESC, ADJUST, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  71. ),
  72. /* Dvorak
  73. * ,-----------------------------------------. ,-----------------------------------------.
  74. * | Tab | ' | , | . | P | Y | | F | G | C | R | L | Del |
  75. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  76. * | Ctrl | A | O | E | U | I | | D | H | T | N | S | / |
  77. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  78. * | Shift| ; | Q | J | K | X | | B | M | W | V | Z |Enter |
  79. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  80. * | Esc |ADJUST| Alt | Win |LOWER |Space | | Space| RAISE| Left | Down | Up | Right|
  81. * `-----------------------------------------' `-----------------------------------------'
  82. */
  83. [_DVORAK] = LAYOUT_ortho_4x12(
  84. KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_DEL,
  85. KC_LCTL, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH,
  86. KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT ,
  87. KC_ESC, ADJUST, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  88. ),
  89. /* Lower
  90. * ,-----------------------------------------. ,-----------------------------------------.
  91. * | ~ | ! | @ | # | $ | % | | ^ | & | * | ( | ) | |
  92. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  93. * | | | | | | | | - | _ | + | { | } | | |
  94. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  95. * | | | | | | | | | | | Home | End | |
  96. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  97. * | | | | | | | | | | Next | Vol- | Vol+ | Play |
  98. * `-----------------------------------------' `-----------------------------------------'
  99. */
  100. [_LOWER] = LAYOUT_ortho_4x12(
  101. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, _______,
  102. _______, _______, _______, _______, _______, _______, KC_MINS, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE,
  103. _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_END, _______,
  104. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
  105. ),
  106. /* Raise
  107. * ,-----------------------------------------. ,-----------------------------------------.
  108. * | ` | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | Del |
  109. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  110. * | | F1 | F2 | F3 | F4 | F5 | | F6 | - | = | [ | ] | \ |
  111. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  112. * | | F7 | F8 | F9 | F10 | F11 | | F12 | | | | |
  113. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  114. * | | | | | | | | | | Next | Vol- | Vol+ | Play |
  115. * `-----------------------------------------' `-----------------------------------------'
  116. */
  117. [_RAISE] = LAYOUT_ortho_4x12(
  118. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL,
  119. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS,
  120. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, _______, _______,
  121. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
  122. ),
  123. /* Adjust (Lower + Raise)
  124. * ,-----------------------------------------. ,-----------------------------------------.
  125. * | | Reset|RGBRST|Aud on|Audoff| | | |Qwerty|Colemk|Dvorak| | Ins |
  126. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  127. * | |RGB ON| HUE+ | SAT+ | VAL+ | Mac | | Win | - | = |Print |ScLock|Pause |
  128. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  129. * |MODE R| MODE | HUE- | SAT- | VAL- | | | | | | |PageUp| |
  130. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  131. * | | | | EISU | EISU | EISU | | KANA | KANA | Home |PageDn|PageUp| End |
  132. * `-----------------------------------------' `-----------------------------------------'
  133. */
  134. [_ADJUST] = LAYOUT_ortho_4x12(
  135. _______, QK_BOOT, RGBRST, _______, _______, _______, _______, QWERTY, COLEMAK, DVORAK, _______, KC_INS,
  136. _______, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, AG_NORM, AG_SWAP, KC_MINS, KC_EQL, KC_PSCR, KC_SCRL, KC_PAUS,
  137. RGB_RMOD,RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD, _______, _______, _______, _______, _______, KC_PGUP, _______,
  138. _______, _______, _______, EISU, EISU, EISU, KANA, KANA, KANA, KC_HOME, KC_PGDN, KC_END
  139. )
  140. };
  141. // define variables for reactive RGB
  142. bool TOG_STATUS = false;
  143. // Setting ADJUST layer RGB back to default
  144. void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  145. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  146. #ifdef RGBLIGHT_ENABLE
  147. rgblight_mode_noeeprom(RGB_current_config.mode);
  148. #endif
  149. layer_on(layer3);
  150. } else {
  151. layer_off(layer3);
  152. }
  153. }
  154. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  155. switch (keycode) {
  156. case QWERTY:
  157. if (record->event.pressed) {
  158. set_single_persistent_default_layer(_QWERTY);
  159. }
  160. return false;
  161. break;
  162. case COLEMAK:
  163. if (record->event.pressed) {
  164. set_single_persistent_default_layer(_COLEMAK);
  165. }
  166. return false;
  167. break;
  168. case DVORAK:
  169. if (record->event.pressed) {
  170. set_single_persistent_default_layer(_DVORAK);
  171. }
  172. return false;
  173. break;
  174. case LOWER:
  175. if (record->event.pressed) {
  176. //not sure how to have keyboard check mode and set it to a variable, so my work around
  177. //uses another variable that would be set to true after the first time a reactive key is pressed.
  178. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  179. } else {
  180. TOG_STATUS = !TOG_STATUS;
  181. #ifdef RGBLIGHT_ENABLE
  182. rgblight_mode_noeeprom(16);
  183. #endif
  184. }
  185. layer_on(_LOWER);
  186. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  187. } else {
  188. #ifdef RGBLIGHT_ENABLE
  189. rgblight_mode_noeeprom(RGB_current_config.mode); // revert RGB to initial mode prior to RGB mode change
  190. #endif
  191. TOG_STATUS = false;
  192. layer_off(_LOWER);
  193. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  194. }
  195. return false;
  196. break;
  197. case RAISE:
  198. if (record->event.pressed) {
  199. //not sure how to have keyboard check mode and set it to a variable, so my work around
  200. //uses another variable that would be set to true after the first time a reactive key is pressed.
  201. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  202. } else {
  203. TOG_STATUS = !TOG_STATUS;
  204. #ifdef RGBLIGHT_ENABLE
  205. rgblight_mode_noeeprom(15);
  206. #endif
  207. }
  208. layer_on(_RAISE);
  209. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  210. } else {
  211. #ifdef RGBLIGHT_ENABLE
  212. rgblight_mode_noeeprom(RGB_current_config.mode); // revert RGB to initial mode prior to RGB mode change
  213. #endif
  214. layer_off(_RAISE);
  215. TOG_STATUS = false;
  216. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  217. }
  218. return false;
  219. break;
  220. case ADJUST:
  221. if (record->event.pressed) {
  222. layer_on(_ADJUST);
  223. } else {
  224. layer_off(_ADJUST);
  225. }
  226. return false;
  227. break;
  228. //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
  229. case RGB_RMOD:
  230. #if defined(RGBLIGHT_ENABLE)
  231. if (record->event.pressed) {
  232. rgblight_mode_noeeprom(RGB_current_config.mode);
  233. rgblight_step_reverse();
  234. RGB_current_config.mode = rgblight_config.mode;
  235. }
  236. return false;
  237. #endif
  238. break;
  239. case RGB_MOD:
  240. #if defined(RGBLIGHT_ENABLE)
  241. if (record->event.pressed) {
  242. rgblight_mode_noeeprom(RGB_current_config.mode);
  243. rgblight_step();
  244. RGB_current_config.mode = rgblight_config.mode;
  245. }
  246. return false;
  247. #endif
  248. break;
  249. case EISU:
  250. if (record->event.pressed) {
  251. if(keymap_config.swap_lalt_lgui==false){
  252. register_code(KC_LNG2);
  253. }else{
  254. SEND_STRING(SS_LALT("`"));
  255. }
  256. } else {
  257. unregister_code(KC_LNG2);
  258. }
  259. return false;
  260. break;
  261. case KANA:
  262. if (record->event.pressed) {
  263. if(keymap_config.swap_lalt_lgui==false){
  264. register_code(KC_LNG1);
  265. }else{
  266. SEND_STRING(SS_LALT("`"));
  267. }
  268. } else {
  269. unregister_code(KC_LNG1);
  270. }
  271. return false;
  272. break;
  273. case RGBRST:
  274. #ifdef RGBLIGHT_ENABLE
  275. if (record->event.pressed) {
  276. eeconfig_update_rgblight_default();
  277. rgblight_enable();
  278. RGB_current_config = rgblight_config;
  279. }
  280. #endif
  281. break;
  282. }
  283. return true;
  284. }
  285. void matrix_init_user(void) {
  286. #ifdef RGBLIGHT_ENABLE
  287. rgblight_init();
  288. RGB_current_config = rgblight_config;
  289. #endif
  290. }