keymap.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. #include <keymap_extras/keymap_colemak.h>
  2. #include "ergodox_ez.h"
  3. #include "debug.h"
  4. #include "action_layer.h"
  5. #define BASE 0 // default layer
  6. #define SYMB 1 // symbols
  7. #define MDIA 2 // media keys
  8. #define LSFTO M(0) // Left shift, open parens when tapped
  9. #define RSFTC M(1) // Right shift, close parens when tapped
  10. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  11. /* Keymap 0: Basic layer
  12. *
  13. * ,--------------------------------------------------. ,--------------------------------------------------.
  14. * | = | 1 | 2 | 3 | 4 | 5 | LEFT | | RIGHT| 6 | 7 | 8 | 9 | 0 | - |
  15. * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------|
  16. * | Del | Q | W | E | R | T | L1 | | L1 | Y | U | I | O | P | \ |
  17. * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
  18. * | BkSp | A | S | D | F | G |------| |------| H | Alt/J| K | L |; / L2| LGui/' |
  19. * |--------+------+------+------+------+------| Hyper| | Meh |------+------+------+------+------+--------|
  20. * |LShift/(|Z/Ctrl| X | C | V | B | [ | | ] | N | M | , | . |//Ctrl|RShift/)|
  21. * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
  22. * |Grv/L1| '" |AltShf| Left | Right| | Up | Down | [ | ] | -/L1 |
  23. * `----------------------------------' `----------------------------------'
  24. * ,-------------. ,-------------.
  25. * | App | LGui | | Alt |Ctrl/Esc|
  26. * ,------|------|------| |------+--------+------.
  27. * | | L1 | Home | | PgUp | | |
  28. * | Space| Tap/ |------| |------| Tab/L1 |Enter |
  29. * | |Toggle| End | | PgDn | | |
  30. * `--------------------' `----------------------'
  31. */
  32. // If it accepts an argument (i.e, is a function), it doesn't need KC_.
  33. // Otherwise, it needs KC_*
  34. [BASE] = KEYMAP( // layer 0 : default
  35. // left hand
  36. KC_EQL, KC_1, KC_2, KC_3, KC_4, KC_5, KC_LEFT,
  37. KC_DELT, KC_Q, KC_W, KC_E, KC_R, KC_T, TG(SYMB),
  38. KC_BSPC, KC_A, KC_S, KC_D, KC_F, KC_G,
  39. LSFTO, CTL_T(KC_Z), KC_X, KC_C, KC_V, KC_B, ALL_T(KC_LBRC),
  40. LT(SYMB,KC_GRV),KC_QUOT, LALT(KC_LSFT), KC_LEFT, KC_RGHT,
  41. ALT_T(KC_APP), KC_LGUI,
  42. KC_HOME,
  43. KC_SPC,KC_FN1,KC_END,
  44. // right hand
  45. KC_RGHT, KC_6,KC_7, KC_8, KC_9, KC_0, KC_MINS,
  46. TG(SYMB), KC_Y,KC_U, KC_I, KC_O, KC_P, KC_BSLS,
  47. KC_H,ALT_T(KC_J),KC_K, KC_L, LT(MDIA,KC_SCLN),GUI_T(KC_QUOT),
  48. MEH_T(KC_RBRC),KC_N,KC_M, KC_COMM,KC_DOT, CTL_T(KC_SLSH), RSFTC,
  49. KC_UP, KC_DOWN,KC_LBRC,KC_RBRC, LT(SYMB,KC_MINS),
  50. KC_LALT, CTL_T(KC_ESC),
  51. KC_PGUP,
  52. KC_PGDN,LT(SYMB, KC_TAB), KC_ENT
  53. ),
  54. /* Keymap 1: Symbol Layer
  55. *
  56. * ,--------------------------------------------------. ,--------------------------------------------------.
  57. * | | F1 | F2 | F3 | F4 | F5 | | | | F6 | F7 | F8 | F9 | F10 | F11 |
  58. * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------|
  59. * | | | | | | | | | | | | | | | F12 |
  60. * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
  61. * | | 1 | 2 | 3 | 4 | 5 |------| |------| & | _ | - | ; | + | |
  62. * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
  63. * | | 6 | 7 | 8 | 9 | 0 | | | | | | @ | = | % | | |
  64. * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
  65. * | | | |NxtTab|PrvTab| | | | | | |
  66. * `----------------------------------' `----------------------------------'
  67. * ,-------------. ,-------------.
  68. * | | | | | |
  69. * ,------|------|------| |------+------+------.
  70. * | | | | | | | |
  71. * | | |------| |------| | |
  72. * | | | | | | | |
  73. * `--------------------' `--------------------'
  74. */
  75. // SYMBOLS
  76. [SYMB] = KEYMAP(
  77. // left hand
  78. KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_TRNS,
  79. KC_TRNS, KC_TRNS,KC_TRNS,KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  80. KC_TRNS, KC_1, KC_2, KC_3, KC_4, KC_5,
  81. KC_TRNS, KC_6, KC_7, KC_8, KC_9, KC_0, KC_TRNS,
  82. KC_TRNS, KC_TRNS,KC_TRNS,LCTL(KC_PGUP), LCTL(KC_PGDN),
  83. KC_TRNS,KC_TRNS,
  84. KC_TRNS,
  85. KC_TRNS,KC_TRNS,KC_TRNS,
  86. // right hand
  87. KC_TRNS, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11,
  88. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_F12,
  89. KC_AMPR, KC_UNDS, KC_MINS, CM_SCLN, KC_PLUS, KC_TRNS,
  90. KC_TRNS, KC_PIPE, KC_AT, KC_EQL, KC_PERC, KC_TRNS, KC_TRNS,
  91. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  92. KC_TRNS, KC_TRNS,
  93. KC_TRNS,
  94. KC_TRNS, KC_TRNS, KC_TRNS
  95. ),
  96. /* Keymap 2: Media and mouse keys
  97. *
  98. * ,--------------------------------------------------. ,--------------------------------------------------.
  99. * | | | | | | | | | | | | | | | |
  100. * |--------+------+------+------+------+-------------| |------+------+------+------+------+------+--------|
  101. * | | | | | | | | | | | | | | | |
  102. * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
  103. * | | PgUp | Home | End | PgDn | |------| |------| | | | | | Play |
  104. * |--------+------+------+------+------+------| | | |------+------+------+------+------+--------|
  105. * | | | | | | | | | | | | Prev | Next | | |
  106. * `--------+------+------+------+------+-------------' `-------------+------+------+------+------+--------'
  107. * | | | | | | |VolUp |VolDn | Mute | | |
  108. * `----------------------------------' `----------------------------------'
  109. * ,-------------. ,-------------.
  110. * | | | | | |
  111. * ,------|------|------| |------+------+------.
  112. * | | | | | | |Brwser|
  113. * | | |------| |------| |Back |
  114. * | | | | | | | |
  115. * `--------------------' `--------------------'
  116. */
  117. // MEDIA AND MOUSE
  118. [MDIA] = KEYMAP(
  119. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  120. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  121. KC_TRNS, KC_PGUP, KC_HOME, KC_END, KC_PGDN, KC_TRNS,
  122. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  123. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  124. KC_TRNS, KC_TRNS,
  125. KC_TRNS,
  126. KC_TRNS, KC_TRNS, KC_TRNS,
  127. // right hand
  128. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  129. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
  130. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY,
  131. KC_TRNS, KC_TRNS, KC_TRNS, KC_MPRV, KC_MNXT, KC_TRNS, KC_TRNS,
  132. KC_VOLU, KC_VOLD, KC_MUTE, KC_TRNS, KC_TRNS,
  133. KC_TRNS, KC_TRNS,
  134. KC_TRNS,
  135. KC_TRNS, KC_TRNS, KC_WBAK
  136. ),
  137. };
  138. const uint16_t PROGMEM fn_actions[] = {
  139. [1] = ACTION_LAYER_TAP_TOGGLE(SYMB), // FN1 - Momentary Layer 1 (Symbols)
  140. [2] = ACTION_MACRO_TAP(0), // Eric Tang's Famous Macro!
  141. [3] = ACTION_MACRO_TAP(1) // Eric Tang's Famous Macro!
  142. };
  143. static uint16_t key_timer;
  144. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  145. {
  146. switch(id) {
  147. case 0:
  148. if (record->event.pressed) {
  149. register_mods(MOD_BIT(KC_LSFT));
  150. if (record->tap.count && !record->tap.interrupted) {
  151. register_code(KC_9);
  152. }
  153. else {
  154. record->tap.count = 0;
  155. }
  156. }
  157. else {
  158. if (record->tap.count) {
  159. unregister_code(KC_9);
  160. }
  161. else {
  162. }
  163. unregister_mods(MOD_BIT(KC_LSFT));
  164. }
  165. break;
  166. case 1:
  167. if (record->event.pressed) {
  168. register_mods(MOD_BIT(KC_LSFT));
  169. if (record->tap.count && !record->tap.interrupted) {
  170. register_code(KC_0);
  171. }
  172. else {
  173. record->tap.count = 0;
  174. }
  175. }
  176. else {
  177. if (record->tap.count) {
  178. unregister_code(KC_0);
  179. }
  180. else {
  181. }
  182. unregister_mods(MOD_BIT(KC_LSFT));
  183. }
  184. break;
  185. }
  186. return MACRO_NONE;
  187. };
  188. // Runs just one time when the keyboard initializes.
  189. void matrix_init_user(void) {
  190. };
  191. // Runs constantly in the background, in a loop.
  192. void matrix_scan_user(void) {
  193. uint8_t layer = biton32(layer_state);
  194. ergodox_board_led_off();
  195. ergodox_right_led_1_off();
  196. ergodox_right_led_2_off();
  197. ergodox_right_led_3_off();
  198. switch (layer) {
  199. // TODO: Make this relevant to the ErgoDox EZ.
  200. case 1:
  201. ergodox_right_led_1_on();
  202. break;
  203. case 2:
  204. ergodox_right_led_2_on();
  205. break;
  206. default:
  207. // none
  208. break;
  209. }
  210. };