keymap.c 17 KB

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