You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
11 KiB

  1. /* Copyright 2021 Mss Studio
  2. * Copyright 2022 HorrorTroll <https://github.com/HorrorTroll>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include QMK_KEYBOARD_H
  18. #include <lib/lib8tion/lib8tion.h>
  19. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  20. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  21. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  22. // entirely and just use numbers.
  23. enum layer_names {
  24. _BASE,
  25. _FN,
  26. };
  27. enum user_rgb_mode {
  28. RGB_MODE_ALL,
  29. RGB_MODE_KEYLIGHT,
  30. RGB_MODE_UNDERGLOW,
  31. RGB_MODE_NONE,
  32. };
  33. typedef union {
  34. uint32_t raw;
  35. struct {
  36. uint8_t rgb_mode :8;
  37. };
  38. } user_config_t;
  39. user_config_t user_config;
  40. // enum layer_keycodes { };
  41. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  42. /*
  43. Esc 1 2 3 4 5 6 7 8 9 0 - = Bakspc
  44. Tab q w e r t y u i o p [ ] \
  45. Caps a s d f g h j k l ; ' Enter
  46. LShift z x c v b n m , . / Rft Del
  47. LCrlGUI LAlt Space RAtFn
  48. ! @ # $ % ^ & * ( ) _ +
  49. Q W E R T Y U I O P { } |
  50. Caps A S D F G H J K L : " │ │
  51. LShift Z X C V B N M < > ? Rft
  52. */
  53. /* Row: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 */
  54. [_BASE] = LAYOUT_64_ansi(
  55. KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC,
  56. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS,
  57. KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT,
  58. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_DEL,
  59. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(_FN), KC_LEFT, KC_DOWN, KC_RIGHT
  60. ),
  61. /*
  62. ` F1 F2 F3 F4 F5 F6 F7 F8 F9 F10F11F12 Delete
  63. Reset Ins PSc Hui Mod
  64. Tog
  65. Cal MutVoDVoU Vai
  66. SpdVadSpi
  67. */
  68. /* Row: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 */
  69. [_FN] = LAYOUT_64_ansi(
  70. KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL,
  71. RESET, _______, _______, _______, _______, _______, _______, _______, KC_INS, _______, KC_PSCR, _______, RGB_HUI, RGB_MOD,
  72. _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_TOG, _______, _______, _______,
  73. _______, _______, _______, KC_CALC, _______, _______, _______, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______, RGB_VAI, _______,
  74. _______, _______, _______, _______, _______, _______, RGB_SPD, RGB_VAD, RGB_SPI
  75. ),
  76. };
  77. void keyboard_post_init_user(void) {
  78. user_config.raw = eeconfig_read_user();
  79. switch (user_config.rgb_mode) {
  80. case RGB_MODE_ALL:
  81. rgb_matrix_set_flags(LED_FLAG_ALL);
  82. rgb_matrix_enable_noeeprom();
  83. break;
  84. case RGB_MODE_KEYLIGHT:
  85. rgb_matrix_set_flags(LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR);
  86. rgb_matrix_set_color_all(0, 0, 0);
  87. break;
  88. case RGB_MODE_UNDERGLOW:
  89. rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
  90. rgb_matrix_set_color_all(0, 0, 0);
  91. break;
  92. case RGB_MODE_NONE:
  93. rgb_matrix_set_flags(LED_FLAG_NONE);
  94. rgb_matrix_set_color_all(0, 0, 0);
  95. break;
  96. }
  97. }
  98. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  99. switch (keycode) {
  100. case RGB_TOG:
  101. if (record->event.pressed) {
  102. switch (rgb_matrix_get_flags()) {
  103. case LED_FLAG_ALL: {
  104. rgb_matrix_set_flags(LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR);
  105. rgb_matrix_set_color_all(0, 0, 0);
  106. user_config.rgb_mode = RGB_MODE_KEYLIGHT;
  107. }
  108. break;
  109. case (LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR): {
  110. rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
  111. rgb_matrix_set_color_all(0, 0, 0);
  112. user_config.rgb_mode = RGB_MODE_UNDERGLOW;
  113. }
  114. break;
  115. case (LED_FLAG_UNDERGLOW): {
  116. rgb_matrix_set_flags(LED_FLAG_NONE);
  117. rgb_matrix_set_color_all(0, 0, 0);
  118. user_config.rgb_mode = RGB_MODE_NONE;
  119. }
  120. break;
  121. default: {
  122. rgb_matrix_set_flags(LED_FLAG_ALL);
  123. rgb_matrix_enable_noeeprom();
  124. user_config.rgb_mode = RGB_MODE_ALL;
  125. }
  126. break;
  127. }
  128. eeconfig_update_user(user_config.raw);
  129. }
  130. return false;
  131. }
  132. return true;
  133. }
  134. void rgb_matrix_indicators_user(void) {
  135. HSV hsv = rgb_matrix_config.hsv;
  136. uint8_t time = scale16by8(g_rgb_timer, qadd8(32, 1));
  137. hsv.h = time;
  138. RGB rgb = hsv_to_rgb(hsv);
  139. if ((rgb_matrix_get_flags() & LED_FLAG_KEYLIGHT)) {
  140. if (host_keyboard_led_state().caps_lock) {
  141. rgb_matrix_set_color(28, rgb.r, rgb.g, rgb.b);
  142. }
  143. } else {
  144. if (host_keyboard_led_state().caps_lock) {
  145. rgb_matrix_set_color(28, rgb.r, rgb.g, rgb.b);
  146. } else {
  147. rgb_matrix_set_color(28, 0, 0, 0);
  148. }
  149. }
  150. }