keymap.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. #include QMK_KEYBOARD_H
  2. #ifdef PROTOCOL_LUFA
  3. #include "lufa.h"
  4. #include "split_util.h"
  5. #endif
  6. extern keymap_config_t keymap_config;
  7. #ifdef RGBLIGHT_ENABLE
  8. //Following line allows macro to read current RGB settings
  9. extern rgblight_config_t rgblight_config;
  10. #endif
  11. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  12. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  13. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  14. // entirely and just use numbers.
  15. enum layer_number {
  16. _QWERTY = 0,
  17. _COLEMAK,
  18. _FN,
  19. _ADJ
  20. };
  21. enum custom_keycodes {
  22. QWERTY = SAFE_RANGE,
  23. COLEMAK,
  24. FN,
  25. ADJ,
  26. BACKLIT,
  27. RGBRST
  28. };
  29. enum macro_keycodes {
  30. KC_SAMPLEMACRO,
  31. };
  32. #define FN_ESC LT(_FN, KC_ESC)
  33. #define FN_CAPS LT(_FN, KC_CAPS)
  34. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  35. /* Qwerty
  36. * ,------------------------------------------------. ,------------------------------------------------.
  37. * | GESC | 1 | 2 | 3 | 4 | 5 | - | | = | 6 | 7 | 8 | 9 | 0 | BkSp |
  38. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  39. * | Tab | Q | W | E | R | T | [ | | ] | Y | U | I | O | P | \ |
  40. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  41. * |FN(CAPS)| A | S | D | F | G | ( | | ) | H | J | K | L | ; | ' |
  42. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  43. * |Shift | Z | X | C | V | B | { | | } | N | M | , | . | / |Shift |
  44. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  45. * | Ctrl | Win | Alt | RGB | ADJ | Space| DEL | | Enter| Space| FN | Left | Down | Up |Right |
  46. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------'
  47. * | Space| DEL | | Enter| Space|
  48. * `-------------' `-------------'
  49. */
  50. [_QWERTY] = LAYOUT( \
  51. KC_GESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_MINS, KC_EQL, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, \
  52. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_LBRC, KC_RBRC, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS, \
  53. FN_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_LPRN, KC_RPRN, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, \
  54. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_LCBR, KC_RCBR, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT, \
  55. KC_LCTL, KC_LGUI, KC_LALT, RGB_TOG, ADJ, KC_SPC, KC_DEL, KC_ENT, KC_SPC, FN, KC_LEFT, KC_DOWN, KC_UP,KC_RIGHT, \
  56. KC_SPC, KC_DEL, KC_ENT, KC_SPC \
  57. ),
  58. /* Colemak
  59. * ,------------------------------------------------. ,------------------------------------------------.
  60. * | GESC | 1 | 2 | 3 | 4 | 5 | - | | = | 6 | 7 | 8 | 9 | 0 | BkSp |
  61. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  62. * | Tab | Q | W | F | P | B | [ | | ] | J | L | U | Y | ; | \ |
  63. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  64. * |FN(CAPS)| A | R | S | T | G | ( | | ) | K | N | E | I | O | ' |
  65. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  66. * |Shift | Z | X | C | D | V | { | | } | M | H | , | . | / |Shift |
  67. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  68. * | Ctrl | Win | Alt | RGB | ADJ | Space| DEL | | Enter| Space| FN | Left | Down | Up |Right |
  69. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------'
  70. * | Space| DEL | | Enter| Space|
  71. * `-------------' `-------------'
  72. */
  73. [_COLEMAK] = LAYOUT( \
  74. KC_GESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_MINS, KC_EQL, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC, \
  75. KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_B, KC_LBRC, KC_RBRC, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSLS, \
  76. FN_CAPS, KC_A, KC_R, KC_S, KC_T, KC_G, KC_LPRN, KC_RPRN, KC_K, KC_N, KC_E, KC_I, KC_O, KC_QUOT, \
  77. KC_LSFT, KC_Z, KC_X, KC_C, KC_D, KC_V, KC_LCBR, KC_RCBR, KC_M, KC_H, KC_COMM, KC_DOT, KC_SLSH, KC_ENT, \
  78. KC_LCTL, KC_LGUI, KC_LALT, RGB_TOG, ADJ, KC_SPC, KC_DEL, KC_ENT, KC_SPC, FN, KC_LEFT, KC_DOWN, KC_UP,KC_RIGHT, \
  79. KC_SPC, KC_DEL, KC_ENT, KC_SPC \
  80. ),
  81. /* FN
  82. * ,------------------------------------------------. ,------------------------------------------------.
  83. * | F1 | F2 | F3 | F4 | F5 | F6 | | | | F7 | F8 | F9 | F10 | F11 | F12 |
  84. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  85. * | | PGDN | UP | PGUP | | | | | | | PGDN | UP | PGUP | PRINT| HOME |
  86. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  87. * | | LEFT | DOWN | RIGHT| | | | | | | LEFT | DOWN | RIGHT|INSERT| END |
  88. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  89. * | | | | | | | | | | | | | | | |
  90. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  91. * | | | |RGBMOD| | | | | | | PLAY | NEXT | MUTE | VOL- | VOL+ |
  92. * `------+------+------+------+------+------+------| |------+------+------+------+------+------+------'
  93. * | | | | | |
  94. * `-------------' `-------------'
  95. */
  96. [_FN] = LAYOUT( \
  97. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, _______, KC_PSCR, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \
  98. _______, KC_PGDN, KC_UP, KC_PGUP, _______, _______, _______, _______, _______, KC_PGDN, KC_UP, KC_PGUP, KC_PSCR, KC_HOME, \
  99. _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, _______, KC_LEFT, KC_DOWN, KC_RGHT, KC_INS, KC_END, \
  100. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  101. _______, _______, _______, RGB_MOD, _______, _______, _______, _______, _______, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, \
  102. _______, _______, _______, _______ \
  103. ),
  104. /* ADJ
  105. * ,------------------------------------------------. ,------------------------------------------------.
  106. * | F1 | F2 | F3 | F4 | F5 | F6 | | | | F7 | F8 | F9 | F10 | F11 | F12 |
  107. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  108. * | | SAD | VAI | SAI | RESET| | | | | | | | | | |
  109. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  110. * | | HUD | VAD | HUI |RGBRST| | | | | |QWERTY|COLEMK| | | |
  111. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  112. * | | | | | | | | | | | |RGBTOG| HUI | SAI | VAI |
  113. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  114. * | | | |RGBMOD(| | | | | | | |RGBRMOD| HUD | SAD | VAD |
  115. * `------+------+------+------+------+------+------| |------+------+------+------+------+------+------'
  116. * | | | | | |
  117. * `-------------' `-------------'
  118. */
  119. [_ADJ] = LAYOUT( \
  120. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, _______, _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \
  121. _______, RGB_SAD, RGB_VAI, RGB_SAI, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  122. _______, RGB_HUD, RGB_VAD, RGB_HUI, RGBRST, _______, _______, _______, _______, QWERTY, COLEMAK, _______, _______, _______, \
  123. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, \
  124. _______, _______, _______, RGB_MOD, _______, _______, _______, _______, _______, _______, RGB_RMOD,RGB_HUD, RGB_SAD, RGB_VAD, \
  125. _______, _______, _______, _______ \
  126. )
  127. };
  128. // define variables for reactive RGB
  129. bool TOG_STATUS = false;
  130. int RGB_current_mode;
  131. #ifdef ENCODER_ENABLE
  132. void encoder_update_user(uint8_t index, bool clockwise) {
  133. if (index == 0) { /* First encoder */
  134. if (clockwise) {
  135. tap_code(KC_VOLU);
  136. } else {
  137. tap_code(KC_VOLD);
  138. }
  139. } else if (index == 1) { /* Second encoder*/
  140. if (clockwise) {
  141. tap_code(KC_VOLU);
  142. } else {
  143. tap_code(KC_VOLD);
  144. }
  145. }
  146. }
  147. #endif
  148. // Setting ADJ layer RGB back to default
  149. void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  150. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  151. #ifdef RGBLIGHT_ENABLE
  152. //rgblight_mode(RGB_current_mode);
  153. #endif
  154. layer_on(layer3);
  155. } else {
  156. layer_off(layer3);
  157. }
  158. }
  159. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  160. //uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
  161. switch (keycode) {
  162. case QWERTY:
  163. if (record->event.pressed) {
  164. set_single_persistent_default_layer(_QWERTY);
  165. }
  166. return false;
  167. break;
  168. case COLEMAK:
  169. if(record->event.pressed) {
  170. set_single_persistent_default_layer(_COLEMAK);
  171. }
  172. return false;
  173. break;
  174. case FN:
  175. if (record->event.pressed) {
  176. //not sure how to have keyboard check mode and set it to a variable, so my work around
  177. //uses another variable that would be set to true after the first time a reactive key is pressed.
  178. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  179. } else {
  180. TOG_STATUS = !TOG_STATUS;
  181. #ifdef RGBLIGHT_ENABLE
  182. //rgblight_mode(15);
  183. #endif
  184. }
  185. layer_on(_FN);
  186. } else {
  187. #ifdef RGBLIGHT_ENABLE
  188. //rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  189. #endif
  190. layer_off(_FN);
  191. TOG_STATUS = false;
  192. }
  193. return false;
  194. break;
  195. case ADJ:
  196. if (record->event.pressed) {
  197. layer_on(_ADJ);
  198. } else {
  199. layer_off(_ADJ);
  200. }
  201. return false;
  202. break;
  203. //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
  204. case RGBRST:
  205. #ifdef RGBLIGHT_ENABLE
  206. if (record->event.pressed) {
  207. eeconfig_update_rgblight_default();
  208. rgblight_enable();
  209. RGB_current_mode = rgblight_config.mode;
  210. }
  211. #endif
  212. break;
  213. }
  214. return true;
  215. }
  216. void matrix_init_user(void) {
  217. #ifdef RGBLIGHT_ENABLE
  218. RGB_current_mode = rgblight_config.mode;
  219. #endif
  220. }
  221. // OLED Driver Logic
  222. #ifdef OLED_DRIVER_ENABLE
  223. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  224. if (!has_usb())
  225. return OLED_ROTATION_180; // flip 180 for offhand
  226. return rotation;
  227. }
  228. static void render_logo(void) {
  229. static const char PROGMEM sol_logo[] = {
  230. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
  231. 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
  232. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
  233. oled_write_P(sol_logo, false);
  234. }
  235. //assign the right code to your layers for OLED display
  236. #define L_BASE 0
  237. #define L_FN (1<<_FN)
  238. #define L_ADJ (1<<_ADJ)
  239. #define L_ADJ_TRI (L_ADJ|L_FN)
  240. static void render_status(void) {
  241. // Render to mode icon
  242. static const char PROGMEM mode_logo[4][4] = {
  243. {0x95,0x96,0x0a,0},
  244. {0xb5,0xb6,0x0a,0},
  245. {0x97,0x98,0x0a,0},
  246. {0xb7,0xb8,0x0a,0} };
  247. if (keymap_config.swap_lalt_lgui != false) {
  248. oled_write_P(mode_logo[0], false);
  249. oled_write_P(mode_logo[1], false);
  250. } else {
  251. oled_write_P(mode_logo[2], false);
  252. oled_write_P(mode_logo[3], false);
  253. }
  254. // Define layers here, Have not worked out how to have text displayed for each layer. Copy down the number you see and add a case for it below
  255. oled_write_P(PSTR("Layer: "), false);
  256. switch (layer_state) {
  257. case L_BASE:
  258. oled_write_P(PSTR("Default\n"), false);
  259. break;
  260. case L_FN:
  261. oled_write_P(PSTR("FN \n"), false);
  262. break;
  263. case L_ADJ:
  264. case L_ADJ_TRI:
  265. oled_write_P(PSTR("ADJ \n"), false);
  266. break;
  267. default:
  268. oled_write_P(PSTR("UNDEF \n"), false);
  269. }
  270. // Host Keyboard LED Status
  271. uint8_t led_usb_state = host_keyboard_leds();
  272. oled_write_P(led_usb_state & (1<<USB_LED_NUM_LOCK) ? PSTR("NUMLOCK ") : PSTR(" "), false);
  273. oled_write_P(led_usb_state & (1<<USB_LED_CAPS_LOCK) ? PSTR("CAPS ") : PSTR(" "), false);
  274. oled_write_P(led_usb_state & (1<<USB_LED_SCROLL_LOCK) ? PSTR("SCLK ") : PSTR(" "), false);
  275. }
  276. void oled_task_user(void) {
  277. if (is_keyboard_master())
  278. render_status();
  279. else
  280. render_logo();
  281. }
  282. #endif