logo

qmk_firmware

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

keymap.c (12866B)


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