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.

335 lines
17 KiB

  1. /* Copyright 2021 Glorious, LLC <salman@pcgamingrace.com>
  2. Copyright 2022 Andre Brait <andrebrait@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 layers {
  16. WIN_BASE = 0,
  17. WIN_FN,
  18. MAC_BASE,
  19. MAC_FN
  20. };
  21. #define KC_TASK LGUI(KC_TAB)
  22. #define KC_FLXP LGUI(KC_E)
  23. #define TO_WINB TO(WIN_BASE)
  24. #define TO_MACB TO(MAC_BASE)
  25. #define MO_WINF MO(WIN_FN)
  26. #define MO_MACF MO(MAC_FN)
  27. // clang-format off
  28. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  29. // ESC F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Del Rotary(Play/Pause)
  30. // ~ 1 2 3 4 5 6 7 8 9 0 - (=) BackSpc Home
  31. // Tab Q W E R T Y U I O P [ ] \ PgUp
  32. // Caps A S D F G H J K L ; " Enter PgDn
  33. // Sh_L Z X C V B N M , . ? Sh_R Up End
  34. // Ct_L Win_L Alt_L SPACE Alt_R FN Ct_R Left Down Right
  35. // The FN key by default maps to a momentary toggle to layer 1 to provide access to the QK_BOOT key (to put the board into bootloader mode). Without
  36. // this mapping, you have to open the case to hit the button on the bottom of the PCB (near the USB cable attachment) while plugging in the USB
  37. // cable to get the board into bootloader mode - definitely not fun when you're working on your QMK builds. Remove this and put it back to KC_RGUI
  38. // if that's your preference.
  39. //
  40. // To put the keyboard in bootloader mode, use FN+backslash. If you accidentally put it into bootloader, you can just unplug the USB cable and
  41. // it'll be back to normal when you plug it back in.
  42. //
  43. // This keyboard defaults to 6KRO instead of NKRO for compatibility reasons (some KVMs and BIOSes are incompatible with NKRO).
  44. // Since this is, among other things, a "gaming" keyboard, a key combination to enable NKRO on the fly is provided for convenience.
  45. // Press Fn+N to toggle between 6KRO and NKRO. This setting is persisted to the EEPROM and thus persists between restarts.
  46. //
  47. // RGB and function keys are inspired by the Keychron Q1 layouts instead of using the default keys.
  48. //
  49. // KC_PAUS/KC_BRMU and KC_SCRL/KC_BRMD are aliases for the same keys, but their names reflect better the function in each layout.
  50. [WIN_BASE] = LAYOUT(
  51. 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,
  52. 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,
  53. 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,
  54. 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,
  55. 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_END,
  56. KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO_WINF, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT
  57. ),
  58. [WIN_FN] = LAYOUT(
  59. _______, KC_BRID, KC_BRIU, KC_TASK, KC_FLXP, KC_MPRV, KC_MNXT, KC_MPLY, KC_MSTP, KC_MUTE, KC_VOLD, KC_VOLU, XXXXXXX, KC_INS, XXXXXXX,
  60. XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_PSCR,
  61. RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, QK_BOOT, KC_PAUS,
  62. TO_MACB, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_SCRL,
  63. _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, NK_TOGG, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
  64. _______, _______, _______, XXXXXXX, _______, _______, _______, XXXXXXX, XXXXXXX, XXXXXXX
  65. ),
  66. [MAC_BASE] = LAYOUT(
  67. 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,
  68. 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,
  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, KC_PGUP,
  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, KC_PGDN,
  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_END,
  72. KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, KC_RALT, MO_MACF, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT
  73. ),
  74. [MAC_FN] = LAYOUT(
  75. _______, KC_BRID, KC_BRIU, KC_MCTL, KC_LPAD, KC_MPRV, KC_MNXT, KC_MPLY, KC_MSTP, KC_MUTE, KC_VOLD, KC_VOLU, XXXXXXX, KC_INS, XXXXXXX,
  76. XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_PSCR,
  77. RGB_TOG, RGB_MOD, RGB_VAI, RGB_HUI, RGB_SAI, RGB_SPI, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, QK_BOOT, KC_BRMU,
  78. TO_WINB, RGB_RMOD, RGB_VAD, RGB_HUD, RGB_SAD, RGB_SPD, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_BRMD,
  79. _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, NK_TOGG, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,
  80. _______, _______, _______, XXXXXXX, _______, _______, _______, XXXXXXX, XXXXXXX, XXXXXXX
  81. )
  82. };
  83. // clang-format on
  84. #ifdef RGB_MATRIX_ENABLE
  85. /* Renaming those to make the purpose on this keymap clearer */
  86. #define LED_FLAG_CAPS LED_FLAG_NONE
  87. #define LED_FLAG_EFFECTS LED_FLAG_INDICATOR
  88. static void set_rgb_caps_leds(void);
  89. static uint16_t effect_started_time = 0;
  90. static uint8_t r_effect = 0x0, g_effect = 0x0, b_effect = 0x0;
  91. static void start_effects(void);
  92. /* The interval time in ms */
  93. #ifndef EFFECTS_TIME
  94. #define EFFECTS_TIME 2000
  95. #endif
  96. #ifndef EFFECTS_INTERVAL
  97. #define EFFECTS_INTERVAL 250
  98. #endif
  99. #if EFFECTS_TIME <= 0 || EFFECTS_TIME >= 32767
  100. #error "EFFECTS_TIME must be a positive integer smaller than 32767"
  101. #endif
  102. #if EFFECTS_INTERVAL <= 0 || EFFECTS_INTERVAL >= 32767
  103. #error "EFFECTS_INTERVAL must be a positive integer smaller than 32767"
  104. #endif
  105. #define effect_red() r_effect = 0xFF, g_effect = 0x0, b_effect = 0x0
  106. #define effect_green() r_effect = 0x0, g_effect = 0xFF, b_effect = 0x0
  107. #define effect_blue() r_effect = 0x0, g_effect = 0x0, b_effect = 0xFF
  108. #define effect_white() r_effect = 0xFF, g_effect = 0xFF, b_effect = 0xFF
  109. static uint8_t previous_effect_layer = 255;
  110. layer_state_t layer_state_set_user(layer_state_t state) {
  111. uint8_t current_layer = get_highest_layer(state);
  112. switch (current_layer) {
  113. case WIN_BASE:
  114. if (previous_effect_layer != current_layer) {
  115. previous_effect_layer = current_layer;
  116. effect_blue();
  117. start_effects();
  118. }
  119. break;
  120. case MAC_BASE:
  121. if (previous_effect_layer != current_layer) {
  122. previous_effect_layer = current_layer;
  123. effect_white();
  124. start_effects();
  125. }
  126. break;
  127. }
  128. return state;
  129. }
  130. bool led_update_user(led_t led_state) {
  131. if (led_state.caps_lock) {
  132. if (!rgb_matrix_is_enabled()) {
  133. /* Turn ON the RGB Matrix for CAPS LOCK */
  134. rgb_matrix_set_flags(LED_FLAG_CAPS);
  135. rgb_matrix_enable();
  136. }
  137. } else if (rgb_matrix_get_flags() == LED_FLAG_CAPS) {
  138. /* RGB Matrix was only ON because of CAPS LOCK. Turn it OFF. */
  139. rgb_matrix_set_flags(LED_FLAG_ALL);
  140. rgb_matrix_disable();
  141. }
  142. return true;
  143. }
  144. #endif // RGB_MATRIX_ENABLE
  145. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  146. switch (keycode) {
  147. #ifdef RGB_MATRIX_ENABLE
  148. #ifdef NKRO_ENABLE
  149. case NK_TOGG:
  150. if (record->event.pressed) {
  151. if (keymap_config.nkro) {
  152. /* Turning NKRO OFF */
  153. effect_red();
  154. } else {
  155. /* Turning NKRO ON */
  156. effect_green();
  157. }
  158. start_effects();
  159. }
  160. break;
  161. #endif // NKRO_ENABLE
  162. case RGB_MOD:
  163. case RGB_RMOD:
  164. case RGB_HUI:
  165. case RGB_HUD:
  166. case RGB_SAI:
  167. case RGB_SAD:
  168. case RGB_VAI:
  169. case RGB_VAD:
  170. case RGB_SPI:
  171. case RGB_SPD:
  172. if (record->event.pressed) {
  173. if (rgb_matrix_get_flags() != LED_FLAG_ALL) {
  174. /* Ignore changes to RGB settings while only it's supposed to be OFF */
  175. return false; // Skip all further processing of this key
  176. }
  177. }
  178. break;
  179. case RGB_TOG:
  180. if (record->event.pressed) {
  181. if (rgb_matrix_is_enabled()) {
  182. switch (rgb_matrix_get_flags()) {
  183. case LED_FLAG_EFFECTS:
  184. case LED_FLAG_CAPS:
  185. /* Turned ON because of EFFECTS or CAPS, is actually OFF */
  186. /* Change to LED_FLAG_ALL to signal it's really ON */
  187. rgb_matrix_set_flags(LED_FLAG_ALL);
  188. /* Will be re-enabled by the processing of the toggle */
  189. rgb_matrix_disable_noeeprom();
  190. break;
  191. case LED_FLAG_ALL:
  192. /* Is actually ON */
  193. if (effect_started_time > 0) {
  194. /* Signal EFFECTS */
  195. rgb_matrix_set_flags(LED_FLAG_EFFECTS);
  196. /* Will be re-enabled by the processing of the toggle */
  197. rgb_matrix_disable_noeeprom();
  198. } else
  199. if (host_keyboard_led_state().caps_lock) {
  200. /* Signal CAPS */
  201. rgb_matrix_set_flags(LED_FLAG_CAPS);
  202. /* Will be re-enabled by the processing of the toggle */
  203. rgb_matrix_disable_noeeprom();
  204. }
  205. break;
  206. }
  207. }
  208. }
  209. break;
  210. #endif // RGB_MATRIX_ENABLE
  211. }
  212. return true;
  213. }
  214. #ifdef RGB_MATRIX_ENABLE
  215. bool rgb_matrix_indicators_user(void) {
  216. if (effect_started_time > 0) {
  217. /* Render blinking EFFECTS */
  218. const uint16_t deltaTime = sync_timer_elapsed(effect_started_time);
  219. if (deltaTime <= EFFECTS_TIME) {
  220. const uint8_t led_state = ((deltaTime / EFFECTS_INTERVAL) + 1) & 0x01;
  221. const uint8_t val_r = led_state * r_effect;
  222. const uint8_t val_g = led_state * g_effect;
  223. const uint8_t val_b = led_state * b_effect;
  224. rgb_matrix_set_color_all(val_r, val_g, val_b);
  225. if (host_keyboard_led_state().caps_lock) {
  226. set_rgb_caps_leds();
  227. }
  228. return false;
  229. } else {
  230. /* EFFECTS duration is finished */
  231. effect_started_time = 0;
  232. if (rgb_matrix_get_flags() == LED_FLAG_EFFECTS) {
  233. /* It was turned ON because of EFFECTS */
  234. if (host_keyboard_led_state().caps_lock) {
  235. /* CAPS is still ON. Demote to CAPS */
  236. rgb_matrix_set_flags(LED_FLAG_CAPS);
  237. } else {
  238. /* There is nothing else keeping RGB enabled. Reset flags and turn if off. */
  239. rgb_matrix_set_flags(LED_FLAG_ALL);
  240. rgb_matrix_disable_noeeprom();
  241. }
  242. }
  243. }
  244. }
  245. if (rgb_matrix_get_flags() == LED_FLAG_CAPS) {
  246. rgb_matrix_set_color_all(0x0, 0x0, 0x0);
  247. }
  248. if (host_keyboard_led_state().caps_lock) {
  249. set_rgb_caps_leds();
  250. }
  251. return false;
  252. }
  253. static void start_effects(void) {
  254. effect_started_time = sync_timer_read();
  255. if (!rgb_matrix_is_enabled()) {
  256. /* Turn it ON, signal the cause (EFFECTS) */
  257. rgb_matrix_set_flags(LED_FLAG_EFFECTS);
  258. rgb_matrix_enable_noeeprom();
  259. } else if (rgb_matrix_get_flags() == LED_FLAG_CAPS) {
  260. /* It's already ON, promote the cause from CAPS to EFFECTS */
  261. rgb_matrix_set_flags(LED_FLAG_EFFECTS);
  262. }
  263. }
  264. // RGB led number layout, function of the key
  265. // 67, led 01 0, ESC 6, F1 12, F2 18, F3 23, F4 28, F5 34, F6 39, F7 44, F8 50, F9 56, F10 61, F11 66, F12 69, Prt Rotary(Mute) 68, led 12
  266. // 70, led 02 1, ~ 7, 1 13, 2 19, 3 24, 4 29, 5 35, 6 40, 7 45, 8 51, 9 57, 0 62, -_ 78, (=+) 85, BackSpc 72, Home 71, led 13
  267. // 73, led 03 2, Tab 8, Q 14, W 20. E 25, R 30, T 36, Y 41, U 46, I 52, O 58, P 63, [{ 89, ]} 93, \| 75, PgUp 74, led 14
  268. // 76, led 04 3, Caps 9, A 15, S 21, D 26, F 31, G 37, H 42, J 47, K 53, L 59, ;: 64, '" 96, Enter 86, PgDn 77, led 15
  269. // 80, led 05 4, Sh_L 10, Z 16, X 22, C 27, V 32, B 38, N 43, M 48, ,< 54, .< 60, /? 90, Sh_R 94, Up 82, End 81, led 16
  270. // 83, led 06 5, Ct_L 11,Win_L 17, Alt_L 33, SPACE 49, Alt_R 55, FN 65, Ct_R 95, Left 97, Down 79, Right 84, led 17
  271. // 87, led 07 88, led 18
  272. // 91, led 08 92, led 19
  273. static void set_rgb_caps_leds(void) {
  274. rgb_matrix_set_color(0, 0xFF, 0x0, 0x0); // ESC
  275. rgb_matrix_set_color(6, 0xFF, 0x0, 0x0); // F1
  276. rgb_matrix_set_color(12, 0xFF, 0x0, 0x0); // F2
  277. rgb_matrix_set_color(18, 0xFF, 0x0, 0x0); // F3
  278. rgb_matrix_set_color(23, 0xFF, 0x0, 0x0); // F4
  279. rgb_matrix_set_color(28, 0xFF, 0x0, 0x0); // F5
  280. rgb_matrix_set_color(34, 0xFF, 0x0, 0x0); // F6
  281. rgb_matrix_set_color(39, 0xFF, 0x0, 0x0); // F7
  282. rgb_matrix_set_color(44, 0xFF, 0x0, 0x0); // F8
  283. rgb_matrix_set_color(50, 0xFF, 0x0, 0x0); // F9
  284. rgb_matrix_set_color(56, 0xFF, 0x0, 0x0); // F10
  285. rgb_matrix_set_color(61, 0xFF, 0x0, 0x0); // F11
  286. rgb_matrix_set_color(66, 0xFF, 0x0, 0x0); // F12
  287. rgb_matrix_set_color(69, 0xFF, 0x0, 0x0); // Prt
  288. rgb_matrix_set_color(67, 0xFF, 0x0, 0x0); // Left side LED 1
  289. rgb_matrix_set_color(68, 0xFF, 0x0, 0x0); // Right side LED 1
  290. rgb_matrix_set_color(70, 0xFF, 0x0, 0x0); // Left side LED 2
  291. rgb_matrix_set_color(71, 0xFF, 0x0, 0x0); // Right side LED 2
  292. rgb_matrix_set_color(73, 0xFF, 0x0, 0x0); // Left side LED 3
  293. rgb_matrix_set_color(74, 0xFF, 0x0, 0x0); // Right side LED 3
  294. rgb_matrix_set_color(76, 0xFF, 0x0, 0x0); // Left side LED 4
  295. rgb_matrix_set_color(77, 0xFF, 0x0, 0x0); // Right side LED 4
  296. rgb_matrix_set_color(80, 0xFF, 0x0, 0x0); // Left side LED 5
  297. rgb_matrix_set_color(81, 0xFF, 0x0, 0x0); // Right side LED 5
  298. rgb_matrix_set_color(83, 0xFF, 0x0, 0x0); // Left side LED 6
  299. rgb_matrix_set_color(84, 0xFF, 0x0, 0x0); // Right side LED 6
  300. rgb_matrix_set_color(87, 0xFF, 0x0, 0x0); // Left side LED 7
  301. rgb_matrix_set_color(88, 0xFF, 0x0, 0x0); // Right side LED 7
  302. rgb_matrix_set_color(91, 0xFF, 0x0, 0x0); // Left side LED 8
  303. rgb_matrix_set_color(92, 0xFF, 0x0, 0x0); // Right side LED 8
  304. rgb_matrix_set_color(3, 0xFF, 0x0, 0x0); // CAPS LED
  305. }
  306. #endif // RGB_MATRIX_ENABLE