logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

keymap.c (7002B)


  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. #define LOWER TT(_LWR)
  22. #define RAISE TT(_RSE)
  23. #ifdef RGBLIGHT_ENABLE
  24. const rgblight_segment_t PROGMEM my_qwerty_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLIGHT_LED_COUNT, HSV_PURPLE});
  25. const rgblight_segment_t PROGMEM my_lwr_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLIGHT_LED_COUNT, HSV_CYAN});
  26. const rgblight_segment_t PROGMEM my_rse_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLIGHT_LED_COUNT, HSV_RED});
  27. const rgblight_segment_t PROGMEM my_adj_layer[] = RGBLIGHT_LAYER_SEGMENTS({0, RGBLIGHT_LED_COUNT, HSV_GREEN});
  28. const rgblight_segment_t* const PROGMEM my_rgb_layers[] = RGBLIGHT_LAYERS_LIST(my_qwerty_layer, my_lwr_layer, my_rse_layer, my_adj_layer);
  29. #endif
  30. // clang-format off
  31. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  32. [_QW] = LAYOUT_ortho_5x12(
  33. KC_GRV , KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , KC_BSPC,
  34. KC_ESC , KC_Q , KC_W , KC_E , KC_R , KC_T , KC_Y , KC_U , KC_I , KC_O , KC_P , KC_DEL ,
  35. KC_TAB , KC_A , KC_S , KC_D , KC_F , KC_G , KC_H , KC_J , KC_K , KC_L , KC_SCLN, KC_QUOT,
  36. KC_LSFT, KC_Z , KC_X , KC_C , KC_V , KC_B , KC_N , KC_M , KC_COMM, KC_DOT , KC_SLSH, KC_ENT ,
  37. KC_LCTL, KC_LGUI, KC_LALT, KC_APP, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP , KC_RGHT
  38. ),
  39. [_LWR] = LAYOUT_ortho_5x12(
  40. KC_TILD, KC_EXLM, KC_AT , KC_HASH, KC_DLR , KC_PERC, KC_CIRC, KC_AMPR , KC_ASTR , KC_LPRN, KC_RPRN, KC_DEL ,
  41. KC_DEL , KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , KC_F6 , KC_UNDS , KC_PLUS , KC_LCBR, KC_RCBR, KC_PIPE,
  42. _______, KC_F7 , KC_F8 , KC_F9 , KC_F10 , KC_F11 , KC_F12 , S(KC_NUHS), S(KC_NUBS), _______, _______, _______,
  43. _______, _______, _______, _______, _______, _______, _______, _______ , KC_MNXT , KC_VOLD, KC_VOLU, KC_MPLY,
  44. _______, _______, _______, _______, _______, _______, _______, _______ , _______ , _______, _______, _______
  45. ),
  46. [_RSE] = LAYOUT_ortho_5x12(
  47. KC_GRV , KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , KC_DEL ,
  48. KC_DEL , KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , KC_F6 , KC_MINS, KC_EQL , KC_LBRC, KC_RBRC, KC_BSLS,
  49. _______, KC_F7 , KC_F8 , KC_F9 , KC_F10 , KC_F11 , KC_F12 , KC_NUHS, KC_NUBS, _______, _______, _______,
  50. _______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY,
  51. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  52. ),
  53. [_ADJ] = LAYOUT_ortho_5x12(
  54. _______, QK_BOOT, _______, _______, _______, _______, UG_TOGG, UG_NEXT, UG_PREV, RGB_M_G, QK_BOOT, _______,
  55. _______, _______, _______, _______, _______, _______, UG_HUEU, UG_SATU, UG_VALU , _______, _______, _______,
  56. _______, _______, _______, _______, _______, _______, UG_HUED, UG_SATD, UG_VALD , _______, _______, _______,
  57. _______, _______, _______, _______, _______, _______, _______, _______, _______ , _______, _______, _______,
  58. _______, _______, _______, _______, _______, _______, _______, _______, _______ , _______, _______, _______
  59. )
  60. };
  61. // clang-format on
  62. // let us assume we start with both layers off
  63. bool toggle_lwr = false;
  64. bool toggle_rse = false;
  65. bool led_update_user(led_t led_state) {
  66. // Disable the default LED update code, so that lock LEDs could be reused to show layer status.
  67. return false;
  68. }
  69. void matrix_scan_user(void) {
  70. led_lwr(toggle_lwr);
  71. led_rse(toggle_rse);
  72. led_t led_state = host_keyboard_led_state();
  73. led_caps(led_state.caps_lock);
  74. if (layer_state_is(_ADJ)) {
  75. led_lwr(true);
  76. led_rse(true);
  77. }
  78. }
  79. void matrix_slave_scan_user(void) {
  80. matrix_scan_user();
  81. if (IS_LAYER_ON(_LWR)) {
  82. led_lwr(layer_state_is(_LWR));
  83. }
  84. if (IS_LAYER_ON(_RSE)) {
  85. led_rse(layer_state_is(_RSE));
  86. }
  87. }
  88. bool process_record_user(uint16_t keycode, keyrecord_t* record) {
  89. switch (keycode) {
  90. case (TT(_LWR)):
  91. if (!record->event.pressed && record->tap.count == TAPPING_TOGGLE) {
  92. // This runs before the TT() handler toggles the layer state, so the current layer state is the opposite of the final one after toggle.
  93. toggle_lwr = !layer_state_is(_LWR);
  94. }
  95. return true;
  96. break;
  97. case (TT(_RSE)):
  98. if (record->event.pressed && record->tap.count == TAPPING_TOGGLE) {
  99. toggle_rse = !layer_state_is(_RSE);
  100. }
  101. return true;
  102. break;
  103. default:
  104. return true;
  105. }
  106. }
  107. layer_state_t layer_state_set_user(layer_state_t state) {
  108. #ifdef RGBLIGHT_ENABLE
  109. rgblight_set_layer_state(0, layer_state_cmp(state, _QW));
  110. rgblight_set_layer_state(1, layer_state_cmp(state, _LWR));
  111. rgblight_set_layer_state(2, layer_state_cmp(state, _RSE));
  112. rgblight_set_layer_state(3, layer_state_cmp(state, _ADJ));
  113. #endif
  114. return update_tri_layer_state(state, _LWR, _RSE, _ADJ);
  115. }
  116. #ifdef RGBLIGHT_ENABLE
  117. layer_state_t default_layer_state_set_user(layer_state_t state) {
  118. rgblight_set_layer_state(0, layer_state_cmp(state, _QW));
  119. return state;
  120. }
  121. void keyboard_post_init_user(void) {
  122. // Enable the LED layers
  123. rgblight_layers = my_rgb_layers;
  124. }
  125. #endif
  126. #ifdef ENCODER_ENABLE
  127. # define MEDIA_KEY_DELAY 10
  128. static inline void my_encoders(const uint8_t index, const bool clockwise) {
  129. if (index == 0 || (index == 1)) { /* First encoder on each side*/
  130. if (IS_LAYER_ON(_LWR)) {
  131. if (clockwise) {
  132. rgblight_decrease_val_noeeprom();
  133. } else {
  134. rgblight_increase_val_noeeprom();
  135. }
  136. } else if (IS_LAYER_ON(_RSE)) {
  137. if (clockwise) {
  138. rgblight_decrease_hue_noeeprom();
  139. } else {
  140. rgblight_increase_hue_noeeprom();
  141. }
  142. } else {
  143. if (clockwise) {
  144. tap_code_delay(KC_VOLD, MEDIA_KEY_DELAY);
  145. } else {
  146. tap_code_delay(KC_VOLU, MEDIA_KEY_DELAY);
  147. }
  148. }
  149. }
  150. }
  151. bool encoder_update_user(uint8_t index, bool clockwise) {
  152. my_encoders(index, clockwise);
  153. return true;
  154. }
  155. #endif