keymap.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. #include QMK_KEYBOARD_H
  2. #define MAXIMIZ A(G(KC_F))
  3. #define NXTDSPL C(A(G(KC_RIGHT)))
  4. #define BTMHALF A(G(KC_DOWN))
  5. #define TOPHALF A(G(KC_UP))
  6. #define NXTTHRD SS_LCTL(SS_LALT(SS_TAP(X_RIGHT)))
  7. #define PRVTHRD C(A(KC_LEFT))
  8. #define LT_MSTP LT(_LAYER_SELECT, KC_MSTP)
  9. #define LT_ESC LT(_LAYER_SELECT, KC_ESC)
  10. #define LT_NXTH TD(TD_SPEC)
  11. #define writeLayerLedState(layer) writePin(layer)
  12. #define layer_led_0_off B6, false
  13. #define layer_led_1_off D5, true
  14. #define layer_led_2_off B0, false
  15. #define layer_led_0_on B6, true
  16. #define layer_led_1_on D5, false
  17. #define layer_led_2_on B0, true
  18. void led_init_animation(void);
  19. void led_set_layer(int layer);
  20. void td_spectacles_finish(qk_tap_dance_state_t *state, void *user_data);
  21. void td_spectacles_reset(qk_tap_dance_state_t *state, void *user_data);
  22. enum layer_led_mode {
  23. ALL_LAYERS_OFF = -1,
  24. LAYER_0,
  25. LAYER_1,
  26. LAYER_2,
  27. LAYER_3,
  28. LAYER_4,
  29. LAYER_5,
  30. ALL_LAYERS_ON,
  31. };
  32. enum mini_layers {
  33. _MEDIA,
  34. _COPYPASTA,
  35. _SPECTACLES,
  36. _LAYER_3,
  37. _LAYER_4,
  38. _LAYER_5,
  39. _LAYER_SELECT,
  40. };
  41. enum { TD_SPEC = 0 };
  42. qk_tap_dance_action_t tap_dance_actions[] = {
  43. /* Tap once for spectacles macro, hold for layer toggle */
  44. [TD_SPEC] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, td_spectacles_finish, td_spectacles_reset),
  45. };
  46. /*
  47. * Key Layout
  48. * _____ _____ _____
  49. * | | | | | |
  50. * | 1 | | 2 | | 3 |
  51. * |_____| |_____| |_____|
  52. * _____ _____ _____
  53. * | | | | | |
  54. * | 4 | | 5 | | 6 |
  55. * |_____| |_____| |_____|
  56. *
  57. * Hold 1 and:
  58. * - press 4, 5, or 6 to change layers
  59. * - press 3 to reset, or press and hold 3 to enter DFU programming mode
  60. *
  61. * If something prevents you from using the above to reprogram, you can hold 3 while powering on as a fallback.
  62. */
  63. /* clang-format off */
  64. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  65. /*
  66. * Layer 0 (Media Keys)
  67. * _____ _____ _____
  68. * | | | | | |
  69. * |Stop | |VolUp| |Play |
  70. * |_____| |_____| |_____|
  71. * _____ _____ _____
  72. * | | | | | |
  73. * |Prev | |VolDn| |Next |
  74. * |_____| |_____| |_____|
  75. *
  76. */
  77. [_MEDIA] = LAYOUT(
  78. LT_MSTP, KC_VOLU, KC_MPLY,
  79. KC_MPRV, KC_VOLD, KC_MNXT
  80. ),
  81. /*
  82. * Layer 1 (Copy and Paste Macros)
  83. * _____ _____ _____
  84. * | | | | | |
  85. * | ESC | |Ctl+Z| |CSf+Z|
  86. * |_____| |_____| |_____|
  87. * _____ _____ _____
  88. * | | | | | |
  89. * |Ctl+X| |Ctl+C| |Ctl+V|
  90. * |_____| |_____| |_____|
  91. *
  92. */
  93. [_COPYPASTA] = LAYOUT(
  94. LT_ESC, C(KC_Z), C(S(KC_Z)),
  95. C(KC_X), C(KC_C), C(KC_V)
  96. ),
  97. /*
  98. * Layer 2 (Spectacles Macros)
  99. * _LT&_ _____ _____
  100. * | Win | | Win | | Win |
  101. * | Next| | Top | |Mximze
  102. * |_1/3_| |_1/2_| |_____|
  103. * _____ _____ _____
  104. * | Win | | Win | | Win |
  105. * | Prev| | Bot | | Next|
  106. * |_1/3_| |_1/2_| |Displ|
  107. *
  108. */
  109. [_SPECTACLES] = LAYOUT(
  110. LT_NXTH,TOPHALF,MAXIMIZ,
  111. PRVTHRD,BTMHALF,NXTDSPL
  112. ),
  113. /*
  114. * Layer 6 (Layer Select/Reset)
  115. * _____ _____ _____
  116. * | | | | | |
  117. * |None | |None | |Reset|
  118. * |_____| |_____| |_____|
  119. * _____ _____ _____
  120. * |Layer| |Layer| |Layer|
  121. * | 0 | | 1 | | 2 |
  122. * |_____| |_____| |_____|
  123. *
  124. * Layers 0, 1, and 2 have the top left button held to activate this layer.
  125. * Then press the specific layer to switch to it.
  126. *
  127. */
  128. [_LAYER_SELECT] = LAYOUT(
  129. _______, _______, RESET,
  130. TO(_MEDIA),TO(_COPYPASTA),TO(_SPECTACLES)
  131. )
  132. };
  133. /* clang-format on */
  134. /*
  135. * Knops Mini LED Numbers:
  136. * _____ _____ _____
  137. * | | | | | |
  138. * | 1 | | 2 | | 3 | <---
  139. * |_____| |_____| |_____| | These LEDs are called 'Switch LEDs'
  140. * _____ _____ _____ |----- To turn on/off these leds, use:
  141. * | | | | | | | set_switch_led( [1-6], [true/false]);
  142. * | 4 | | 5 | | 6 | <---
  143. * |_____| |_____| |_____|
  144. *
  145. * < 0 > < 1 > < 2 > <--- These front-LEDs are called 'Layer LEDs'
  146. * To turn on/off these leds, use:
  147. * set_layer_led( [0-2], [true/false] );
  148. */
  149. void set_switch_led(int ledId, bool state) {
  150. switch (ledId) {
  151. case 1:
  152. writePin(D7, state);
  153. break;
  154. case 2:
  155. writePin(readPin(B7) ? C6 : C7, state);
  156. break;
  157. case 3:
  158. writePin(D4, state);
  159. break;
  160. case 4:
  161. writePin(E6, state);
  162. break;
  163. case 5:
  164. writePin(B4, state);
  165. break;
  166. case 6:
  167. writePin(D6, state);
  168. break;
  169. }
  170. }
  171. void set_layer_led(int layerLedMode) {
  172. writeLayerLedState(layer_led_0_off);
  173. writeLayerLedState(layer_led_1_off);
  174. writeLayerLedState(layer_led_2_off);
  175. switch (layerLedMode) {
  176. case ALL_LAYERS_OFF:
  177. break;
  178. case LAYER_0:
  179. writeLayerLedState(layer_led_0_on);
  180. break;
  181. case LAYER_1:
  182. writeLayerLedState(layer_led_1_on);
  183. break;
  184. case LAYER_2:
  185. writeLayerLedState(layer_led_2_on);
  186. break;
  187. case LAYER_3:
  188. writeLayerLedState(layer_led_0_on);
  189. writeLayerLedState(layer_led_1_on);
  190. break;
  191. case LAYER_4:
  192. writeLayerLedState(layer_led_1_on);
  193. writeLayerLedState(layer_led_2_on);
  194. break;
  195. case LAYER_5:
  196. writeLayerLedState(layer_led_0_on);
  197. writeLayerLedState(layer_led_2_on);
  198. break;
  199. default:
  200. writeLayerLedState(layer_led_0_on);
  201. writeLayerLedState(layer_led_1_on);
  202. writeLayerLedState(layer_led_2_on);
  203. break;
  204. }
  205. }
  206. void led_init_animation() {
  207. for (int i = ALL_LAYERS_OFF; i <= ALL_LAYERS_ON; i++) {
  208. led_set_layer(i);
  209. }
  210. led_set_layer(LAYER_0);
  211. }
  212. /*
  213. * This function led_set_layer gets called when you switch between layers.
  214. * It allows you to turn on and off leds for each different layer and do
  215. * other cool stuff.
  216. */
  217. void led_set_layer(int layer) {
  218. switch (layer) {
  219. case ALL_LAYERS_OFF:
  220. set_switch_led(1, false);
  221. set_switch_led(2, false);
  222. set_switch_led(3, false);
  223. set_switch_led(4, false);
  224. set_switch_led(5, false);
  225. set_switch_led(6, false);
  226. case _LAYER_SELECT:
  227. set_switch_led(1, false);
  228. set_switch_led(2, false);
  229. set_switch_led(3, false);
  230. set_switch_led(4, true);
  231. set_switch_led(5, true);
  232. set_switch_led(6, true);
  233. break;
  234. default:
  235. set_switch_led(1, true);
  236. set_switch_led(2, true);
  237. set_switch_led(3, true);
  238. set_switch_led(4, true);
  239. set_switch_led(5, true);
  240. set_switch_led(6, true);
  241. break;
  242. }
  243. set_layer_led(layer);
  244. }
  245. /*
  246. * Prepare all LED ports for output
  247. */
  248. void led_init_ports() {
  249. setPinOutput(D7); // Switch 1 LED
  250. setPinOutput(C6); // Switch 2 LED Pin1
  251. setPinOutput(C7); // Switch 2 LED Pin2
  252. setPinOutput(D4); // Switch 3 LED
  253. setPinOutput(E6); // Switch 4 LED
  254. setPinOutput(B4); // Switch 5 LED
  255. setPinOutput(D6); // Switch 6 LED
  256. setPinOutput(D5); // Layer 0 LED
  257. setPinOutput(B6); // Layer 1 LED
  258. setPinOutput(B0); // Layer 2 LED
  259. }
  260. // Runs on layer change, no matter where the change was initiated
  261. layer_state_t layer_state_set_user(layer_state_t state) {
  262. set_layer_led(get_highest_layer(state));
  263. led_set_layer(get_highest_layer(state));
  264. return state;
  265. }
  266. void matrix_init_user(void) {
  267. led_init_ports();
  268. led_init_animation();
  269. }
  270. void td_spectacles_finish(qk_tap_dance_state_t *state, void *user_data) {
  271. if (state->pressed) {
  272. layer_on(_LAYER_SELECT);
  273. } else {
  274. SEND_STRING(NXTTHRD);
  275. }
  276. }
  277. void td_spectacles_reset(qk_tap_dance_state_t *state, void *user_data) { layer_off(_LAYER_SELECT); }