keymap.c 13 KB

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