keymap.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. #include "planck.h"
  2. #include "action_layer.h"
  3. #include "eeconfig.h"
  4. #include "keymap_plover.h"
  5. #include "action_tapping.h"
  6. extern keymap_config_t keymap_config;
  7. // Keymap layers
  8. enum planck_layers {
  9. BASE_QWERTY_LAYER,
  10. BASE_COLEMAK_LAYER,
  11. BASE_STENO_LAYER,
  12. LOWER_LAYER,
  13. RAISE_LAYER,
  14. NAVIGATION_LAYER,
  15. GUI_LAYER,
  16. KEYBOARD_LAYER
  17. };
  18. // Key aliases for legibility
  19. #define _______ KC_TRNS
  20. #define ___x___ KC_NO
  21. // Macros
  22. enum planck_macros {
  23. LALT_BRACE,
  24. RALT_BRACE
  25. };
  26. // Dashes (macOS)
  27. #define KC_NDSH LALT(KC_MINS)
  28. #define KC_MDSH S(LALT(KC_MINS))
  29. // Window manager keys
  30. #define WM_FULL LALT(LGUI(KC_F))
  31. #define WM_NEXT LCTL(LALT(LGUI(KC_RGHT)))
  32. #define WM_PREV LCTL(LALT(LGUI(KC_LEFT)))
  33. #define WM_NW LCTL(LGUI(KC_LEFT))
  34. #define WM_N LALT(LGUI(KC_UP))
  35. #define WM_NE LCTL(LGUI(KC_RGHT))
  36. #define WM_E LALT(LGUI(KC_RGHT))
  37. #define WM_SE S(LCTL(LGUI(KC_RGHT)))
  38. #define WM_S LALT(LGUI(KC_DOWN))
  39. #define WM_SW S(LCTL(LGUI(KC_LEFT)))
  40. #define WM_W LALT(LGUI(KC_LEFT))
  41. #define WM_CNTR LALT(LGUI(KC_C))
  42. // Special key codes
  43. enum planck_keycodes {
  44. QWERTY = SAFE_RANGE,
  45. COLEMAK,
  46. STENO,
  47. LOWER,
  48. RAISE,
  49. PV_EXIT,
  50. PV_LOOK
  51. };
  52. //Tap Dance Declarations
  53. enum {
  54. TD_ESC_GRV = 0
  55. };
  56. // Tap Dance Definitions
  57. qk_tap_dance_action_t tap_dance_actions[] = {
  58. // Tap once for Esc, twice for Backspace
  59. [TD_ESC_GRV] = ACTION_TAP_DANCE_DOUBLE(KC_ESC, KC_GRV)
  60. // Other declarations would go here, separated by commas, if you have them
  61. };
  62. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  63. /* Base layer (Qwerty)
  64. * ,-----------------------------------------------------------------------.
  65. * Double tap 4 ~ | ESC | Q | W | E | R | T | Y | U | I | O | P | ' |
  66. * |-----------------------------------------------------------------------|
  67. * Tap for Tab -- |Ctrl | A | S | D | F | G | H | J | K | L |; Fn4|Ctrl | -- Tap for Enter
  68. * |-----------------------------------------------------------------------|
  69. * Tap for ( -- |Shift| Z | X | C | V | B | N | M | , | . | / |Shift| -- Tap for )
  70. * |-----------------------------------------------------------------------|
  71. * Tap for [ -- | Fn3 |Hyper| Alt |Super| Fn1 | Space | Fn2 |Super| Alt |Hyper| Fn3 | -- Tap for ]
  72. * `-----------------------------------------------------------------------'
  73. * / /
  74. * Tap for ] [ --------'-----------------------------------------------------'
  75. */
  76. [BASE_QWERTY_LAYER] = {
  77. {TD(TD_ESC_GRV), KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_QUOT},
  78. {F(5), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, F(1), F(6)},
  79. {KC_LSPO, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSPC},
  80. {F(3), ALL_T(KC_RBRC), M(LALT_BRACE), KC_LGUI, LOWER, KC_SPC, KC_BSPC, RAISE, KC_RGUI, M(RALT_BRACE), ALL_T(KC_LBRC), F(4)}
  81. },
  82. /* Base layer (Colemak)
  83. * ,-----------------------------------------------------------------------.
  84. * | | Q | W | F | P | G | J | L | U | Y | ; | |
  85. * |-----------------------------------------------------------------------|
  86. * | | A | R | S | T | D | H | N | E | I |O Fn4| |
  87. * |-----------------------------------------------------------------------|
  88. * | | Z | X | C | V | B | K | M | | | | |
  89. * |-----------------------------------------------------------------------|
  90. * | | | | | | | | | | | |
  91. * `-----------------------------------------------------------------------'
  92. */
  93. [BASE_COLEMAK_LAYER] = {
  94. {_______, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, _______},
  95. {_______, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, F(2), _______},
  96. {_______, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, _______, _______, _______, _______},
  97. {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______}
  98. },
  99. /* Base layer (Qwerty-Steno)
  100. * ,-----------------------------------------------------------------------.
  101. * | # | # | # | # | # | # | # | # | # | # | # | # |
  102. * |-----------------------------------------------------------------------|
  103. * |Look | | T | P | H | | F | P | L | T | D |
  104. * | -up | S |-----+-----+-----| * |-----+-----+-----+-----+-----|
  105. * | | | K | W | R | | R | B | G | S | Z |
  106. * |-----------------------------------------------------------------------|
  107. * |Exit | | | A | O | | E | U | | | |
  108. * `-----------------------------------------------------------------------'
  109. */
  110. [BASE_STENO_LAYER] = {
  111. {PV_NUM, PV_NUM, PV_NUM, PV_NUM, PV_NUM, PV_NUM, PV_NUM, PV_NUM, PV_NUM, PV_NUM, PV_NUM, PV_NUM},
  112. {PV_LOOK, PV_LS, PV_LT, PV_LP, PV_LH, PV_STAR, PV_STAR, PV_RF, PV_RP, PV_RL, PV_RT, PV_RD},
  113. {PV_LOOK, PV_LS, PV_LK, PV_LW, PV_LR, PV_STAR, PV_STAR, PV_RR, PV_RB, PV_RG, PV_RS, PV_RZ},
  114. {PV_EXIT, ___x___, ___x___, PV_A, PV_O, _______, _______, PV_E, PV_U, ___x___, ___x___, ___x___}
  115. },
  116. /* Numeric layer
  117. * ,-----------------------------------------------------------------------.
  118. * Application -- |D-Grv| F1 | F2 | F3 | F4 | F5 | F6 | F7 | F8 | F9 | F10 | # |
  119. * window |-----------------------------------------------------------------------|
  120. * switcher | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | |
  121. * |-----------------------------------------------------------------------|
  122. * | | - | = | ` | \ | |ndash|mdash| , | . | / | |
  123. * |-----------------------------------------------------------------------|
  124. * | | | | | | Backspace | | | | | |
  125. * `-----------------------------------------------------------------------'
  126. */
  127. [LOWER_LAYER] = {
  128. {LGUI(KC_GRV), KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, S(KC_3)},
  129. {F(5), KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, F(6)},
  130. {KC_LSPO, KC_MINS, KC_EQL, KC_GRV, KC_BSLS, ___x___, KC_NDSH, KC_MDSH, KC_COMM, KC_DOT, KC_SLSH, KC_RSPC},
  131. {F(3), ALL_T(KC_LBRC), M(LALT_BRACE), KC_LGUI, LOWER, KC_BSPC, KC_BSPC, RAISE, KC_RGUI, M(RALT_BRACE), ALL_T(KC_RBRC), F(4)}
  132. },
  133. /* Symbol layer
  134. * ,-----------------------------------------------------------------------.
  135. * | | F11 | F12 | F13 | F14 | F15 | F16 | F17 | F18 | F19 | F20 | # |
  136. * |-----------------------------------------------------------------------|
  137. * | | ! | @ | # | $ | % | ^ | & | * | ' | " | | \
  138. * |-----------------------------------------------------------------------| |-- Mostly shifted version
  139. * | | _ | + | ~ | | | |ndash|mdash| , | . | / | | / of lower layer
  140. * |-----------------------------------------------------------------------|
  141. * | | | | | | Delete | | | | | |
  142. * `-----------------------------------------------------------------------'
  143. */
  144. [RAISE_LAYER] = {
  145. {_______, KC_F11, KC_F12, KC_F13, KC_F14, KC_F15, KC_F16, KC_F17, KC_F18, KC_F19, KC_F20, S(KC_3)},
  146. {_______, S(KC_1), S(KC_2), S(KC_3), S(KC_4), S(KC_5), S(KC_6), S(KC_7), S(KC_8), KC_QUOT, S(KC_QUOT), _______},
  147. {_______, KC_UNDS, KC_PLUS, KC_TILD, KC_PIPE, ___x___, KC_NDSH, KC_MDSH, KC_COMM, KC_DOT, KC_SLSH, _______},
  148. {_______, _______, _______, _______, _______, KC_DEL, KC_DEL, _______, _______, _______, _______, _______}
  149. },
  150. /* Directional navigation layer
  151. *
  152. * Large movements -----/```````````````````\ /```````````````````\----- Vim-style arrow keys
  153. * ,-----------------------------------------------------------------------.
  154. * | | | | | | | | | | | | |
  155. * |-----------------------------------------------------------------------|
  156. * | | |Home |PgUp |PgDn | End |Left |Down | Up |Right| | |
  157. * |-----------------------------------------------------------------------|
  158. * | | | | | | | | | | | | |
  159. * |-----------------------------------------------------------------------|
  160. * | | | | | | | | | | | |
  161. * `-----------------------------------------------------------------------'
  162. */
  163. [NAVIGATION_LAYER] = {
  164. {___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___},
  165. {_______, ___x___, KC_HOME, KC_PGUP, KC_PGDN, KC_END, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, F(1), _______},
  166. {_______, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, _______},
  167. {_______, _______, _______, _______, ___x___, ___x___, ___x___, ___x___, _______, _______, _______, _______}
  168. },
  169. /* GUI (window management/mouse/media controls) layer
  170. *
  171. * Mouse keys -----/```````````````````\ /```````````````````\----- Window manager
  172. * ,-----------------------------------------------------------------------.
  173. * | |Ms B2|Ms Up|Ms B1|Ms WD| | |Prev | NW | N | NE | |
  174. * |-----------------------------------------------------------------------|
  175. * | |Ms L |Ms Dn|Ms R |Ms WU| | |Full | W |Centr| E | |
  176. * |-----------------------------------------------------------------------|
  177. * | |Ms WL|Ms B3|Ms WR| | | |Next | SW | S | SE | |
  178. * |-----------------------------------------------------------------------|
  179. * | |Prev |Play |Next |Brig-| Sleep |Brig+|Mute |Vol- |Vol+ | |
  180. * `-----------------------------------------------------------------------'
  181. * \___ Media ___/ \___ Screen/sleep __/ \___ Volume __/
  182. */
  183. [GUI_LAYER] = {
  184. {_______, KC_BTN2, KC_MS_U, KC_BTN1, KC_WH_D, ___x___, ___x___, WM_PREV, WM_NW, WM_N, WM_NE, _______},
  185. {_______, KC_MS_L, KC_MS_D, KC_MS_R, KC_WH_U, ___x___, ___x___, WM_FULL, WM_W, WM_CNTR, WM_E, _______},
  186. {_______, KC_WH_L, KC_BTN3, KC_WH_R, ___x___, ___x___, ___x___, WM_NEXT, WM_SW, WM_S, WM_SE, _______},
  187. {_______, KC_MPRV, KC_MPLY, KC_MNXT, KC_SLCK, KC_SLEP, KC_SLEP, KC_PAUS, KC_MUTE, KC_VOLD, KC_VOLU, _______}
  188. },
  189. /* Keyboard settings layer
  190. * ,-----------------------------------------------------------------------.
  191. * Firmware -- | |Reset| | | | | | | | | | |
  192. * |-----------------------------------------------------------------------|
  193. * Set layer -- | |Qwert|Colem|Steno| ... | | | | | | | |
  194. * |-----------------------------------------------------------------------|
  195. * Audio -- | |Voic-|Voic+|Mus +|Mus -|MIDI+|MIDI-| | |Aud +|Aud -| |
  196. * |-----------------------------------------------------------------------|
  197. * | | | | | | Toggle | |Toggl| BL- | BL+ | |
  198. * `-----------------------------------------------------------------------'
  199. * \_____________\_ Backlight _/
  200. */
  201. [KEYBOARD_LAYER] = {
  202. {___x___, RESET, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___},
  203. {___x___, QWERTY, COLEMAK, STENO, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___, ___x___},
  204. {___x___, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, ___x___, ___x___, AU_ON, AU_OFF, ___x___},
  205. {___x___, ___x___, ___x___, ___x___, LOWER, BL_TOGG, BL_TOGG, RAISE, BL_TOGG, BL_DEC, BL_INC, ___x___}
  206. }
  207. };
  208. const uint16_t PROGMEM fn_actions[] = {
  209. // Layer switching
  210. [1] = ACTION_LAYER_TAP_KEY(NAVIGATION_LAYER, KC_SCOLON),
  211. [2] = ACTION_LAYER_TAP_KEY(NAVIGATION_LAYER, KC_O),
  212. [3] = ACTION_LAYER_TAP_KEY(GUI_LAYER, KC_LBRACKET),
  213. [4] = ACTION_LAYER_TAP_KEY(GUI_LAYER, KC_RBRACKET),
  214. // Modifiers
  215. [5] = ACTION_MODS_TAP_KEY(MOD_LCTL, KC_TAB),
  216. [6] = ACTION_MODS_TAP_KEY(MOD_RCTL, KC_ENT),
  217. };
  218. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  219. {
  220. switch(id) {
  221. case LALT_BRACE:
  222. if (record->event.pressed) {
  223. register_mods(MOD_LALT);
  224. record->tap.interrupted = 0;
  225. } else {
  226. unregister_mods(MOD_LALT);
  227. if (record->tap.count && !record->tap.interrupted) {
  228. add_weak_mods(MOD_LSFT);
  229. register_code(KC_LBRACKET);
  230. unregister_code(KC_LBRACKET);
  231. del_weak_mods(MOD_LSFT);
  232. }
  233. record->tap.count = 0;
  234. }
  235. break;
  236. case RALT_BRACE:
  237. if (record->event.pressed) {
  238. register_mods(MOD_RALT);
  239. record->tap.interrupted = 0;
  240. } else {
  241. unregister_mods(MOD_RALT);
  242. if (record->tap.count && !record->tap.interrupted) {
  243. add_weak_mods(MOD_LSFT);
  244. register_code(KC_RBRACKET);
  245. unregister_code(KC_RBRACKET);
  246. del_weak_mods(MOD_LSFT);
  247. }
  248. record->tap.count = 0;
  249. }
  250. break;
  251. }
  252. return MACRO_NONE;
  253. }
  254. #ifdef AUDIO_ENABLE
  255. float tone_startup[][2] = SONG(STARTUP_SOUND);
  256. float tone_qwerty[][2] = SONG(QWERTY_SOUND);
  257. float tone_colemak[][2] = SONG(COLEMAK_SOUND);
  258. float tone_plover[][2] = SONG(PLOVER_SOUND);
  259. float tone_plover_gb[][2] = SONG(PLOVER_GOODBYE_SOUND);
  260. float music_scale[][2] = SONG(MUSIC_SCALE_SOUND);
  261. float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
  262. #endif
  263. void persistant_default_layer_set(uint16_t default_layer) {
  264. eeconfig_update_default_layer(default_layer);
  265. default_layer_set(default_layer);
  266. }
  267. // Send PHROPB ({PLOVER:RESUME}).
  268. void plover_resume(void) {
  269. register_code(PV_LP);
  270. register_code(PV_LH);
  271. register_code(PV_LR);
  272. register_code(PV_O);
  273. register_code(PV_RP);
  274. register_code(PV_RB);
  275. unregister_code(PV_LP);
  276. unregister_code(PV_LH);
  277. unregister_code(PV_LR);
  278. unregister_code(PV_O);
  279. unregister_code(PV_RP);
  280. unregister_code(PV_RB);
  281. }
  282. // Send PHROF ({PLOVER:SUSPEND}).
  283. void plover_suspend(void) {
  284. register_code(PV_LP);
  285. register_code(PV_LH);
  286. register_code(PV_LR);
  287. register_code(PV_O);
  288. register_code(PV_RF);
  289. unregister_code(PV_LP);
  290. unregister_code(PV_LH);
  291. unregister_code(PV_LR);
  292. unregister_code(PV_O);
  293. unregister_code(PV_RF);
  294. }
  295. // Send PHROBG ({PLOVER:LOOKUP}).
  296. void plover_lookup(void) {
  297. register_code(PV_LP);
  298. register_code(PV_LH);
  299. register_code(PV_LR);
  300. register_code(PV_O);
  301. register_code(PV_RB);
  302. register_code(PV_RG);
  303. unregister_code(PV_LP);
  304. unregister_code(PV_LH);
  305. unregister_code(PV_LR);
  306. unregister_code(PV_O);
  307. unregister_code(PV_RB);
  308. unregister_code(PV_RG);
  309. }
  310. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  311. switch (keycode) {
  312. case QWERTY:
  313. if (record->event.pressed) {
  314. persistant_default_layer_set(1UL<<BASE_QWERTY_LAYER);
  315. }
  316. return false;
  317. case COLEMAK:
  318. if (record->event.pressed) {
  319. persistant_default_layer_set(1UL<<BASE_COLEMAK_LAYER);
  320. }
  321. return false;
  322. case LOWER:
  323. if (record->event.pressed) {
  324. layer_on(LOWER_LAYER);
  325. update_tri_layer(LOWER_LAYER, RAISE_LAYER, KEYBOARD_LAYER);
  326. } else {
  327. layer_off(LOWER_LAYER);
  328. update_tri_layer(LOWER_LAYER, RAISE_LAYER, KEYBOARD_LAYER);
  329. }
  330. return false;
  331. case RAISE:
  332. if (record->event.pressed) {
  333. layer_on(RAISE_LAYER);
  334. update_tri_layer(LOWER_LAYER, RAISE_LAYER, KEYBOARD_LAYER);
  335. } else {
  336. layer_off(RAISE_LAYER);
  337. update_tri_layer(LOWER_LAYER, RAISE_LAYER, KEYBOARD_LAYER);
  338. }
  339. return false;
  340. case STENO:
  341. if (record->event.pressed) {
  342. layer_off(RAISE_LAYER);
  343. layer_off(LOWER_LAYER);
  344. layer_off(KEYBOARD_LAYER);
  345. layer_on(BASE_STENO_LAYER);
  346. if (!eeconfig_is_enabled()) {
  347. eeconfig_init();
  348. }
  349. keymap_config.raw = eeconfig_read_keymap();
  350. keymap_config.nkro = 1;
  351. eeconfig_update_keymap(keymap_config.raw);
  352. plover_resume();
  353. }
  354. return false;
  355. case PV_EXIT:
  356. if (record->event.pressed) {
  357. plover_suspend();
  358. layer_off(BASE_STENO_LAYER);
  359. }
  360. return false;
  361. case PV_LOOK:
  362. if (record->event.pressed) {
  363. plover_lookup();
  364. }
  365. return false;
  366. }
  367. return true;
  368. }
  369. void matrix_init_user(void) {
  370. #ifdef AUDIO_ENABLE
  371. startup_user();
  372. #endif
  373. }