keymap.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. _FN,
  18. _ADJ
  19. };
  20. enum custom_keycodes {
  21. QWERTY = SAFE_RANGE,
  22. FN,
  23. ADJ,
  24. RGBRST
  25. };
  26. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  27. /* QWERTY
  28. * ,------------------------------------------------. ,------------------------------------------------.
  29. * | ` | 1 | 2 | 3 | 4 | 5 | - | | = | 6 | 7 | 8 | 9 | 0 | Bspc |
  30. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  31. * | Tab | Q | W | E | R | T | [ | | ] | Y | U | I | O | P | \ |
  32. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  33. * | Esc | A | S | D | F | G | | | | H | J | K | L | ; | ' |
  34. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  35. * | Shift| Z | X | C | V | B | | | | N | M | , | . | / | Shift|
  36. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  37. * | Ctrl | Alt | FN | LGui | RGB | Spc | Del | | Bspc | Spc | Adj | LGui | FN | Alt | Ctrl |
  38. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  39. * | Spc | Ent | | Ent | Spc |
  40. * `-------------' `-------------'
  41. */
  42. [_QWERTY] = LAYOUT_kc( \
  43. //,--------+--------+--------+--------+--------+--------+--+--------+. ,--------+--+--------+--------+--------+--------+--------+--------+
  44. GRV, 1, 2, 3, 4, 5, MINS, EQL, 6, 7, 8, 9, 0, BSPC,
  45. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  46. TAB, Q, W, E, R, T, LBRC, RBRC, Y, U, I, O, P, BSLS,
  47. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  48. ESC, A, S, D, F, G, _______, _______, H, J, K, L, SCLN, QUOT,
  49. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  50. LSPO, Z, X, C, V, B, _______, _______, N, M, COMM, DOT, SLSH, RSPC,
  51. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  52. LCTL, LALT, FN, LGUI, RGB_MOD, SPC, DEL, BSPC, SPC, ADJ, LGUI, FN, LALT, LCTL,
  53. //|--------+--------+--------+--------+--------+--+--------+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  54. SPC, ENT, ENT, SPC
  55. // |--------+--------| |--------+-----------+
  56. ),
  57. /* FN
  58. * ,------------------------------------------------. ,------------------------------------------------.
  59. * | F1 | F2 | F3 | F4 | F5 | F6 | | | | F7 | F8 | F9 | F10 | F11 | F12 |
  60. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  61. * | | | | Up | | | | | | | | | | | |
  62. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  63. * | | | Left | Down | Right| | | | | Play | Next | Mute | V-Up |V-Down| |
  64. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  65. * | | | | | | | | | | | | | | | |
  66. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  67. * | | | | | | | | | | | | | | | |
  68. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  69. * | | | | | |
  70. * `-------------' `-------------'
  71. */
  72. [_FN] = LAYOUT_kc( \
  73. //,--------+--------+--------+--------+--------+--------+--+--------+. ,--------+--+--------+--------+--------+--------+--------+--------+
  74. F1, F2, F3, F4, F5, F6, _______, _______, F7, F8, F9, F10, F11, F12,
  75. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  76. _______, _______, _______, UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  77. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  78. _______, _______, LEFT, DOWN, RGHT, _______, _______, _______, MPLY, MNXT, MUTE, VOLD, VOLU, _______,
  79. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  80. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  81. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  82. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  83. //|--------+--------+--------+--------+--------+--+--------+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  84. _______, _______, _______, _______
  85. // |--------+--------| |--------+-----------+
  86. ),
  87. /* ADJ
  88. * ,------------------------------------------------. ,------------------------------------------------.
  89. * | | | | | | | | | | | | | | | |
  90. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  91. * | | Sat+ | Val+ | Hue+ |Speed+|Toggle| | | | | | | | | |
  92. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  93. * | | Sat- | Val- | Hue- |Speed-|Reset | | | | |QWERTY| COLE | | | |
  94. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  95. * | | | | | | | | | | | | | | | |
  96. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  97. * | | | | | | | | | | | | | | | |
  98. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  99. * | | | | | |
  100. * `-------------' `-------------'
  101. */
  102. [_ADJ] = LAYOUT( \
  103. //,--------+--------+--------+--------+--------+--------+--+--------+. ,--------+--+--------+--------+--------+--------+--------+--------+
  104. RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RESET, \
  105. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  106. _______, RGB_SAI, RGB_VAI, RGB_HUI, RGB_SPI, RGB_TOG, _______, _______, _______, _______, _______, _______, _______, _______, \
  107. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  108. _______, RGB_SAD, RGB_VAD, RGB_HUD, RGB_SPD, RGBRST, _______, _______, _______, _______, _______, _______, _______, _______, \
  109. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  110. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  111. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  112. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  113. //|--------+--------+--------+--------+--------+--+--------+--------| |--------+--------+--+--------+--------+--------+--------+--------|
  114. _______, _______, _______, _______ \
  115. // |--------+--------| |--------+--------+
  116. )
  117. };
  118. // define variables for reactive RGB
  119. bool TOG_STATUS = false;
  120. int RGB_current_mode;
  121. #ifdef ENCODER_ENABLE
  122. void encoder_update_user(uint8_t index, bool clockwise) {
  123. if (index == 0) { /* First encoder */
  124. if (clockwise) {
  125. tap_code(KC_VOLU);
  126. } else {
  127. tap_code(KC_VOLD);
  128. }
  129. } else if (index == 1) { /* Second encoder*/
  130. if (clockwise) {
  131. tap_code(KC_UP);
  132. } else {
  133. tap_code(KC_DOWN);
  134. }
  135. }
  136. }
  137. #endif
  138. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  139. switch (keycode) {
  140. case QWERTY:
  141. if (record->event.pressed) {
  142. set_single_persistent_default_layer(_QWERTY);
  143. }
  144. return false;
  145. break;
  146. case FN:
  147. if (record->event.pressed) {
  148. layer_on(_FN);
  149. } else {
  150. layer_off(_FN);
  151. }
  152. return false;
  153. break;
  154. case ADJ:
  155. if (record->event.pressed) {
  156. layer_on(_ADJ);
  157. } else {
  158. layer_off(_ADJ);
  159. }
  160. return false;
  161. break;
  162. //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
  163. case RGBRST:
  164. #ifdef RGBLIGHT_ENABLE
  165. if (record->event.pressed) {
  166. eeconfig_update_rgblight_default();
  167. rgblight_enable();
  168. RGB_current_mode = rgblight_config.mode;
  169. }
  170. #endif
  171. break;
  172. }
  173. return true;
  174. }
  175. void matrix_init_user(void) {
  176. #ifdef RGBLIGHT_ENABLE
  177. RGB_current_mode = rgblight_config.mode;
  178. #endif
  179. }
  180. // OLED Driver Logic
  181. #ifdef OLED_DRIVER_ENABLE
  182. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  183. if (!is_keyboard_master())
  184. return OLED_ROTATION_180; // flip 180 for offhand
  185. return rotation;
  186. }
  187. static void render_logo(void) {
  188. static const char PROGMEM sol_logo[] = {
  189. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
  190. 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
  191. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
  192. oled_write_P(sol_logo, false);
  193. }
  194. //assign the right code to your layers for OLED display
  195. #define L_BASE 0
  196. #define L_FN (1<<_FN)
  197. #define L_ADJ (1<<_ADJ)
  198. #define L_ADJ_TRI (L_ADJ|L_FN)
  199. static void render_status(void) {
  200. // Render to mode icon
  201. static const char PROGMEM mode_logo[4][4] = {
  202. {0x95,0x96,0x0a,0},
  203. {0xb5,0xb6,0x0a,0},
  204. {0x97,0x98,0x0a,0},
  205. {0xb7,0xb8,0x0a,0} };
  206. if (keymap_config.swap_lalt_lgui != false) {
  207. oled_write_P(mode_logo[0], false);
  208. oled_write_P(mode_logo[1], false);
  209. } else {
  210. oled_write_P(mode_logo[2], false);
  211. oled_write_P(mode_logo[3], false);
  212. }
  213. // 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
  214. oled_write_P(PSTR("Layer: "), false);
  215. switch (layer_state) {
  216. case L_BASE:
  217. oled_write_P(PSTR("Laser \n"), false);
  218. break;
  219. case L_FN:
  220. oled_write_P(PSTR("Function \n"), false);
  221. break;
  222. case L_ADJ:
  223. case L_ADJ_TRI:
  224. oled_write_P(PSTR("Adjustment\n"), false);
  225. break;
  226. default:
  227. oled_write_P(PSTR("Undefined \n"), false);
  228. }
  229. // Host Keyboard LED Status
  230. uint8_t led_usb_state = host_keyboard_leds();
  231. oled_write_P(led_usb_state & (1<<USB_LED_NUM_LOCK) ? PSTR("NUMLOCK ") : PSTR(" "), false);
  232. oled_write_P(led_usb_state & (1<<USB_LED_CAPS_LOCK) ? PSTR("CAPS ") : PSTR(" "), false);
  233. oled_write_P(led_usb_state & (1<<USB_LED_SCROLL_LOCK) ? PSTR("SCLK ") : PSTR(" "), false);
  234. }
  235. void oled_task_user(void) {
  236. if (is_keyboard_master())
  237. render_status();
  238. else
  239. render_logo();
  240. }
  241. #endif