keymap.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
  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 "drashna.h"
  17. #ifdef RGBLIGHT_ENABLE
  18. // Following line allows macro to read current RGB settings
  19. extern rgblight_config_t rgblight_config;
  20. #endif
  21. enum crkbd_keycodes { RGBRST = NEW_SAFE_RANGE };
  22. /*
  23. * The `LAYOUT_crkbd_base` macro is a template to allow the use of identical
  24. * modifiers for the default layouts (eg QWERTY, Colemak, Dvorak, etc), so
  25. * that there is no need to set them up for each layout, and modify all of
  26. * them if I want to change them. This helps to keep consistency and ease
  27. * of use. K## is a placeholder to pass through the individual keycodes
  28. */
  29. #define LAYOUT_split_3x6_3_base( \
  30. K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, \
  31. K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, \
  32. K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A \
  33. ) \
  34. LAYOUT_split_3x6_3_wrapper( \
  35. KC_ESC, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, KC_MINS, \
  36. ALT_T(KC_TAB), K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, RALT_T(KC_QUOT), \
  37. OS_LSFT, CTL_T(K21), K22, K23, K24, K25, K26, K27, K28, K29, RCTL_T(K2A), OS_RSFT, \
  38. KC_GRV, KC_SPC, BK_LWER, DL_RAIS, KC_ENT, OS_RGUI \
  39. )
  40. #define LAYOUT_split_3x6_3_base_wrapper(...) LAYOUT_split_3x6_3_base(__VA_ARGS__)
  41. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  42. [_QWERTY] = LAYOUT_split_3x6_3_base_wrapper(
  43. _________________QWERTY_L1_________________, _________________QWERTY_R1_________________,
  44. _________________QWERTY_L2_________________, _________________QWERTY_R2_________________,
  45. _________________QWERTY_L3_________________, _________________QWERTY_R3_________________
  46. ),
  47. [_COLEMAK] = LAYOUT_split_3x6_3_base_wrapper(
  48. _________________COLEMAK_L1________________, _________________COLEMAK_R1________________,
  49. _________________COLEMAK_L2________________, _________________COLEMAK_R2________________,
  50. _________________COLEMAK_L3________________, _________________COLEMAK_R3________________
  51. ),
  52. [_DVORAK] = LAYOUT_split_3x6_3_base_wrapper(
  53. _________________DVORAK_L1_________________, _________________DVORAK_R1_________________,
  54. _________________DVORAK_L2_________________, _________________DVORAK_R2_________________,
  55. _________________DVORAK_L3_________________, _________________DVORAK_R3_________________
  56. ),
  57. [_WORKMAN] = LAYOUT_split_3x6_3_base_wrapper(
  58. _________________WORKMAN_L1________________, _________________WORKMAN_R1________________,
  59. _________________WORKMAN_L2________________, _________________WORKMAN_R2________________,
  60. _________________WORKMAN_L3________________, _________________WORKMAN_R3________________
  61. ),
  62. [_NORMAN] = LAYOUT_split_3x6_3_base_wrapper(
  63. _________________NORMAN_L1_________________, _________________NORMAN_L1_________________,
  64. _________________NORMAN_L2_________________, _________________NORMAN_R2_________________,
  65. _________________NORMAN_L3_________________, _________________NORMAN_R3_________________
  66. ),
  67. [_MALTRON] = LAYOUT_split_3x6_3_base_wrapper(
  68. _________________MALTRON_L1________________, _________________MALTRON_R1________________,
  69. _________________MALTRON_L2________________, _________________MALTRON_R2________________,
  70. _________________MALTRON_L3________________, _________________MALTRON_R3________________
  71. ),
  72. [_EUCALYN] = LAYOUT_split_3x6_3_base_wrapper(
  73. _________________EUCALYN_L1________________, _________________EUCALYN_R1________________,
  74. _________________EUCALYN_L2________________, _________________EUCALYN_R2________________,
  75. _________________EUCALYN_L3________________, _________________EUCALYN_R3________________
  76. ),
  77. [_CARPLAX] = LAYOUT_split_3x6_3_base_wrapper(
  78. _____________CARPLAX_QFMLWY_L1_____________, _____________CARPLAX_QFMLWY_R1_____________,
  79. _____________CARPLAX_QFMLWY_L2_____________, _____________CARPLAX_QFMLWY_R2_____________,
  80. _____________CARPLAX_QFMLWY_L3_____________, _____________CARPLAX_QFMLWY_R3_____________
  81. ),
  82. [_MODS] = LAYOUT_split_3x6_3_wrapper(
  83. _______, ___________________BLANK___________________, ___________________BLANK___________________, _______,
  84. _______, ___________________BLANK___________________, ___________________BLANK___________________, _______,
  85. KC_LSFT, ___________________BLANK___________________, ___________________BLANK___________________, KC_RSFT,
  86. _______, _______, _______, _______, _______, _______
  87. ),
  88. [_LOWER] = LAYOUT_split_3x6_3_wrapper(
  89. KC_F11, _________________LOWER_L1__________________, _________________LOWER_R1__________________, KC_F11,
  90. KC_F12, _________________LOWER_L2__________________, _________________LOWER_R2__________________, KC_PIPE,
  91. _______, _________________LOWER_L3__________________, _________________LOWER_R3__________________, _______,
  92. _______, _______, _______, _______, _______, _______
  93. ),
  94. [_RAISE] = LAYOUT_split_3x6_3_wrapper( \
  95. _______, _________________RAISE_L1__________________, _________________RAISE_R1__________________, _______,
  96. _______, _________________RAISE_L2__________________, _________________RAISE_R2__________________, KC_BSLS,
  97. _______, _________________RAISE_L3__________________, _________________RAISE_R3__________________, _______,
  98. _______, _______, _______, _______, _______, _______
  99. ),
  100. [_ADJUST] = LAYOUT_split_3x6_3_wrapper( \
  101. KC_MAKE, _________________ADJUST_L1_________________, _________________ADJUST_R1_________________, KC_RESET,
  102. VRSN, _________________ADJUST_L2_________________, _________________ADJUST_R2_________________, EEP_RST,
  103. MG_NKRO, _________________ADJUST_L3_________________, _________________ADJUST_R3_________________, RGB_IDL,
  104. HPT_TOG, KC_NUKE, _______, _______, TG_MODS, HPT_FBK
  105. )
  106. };
  107. // clang-format on
  108. bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  109. if (record->event.pressed) {
  110. #ifndef SPLIT_KEYBOARD
  111. if (keycode == RESET && !is_master) {
  112. return false;
  113. }
  114. #endif
  115. }
  116. return true;
  117. }
  118. #ifdef OLED_DRIVER_ENABLE
  119. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  120. # ifndef SPLIT_KEYBOARD
  121. if (is_master) {
  122. # endif
  123. return OLED_ROTATION_270;
  124. # ifndef SPLIT_KEYBOARD
  125. } else {
  126. return rotation;
  127. }
  128. # endif
  129. }
  130. #endif
  131. uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) {
  132. switch (keycode) {
  133. case ALT_T(KC_A):
  134. return TAPPING_TERM + 100;
  135. default:
  136. return TAPPING_TERM;
  137. }
  138. }
  139. #ifdef RGB_MATRIX_ENABLE
  140. void suspend_power_down_keymap(void) { rgb_matrix_set_suspend_state(true); }
  141. void suspend_wakeup_init_keymap(void) { rgb_matrix_set_suspend_state(false); }
  142. void check_default_layer(uint8_t mode, uint8_t type) {
  143. switch (get_highest_layer(default_layer_state)) {
  144. case _QWERTY:
  145. rgb_matrix_layer_helper(HSV_CYAN, mode, rgb_matrix_config.speed, type);
  146. break;
  147. case _COLEMAK:
  148. rgb_matrix_layer_helper(HSV_MAGENTA, mode, rgb_matrix_config.speed, type);
  149. break;
  150. case _DVORAK:
  151. rgb_matrix_layer_helper(HSV_SPRINGGREEN, mode, rgb_matrix_config.speed, type);
  152. break;
  153. case _WORKMAN:
  154. rgb_matrix_layer_helper(HSV_GOLDENROD, mode, rgb_matrix_config.speed, type);
  155. break;
  156. case _NORMAN:
  157. rgb_matrix_layer_helper(HSV_CORAL, mode, rgb_matrix_config.speed, type);
  158. break;
  159. case _MALTRON:
  160. rgb_matrix_layer_helper(HSV_YELLOW, mode, rgb_matrix_config.speed, type);
  161. break;
  162. case _EUCALYN:
  163. rgb_matrix_layer_helper(HSV_PINK, mode, rgb_matrix_config.speed, type);
  164. break;
  165. case _CARPLAX:
  166. rgb_matrix_layer_helper(HSV_BLUE, mode, rgb_matrix_config.speed, type);
  167. break;
  168. }
  169. }
  170. void rgb_matrix_indicators_user(void) {
  171. if (userspace_config.rgb_layer_change &&
  172. # ifdef RGB_DISABLE_WHEN_USB_SUSPENDED
  173. !g_suspend_state &&
  174. # endif
  175. # if defined(RGBLIGHT_ENABLE)
  176. (!rgblight_config.enable && rgb_matrix_config.enable)
  177. # else
  178. rgb_matrix_config.enable
  179. # endif
  180. ) {
  181. switch (get_highest_layer(layer_state)) {
  182. case _GAMEPAD:
  183. rgb_matrix_layer_helper(HSV_ORANGE, 0, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
  184. break;
  185. case _DIABLO:
  186. rgb_matrix_layer_helper(HSV_RED, 0, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
  187. break;
  188. case _RAISE:
  189. rgb_matrix_layer_helper(HSV_YELLOW, 0, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
  190. break;
  191. case _LOWER:
  192. rgb_matrix_layer_helper(HSV_GREEN, 0, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
  193. break;
  194. case _ADJUST:
  195. rgb_matrix_layer_helper(HSV_RED, 0, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
  196. break;
  197. default: {
  198. check_default_layer(IS_LAYER_ON(_MODS), LED_FLAG_UNDERGLOW);
  199. break;
  200. }
  201. }
  202. check_default_layer(0, LED_FLAG_MODIFIER);
  203. }
  204. }
  205. #endif