1
0

keymap.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /*
  2. Copyright 2020 Jacob Jerrell <jacob.jerrell@gmail.com> @JacobJerrell
  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 "bocaj.h"
  15. #ifdef BACKLIGHT_ENABLE
  16. enum planck_keycodes {
  17. BACKLIT = NEW_SAFE_RANGE,
  18. TH_LVL,
  19. };
  20. #else
  21. # define BACKLIT OSM(MOD_LSFT)
  22. enum planck_keycodes {
  23. TH_LVL = NEW_SAFE_RANGE,
  24. };
  25. #endif
  26. /*
  27. * Tap/Hold Wrapper
  28. * ,-----------------------------------------------------------------------------------.
  29. * | | | | | | | | | | | | |
  30. * |------+------+------+------+------+------+------+------+------+------+------+------|
  31. * | | |Shift | Cmd | Alt | | | Alt | Cmd |Shift | | |
  32. * |------+------+------+------+------+------+------+------+------+------+------+------|
  33. * | | Ctrl | | | | | | | | | Ctrl | |
  34. * |------+------+------+------+------+------+------+------+------+------+------+------|
  35. * | | | | |Lower | |Raise | | | | |
  36. * `-----------------------------------------------------------------------------------'
  37. */
  38. #define LAYOUT_ortho_4x12_bocaj(...) WRAPPER_planck_bocaj(__VA_ARGS__)
  39. /*
  40. * Base Alphanumeric Wrapper + Tap/Hold Wrapper
  41. * ,-----------------------------------------------------------------------------------.
  42. * | Esc | | | | | | | | | | | - |
  43. * |------+------+------+------+------+------+------+------+------+------+------+------|
  44. * | Tab | | | | | HYPR | MEH | | | | | ' |
  45. * |------+------+------+------+------+------+------+------+------+------+------+------|
  46. * | Shift| | | | | | | | | | | TTMOD|
  47. * |------+------+------+------+------+------+------+------+------+------+------+------|
  48. * | MOMOD| Lead | Up | Left |BkSpc | Space |Enter |Right | Down | XXX | XXX |
  49. * `-----------------------------------------------------------------------------------'
  50. */
  51. #define LAYOUT_ortho_4x12_bocaj_base(...) WRAPPER_planck_bocaj_base(__VA_ARGS__)
  52. #define LAYOUT_ortho_4x12_bocaj_base_WIN(...) WRAPPER_planck_bocaj_base_WIN(__VA_ARGS__)
  53. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  54. [_WORKMAN] = LAYOUT_ortho_4x12_bocaj_base(
  55. _________________WORKMAN_L1________________, _________________WORKMAN_R1________________,
  56. _________________WORKMAN_L2________________, _________________WORKMAN_R2________________,
  57. _________________WORKMAN_L3________________, _________________WORKMAN_R3________________
  58. ),
  59. [_WWORKMAN] = LAYOUT_ortho_4x12_bocaj_base_WIN(
  60. _________________WORKMAN_L1________________, _________________WORKMAN_R1________________,
  61. _________________WORKMAN_L2________________, _________________WORKMAN_R2________________,
  62. _________________WORKMAN_L3________________, _________________WORKMAN_R3________________
  63. ),
  64. [_QWERTY] = LAYOUT_ortho_4x12_bocaj_base(
  65. _________________QWERTY_L1_________________, _________________QWERTY_R1_________________,
  66. _________________QWERTY_L2_________________, _________________QWERTY_R2_________________,
  67. _________________QWERTY_L3_________________, _________________QWERTY_R3_________________
  68. ),
  69. [_WQWERTY] = LAYOUT_ortho_4x12_bocaj_base_WIN(
  70. _________________QWERTY_L1_________________, _________________QWERTY_R1_________________,
  71. _________________QWERTY_L2_________________, _________________QWERTY_R2_________________,
  72. _________________QWERTY_L3_________________, _________________QWERTY_R3_________________
  73. ),
  74. [_LOWER] = LAYOUT_ortho_4x12_bocaj(
  75. ___________________LOWER_L1_EXT____________________, ___________________LOWER_R1_EXT____________________,
  76. ___________________LOWER_L2_EXT____________________, ___________________LOWER_R2_EXT____________________,
  77. ___________________LOWER_L3_EXT____________________, ___________________LOWER_R3_EXT____________________,
  78. _______, _______, _______, _______, _______, _______, _______, KC_0, KC_DOT, KC_COMM, _______, _______
  79. ),
  80. [_RAISE] = LAYOUT_ortho_4x12_bocaj(
  81. KC_TILD, _________________RAISE_L1__________________, _________________RAISE_R1__________________, KC_EQUAL,
  82. KC_F11, _________________RAISE_L2__________________, _________________RAISE_R2__________________, KC_F12,
  83. _______, _________________RAISE_L3__________________, _________________RAISE_R3__________________, _______,
  84. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  85. ),
  86. [_ADJUST] = WRAPPER_ortho_4x12(
  87. KC_MAKE, _________________ADJUST_L1_________________, _________________ADJUST_R1_________________, KC_RST,
  88. VRSN, _________________ADJUST_L2_________________, _________________ADJUST_R2_________________, EEP_RST,
  89. TH_LVL, _________________ADJUST_L3_________________, _________________ADJUST_R3_________________, RGB_IDL,
  90. HPT_TOG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
  91. )
  92. };
  93. // clang-format on
  94. bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  95. switch (keycode) {
  96. #ifdef BACKLIGHT_ENABLE
  97. case BACKLIT:
  98. if (record->event.pressed) {
  99. register_code(KC_RSFT);
  100. # ifdef BACKLIGHT_ENABLE
  101. backlight_step();
  102. # endif
  103. } else {
  104. unregister_code(KC_RSFT);
  105. }
  106. break;
  107. #endif
  108. #ifdef KEYBOARD_planck_ez
  109. case TH_LVL:
  110. if (record->event.pressed) {
  111. keyboard_config.led_level++;
  112. if (keyboard_config.led_level > 4) {
  113. keyboard_config.led_level = 0;
  114. }
  115. planck_ez_right_led_level((uint8_t)keyboard_config.led_level * 255 / 4);
  116. planck_ez_left_led_level((uint8_t)keyboard_config.led_level * 255 / 4);
  117. eeconfig_update_kb(keyboard_config.raw);
  118. layer_state_set_kb(layer_state);
  119. }
  120. break;
  121. #endif
  122. }
  123. return true;
  124. }
  125. bool music_mask_user(uint16_t keycode) {
  126. switch (keycode) {
  127. default:
  128. return true;
  129. }
  130. }
  131. #ifdef RGB_MATRIX_ENABLE
  132. // clang-format off
  133. void suspend_power_down_keymap(void) {
  134. rgb_matrix_set_suspend_state(true);
  135. }
  136. void suspend_wakeup_init_keymap(void) {
  137. rgb_matrix_set_suspend_state(false);
  138. }
  139. // clang-format on
  140. void rgb_matrix_indicators_user(void) {
  141. uint8_t this_mod = get_mods();
  142. uint8_t this_led = host_keyboard_leds();
  143. uint8_t this_osm = get_oneshot_mods();
  144. bool is_ez;
  145. # ifdef KEYBOARD_planck_ez
  146. is_ez = true;
  147. # endif
  148. if (g_suspend_state || !rgb_matrix_config.enable) return;
  149. # if defined(RGBLIGHT_ENABLE)
  150. if (!userspace_config.rgb_layer_change)
  151. # else
  152. if (userspace_config.rgb_layer_change)
  153. # endif
  154. {
  155. switch (get_highest_layer(layer_state)) {
  156. case _MOD:
  157. rgb_matrix_layer_helper(HSV_ORANGE, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER);
  158. break;
  159. case _RAISE:
  160. rgb_matrix_layer_helper(HSV_BLUE, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER);
  161. break;
  162. case _LOWER:
  163. rgb_matrix_layer_helper(HSV_GREEN, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER);
  164. break;
  165. case _ADJUST:
  166. rgb_matrix_layer_helper(HSV_RED, 1, rgb_matrix_config.speed, LED_FLAG_MODIFIER);
  167. break;
  168. default: {
  169. bool mods_enabled = false;
  170. switch (get_highest_layer(default_layer_state)) {
  171. case _QWERTY:
  172. rgb_matrix_layer_helper(HSV_CYAN, mods_enabled, rgb_matrix_config.speed, LED_FLAG_MODIFIER);
  173. break;
  174. case _WQWERTY:
  175. rgb_matrix_layer_helper(HSV_BLUE, mods_enabled, rgb_matrix_config.speed, LED_FLAG_MODIFIER);
  176. break;
  177. case _WORKMAN:
  178. rgb_matrix_layer_helper(HSV_SPRINGGREEN, mods_enabled, rgb_matrix_config.speed, LED_FLAG_MODIFIER);
  179. break;
  180. case _WWORKMAN:
  181. rgb_matrix_layer_helper(HSV_GREEN, mods_enabled, rgb_matrix_config.speed, LED_FLAG_MODIFIER);
  182. break;
  183. }
  184. break;
  185. }
  186. }
  187. }
  188. switch (get_highest_layer(default_layer_state)) {
  189. case _QWERTY:
  190. rgb_matrix_set_color(is_ez ? 41 : 42, 0x00, 0xFF, 0xFF);
  191. break;
  192. case _WORKMAN:
  193. rgb_matrix_set_color(is_ez ? 41 : 42, 0xD9, 0xA5, 0x21);
  194. break;
  195. }
  196. if ((this_mod | this_osm) & MODS_SHIFT_MASK || this_led & (1 << USB_LED_CAPS_LOCK)) {
  197. rgb_matrix_set_color_row(0, 0x00, 0xFF, 0x00);
  198. }
  199. if ((this_mod | this_osm) & MODS_CTRL_MASK && (this_mod | this_osm) & MODS_GUI_MASK) {
  200. rgb_matrix_set_color_row(1, 0xFF, 0xD9, 0xFF);
  201. } else if ((this_mod | this_osm) & MODS_CTRL_MASK) {
  202. rgb_matrix_set_color_row(1, 0xFF, 0x00, 0x00);
  203. } else if ((this_mod | this_osm) & MODS_GUI_MASK) {
  204. rgb_matrix_set_color_row(1, 0xFF, 0xD9, 0x00);
  205. }
  206. if ((this_mod | this_osm) & MODS_ALT_MASK) {
  207. rgb_matrix_set_color_row(2, 0x00, 0x00, 0xFF);
  208. }
  209. }
  210. #endif // RGB_MATRIX_INIT
  211. void matrix_init_keymap(void) {}
  212. #ifdef ENCODER_ENABLE
  213. bool encoder_update_user(uint8_t index, bool clockwise) {
  214. switch (get_highest_layer(layer_state)) {
  215. case _RAISE:
  216. clockwise ? tap_code(KC_VOLD) : tap_code(KC_VOLU);
  217. break;
  218. case _LOWER:
  219. # ifdef RGB_MATRIX_ENABLE
  220. clockwise ? rgb_matrix_step() : rgb_matrix_step_reverse();
  221. # else
  222. clockwise ? tap_code(KC_PGDN) : tap_code(KC_PGUP);
  223. # endif
  224. break;
  225. case _ADJUST:
  226. # ifdef AUDIO_CLICKY
  227. clockwise ? clicky_freq_up() : clicky_freq_down();
  228. # endif
  229. break;
  230. default:
  231. clockwise ? tap_code(KC_DOWN) : tap_code(KC_UP);
  232. }
  233. # ifdef AUDIO_CLICKY
  234. clicky_play();
  235. # endif
  236. return true;
  237. }
  238. #endif // ENCODER_ENABLE
  239. #ifdef KEYBOARD_planck_ez
  240. layer_state_t layer_state_set_keymap(layer_state_t state) {
  241. planck_ez_left_led_off();
  242. planck_ez_right_led_off();
  243. switch (get_highest_layer(state)) {
  244. case _LOWER:
  245. planck_ez_left_led_on();
  246. break;
  247. case _RAISE:
  248. planck_ez_right_led_on();
  249. break;
  250. case _ADJUST:
  251. planck_ez_right_led_on();
  252. planck_ez_left_led_on();
  253. break;
  254. default:
  255. break;
  256. }
  257. return state;
  258. }
  259. #endif