keymap.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. #include QMK_KEYBOARD_H
  2. #include "debug.h"
  3. #include "action_layer.h"
  4. #include "eeconfig.h"
  5. #include "eeprom.h"
  6. #define LAYER_ON(pos) ((layer_state) & (1<<(pos)))
  7. #define _______ KC_TRNS
  8. #define EECONFIG_BELAK_MAGIC (uint16_t)0xBE42
  9. // NOTE: This is just a number that's a bit beyond the end of what's already
  10. // defined. As there is no other define we can base this on, it may need to be
  11. // changed in the future. The initial value here is used as a placeholder with a
  12. // magic word, similar to the normal eeconfig. Note that all the storage being
  13. // used needs to fit inside the 32 bytes of the Ergodox Infinity.
  14. #define EECONFIG_BELAK (uint16_t *)16
  15. // The correct way to do this would be how the normal eeconfig handles it and
  16. // use a bitfield. However, the eeprom has a ton of space which isn't being
  17. // used so I don't really care and have a separate byte for every setting.
  18. #define EECONFIG_BELAK_SWAP_GUI_CTRL (uint8_t *)18
  19. static uint8_t swap_gui_ctrl = 0;
  20. static uint8_t td_led_override = 0;
  21. enum belak_keycodes {
  22. // Function codes
  23. BEL_F0 = SAFE_RANGE,
  24. BEL_F1,
  25. E_SHRUG,
  26. E_TFLIP,
  27. E_TSET,
  28. };
  29. inline void tap(uint16_t keycode) {
  30. register_code(keycode);
  31. unregister_code(keycode);
  32. };
  33. // TODO: Add LED support to the tap dance by using the advanced macro
  34. #define LTOGGLE TD(TD_LAYER_TOGGLE)
  35. #define BASE 0 // default layer
  36. #define SYMB 1 // symbols
  37. #define NUMP 2 // numpad
  38. #define SWPH 3 // swap gui/ctrl on the hands
  39. enum belak_td {
  40. TD_LAYER_TOGGLE = 0,
  41. };
  42. void belak_td_each(qk_tap_dance_state_t *state, void *user_data);
  43. void belak_td_finished(qk_tap_dance_state_t *state, void *user_data);
  44. void belak_td_reset(qk_tap_dance_state_t *state, void *user_data);
  45. qk_tap_dance_action_t tap_dance_actions[] = {
  46. [TD_LAYER_TOGGLE] = ACTION_TAP_DANCE_FN_ADVANCED(belak_td_each, belak_td_finished, belak_td_reset),
  47. };
  48. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  49. /* Keymap 0: Basic layer
  50. *
  51. * ,--------------------------------------------------. ,--------------------------------------------------.
  52. * | Esc | 1 | 2 | 3 | 4 | 5 | L1 | | L2 | 6 | 7 | 8 | 9 | 0 | = |
  53. * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------|
  54. * | Tab | Q | W | E | R | T | [ | | ] | Y | U | I | O | P | - |
  55. * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
  56. * | \ | A | S | D | F | G |------| |------| H | J | K | L | ; | ' |
  57. * |--------+------+------+------+------+------| LGui | | RGui |------+------+------+------+------+--------|
  58. * | LShift | Z | X | C | V | B | | | | N | M | , | . | / | RShift |
  59. * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
  60. * |Layers| LCtrl| Left | Right| LAlt | | RAlt | Up | Down | RCtrl|Layers|
  61. * `----------------------------------' `----------------------------------'
  62. * ,-------------. ,--------------.
  63. * | ~L2 | Ins | | Grv | ~L1 |
  64. * ,-------|------|------| |------+-------+-------.
  65. * | Back | | Home | | PgUp | | |
  66. * | Space | Del |------| |------| Enter | Space |
  67. * | | | End | | PgDn | | |
  68. * `---------------------' `----------------------'
  69. */
  70. [BASE] = LAYOUT_ergodox( // layer 0 : default
  71. // left hand
  72. KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, TG(SYMB),
  73. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_LBRC,
  74. CTL_T(KC_BSLS), KC_A, KC_S, KC_D, KC_F, KC_G,
  75. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_LGUI,
  76. LTOGGLE, KC_LCTRL, KC_LEFT,KC_RGHT,KC_LALT,
  77. MO(NUMP),KC_INS,
  78. KC_HOME,
  79. CTL_T(KC_BSPC),GUI_T(KC_DEL),KC_END,
  80. // right hand
  81. TG(NUMP), KC_6, KC_7, KC_8, KC_9, KC_0, KC_EQL,
  82. KC_RBRC, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_MINS,
  83. KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  84. KC_RGUI, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT,
  85. KC_RALT,KC_UP, KC_DOWN,KC_RCTRL, LTOGGLE,
  86. KC_GRV, MO(SYMB),
  87. KC_PGUP,
  88. KC_PGDN, GUI_T(KC_ENT), CTL_T(KC_SPC)
  89. ),
  90. /* Keymap 1: Symbol Layer
  91. *
  92. * ,--------------------------------------------------. ,--------------------------------------------------.
  93. * | | F1 | F2 | F3 | F4 | F5 | | | | F6 | F7 | F8 | F9 | F10 | F11 |
  94. * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------|
  95. * | | ! | @ | { | } | | | | | | Up | | Up | | | F12 |
  96. * |--------+------+------+------+------+------| TFLIP| | TSET |------+------+------+------+------+--------|
  97. * | | # | $ | ( | ) | ` |------| |------| Down | Left | Down | Rght | | |
  98. * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
  99. * | | % | ^ | [ | ] | ~ | SHRUG| | | & | | | | | |
  100. * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
  101. * |LClear| | | | | | | | | |LClear|
  102. * `----------------------------------' `----------------------------------'
  103. * ,-------------. ,-------------.
  104. * | TOGL | | | | TOGL |
  105. * ,------|------|------| |------+------+------.
  106. * | | | | | | | |
  107. * | | |------| |------| | |
  108. * | | | | | | | |
  109. * `--------------------' `--------------------'
  110. */
  111. [SYMB] = LAYOUT_ergodox(
  112. // left hand
  113. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, E_TFLIP,
  114. _______, KC_EXLM, KC_AT, KC_LCBR, KC_RCBR, KC_PIPE, E_TSET,
  115. _______, KC_HASH, KC_DLR, KC_LPRN, KC_RPRN, KC_GRV,
  116. _______, KC_PERC, KC_CIRC, KC_LBRC, KC_RBRC, KC_TILD, E_SHRUG,
  117. BEL_F1, _______, _______, _______, _______,
  118. BEL_F0, _______,
  119. _______,
  120. _______, _______, _______,
  121. // right hand
  122. _______, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11,
  123. _______, KC_UP, _______, KC_UP, _______, _______, KC_F12,
  124. KC_DOWN, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______,
  125. _______, KC_AMPR, _______, _______, _______, _______, _______,
  126. _______, _______, _______, _______, BEL_F1,
  127. _______, BEL_F0,
  128. _______,
  129. _______, _______, _______
  130. ),
  131. /* Keymap 2: Numpad Layer
  132. *
  133. * ,--------------------------------------------------. ,--------------------------------------------------.
  134. * | | | | | | | | | | | | | | | |
  135. * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------|
  136. * | | | | | | | | | | | 7 | 8 | 9 | * | |
  137. * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
  138. * | | | | | | |------| |------| | 4 | 5 | 6 | + | |
  139. * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
  140. * | | | | | | | | | | | 1 | 2 | 3 | \ | |
  141. * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
  142. * |LClear| | | | | | 0 | 0 | . | = |LClear|
  143. * `----------------------------------' `----------------------------------'
  144. * ,-------------. ,-------------.
  145. * | TOGL | | | | TOGL |
  146. * ,------|------|------| |------+------+------.
  147. * | | | | | | | |
  148. * | | |------| |------| | |
  149. * | | | | | | | |
  150. * `--------------------' `--------------------'
  151. */
  152. [NUMP] = LAYOUT_ergodox(
  153. // left hand
  154. _______, _______, _______, _______, _______, _______, _______,
  155. _______, _______, _______, _______, _______, _______, _______,
  156. _______, _______, _______, _______, _______, _______,
  157. _______, _______, _______, _______, _______, _______, _______,
  158. BEL_F1, _______, _______, _______, _______,
  159. BEL_F0, _______,
  160. _______,
  161. _______, _______, _______,
  162. // right hand
  163. _______, _______, _______, _______, _______, _______, _______,
  164. _______, _______, KC_7, KC_8, KC_9, KC_ASTR, _______,
  165. _______, KC_4, KC_5, KC_6, KC_PLUS, _______,
  166. _______, _______, KC_1, KC_2, KC_3, KC_BSLS, _______,
  167. KC_0, KC_0, KC_DOT, KC_EQL, BEL_F1,
  168. _______, BEL_F0,
  169. _______,
  170. _______, _______, _______
  171. ),
  172. /* Keymap 3: Swap control and gui on the thumb */
  173. [SWPH] = LAYOUT_ergodox(
  174. // left hand
  175. _______, _______, _______, _______, _______, _______, _______,
  176. _______, _______, _______, _______, _______, _______, _______,
  177. _______, _______, _______, _______, _______, _______,
  178. _______, _______, _______, _______, _______, _______, _______,
  179. _______, _______, _______, _______, _______,
  180. _______, _______,
  181. _______,
  182. GUI_T(KC_BSPC), CTL_T(KC_DEL), _______,
  183. // right hand
  184. _______, _______, _______, _______, _______, _______, _______,
  185. _______, _______, _______, _______, _______, _______, _______,
  186. _______, _______, _______, _______, _______, _______,
  187. _______, _______, _______, _______, _______, _______, _______,
  188. _______, _______, _______, _______, _______,
  189. _______, _______,
  190. _______,
  191. _______, CTL_T(KC_ENT), GUI_T(KC_SPC)
  192. ),
  193. };
  194. // Runs just one time when the keyboard initializes.
  195. void matrix_init_user(void) {
  196. // If our magic word wasn't set properly, we need to zero out the settings.
  197. if (eeprom_read_word(EECONFIG_BELAK) != EECONFIG_BELAK_MAGIC) {
  198. eeprom_update_word(EECONFIG_BELAK, EECONFIG_BELAK_MAGIC);
  199. eeprom_update_byte(EECONFIG_BELAK_SWAP_GUI_CTRL, 0);
  200. }
  201. if (eeprom_read_byte(EECONFIG_BELAK_SWAP_GUI_CTRL)) {
  202. layer_on(SWPH);
  203. swap_gui_ctrl = 1;
  204. }
  205. };
  206. // Runs constantly in the background, in a loop.
  207. void matrix_scan_user(void) {
  208. ergodox_board_led_off();
  209. ergodox_right_led_1_off();
  210. ergodox_right_led_2_off();
  211. ergodox_right_led_3_off();
  212. switch (td_led_override) {
  213. case 1:
  214. ergodox_right_led_1_on();
  215. break;
  216. case 2:
  217. ergodox_right_led_2_on();
  218. break;
  219. default:
  220. // Layer 1 and 2 are both overlay layers, so they could both be on. This
  221. // means we can't use the lazy check of checking for the first significant
  222. // bit.
  223. if (LAYER_ON(SYMB)) {
  224. ergodox_right_led_1_on();
  225. }
  226. if (LAYER_ON(NUMP)) {
  227. ergodox_right_led_2_on();
  228. }
  229. }
  230. };
  231. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  232. switch (keycode) {
  233. case BEL_F0:
  234. if(record->event.pressed){
  235. swap_gui_ctrl = !swap_gui_ctrl;
  236. eeprom_update_byte(EECONFIG_BELAK_SWAP_GUI_CTRL, swap_gui_ctrl);
  237. if (swap_gui_ctrl) {
  238. layer_on(SWPH);
  239. } else {
  240. layer_off(SWPH);
  241. }
  242. return false;
  243. }
  244. break;
  245. case BEL_F1:
  246. if(record->event.pressed){
  247. layer_off(SYMB);
  248. layer_off(NUMP);
  249. return false;
  250. }
  251. break;
  252. case E_SHRUG: // ¯\_(ツ)_/¯
  253. if (record->event.pressed) {
  254. process_unicode((0x00AF|QK_UNICODE), record); // Hand
  255. tap(KC_BSLS); // Arm
  256. register_code(KC_RSFT);
  257. tap(KC_UNDS); // Arm
  258. tap(KC_LPRN); // Head
  259. unregister_code(KC_RSFT);
  260. process_unicode((0x30C4|QK_UNICODE), record); // Face
  261. register_code(KC_RSFT);
  262. tap(KC_RPRN); // Head
  263. tap(KC_UNDS); // Arm
  264. unregister_code(KC_RSFT);
  265. tap(KC_SLSH); // Arm
  266. process_unicode((0x00AF|QK_UNICODE), record); // Hand
  267. }
  268. return false;
  269. break;
  270. case E_TFLIP: // (╯°□°)╯ ︵ ┻━┻
  271. if (record->event.pressed) {
  272. register_code(KC_RSFT);
  273. tap(KC_9);
  274. unregister_code(KC_RSFT);
  275. process_unicode((0x256F|QK_UNICODE), record); // Arm
  276. process_unicode((0x00B0|QK_UNICODE), record); // Eye
  277. process_unicode((0x25A1|QK_UNICODE), record); // Mouth
  278. process_unicode((0x00B0|QK_UNICODE), record); // Eye
  279. register_code(KC_RSFT);
  280. tap(KC_0);
  281. unregister_code(KC_RSFT);
  282. process_unicode((0x256F|QK_UNICODE), record); // Arm
  283. tap(KC_SPC);
  284. process_unicode((0x0361|QK_UNICODE), record); // Flippy
  285. tap(KC_SPC);
  286. process_unicode((0x253B|QK_UNICODE), record); // Table
  287. process_unicode((0x2501|QK_UNICODE), record); // Table
  288. process_unicode((0x253B|QK_UNICODE), record); // Table
  289. }
  290. return false;
  291. break;
  292. case E_TSET: // ┬──┬ ノ( ゜-゜ノ)
  293. if (record->event.pressed) {
  294. process_unicode((0x252C|QK_UNICODE), record); // Table
  295. process_unicode((0x2500|QK_UNICODE), record); // Table
  296. process_unicode((0x2500|QK_UNICODE), record); // Table
  297. process_unicode((0x252C|QK_UNICODE), record); // Table
  298. tap(KC_SPC);
  299. process_unicode((0x30CE|QK_UNICODE), record); // Arm
  300. register_code(KC_RSFT);
  301. tap(KC_9);
  302. unregister_code(KC_RSFT);
  303. tap(KC_SPC);
  304. process_unicode((0x309C|QK_UNICODE), record); // Eye
  305. tap(KC_MINS);
  306. process_unicode((0x309C|QK_UNICODE), record); // Eye
  307. process_unicode((0x30CE|QK_UNICODE), record); // Arm
  308. register_code(KC_RSFT);
  309. tap(KC_0);
  310. unregister_code(KC_RSFT);
  311. }
  312. return false;
  313. break;
  314. }
  315. return true;
  316. }
  317. void belak_td_each(qk_tap_dance_state_t *state, void *user_data) {
  318. switch (state->count) {
  319. case 1:
  320. td_led_override = 1;
  321. break;
  322. case 2:
  323. td_led_override = 2;
  324. break;
  325. default:
  326. reset_tap_dance(state);
  327. }
  328. }
  329. void belak_td_finished(qk_tap_dance_state_t *state, void *user_data) {
  330. switch (state->count) {
  331. case 1:
  332. layer_on(SYMB);
  333. break;
  334. case 2:
  335. layer_on(NUMP);
  336. break;
  337. }
  338. td_led_override = 0;
  339. }
  340. void belak_td_reset(qk_tap_dance_state_t *state, void *user_data) {
  341. td_led_override = 0;
  342. }