keymap.c 17 KB

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