keymap.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. // Copyright 2022 Ryan Neff (@JellyTitan)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include QMK_KEYBOARD_H
  4. enum custom_layers {
  5. _QWERTY,
  6. _LOWER,
  7. _RAISE,
  8. _ADJUST,
  9. };
  10. /* Defines macros for use with the configurators "Any" key. (These are non-standard macros). */
  11. /* Move active application right half. */
  12. #define KC_CSGRA LCTL(LSFT(LGUI(KC_RGHT)))
  13. /* Move active application to left half. */
  14. #define KC_CSGLA LCTL(LSFT(LGUI(KC_LEFT)))
  15. /* Maximize active application. */
  16. #define KC_MAXIM LCTL(LSFT(LGUI(KC_UP)))
  17. /* Minimize active application. */
  18. #define KC_MINIM LCTL(LSFT(LGUI(KC_DOWN)))
  19. /* Rotary encoder variables used to hold down Command (GUI) key while cycling through open programs. */
  20. bool is_cmd_tab_active = false;
  21. uint16_t cmd_tab_timer = 0;
  22. enum custom_keycodes {
  23. QWERTY = SAFE_RANGE,
  24. LOWER,
  25. RAISE,
  26. ADJUST,
  27. CMD_TAB_CW,
  28. CMD_TAB_CCW,
  29. };
  30. /**
  31. * Tap Dance declarations
  32. */
  33. enum tapdances {
  34. _TD_FIVE_ENTER,
  35. };
  36. /* Tapdance */
  37. #define TD_FIVE_ENTER TD(_TD_FIVE_ENTER)
  38. /**
  39. * Tap Dance definitions
  40. *
  41. * NOTE - if your not using tapdance, comment out:
  42. * TAP_DANCE_ENABLE = yes in rules.mk
  43. * define TAPPING_TERM 175 in config.h
  44. * else you'll get a compile error.
  45. *
  46. * To use this in the configurator, enter the name 'TD_FIVE_ENTER' in the "Any" key.
  47. */
  48. qk_tap_dance_action_t tap_dance_actions[] = {
  49. /* Tap once for 5, twice for Enter. */
  50. [_TD_FIVE_ENTER] = ACTION_TAP_DANCE_DOUBLE(KC_5, KC_ENT),
  51. };
  52. /**
  53. * Keymap. Generated via configurator.
  54. *
  55. * You can download/upload the two_know.json to the configurator:
  56. * https://config.qmk.fm/#/keebio/iris/rev6a/LAYOUT
  57. *
  58. * If you make changes and download the json, you can run qmk json2c two_knob.json to get converted text.
  59. * You can copy and paste it here.
  60. * You will have to reneame the array keys from ints to the custom keycode names.
  61. *
  62. * The rotary encoders are programmed manually below because the configurator does not support them yet.
  63. */
  64. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  65. [_QWERTY] = LAYOUT(KC_EQL, KC_1, KC_2, KC_3, KC_4, TD_FIVE_ENTER, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS, LT(1, KC_DEL), LT(2, KC_A), LCTL_T(KC_S), KC_D, LGUI_T(KC_F), KC_G, KC_H, RGUI_T(KC_J), KC_K, RCTL_T(KC_L), LT(2, KC_SCLN), LT(1, KC_QUOT), SC_LSPO, LALT_T(KC_Z), KC_X, KC_C, KC_V, KC_B, KC_MINIM, KC_MAXIM, KC_N, KC_M, KC_COMM, KC_DOT, RALT_T(KC_SLSH), SC_RSPC, QK_GESC, KC_SPC, KC_BSPC, KC_TAB, KC_ENT, KC_DEL),
  66. [_LOWER] = LAYOUT(KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_TRNS, KC_EXLM, KC_AT, KC_LCBR, KC_RCBR, KC_PIPE, DT_PRNT, KC_7, KC_8, KC_9, KC_ASTR, KC_F12, KC_TRNS, KC_HASH, KC_DLR, KC_LPRN, KC_RPRN, KC_GRV, DT_UP, KC_4, KC_5, KC_6, KC_PPLS, KC_TRNS, KC_TRNS, KC_HASH, KC_DLR, KC_LBRC, KC_RBRC, KC_TILD, KC_TRNS, KC_TRNS, DT_DOWN, KC_1, KC_2, KC_3, KC_PSLS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_P0),
  67. [_RAISE] = LAYOUT(RGB_TOG, KC_ACL0, KC_ACL1, KC_ACL2, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_MOD, RGB_RMOD, RGB_HUI, RGB_HUD, KC_TRNS, KC_TRNS, KC_TRNS, KC_MS_U, KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN1, KC_UP, KC_BTN2, RGB_SAI, RGB_SAD, KC_TRNS, KC_TRNS, KC_MS_L, KC_MS_D, KC_MS_R, KC_TRNS, KC_TRNS, KC_LEFT, KC_DOWN, KC_RGHT, RGB_VAI, RGB_VAD, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_SPI, RGB_SPD, KC_TRNS, KC_TRNS, KC_CSGLA, KC_CSGRA, KC_TRNS, KC_TRNS),
  68. [_ADJUST] = LAYOUT(
  69. //┌────────┬────────┬────────┬────────┬────────┬────────┐ ┌────────┬────────┬────────┬────────┬────────┬────────┐
  70. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  71. //├────────┼────────┼────────┼────────┼────────┼────────┤ ├────────┼────────┼────────┼────────┼────────┼────────┤
  72. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  73. //├────────┼────────┼────────┼────────┼────────┼────────┤ ├────────┼────────┼────────┼────────┼────────┼────────┤
  74. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  75. //├────────┼────────┼────────┼────────┼────────┼────────┼────────┐ ┌────────┼────────┼────────┼────────┼────────┼────────┼────────┤
  76. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  77. //└────────┴────────┴────────┴───┬────┴───┬────┴───┬────┴───┬────┘ └───┬────┴───┬────┴───┬────┴───┬────┴────────┴────────┴────────┘
  78. _______, _______, _______, _______, _______, _______
  79. // └────────┴────────┴────────┘ └────────┴────────┴────────┘
  80. )
  81. };
  82. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  83. switch (keycode) {
  84. case LOWER:
  85. if (record->event.pressed) {
  86. layer_on(_LOWER);
  87. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  88. } else {
  89. layer_off(_LOWER);
  90. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  91. }
  92. return false;
  93. break;
  94. case RAISE:
  95. if (record->event.pressed) {
  96. layer_on(_RAISE);
  97. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  98. } else {
  99. layer_off(_RAISE);
  100. update_tri_layer(_LOWER, _RAISE, _ADJUST);
  101. }
  102. return false;
  103. case CMD_TAB_CW:
  104. if (record->event.pressed) {
  105. if (!is_cmd_tab_active) {
  106. is_cmd_tab_active = true;
  107. register_code(KC_LGUI);
  108. }
  109. cmd_tab_timer = timer_read();
  110. register_code(KC_TAB);
  111. } else {
  112. unregister_code(KC_TAB);
  113. }
  114. break;
  115. case CMD_TAB_CCW:
  116. if (record->event.pressed) {
  117. if (!is_cmd_tab_active) {
  118. is_cmd_tab_active = true;
  119. register_code(KC_LGUI);
  120. }
  121. cmd_tab_timer = timer_read();
  122. tap_code16(S(KC_TAB));
  123. } else {
  124. unregister_code(KC_TAB);
  125. }
  126. break;
  127. }
  128. return true;
  129. }
  130. /**
  131. * Define lighting layers.
  132. *
  133. * Iris rev6a uses WS2812 RGB Matrix lighting.
  134. * The RGB Matrix lighting option has already been enabled in ../../rev6a/config.h
  135. * You'll need to add #define SPLIT_LAYER_STATE_ENABLE to config.h if you
  136. * will be customizing the LED's per key.
  137. *
  138. * Here's how to customize the colors per layer and per key:
  139. * https://github.com/qmk/qmk_firmware/blob/master/docs/feature_rgb_matrix.md#direct-operation-iddirect-operation
  140. *
  141. * If you start getting real weird with it, your likely to exceed the firmware limit of 28672.
  142. * You may need to selectively disable some effects:
  143. * https://github.com/qmk/qmk_firmware/blob/master/docs/feature_rgb_matrix.md#rgb-matrix-effects-idrgb-matrix-effects
  144. *
  145. * There are 68 Leds. Printed on the board itself, the led numbers are 1-68.
  146. * For color addressing, use 0-67 as the index number.
  147. * rgb_matrix_set_color(index, r, g, b)
  148. *
  149. * Here's an LED number guide:
  150. * FRONT
  151. * Left Hand Right Hand
  152. * |00|01|02|03|04|05| |39|38|37|36|35|34|
  153. * |11|10|09|08|07|06| |40|41|42|43|44|45|
  154. * |12|13|14|15|16|17| |51|50|49|48|47|46|
  155. * |23|22|21|20|19|18|27| |61|52|53|54|55|56|57|
  156. * |24|25|26| |60|59|58|
  157. * REVERSE
  158. * Right Hand Left Hand
  159. * |65|--|--|66|--|67| |33|--|32|--|--|31|
  160. * |--|--|--|--|--|--| |--|--|--|--|--|--|
  161. * |--|--|--|--|--|--| |--|--|--|--|--|--|
  162. * |64|--|--|63|--|--|--| |--|--|--|29|--|--|30|
  163. * |--|62|--| |--|28|--|
  164. */
  165. // bool rgb_matrix_indicators_user(void) {
  166. // if (IS_LAYER_ON(1)) {
  167. // /* Upperleft most key red: */
  168. // rgb_matrix_set_color(0,255,0,0);
  169. // /* Upperright most front key blue: */
  170. // rgb_matrix_set_color(0,0,255,0);
  171. // /* Bottom right on lefthand Green: */
  172. // rgb_matrix_set_color(0, RGB_GREEN);
  173. // }
  174. // else if (IS_LAYER_ON(2)) {
  175. // /* RGB +/- controls. */
  176. // rgb_matrix_set_color(35, RGB_RED);
  177. // rgb_matrix_set_color(34, RGB_BLUE);
  178. // rgb_matrix_set_color(37, RGB_RED);
  179. // rgb_matrix_set_color(36, RGB_BLUE);
  180. // rgb_matrix_set_color(44, RGB_RED);
  181. // rgb_matrix_set_color(45, RGB_BLUE);
  182. // rgb_matrix_set_color(47, RGB_RED);
  183. // rgb_matrix_set_color(46, RGB_BLUE);
  184. // rgb_matrix_set_color(56, RGB_RED);
  185. // rgb_matrix_set_color(57, RGB_BLUE);
  186. // /* RGB Toggle. */
  187. // rgb_matrix_set_color(00, RGB_PURPLE);
  188. // /* Move screen left/right. */
  189. // rgb_matrix_set_color(26, RGB_YELLOW);
  190. // rgb_matrix_set_color(60, RGB_YELLOW);
  191. // /* Arrow keys. */
  192. // rgb_matrix_set_color(50, RGB_PURPLE);
  193. // rgb_matrix_set_color(49, RGB_PURPLE);
  194. // rgb_matrix_set_color(48, RGB_PURPLE);
  195. // rgb_matrix_set_color(42, RGB_PURPLE);
  196. // /* Mouse movement arrows. */
  197. // rgb_matrix_set_color(14, RGB_ORANGE);
  198. // rgb_matrix_set_color(15, RGB_ORANGE);
  199. // rgb_matrix_set_color(16, RGB_ORANGE);
  200. // rgb_matrix_set_color(8, RGB_ORANGE);
  201. // /* Mouse buttons. */
  202. // rgb_matrix_set_color(41, RGB_ORANGE);
  203. // rgb_matrix_set_color(43, RGB_ORANGE);
  204. // /* Mouse acceleration. */
  205. // rgb_matrix_set_color(01, 200, 165, 0);
  206. // rgb_matrix_set_color(02, 255, 200, 0);
  207. // rgb_matrix_set_color(03, 255, 235, 0);
  208. // }
  209. // return false;
  210. // }
  211. /**
  212. * Rotary Encoder.
  213. *
  214. * This can't be programmed through configurator. You must do it here.
  215. *
  216. * This uses the amazing "Encoder map" feature which replicates the normal keyswitch layer handling functionality, but with encoders.
  217. * https://docs.qmk.fm/#/feature_encoders?id=encoder-map
  218. *
  219. * Uses a variant of the Super-alt-tab macro to switch between open applications on a mac. (Command-tab)
  220. * https://docs.qmk.fm/#/feature_macros?id=super-alt%e2%86%aftab
  221. */
  222. #if defined(ENCODER_MAP_ENABLE)
  223. const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][2] = {
  224. /* Left Hand */ /* Right Hand */
  225. /* Switch between tabs. (Control + Tab). */ /* Switch between open apps on Mac. (Command + Tab + timer logic) */
  226. [_QWERTY] = { ENCODER_CCW_CW(S(C(KC_TAB)), C(KC_TAB)), ENCODER_CCW_CW(CMD_TAB_CCW, CMD_TAB_CW) },
  227. /* Scrolls left & right. (Shift + Mouse Wheel Up). */ /* Scrolls up and down. (Page Down & Page Up - mouse wheel scroll incraments are too small) */
  228. [_LOWER] = { ENCODER_CCW_CW(S(KC_MS_WH_UP), S(KC_MS_WH_DOWN)), ENCODER_CCW_CW(KC_PGDN, KC_PGUP) },
  229. /* Selects adjacent words. (Command + Shift + Right Arrow). */ /* Jumps to end/start of line. Hold shift to select. (Gui + arrow). */
  230. [_RAISE] = { ENCODER_CCW_CW(C(S(KC_LEFT)), C(S(KC_RGHT))), ENCODER_CCW_CW(G(KC_LEFT), G(KC_RGHT)) },
  231. /* Scroll through RGB Modes */ /* Right & left arrow */
  232. [_ADJUST] = { ENCODER_CCW_CW(RGB_RMOD, RGB_MOD), ENCODER_CCW_CW(KC_LEFT, KC_RGHT) },
  233. };
  234. #endif
  235. /**
  236. * Helper function for rotary encoder.
  237. *
  238. * If the timer has elapsed, the Command/Gui tab will be released.
  239. * You can adjust the milliseconds to speed up the CMD key release.
  240. */
  241. void matrix_scan_user(void) {
  242. if (is_cmd_tab_active) {
  243. if (timer_elapsed(cmd_tab_timer) > 900) {
  244. unregister_code(KC_LGUI);
  245. is_cmd_tab_active = false;
  246. }
  247. }
  248. }