keymap.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Copyright 2021 Danny Nguyen <danny@keeb.io>
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 2 of the License, or
  5. (at your option) any later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #include QMK_KEYBOARD_H
  14. enum custom_layer {
  15. _QWERTY,
  16. _LOWER,
  17. _RAISE,
  18. _ADJUST,
  19. };
  20. enum custom_keycodes {
  21. QWERTY = SAFE_RANGE,
  22. LOWER,
  23. RAISE,
  24. ADJUST,
  25. };
  26. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  27. /* Default Layer
  28. * ,-----------------------------------------------------------.
  29. * | Esc| Q | W | E | R | T | Y | U | I | O | P | BS |
  30. * |-----------------------------------------------------------|
  31. * | Tab | A | S | D | F | G | H | J | K | L | Ent |
  32. * |-----------------------------------------------------------|
  33. * | LSft | Z | X | C | V | B | N | M | , | . | /? |
  34. * |-----------------------------------------------------------|
  35. * | LCtl | LGui| LAlt| spc fn0 | spc fn1 |fn2|RAlt|RCtl |
  36. * `-----------------------------------------------------------'
  37. */
  38. [_QWERTY] = LAYOUT(
  39. KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  40. KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_ENT,
  41. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH,
  42. KC_LCTL, KC_LGUI, KC_LALT, LT(_LOWER, KC_SPC), LT(_RAISE, KC_SPC), LT(_ADJUST, KC_LGUI), KC_RALT, KC_RCTL
  43. ),
  44. [_LOWER] = LAYOUT(
  45. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC,
  46. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE,
  47. KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,S(KC_NUHS),S(KC_NUBS),BL_TOGG, BL_UP, BL_DOWN,
  48. _______, _______, _______, _______, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  49. ),
  50. [_RAISE] = LAYOUT(
  51. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
  52. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS,
  53. KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, _______, _______, KC_DEL,
  54. _______, KC_TRNS, _______, KC_TRNS, KC_TRNS, _______, _______, RGB_TOG
  55. ),
  56. [_ADJUST] = LAYOUT(
  57. _______, QK_BOOT, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL,
  58. _______, _______, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, _______, _______, _______, _______,
  59. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  60. _______, _______, _______, _______, _______, _______, _______, _______
  61. )
  62. };
  63. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  64. switch (keycode) {
  65. case LOWER:
  66. if (record->event.pressed) {
  67. layer_on(_LOWER);
  68. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  69. } else {
  70. layer_off(_LOWER);
  71. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  72. }
  73. return false;
  74. break;
  75. case RAISE:
  76. if (record->event.pressed) {
  77. layer_on(_RAISE);
  78. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  79. } else {
  80. layer_off(_RAISE);
  81. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  82. }
  83. return false;
  84. break;
  85. case ADJUST:
  86. if (record->event.pressed) {
  87. layer_on(_ADJUST);
  88. } else {
  89. layer_off(_ADJUST);
  90. }
  91. return false;
  92. break;
  93. }
  94. return true;
  95. }
  96. bool encoder_update_user(uint8_t index, bool clockwise) {
  97. if (index == 0) {
  98. if (clockwise) {
  99. tap_code(KC_VOLU);
  100. } else {
  101. tap_code(KC_VOLD);
  102. }
  103. }
  104. return false;
  105. }