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.

188 lines
13 KiB

  1. /* Copyright 2022 ML
  2. *
  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. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include QMK_KEYBOARD_H
  17. #include <string.h>
  18. #include <math.h>
  19. #include <lib/lib8tion/lib8tion.h>
  20. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  21. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  22. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  23. // entirely and just use numbers.
  24. enum layer_names {
  25. _BASE,
  26. _FN,
  27. };
  28. enum user_rgb_mode {
  29. RGB_MODE_ALL,
  30. RGB_MODE_NONE,
  31. };
  32. typedef union {
  33. uint32_t raw;
  34. struct {
  35. uint8_t rgb_mode :8;
  36. };
  37. } user_config_t;
  38. user_config_t user_config;
  39. // enum layer_keycodes { };
  40. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  41. /*
  42. EscF1 F2 F3 F4 F5 F6 F7 F8 F9 F10F11F12PseDel
  43. ` 1 2 3 4 5 6 7 8 9 0 - = BckspcDel
  44. Tab q w e r t y u i o p [ ] \ PgU
  45. Caps a s d f g h j k l ; ' Enter PgD
  46. LShift z x c v b n m , . / RSft
  47. LCrlGUI LAlt Space RAlt Fn
  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 < > ? RSft
  52. */
  53. /* Row: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */
  54. [_BASE] = LAYOUT(
  55. KC_ESC, 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, KC_MUTE,
  56. KC_GRV, 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, KC_HOME,
  57. 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, KC_PGUP,
  58. 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, KC_PGDN,
  59. 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,
  60. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(_FN), KC_LEFT, KC_DOWN, KC_RIGHT
  61. ),
  62. /*
  63. Rst Tog
  64. Hui
  65. Hud
  66. Vai
  67. SpdVadSpi
  68. */
  69. /* Row: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 */
  70. [_FN] = LAYOUT(
  71. QK_BOOT, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_TOG,
  72. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_HUI,
  73. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_HUD,
  74. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  75. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_VAI,
  76. _______, _______, _______, _______, _______, _______, RGB_SPD, RGB_VAD, RGB_SPI
  77. ),
  78. };
  79. void keyboard_post_init_user(void) {
  80. user_config.raw = eeconfig_read_user();
  81. switch (user_config.rgb_mode) {
  82. case RGB_MODE_ALL:
  83. rgb_matrix_set_flags(LED_FLAG_ALL);
  84. rgb_matrix_enable_noeeprom();
  85. break;
  86. case RGB_MODE_NONE:
  87. rgb_matrix_set_flags(LED_FLAG_NONE);
  88. rgb_matrix_set_color_all(0, 0, 0);
  89. break;
  90. }
  91. }
  92. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  93. switch (keycode) {
  94. case RGB_TOG:
  95. if (record->event.pressed) {
  96. switch (rgb_matrix_get_flags()) {
  97. case LED_FLAG_ALL: {
  98. rgb_matrix_set_flags(LED_FLAG_NONE);
  99. rgb_matrix_set_color_all(0, 0, 0);
  100. user_config.rgb_mode = RGB_MODE_NONE;
  101. }
  102. break;
  103. default: {
  104. rgb_matrix_set_flags(LED_FLAG_ALL);
  105. rgb_matrix_enable_noeeprom();
  106. user_config.rgb_mode = RGB_MODE_ALL;
  107. }
  108. break;
  109. }
  110. eeconfig_update_user(user_config.raw);
  111. }
  112. return false;
  113. }
  114. return true;
  115. }
  116. #ifdef ENCODER_MAP_ENABLE
  117. const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
  118. [0] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) },
  119. [1] = { ENCODER_CCW_CW(RGB_RMOD, RGB_MOD) },
  120. };
  121. #endif
  122. bool rgb_matrix_indicators_user(void) {
  123. rgb_matrix_set_color(2, 0, 0, 0);
  124. HSV hsv = rgb_matrix_config.hsv;
  125. uint8_t time = scale16by8(g_rgb_timer, qadd8(32, 1));
  126. hsv.h = time;
  127. RGB rgb = hsv_to_rgb(hsv);
  128. if ((rgb_matrix_get_flags() & LED_FLAG_KEYLIGHT)) {
  129. if (host_keyboard_led_state().caps_lock) {
  130. rgb_matrix_set_color(2, rgb.r, rgb.g, rgb.b);
  131. }
  132. } else {
  133. if (host_keyboard_led_state().caps_lock) {
  134. rgb_matrix_set_color(2, rgb.r, rgb.g, rgb.b);
  135. } else {
  136. rgb_matrix_set_color(2, 0, 0, 0);
  137. }
  138. }
  139. return false;
  140. }