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.

217 lines
10 KiB

  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. #define PLNK_1 SP_LWER
  18. #define PLNK_2 BK_LWER
  19. #define PLNK_3 DL_RAIS
  20. #define PLNK_4 ET_RAIS
  21. /*
  22. * The `LAYOUT_ortho_4x12_base` macro is a template to allow the use of identical
  23. * modifiers for the default layouts (eg QWERTY, Colemak, Dvorak, etc), so
  24. * that there is no need to set them up for each layout, and modify all of
  25. * them if I want to change them. This helps to keep consistency and ease
  26. * of use. K## is a placeholder to pass through the individual keycodes
  27. */
  28. // clang-format off
  29. #define LAYOUT_wrapper(...) LAYOUT(__VA_ARGS__)
  30. #define LAYOUT_base( \
  31. K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, \
  32. K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, \
  33. K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A \
  34. ) \
  35. LAYOUT_wrapper( \
  36. KC_ESC, K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, KC_DEL, KC_MUTE, \
  37. LALT_T(KC_TAB), K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, RALT_T(K1B), \
  38. KC_MLSF, CTL_T(K21), K22, K23, K24, K25, K26, K27, K28, K29, RCTL_T(K2A), KC_ENT, \
  39. OS_LSFT, OS_LCTL, OS_LALT, OS_LGUI, PLNK_1, PLNK_2, PLNK_3, PLNK_4, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \
  40. )
  41. #define LAYOUT_base_wrapper(...) LAYOUT_base(__VA_ARGS__)
  42. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  43. [_DEFAULT_LAYER_1] = LAYOUT_base_wrapper(
  44. _________________QWERTY_L1_________________, _________________QWERTY_R1_________________,
  45. _________________QWERTY_L2_________________, _________________QWERTY_R2_________________,
  46. _________________QWERTY_L3_________________, _________________QWERTY_R3_________________
  47. ),
  48. [_DEFAULT_LAYER_2] = LAYOUT_base_wrapper(
  49. ______________COLEMAK_MOD_DH_L1____________, ______________COLEMAK_MOD_DH_R1____________,
  50. ______________COLEMAK_MOD_DH_L2____________, ______________COLEMAK_MOD_DH_R2____________,
  51. ______________COLEMAK_MOD_DH_L3____________, ______________COLEMAK_MOD_DH_R3____________
  52. ),
  53. [_DEFAULT_LAYER_3] = LAYOUT_base_wrapper(
  54. _________________COLEMAK_L1________________, _________________COLEMAK_R1________________,
  55. _________________COLEMAK_L2________________, _________________COLEMAK_R2________________,
  56. _________________COLEMAK_L3________________, _________________COLEMAK_R3________________
  57. ),
  58. [_DEFAULT_LAYER_4] = LAYOUT_base_wrapper(
  59. _________________DVORAK_L1_________________, _________________DVORAK_R1_________________,
  60. _________________DVORAK_L2_________________, _________________DVORAK_R2_________________,
  61. _________________DVORAK_L3_________________, _________________DVORAK_R3_________________
  62. ),
  63. [_LOWER] = LAYOUT_wrapper(
  64. KC_TILD, _________________LOWER_L1__________________, _________________LOWER_R1__________________, KC_BSPC, _______,
  65. KC_DEL, _________________LOWER_L2__________________, _________________LOWER_R2__________________, KC_PIPE,
  66. _______, _________________LOWER_L3__________________, _________________LOWER_R3__________________, _______,
  67. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  68. ),
  69. [_RAISE] = LAYOUT_wrapper(
  70. KC_GRV, _________________RAISE_L1__________________, _________________RAISE_R1__________________, KC_BSPC, _______,
  71. KC_DEL, _________________RAISE_L2__________________, _________________RAISE_R2__________________, KC_BSLS,
  72. _______, _________________RAISE_L3__________________, _________________RAISE_R3__________________, _______,
  73. _______, _______, _______, _______, _______, _______, _______, _________________RAISE_R3__________________
  74. ),
  75. [_ADJUST] = LAYOUT_wrapper(
  76. KC_MAKE, _________________ADJUST_L1_________________, _________________ADJUST_R1_________________, KC_RST, _______,
  77. VRSN, _________________ADJUST_L2_________________, _________________ADJUST_R2_________________, EEP_RST,
  78. _______, _________________ADJUST_L3_________________, _________________ADJUST_R3_________________, RGB_IDL,
  79. KEYLOCK, _______, _______, _______, _______, KC_NUKE, _______, _______, _______, _______, _______, TG_MODS
  80. )
  81. };
  82. #ifdef ENCODER_ENABLE
  83. # ifdef ENCODER_MAP_ENABLE
  84. const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = {
  85. [_DEFAULT_LAYER_1] = { { KC_DOWN, KC_UP } },
  86. [_DEFAULT_LAYER_2] = { { _______, _______ } },
  87. [_DEFAULT_LAYER_3] = { { _______, _______ } },
  88. [_DEFAULT_LAYER_4] = { { _______, _______ } },
  89. [_GAMEPAD] = { { _______, _______ } },
  90. [_DIABLO] = { { _______, _______ } },
  91. [_MOUSE] = { { KC_WH_D, KC_WH_U } },
  92. [_MEDIA] = { { _______, _______ } },
  93. [_RAISE] = { { KC_VOLD, KC_VOLU } },
  94. [_LOWER] = { { RGB_MOD, RGB_RMOD} },
  95. [_ADJUST] = { { CK_DOWN, CK_UP } },
  96. };
  97. // clang-format on
  98. # else
  99. bool encoder_update_user(uint8_t index, bool clockwise) {
  100. switch (get_highest_layer(layer_state)) {
  101. case _RAISE:
  102. clockwise ? rgblight_step() : rgblight_step_reverse();
  103. break;
  104. case _LOWER:
  105. clockwise ? rgb_matrix_step() : rgb_matrix_step_reverse();
  106. break;
  107. default:
  108. clockwise ? tap_code(KC_VOLD) : tap_code(KC_VOLU);
  109. break;
  110. }
  111. return false;
  112. }
  113. # endif // ENCODER_ENABLE
  114. #endif
  115. void rgb_matrix_indicators_user(void) {}
  116. void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
  117. uint8_t this_mod = get_mods();
  118. uint8_t this_led = host_keyboard_leds();
  119. uint8_t this_osm = get_oneshot_mods();
  120. #define THUMB_LED 6
  121. #define RGB_MATRIX_INDICATOR_SET_COLOR_wrapper(...) RGB_MATRIX_INDICATOR_SET_COLOR(__VA_ARGS__)
  122. if (!userspace_config.rgb_layer_change) {
  123. switch (get_highest_layer(layer_state | default_layer_state)) {
  124. case _GAMEPAD:
  125. rgb_matrix_layer_helper(HSV_ORANGE, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
  126. break;
  127. case _DIABLO:
  128. rgb_matrix_layer_helper(HSV_RED, 1, rgb_matrix_config.speed * 8, LED_FLAG_MODIFIER, led_min, led_max);
  129. break;
  130. case _RAISE:
  131. rgb_matrix_layer_helper(HSV_YELLOW, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
  132. break;
  133. case _LOWER:
  134. rgb_matrix_layer_helper(HSV_GREEN, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
  135. break;
  136. case _ADJUST:
  137. rgb_matrix_layer_helper(HSV_RED, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
  138. break;
  139. case _DEFAULT_LAYER_1:
  140. rgb_matrix_layer_helper(DEFAULT_LAYER_1_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
  141. break;
  142. case _DEFAULT_LAYER_2:
  143. rgb_matrix_layer_helper(DEFAULT_LAYER_2_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
  144. break;
  145. case _DEFAULT_LAYER_3:
  146. rgb_matrix_layer_helper(DEFAULT_LAYER_3_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
  147. break;
  148. case _DEFAULT_LAYER_4:
  149. rgb_matrix_layer_helper(DEFAULT_LAYER_4_HSV, 0, rgb_matrix_config.speed, LED_FLAG_MODIFIER, led_min, led_max);
  150. break;
  151. }
  152. }
  153. extern bool host_driver_disabled;
  154. if (host_driver_disabled) {
  155. RGB_MATRIX_INDICATOR_SET_COLOR_wrapper(THUMB_LED, RGB_OFF);
  156. } else {
  157. switch (get_highest_layer(default_layer_state)) {
  158. case _DEFAULT_LAYER_1:
  159. RGB_MATRIX_INDICATOR_SET_COLOR_wrapper(THUMB_LED, DEFAULT_LAYER_1_RGB);
  160. break;
  161. case _DEFAULT_LAYER_2:
  162. RGB_MATRIX_INDICATOR_SET_COLOR_wrapper(THUMB_LED, DEFAULT_LAYER_2_RGB);
  163. break;
  164. case _DEFAULT_LAYER_3:
  165. RGB_MATRIX_INDICATOR_SET_COLOR_wrapper(THUMB_LED, DEFAULT_LAYER_3_RGB);
  166. break;
  167. case _DEFAULT_LAYER_4:
  168. RGB_MATRIX_INDICATOR_SET_COLOR_wrapper(THUMB_LED, DEFAULT_LAYER_4_RGB);
  169. break;
  170. }
  171. }
  172. if ((this_mod | this_osm) & MOD_MASK_SHIFT || this_led & (1 << USB_LED_CAPS_LOCK)) {
  173. if (!layer_state_is(_ADJUST)) {
  174. RGB_MATRIX_INDICATOR_SET_COLOR(12, 0x00, 0xFF, 0x00);
  175. RGB_MATRIX_INDICATOR_SET_COLOR(13, 0x00, 0xFF, 0x00);
  176. }
  177. RGB_MATRIX_INDICATOR_SET_COLOR(24, 0x00, 0xFF, 0x00);
  178. }
  179. if ((this_mod | this_osm) & MOD_MASK_CTRL) {
  180. RGB_MATRIX_INDICATOR_SET_COLOR(11, 0xFF, 0x00, 0x00);
  181. RGB_MATRIX_INDICATOR_SET_COLOR(23, 0xFF, 0x00, 0x00);
  182. RGB_MATRIX_INDICATOR_SET_COLOR(14, 0xFF, 0x00, 0x00);
  183. }
  184. if ((this_mod | this_osm) & MOD_MASK_GUI) {
  185. RGB_MATRIX_INDICATOR_SET_COLOR(9, 0xFF, 0xD9, 0x00);
  186. }
  187. if ((this_mod | this_osm) & MOD_MASK_ALT) {
  188. RGB_MATRIX_INDICATOR_SET_COLOR(10, 0x00, 0x00, 0xFF);
  189. RGB_MATRIX_INDICATOR_SET_COLOR(25, 0x00, 0x00, 0xFF);
  190. RGB_MATRIX_INDICATOR_SET_COLOR(36, 0x00, 0x00, 0xFF);
  191. }
  192. if (layer_state_is(_LOWER)) {
  193. RGB_MATRIX_INDICATOR_SET_COLOR(7, 0x00, 0xFF, 0x00);
  194. RGB_MATRIX_INDICATOR_SET_COLOR(8, 0x00, 0xFF, 0x00);
  195. }
  196. if (layer_state_is(_RAISE)) {
  197. RGB_MATRIX_INDICATOR_SET_COLOR(4, 0xFF, 0xFF, 0x00);
  198. RGB_MATRIX_INDICATOR_SET_COLOR(5, 0xFF, 0xFF, 0x00);
  199. }
  200. }