Indigosun

keymap.c/rev6

Jun 15th, 2019
142
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Copyright 2015-2017 Jack Humbert
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16.  
  17. #include "planck.h"
  18. #include "action_layer.h"
  19. #include "muse.h"
  20.  
  21. extern keymap_config_t keymap_config;
  22.  
  23. enum planck_layers {
  24. _QWERTY,
  25. _COLEMAK,
  26. _DVORAK,
  27. _LOWER,
  28. _RAISE,
  29. _PLOVER,
  30. _ADJUST
  31. };
  32.  
  33. enum planck_keycodes {
  34. QWERTY = SAFE_RANGE,
  35. COLEMAK,
  36. DVORAK,
  37. PLOVER,
  38. BACKLIT,
  39. EXT_PLV
  40. };
  41.  
  42. #define LOWER MO(_LOWER)
  43. #define RAISE MO(_RAISE)
  44.  
  45. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  46.  
  47. /* Qwerty
  48. * ,-----------------------------------------------------------------------------------.
  49. * | Mute | Q | W | E | R | T | Y | U | I | O | P | Bksp |
  50. * |------+------+------+------+------+-------------+------+------+------+------+------|
  51. * | Tab | A | S | D | F | G | H | J | K | L | ; | " |
  52. * |------+------+------+------+------+------|------+------+------+------+------+------|
  53. * | Shift| Z | X | C | V | B | N | M | , | . | / |Enter |
  54. * |------+------+------+------+------+------+------+------+------+------+------+------|
  55. * | Ctrl | Del | Alt | GUI |Lower | Esc | Spc |Raise | Left | Up | Down |Right |
  56. * `-----------------------------------------------------------------------------------'
  57. */
  58. [_QWERTY] = LAYOUT_planck_grid(
  59. KC_MUTE, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  60. KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  61. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT ,
  62. KC_LCTL, KC_DEL, KC_LALT, KC_LGUI, LOWER, KC_ESC, KC_SPC, RAISE, KC_LEFT, KC_UP, KC_DOWN, KC_RGHT
  63. ),
  64.  
  65. /* Lower
  66. * ,-----------------------------------------------------------------------------------.
  67. * |Sleep | F1 | F2 | F3 | F4 | | | | { | } | | |
  68. * |------+------+------+------+------+-------------+------+------+------+------+------|
  69. * | ~ | F5 | F6 | F7 | F5 | | | | ( | ) | | | |
  70. * |------+------+------+------+------+------|------+------+------+------+------+------|
  71. * | Caps | F9 | F10 | F11 | F12 | | | | [ | ] | | |
  72. * |------+------+------+------+------+------+------+------+------+------+------+------|
  73. * | | | | | | Esc | - | | | | | |
  74. * `-----------------------------------------------------------------------------------'
  75. */
  76. [_LOWER] = LAYOUT_planck_grid(
  77. KC_SLEP, KC_F1, KC_F2, KC_F3, KC_F4, _______, _______, _______, KC_LCBR, KC_RCBR, _______, _______,
  78. KC_TILD, KC_F5, KC_F6, KC_F7, KC_F8, _______, _______, _______, KC_LPRN, KC_RPRN, _______, KC_PIPE,
  79. KC_CAPS, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______, _______, KC_LBRC, KC_RBRC, _______, _______,
  80. _______, _______, _______, _______, _______, KC_ESC, KC_PMNS, _______, _______, _______, _______, _______
  81. ),
  82.  
  83. /* Raise
  84. * ,-----------------------------------------------------------------------------------.
  85. * | Pwr | ! | @ | # | $ | | | PrSc | 7 | 8 | 9 | * |
  86. * |------+------+------+------+------+-------------+------+------+------+------+------|
  87. * | ` | % | ^ | & | * | | | Home | 4 | 5 | 6 | \ |
  88. * |------+------+------+------+------+------|------+------+------+------+------+------|
  89. * | | | | | | | | End | 1 | 2 | 3 | = |
  90. * |------+------+------+------+------+------+------+------+------+------+------+------|
  91. * | | | | | | Esc | _ | | 0 | . | - | + |
  92. * `-----------------------------------------------------------------------------------'
  93. */
  94. [_RAISE] = LAYOUT_planck_grid(
  95. KC_PWR, KC_EXLM, KC_AT, KC_HASH, KC_DLR, _______, _______, KC_PSCR, KC_7, KC_8, KC_9, KC_PAST,
  96. KC_GRV, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, _______, _______, KC_HOME, KC_4, KC_5, KC_6, KC_BSLS,
  97. _______, _______, _______, _______, _______, _______, _______, KC_END, KC_1, KC_2, KC_3, KC_PEQL,
  98. _______, _______, _______, _______, _______, KC_ESC, KC_UNDS, _______, KC_0, KC_DOT, KC_MINS, KC_PPLS
  99. ),
  100.  
  101. /* Adjust (Lower + Raise)
  102. * ,-----------------------------------------------------------------------------------.
  103. * |Reset | | | | | | | | | | | |
  104. * |------+------+------+------+------+-------------+------+------+------+------+------|
  105. * | |Audio | | | | | | | | | | |
  106. * |------+------+------+------+------+------|------+------+------+------+------+------|
  107. * | | | | | | | | | | | | |
  108. * |------+------+------+------+------+------+------+------+------+------+------+------|
  109. * | | | | | |Reset | | | |QWERTY|COLMK | |
  110. * `-----------------------------------------------------------------------------------'
  111. */
  112. [_ADJUST] = LAYOUT_planck_grid(
  113. RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  114. _______, AU_TOG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  115. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  116. _______, _______, _______, _______, _______, RESET, _______, _______, _______, QWERTY, COLEMAK, _______
  117. ),
  118.  
  119. /* Colemak
  120. * ,-----------------------------------------------------------------------------------.
  121. * | Tab | Q | W | F | P | G | J | L | U | Y | ; | Bksp |
  122. * |------+------+------+------+------+-------------+------+------+------+------+------|
  123. * | Esc | A | R | S | T | D | H | N | E | I | O | " |
  124. * |------+------+------+------+------+------|------+------+------+------+------+------|
  125. * | Shift| Z | X | C | V | B | K | M | , | . | / |Enter |
  126. * |------+------+------+------+------+------+------+------+------+------+------+------|
  127. * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
  128. * `-----------------------------------------------------------------------------------'
  129. */
  130. [_COLEMAK] = LAYOUT_planck_grid(
  131. KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC,
  132. KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT,
  133. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT ,
  134. BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  135. ),
  136.  
  137. /* Dvorak
  138. * ,-----------------------------------------------------------------------------------.
  139. * | Tab | " | , | . | P | Y | F | G | C | R | L | Bksp |
  140. * |------+------+------+------+------+-------------+------+------+------+------+------|
  141. * | Esc | A | O | E | U | I | D | H | T | N | S | / |
  142. * |------+------+------+------+------+------|------+------+------+------+------+------|
  143. * | Shift| ; | Q | J | K | X | B | M | W | V | Z |Enter |
  144. * |------+------+------+------+------+------+------+------+------+------+------+------|
  145. * | Brite| Ctrl | Alt | GUI |Lower | Space |Raise | Left | Down | Up |Right |
  146. * `-----------------------------------------------------------------------------------'
  147. */
  148. [_DVORAK] = LAYOUT_planck_grid(
  149. KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC,
  150. KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH,
  151. KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT ,
  152. BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT
  153. ),
  154.  
  155. /* Plover layer (http://opensteno.org)
  156. * ,-----------------------------------------------------------------------------------.
  157. * | # | # | # | # | # | # | # | # | # | # | # | # |
  158. * |------+------+------+------+------+-------------+------+------+------+------+------|
  159. * | | S | T | P | H | * | * | F | P | L | T | D |
  160. * |------+------+------+------+------+------|------+------+------+------+------+------|
  161. * | | S | K | W | R | * | * | R | B | G | S | Z |
  162. * |------+------+------+------+------+------+------+------+------+------+------+------|
  163. * | Exit | | | A | O | | E | U | | | |
  164. * `-----------------------------------------------------------------------------------'
  165. */
  166.  
  167. [_PLOVER] = LAYOUT_planck_grid(
  168. KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1, KC_1 ,
  169. XXXXXXX, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC,
  170. XXXXXXX, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  171. EXT_PLV, XXXXXXX, XXXXXXX, KC_C, KC_V, XXXXXXX, XXXXXXX, KC_N, KC_M, XXXXXXX, XXXXXXX, XXXXXXX
  172. ),
  173. };
  174.  
  175. #ifdef AUDIO_ENABLE
  176. float plover_song[][2] = SONG(PLOVER_SOUND);
  177. float plover_gb_song[][2] = SONG(PLOVER_GOODBYE_SOUND);
  178. #endif
  179.  
  180. uint32_t layer_state_set_user(uint32_t state) {
  181. return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
  182. }
  183.  
  184. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  185. switch (keycode) {
  186. case QWERTY:
  187. if (record->event.pressed) {
  188. print("mode just switched to qwerty and this is a huge string\n");
  189. set_single_persistent_default_layer(_QWERTY);
  190. }
  191. return false;
  192. break;
  193. case COLEMAK:
  194. if (record->event.pressed) {
  195. set_single_persistent_default_layer(_COLEMAK);
  196. }
  197. return false;
  198. break;
  199. case DVORAK:
  200. if (record->event.pressed) {
  201. set_single_persistent_default_layer(_DVORAK);
  202. }
  203. return false;
  204. break;
  205. case BACKLIT:
  206. if (record->event.pressed) {
  207. register_code(KC_RSFT);
  208. #ifdef BACKLIGHT_ENABLE
  209. backlight_step();
  210. #endif
  211. #ifdef KEYBOARD_planck_rev5
  212. PORTE &= ~(1<<6);
  213. #endif
  214. } else {
  215. unregister_code(KC_RSFT);
  216. #ifdef KEYBOARD_planck_rev5
  217. PORTE |= (1<<6);
  218. #endif
  219. }
  220. return false;
  221. break;
  222. case PLOVER:
  223. if (record->event.pressed) {
  224. #ifdef AUDIO_ENABLE
  225. stop_all_notes();
  226. PLAY_SONG(plover_song);
  227. #endif
  228. layer_off(_RAISE);
  229. layer_off(_LOWER);
  230. layer_off(_ADJUST);
  231. layer_on(_PLOVER);
  232. if (!eeconfig_is_enabled()) {
  233. eeconfig_init();
  234. }
  235. keymap_config.raw = eeconfig_read_keymap();
  236. keymap_config.nkro = 1;
  237. eeconfig_update_keymap(keymap_config.raw);
  238. }
  239. return false;
  240. break;
  241. case EXT_PLV:
  242. if (record->event.pressed) {
  243. #ifdef AUDIO_ENABLE
  244. PLAY_SONG(plover_gb_song);
  245. #endif
  246. layer_off(_PLOVER);
  247. }
  248. return false;
  249. break;
  250. }
  251. return true;
  252. }
  253.  
  254. bool muse_mode = false;
  255. uint8_t last_muse_note = 0;
  256. uint16_t muse_counter = 0;
  257. uint8_t muse_offset = 70;
  258. uint16_t muse_tempo = 50;
  259.  
  260. void encoder_update(bool clockwise) {
  261. if (IS_LAYER_ON(_RAISE)) {
  262. if (clockwise) {
  263. register_code (KC_PGUP);
  264. unregister_code (KC_PGUP);
  265. } else {
  266. register_code (KC_PGDN);
  267. unregister_code (KC_PGDN);
  268. }
  269. }
  270. if (IS_LAYER_ON(_LOWER)) {
  271. if (clockwise) {
  272. register_code (KC_MS_WH_UP);
  273. unregister_code (KC_MS_WH_UP);
  274. } else {
  275. register_code (KC_MS_WH_DOWN);
  276. unregister_code (KC_MS_WH_DOWN);
  277. }
  278. } else {
  279. if (clockwise) {
  280. register_code(KC_VOLU);
  281. unregister_code(KC_VOLU);
  282. } else {
  283. register_code(KC_VOLD);
  284. unregister_code(KC_VOLD);
  285. }
  286. }
  287. }
  288.  
  289. void dip_update(uint8_t index, bool active) {
  290. switch (index) {
  291. case 0:
  292. if (active) {
  293. #ifdef AUDIO_ENABLE
  294. PLAY_SONG(plover_song);
  295. #endif
  296. layer_on(_ADJUST);
  297. } else {
  298. #ifdef AUDIO_ENABLE
  299. PLAY_SONG(plover_gb_song);
  300. #endif
  301. layer_off(_ADJUST);
  302. }
  303. break;
  304. case 1:
  305. if (active) {
  306. muse_mode = true;
  307. } else {
  308. muse_mode = false;
  309. #ifdef AUDIO_ENABLE
  310. stop_all_notes();
  311. #endif
  312. }
  313. }
  314. }
  315.  
  316. bool music_mask_user(uint16_t keycode) {
  317. switch (keycode) {
  318. case RAISE:
  319. case LOWER:
  320. return false;
  321. default:
  322. return true;
  323. }
  324. }
  325.  
  326. void matrix_scan_user(void) {
  327. #ifdef AUDIO_ENABLE
  328. if (muse_mode) {
  329. if (muse_counter == 0) {
  330. uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
  331. if (muse_note != last_muse_note) {
  332. stop_note(compute_freq_for_midi_note(last_muse_note));
  333. play_note(compute_freq_for_midi_note(muse_note), 0xF);
  334. last_muse_note = muse_note;
  335. }
  336. }
  337. muse_counter = (muse_counter + 1) % muse_tempo;
  338. }
  339. #endif
  340. }
RAW Paste Data