logo

qmk_firmware

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

keymap.c (11009B)


  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. ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐
  44. │Esc│ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 0 │ - │ = │ Bakspc│
  45. ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤
  46. │ Tab │ q │ w │ e │ r │ t │ y │ u │ i │ o │ p │ [ │ ] │ \ │
  47. ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤
  48. │ Caps │ a │ s │ d │ f │ g │ h │ j │ k │ l │ ; │ ' │ Enter │
  49. ├──────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬───┬───┤
  50. │LShift │ z │ x │ c │ v │ b │ n │ m │ , │ . │ / │Rft│ ↑ │Del│
  51. ├────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴───┼───┼───┼───┼───┼───┤
  52. │LCrl│GUI │LAlt│ Space │RAt│Fn │ ← │ ↓ │ → │
  53. └────┴────┴────┴────────────────────────┴───┴───┴───┴───┴───┘
  54. ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐
  55. │ │ ! │ @ │ # │ $ │ % │ ^ │ & │ * │ ( │ ) │ _ │ + │ │
  56. ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤
  57. │ │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │ { │ } │ | │
  58. ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤
  59. │ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │ : │ " │ │
  60. ├──────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬───┬───┤
  61. │LShift │ Z │ X │ C │ V │ B │ N │ M │ < │ > │ ? │Rft│ │ │
  62. ├────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴───┼───┼───┼───┼───┼───┤
  63. │ │ │ │ │ │ │ │ │ │
  64. └────┴────┴────┴────────────────────────┴───┴───┴───┴───┴───┘
  65. */
  66. /* Row: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 */
  67. [_BASE] = LAYOUT_64_ansi(
  68. 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,
  69. 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,
  70. 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,
  71. 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,
  72. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(_FN), KC_LEFT, KC_DOWN, KC_RIGHT
  73. ),
  74. /*
  75. ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐
  76. │ ` │F1 │F2 │F3 │F4 │F5 │F6 │F7 │F8 │F9 │F10│F11│F12│ Delete│
  77. ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤
  78. │Reset│ │ │ │ │ │ │ │Ins│ │PSc│ │Hui│ Mod │
  79. ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤
  80. │ │ │ │ │ │ │ │ │ │Tog│ │ │ │
  81. ├──────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬───┬───┤
  82. │ │ │ │Cal│ │ │ │Mut│VoD│VoU│ │ │Vai│ │
  83. ├────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴───┼───┼───┼───┼───┼───┤
  84. │ │ │ │ │ │ │Spd│Vad│Spi│
  85. └────┴────┴────┴────────────────────────┴───┴───┴───┴───┴───┘
  86. */
  87. /* Row: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 */
  88. [_FN] = LAYOUT_64_ansi(
  89. 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,
  90. QK_BOOT, _______, _______, _______, _______, _______, _______, _______, KC_INS, _______, KC_PSCR, _______, RM_HUEU, RM_NEXT,
  91. _______, _______, _______, _______, _______, _______, _______, _______, _______, RM_TOGG, _______, _______, _______,
  92. _______, _______, _______, KC_CALC, _______, _______, _______, KC_MUTE, KC_VOLD, KC_VOLU, _______, _______, RM_VALU, _______,
  93. _______, _______, _______, _______, _______, _______, RM_SPDD, RM_VALD, RM_SPDU
  94. ),
  95. };
  96. void keyboard_post_init_user(void) {
  97. user_config.raw = eeconfig_read_user();
  98. switch (user_config.rgb_mode) {
  99. case RGB_MODE_ALL:
  100. rgb_matrix_set_flags(LED_FLAG_ALL);
  101. rgb_matrix_enable_noeeprom();
  102. break;
  103. case RGB_MODE_KEYLIGHT:
  104. rgb_matrix_set_flags(LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR);
  105. rgb_matrix_set_color_all(0, 0, 0);
  106. break;
  107. case RGB_MODE_UNDERGLOW:
  108. rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
  109. rgb_matrix_set_color_all(0, 0, 0);
  110. break;
  111. case RGB_MODE_NONE:
  112. rgb_matrix_set_flags(LED_FLAG_NONE);
  113. rgb_matrix_set_color_all(0, 0, 0);
  114. break;
  115. }
  116. }
  117. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  118. switch (keycode) {
  119. case QK_RGB_MATRIX_TOGGLE:
  120. if (record->event.pressed) {
  121. switch (rgb_matrix_get_flags()) {
  122. case LED_FLAG_ALL: {
  123. rgb_matrix_set_flags(LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR);
  124. rgb_matrix_set_color_all(0, 0, 0);
  125. user_config.rgb_mode = RGB_MODE_KEYLIGHT;
  126. }
  127. break;
  128. case (LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR): {
  129. rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
  130. rgb_matrix_set_color_all(0, 0, 0);
  131. user_config.rgb_mode = RGB_MODE_UNDERGLOW;
  132. }
  133. break;
  134. case (LED_FLAG_UNDERGLOW): {
  135. rgb_matrix_set_flags(LED_FLAG_NONE);
  136. rgb_matrix_set_color_all(0, 0, 0);
  137. user_config.rgb_mode = RGB_MODE_NONE;
  138. }
  139. break;
  140. default: {
  141. rgb_matrix_set_flags(LED_FLAG_ALL);
  142. rgb_matrix_enable_noeeprom();
  143. user_config.rgb_mode = RGB_MODE_ALL;
  144. }
  145. break;
  146. }
  147. eeconfig_update_user(user_config.raw);
  148. }
  149. return false;
  150. }
  151. return true;
  152. }
  153. bool rgb_matrix_indicators_user(void) {
  154. hsv_t hsv = rgb_matrix_config.hsv;
  155. uint8_t time = scale16by8(g_rgb_timer, qadd8(32, 1));
  156. hsv.h = time;
  157. rgb_t rgb = hsv_to_rgb(hsv);
  158. if ((rgb_matrix_get_flags() & LED_FLAG_KEYLIGHT)) {
  159. if (host_keyboard_led_state().caps_lock) {
  160. rgb_matrix_set_color(28, rgb.r, rgb.g, rgb.b);
  161. }
  162. } else {
  163. if (host_keyboard_led_state().caps_lock) {
  164. rgb_matrix_set_color(28, rgb.r, rgb.g, rgb.b);
  165. } else {
  166. rgb_matrix_set_color(28, 0, 0, 0);
  167. }
  168. }
  169. return false;
  170. }