keymap.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. Copyright 2021-2022 Alin M Elena <alinm.elena@gmail.com>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include QMK_KEYBOARD_H
  15. enum layer_names {
  16. _QW = 0,
  17. _LWR,
  18. _RSE,
  19. _ADJ
  20. };
  21. #ifdef RGBLIGHT_ENABLE
  22. const rgblight_segment_t PROGMEM my_qwerty_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLED_NUM, HSV_PURPLE});
  23. const rgblight_segment_t PROGMEM my_lwr_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLED_NUM, HSV_CYAN});
  24. const rgblight_segment_t PROGMEM my_rse_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLED_NUM, HSV_RED});
  25. const rgblight_segment_t PROGMEM my_adj_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLED_NUM, HSV_GREEN});
  26. const rgblight_segment_t* const PROGMEM my_rgb_layers[] = RGBLIGHT_LAYERS_LIST(my_qwerty_layer, my_lwr_layer, my_rse_layer, my_adj_layer);
  27. #endif
  28. #define LOWER TT(_LWR)
  29. #define RAISE TT(_RSE)
  30. // clang-format off
  31. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  32. /* Qwerty
  33. * ,-----------------------------------------------------------------------------------.
  34. * | Tab | Q | W | E | R | T | Y | U | I | O | P | Bksp |
  35. * |------+------+------+------+------+------+------+------+------+------+------+------|
  36. * | Esc | A | S | D | F | G | H | J | K | L | ; | " |
  37. * |------+------+------+------+------+------+------+------+------+------+------+------|
  38. * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter |
  39. * |------+------+------+------+------+------+------+------+------+------+------+------|
  40. * | | Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
  41. * `-----------------------------------------------------------------------------------'
  42. */
  43. [_QW] = LAYOUT_ortho_4x12(
  44. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  45. KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  46. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT ,
  47. KC_TRNS,KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  48. ),
  49. /* Lower
  50. * ,-----------------------------------------------------------------------------------.
  51. * | ~ | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp |
  52. * |------+------+------+------+------+------+------+------+------+------+------+------|
  53. * | Del | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | { | } | | |
  54. * |------+------+------+------+------+------+------+------+------+------+------+------|
  55. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | Home | End | |
  56. * |------+------+------+------+------+------+------+------+------+------+------+------|
  57. * | | | | | | | | Next | Vol- | Vol+ | Play |
  58. * `-----------------------------------------------------------------------------------'
  59. */
  60. [_LWR] = LAYOUT_ortho_4x12(
  61. KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC,
  62. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE,
  63. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, S(KC_NUHS), S(KC_NUBS), KC_HOME, KC_END, _______,
  64. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
  65. ),
  66. /* Raise
  67. * ,-----------------------------------------------------------------------------------.
  68. * | ` | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
  69. * |------+------+------+------+------+------+------+------+------+------+------+------|
  70. * | Del | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ |
  71. * |------+------+------+------+------+------+------+------+------+------+------+------|
  72. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / |Pg Up |Pg Dn | |
  73. * |------+------+------+------+------+------+------+------+------+------+------+------|
  74. * | | | | | | | | Next | Vol- | Vol+ | Play |
  75. * `-----------------------------------------------------------------------------------'
  76. */
  77. [_RSE] = LAYOUT_ortho_4x12(
  78. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
  79. KC_DEL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS,
  80. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, KC_PGUP, KC_PGDN, _______,
  81. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY
  82. ),
  83. /* Adjust (Lower + Raise)
  84. * v------------------------RGB CONTROL--------------------v
  85. * ,-----------------------------------------------------------------------------------.
  86. * | | Reset|Debug | RGB |RGBMOD| HUE+ | HUE- | SAT+ | SAT- |BRGTH+|BRGTH-| Del |
  87. * |------+------+------+------+------+------+------+------+------+------+------+------|
  88. * | | |MUSmod|Aud on|Audoff|AGnorm|AGswap| | | | | |
  89. * |------+------+------+------+------+------+------+------+------+------+------+------|
  90. * | |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | | |
  91. * |------+------+------+------+------+------+------+------+------+------+------+------|
  92. * | | | | | | | | | | | |
  93. * `-----------------------------------------------------------------------------------'
  94. */
  95. [_ADJ] = LAYOUT_ortho_4x12(
  96. _______, QK_BOOT, DB_TOGG, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, KC_DEL,
  97. _______, _______, MU_NEXT, AU_ON, AU_OFF, AG_NORM, AG_SWAP, _______, _______, _______, _______, _______,
  98. _______, AU_PREV, AU_NEXT, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, _______,
  99. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  100. )
  101. };
  102. // clang-format on
  103. // let us assume we start with both layers off
  104. bool toggle_lwr = false;
  105. bool toggle_rse = false;
  106. bool led_update_user(led_t led_state) {
  107. // Disable the default LED update code, so that lock LEDs could be reused to show layer status.
  108. return false;
  109. }
  110. void matrix_scan_user(void) {
  111. led_lwr(toggle_lwr);
  112. led_rse(toggle_rse);
  113. led_t led_state = host_keyboard_led_state();
  114. led_caps(led_state.caps_lock);
  115. if (layer_state_is(_ADJ)) {
  116. led_lwr(true);
  117. led_rse(true);
  118. }
  119. }
  120. bool process_record_user(uint16_t keycode, keyrecord_t* record) {
  121. switch (keycode) {
  122. case (TT(_LWR)):
  123. if (!record->event.pressed && record->tap.count == TAPPING_TOGGLE) {
  124. // This runs before the TT() handler toggles the layer state, so the current layer state is the opposite of the final one after toggle.
  125. toggle_lwr = !layer_state_is(_LWR);
  126. }
  127. return true;
  128. break;
  129. case (TT(_RSE)):
  130. if (record->event.pressed && record->tap.count == TAPPING_TOGGLE) {
  131. toggle_rse = !layer_state_is(_RSE);
  132. }
  133. return true;
  134. break;
  135. default:
  136. return true;
  137. }
  138. }
  139. layer_state_t layer_state_set_user(layer_state_t state) {
  140. #ifdef RGBLIGHT_ENABLE
  141. rgblight_set_layer_state(0, layer_state_cmp(state, _QW));
  142. rgblight_set_layer_state(1, layer_state_cmp(state, _LWR));
  143. rgblight_set_layer_state(2, layer_state_cmp(state, _RSE));
  144. rgblight_set_layer_state(3, layer_state_cmp(state, _ADJ));
  145. #endif
  146. return update_tri_layer_state(state, _LWR, _RSE, _ADJ);
  147. }
  148. #ifdef RGBLIGHT_ENABLE
  149. layer_state_t default_layer_state_set_user(layer_state_t state) {
  150. rgblight_set_layer_state(0, layer_state_cmp(state, _QW));
  151. return state;
  152. }
  153. void keyboard_post_init_user(void) {
  154. // Enable the LED layers
  155. rgblight_layers = my_rgb_layers;
  156. }
  157. #endif
  158. #ifdef ENCODER_ENABLE
  159. # define MEDIA_KEY_DELAY 10
  160. static inline void my_encoders(const uint8_t index, const bool clockwise) {
  161. if (index == 0) { /* First encoder */
  162. if (IS_LAYER_ON(_LWR)) {
  163. if (clockwise) {
  164. rgblight_decrease_val_noeeprom();
  165. } else {
  166. rgblight_increase_val_noeeprom();
  167. }
  168. } else if (IS_LAYER_ON(_RSE)) {
  169. if (clockwise) {
  170. rgblight_decrease_hue_noeeprom();
  171. } else {
  172. rgblight_increase_hue_noeeprom();
  173. }
  174. } else {
  175. if (clockwise) {
  176. tap_code_delay(KC_VOLD, MEDIA_KEY_DELAY);
  177. } else {
  178. tap_code_delay(KC_VOLU, MEDIA_KEY_DELAY);
  179. }
  180. }
  181. }
  182. }
  183. bool encoder_update_user(uint8_t index, bool clockwise) {
  184. my_encoders(index, clockwise);
  185. return true;
  186. }
  187. #endif