keymap.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /* Copyright 2017 Cole Markham
  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. #include "meira.h"
  17. #include "lighting.h"
  18. #ifdef RGBLIGHT_ENABLE
  19. //Following line allows macro to read current RGB settings
  20. extern rgblight_config_t rgblight_config;
  21. #endif
  22. #define _QWERTY 0
  23. #define _COLEMAK 1
  24. #define _DVORAK 2
  25. #define _LOWER 3
  26. #define _RAISE 4
  27. #define _ADJUST 16
  28. enum custom_keycodes {
  29. QWERTY = SAFE_RANGE,
  30. COLEMAK,
  31. DVORAK,
  32. LOWER,
  33. RAISE,
  34. ADJUST,
  35. };
  36. #ifdef AUDIO_ENABLE
  37. float tone_my_startup[][2] = SONG(ODE_TO_JOY);
  38. float tone_my_goodbye[][2] = SONG(ROCK_A_BYE_BABY);
  39. float tone_qwerty[][2] = SONG(QWERTY_SOUND);
  40. float tone_dvorak[][2] = SONG(DVORAK_SOUND);
  41. float tone_colemak[][2] = SONG(COLEMAK_SOUND);
  42. #endif /* AUDIO_ENABLE */
  43. // define variables for reactive RGB
  44. bool TOG_STATUS = false;
  45. int RGB_current_mode;
  46. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  47. /* Qwerty
  48. * ,-----------------------------------------------------------------------------------.
  49. * | Esc | 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. * |Adjust| Ctrl | Ctrl | Alt |Lower | Cmd |Space |Raise | Left | Down | Up |Right |
  56. * `-----------------------------------------------------------------------------------'
  57. */
  58. [_QWERTY] = KEYMAP( \
  59. KC_ESC, 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. ADJUST, KC_LCTL, KC_LALT, KC_LALT, LOWER, KC_LGUI, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \
  63. ),
  64. /* Colemak
  65. * ,-----------------------------------------------------------------------------------.
  66. * | Tab | Q | W | F | P | G | J | L | U | Y | ; | Bksp |
  67. * |------+------+------+------+------+-------------+------+------+------+------+------|
  68. * | Esc | A | R | S | T | D | H | N | E | I | O | " |
  69. * |------+------+------+------+------+------|------+------+------+------+------+------|
  70. * | Shift| Z | X | C | V | B | K | M | , | . | / |Enter |
  71. * |------+------+------+------+------+------+------+------+------+------+------+------|
  72. * |Adjust| Ctrl | Alt | GUI |Lower |Space |Space |Raise | Left | Down | Up |Right |
  73. * `-----------------------------------------------------------------------------------'
  74. */
  75. [_COLEMAK] = KEYMAP( \
  76. KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC, \
  77. KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT, \
  78. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , \
  79. ADJUST, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \
  80. ),
  81. /* Dvorak
  82. * ,-----------------------------------------------------------------------------------.
  83. * | Tab | " | , | . | P | Y | F | G | C | R | L | Bksp |
  84. * |------+------+------+------+------+-------------+------+------+------+------+------|
  85. * | Esc | A | O | E | U | I | D | H | T | N | S | / |
  86. * |------+------+------+------+------+------|------+------+------+------+------+------|
  87. * | Shift| ; | Q | J | K | X | B | M | W | V | Z |Enter |
  88. * |------+------+------+------+------+------+------+------+------+------+------+------|
  89. * |Adjust| Ctrl | Alt | GUI |Lower |Space |Space |Raise | Left | Down | Up |Right |
  90. * `-----------------------------------------------------------------------------------'
  91. */
  92. [_DVORAK] = KEYMAP( \
  93. KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_BSPC, \
  94. KC_ESC, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_SLSH, \
  95. KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_ENT , \
  96. ADJUST, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \
  97. ),
  98. /* Lower
  99. * ,-----------------------------------------------------------------------------------.
  100. * | | ! | @ | # | $ | % | ^ | & | * | ( | ) | Bksp |
  101. * |------+------+------+------+------+-------------+------+------+------+------+------|
  102. * | ~ | F1 | F2 | F3 | F4 | F5 | F6 | _ | + | | \ | | |
  103. * |------+------+------+------+------+------|------+------+------+------+------+------|
  104. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO ~ |ISO | | | |Enter |
  105. * |------+------+------+------+------+------+------+------+------+------+------+------|
  106. * | | | | | | | | Next | Vol- | Vol+ | Play |
  107. * `-----------------------------------------------------------------------------------'
  108. */
  109. [_LOWER] = KEYMAP( \
  110. _______, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL, \
  111. KC_TILD, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, \
  112. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,S(KC_NUHS),S(KC_NUBS),_______, _______, KC_QUOT, \
  113. _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END \
  114. ),
  115. /* Raise
  116. * ,-----------------------------------------------------------------------------------.
  117. * | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | Bksp |
  118. * |------+------+------+------+------+-------------+------+------+------+------+------|
  119. * | ` | F1 | F2 | F3 | F4 | F5 | F6 | - | = | [ | ] | \ |
  120. * |------+------+------+------+------+------|------+------+------+------+------+------|
  121. * | | F7 | F8 | F9 | F10 | F11 | F12 |ISO # |ISO / | | |Enter |
  122. * |------+------+------+------+------+------+------+------+------+------+------+------|
  123. * | | | | | | | | Home | PgUp | PgDn | End |
  124. * `-----------------------------------------------------------------------------------'
  125. */
  126. [_RAISE] = KEYMAP( \
  127. _______, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_DEL, \
  128. KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, \
  129. _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_NUHS, KC_NUBS, _______, _______, _______, \
  130. _______, _______, _______, _______, _______, _______, _______, _______, KC_HOME, KC_PGDN, KC_PGUP, KC_END \
  131. ),
  132. /* Adjust (Lower + Raise)
  133. * ,-----------------------------------------------------------------------------------.
  134. * | | Reset| | | | | | | | | | Del |
  135. * |------+------+------+------+------+-------------+------+------+------+------+------|
  136. * | | | |Aud on|Audoff|AGnorm|AGswap|Qwerty|Colemk|Dvorak| | |
  137. * |------+------+------+------+------+------|------+------+------+------+------+------|
  138. * | | | | | | | | | | | | |
  139. * |------+------+------+------+------+------+------+------+------+------+------+------|
  140. * | | | | | | | | | | | |
  141. * `-----------------------------------------------------------------------------------'
  142. */
  143. [_ADJUST] = KEYMAP( \
  144. BL_TOGG, RESET, _______, KC_MRWD, KC_MPLY, KC_MFFD, KC_PSCR, _______, KC_MUTE, KC_VOLD, KC_VOLU, KC_DEL, \
  145. BL_STEP, RGB_MOD, _______, AU_ON, AU_OFF, AG_NORM, AG_SWAP, QWERTY, COLEMAK, DVORAK, _______, _______, \
  146. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  147. _______, KC_PSCR, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
  148. )
  149. };
  150. const uint16_t PROGMEM fn_actions[] = {
  151. };
  152. // Setting ADJUST layer RGB back to default
  153. void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  154. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  155. #ifdef RGBLIGHT_ENABLE
  156. rgblight_mode(RGB_current_mode);
  157. #endif
  158. layer_on(layer3);
  159. } else {
  160. layer_off(layer3);
  161. }
  162. }
  163. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  164. {
  165. // MACRODOWN only works in this function
  166. switch(id) {
  167. case 0:
  168. if (record->event.pressed) {
  169. register_code(KC_RSFT);
  170. } else {
  171. unregister_code(KC_RSFT);
  172. }
  173. break;
  174. }
  175. return MACRO_NONE;
  176. };
  177. void matrix_init_user(void) {
  178. }
  179. void matrix_scan_user(void) {
  180. }
  181. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  182. switch (keycode) {
  183. case QWERTY:
  184. if (record->event.pressed) {
  185. #ifdef AUDIO_ENABLE
  186. PLAY_NOTE_ARRAY(tone_qwerty, false, 0);
  187. #endif
  188. // persistent_default_layer_set(1UL<<_QWERTY);
  189. }
  190. return false;
  191. break;
  192. case COLEMAK:
  193. if (record->event.pressed) {
  194. #ifdef AUDIO_ENABLE
  195. PLAY_NOTE_ARRAY(tone_colemak, false, 0);
  196. #endif
  197. // persistent_default_layer_set(1UL<<_COLEMAK);
  198. }
  199. return false;
  200. break;
  201. case DVORAK:
  202. if (record->event.pressed) {
  203. #ifdef AUDIO_ENABLE
  204. PLAY_NOTE_ARRAY(tone_dvorak, false, 0);
  205. #endif
  206. // persistent_default_layer_set(1UL<<_DVORAK);
  207. }
  208. return false;
  209. break;
  210. case LOWER:
  211. if (record->event.pressed) {
  212. //not sure how to have keyboard check mode and set it to a variable, so my work around
  213. //uses another variable that would be set to true after the first time a reactive key is pressed.
  214. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  215. } else {
  216. TOG_STATUS = !TOG_STATUS;
  217. #ifdef RGBLIGHT_ENABLE
  218. rgblight_mode(16);
  219. #endif
  220. }
  221. layer_on(_LOWER);
  222. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  223. } else {
  224. #ifdef RGBLIGHT_ENABLE
  225. rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  226. #endif
  227. TOG_STATUS = false;
  228. layer_off(_LOWER);
  229. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  230. }
  231. return false;
  232. break;
  233. case RAISE:
  234. if (record->event.pressed) {
  235. //not sure how to have keyboard check mode and set it to a variable, so my work around
  236. //uses another variable that would be set to true after the first time a reactive key is pressed.
  237. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  238. } else {
  239. TOG_STATUS = !TOG_STATUS;
  240. #ifdef RGBLIGHT_ENABLE
  241. rgblight_mode(15);
  242. #endif
  243. }
  244. layer_on(_RAISE);
  245. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  246. } else {
  247. #ifdef RGBLIGHT_ENABLE
  248. rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  249. #endif
  250. layer_off(_RAISE);
  251. TOG_STATUS = false;
  252. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  253. }
  254. return false;
  255. break;
  256. case ADJUST:
  257. // FIXME add RGB feedback
  258. if (record->event.pressed) {
  259. layer_on(_ADJUST);
  260. } else {
  261. layer_off(_ADJUST);
  262. }
  263. return false;
  264. break;
  265. case BL_TOGG:
  266. #ifdef BACKLIGHT_ENABLE
  267. if (record->event.pressed) {
  268. print("Enabling backlight\n");
  269. backlight_init_ports();
  270. }
  271. #endif
  272. return false;
  273. break;
  274. case BL_STEP:
  275. if (record->event.pressed) {
  276. print("Stepping backlight\n");
  277. #ifdef BACKLIGHT_ENABLE
  278. print("Really stepping backlight\n");
  279. backlight_step();
  280. #endif
  281. }
  282. return false;
  283. break;
  284. //led operations - RGB mode change now updates the RGB_current_mode to allow the right RGB mode to be set after reactive keys are released
  285. #ifdef RGBLIGHT_ENABLE
  286. case RGB_MOD:
  287. if (record->event.pressed) {
  288. rgblight_mode(RGB_current_mode);
  289. rgblight_step();
  290. RGB_current_mode = rgblight_config.mode;
  291. }
  292. return false;
  293. break;
  294. #endif
  295. // case BL_INC:
  296. // meira_inc_backlight_level();
  297. // return false;
  298. // break;
  299. }
  300. return true;
  301. }
  302. void led_set_user(uint8_t usb_led) {
  303. }