keymap.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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( \
  43. //,--------+--------+--------+--------+--------+--------+--+--------+. ,--------+--+--------+--------+--------+--------+--------+--------+
  44. KC_GRV, 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,
  45. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  46. 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,
  47. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  48. KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, _______, _______, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  49. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  50. KC_LSPO, KC_Z, KC_X, KC_C, KC_V, KC_B, _______, _______, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSPC,
  51. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  52. KC_LCTL, KC_LALT, FN, KC_LGUI, RGB_MOD, KC_SPC, KC_DEL, KC_BSPC, KC_SPC, ADJ, KC_LGUI, FN, KC_LALT, KC_LCTL,
  53. //|--------+--------+--------+--------+--------+--+--------+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  54. KC_SPC, KC_ENT, KC_ENT, KC_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( \
  73. //,--------+--------+--------+--------+--------+--------+--+--------+. ,--------+--+--------+--------+--------+--------+--------+--------+
  74. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, _______, _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,
  75. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  76. _______, _______, _______, KC_UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
  77. //|--------+--------+--------+--------+--------+--------+--+--------| |--------+--+--------+--------+--------+--------+--------+--------|
  78. _______, _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_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. bool 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. return true;
  137. }
  138. #endif
  139. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  140. switch (keycode) {
  141. case QWERTY:
  142. if (record->event.pressed) {
  143. set_single_persistent_default_layer(_QWERTY);
  144. }
  145. return false;
  146. break;
  147. case FN:
  148. if (record->event.pressed) {
  149. layer_on(_FN);
  150. } else {
  151. layer_off(_FN);
  152. }
  153. return false;
  154. break;
  155. case ADJ:
  156. if (record->event.pressed) {
  157. layer_on(_ADJ);
  158. } else {
  159. layer_off(_ADJ);
  160. }
  161. return false;
  162. break;
  163. //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
  164. case RGBRST:
  165. #ifdef RGBLIGHT_ENABLE
  166. if (record->event.pressed) {
  167. eeconfig_update_rgblight_default();
  168. rgblight_enable();
  169. RGB_current_mode = rgblight_config.mode;
  170. }
  171. #endif
  172. break;
  173. }
  174. return true;
  175. }
  176. void matrix_init_user(void) {
  177. #ifdef RGBLIGHT_ENABLE
  178. RGB_current_mode = rgblight_config.mode;
  179. #endif
  180. }
  181. // OLED Driver Logic
  182. #ifdef OLED_DRIVER_ENABLE
  183. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  184. if (!is_keyboard_master())
  185. return OLED_ROTATION_180; // flip 180 for offhand
  186. return rotation;
  187. }
  188. static void render_logo(void) {
  189. static const char PROGMEM sol_logo[] = {
  190. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
  191. 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
  192. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
  193. oled_write_P(sol_logo, false);
  194. }
  195. //assign the right code to your layers for OLED display
  196. #define L_BASE 0
  197. #define L_FN (1<<_FN)
  198. #define L_ADJ (1<<_ADJ)
  199. #define L_ADJ_TRI (L_ADJ|L_FN)
  200. static void render_status(void) {
  201. // Render to mode icon
  202. static const char PROGMEM mode_logo[4][4] = {
  203. {0x95,0x96,0x0a,0},
  204. {0xb5,0xb6,0x0a,0},
  205. {0x97,0x98,0x0a,0},
  206. {0xb7,0xb8,0x0a,0} };
  207. if (keymap_config.swap_lalt_lgui != false) {
  208. oled_write_P(mode_logo[0], false);
  209. oled_write_P(mode_logo[1], false);
  210. } else {
  211. oled_write_P(mode_logo[2], false);
  212. oled_write_P(mode_logo[3], false);
  213. }
  214. // 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
  215. oled_write_P(PSTR("Layer: "), false);
  216. switch (layer_state) {
  217. case L_BASE:
  218. oled_write_P(PSTR("Laser \n"), false);
  219. break;
  220. case L_FN:
  221. oled_write_P(PSTR("Function \n"), false);
  222. break;
  223. case L_ADJ:
  224. case L_ADJ_TRI:
  225. oled_write_P(PSTR("Adjustment\n"), false);
  226. break;
  227. default:
  228. oled_write_P(PSTR("Undefined \n"), false);
  229. }
  230. // Host Keyboard LED Status
  231. uint8_t led_usb_state = host_keyboard_leds();
  232. oled_write_P(led_usb_state & (1<<USB_LED_NUM_LOCK) ? PSTR("NUMLOCK ") : PSTR(" "), false);
  233. oled_write_P(led_usb_state & (1<<USB_LED_CAPS_LOCK) ? PSTR("CAPS ") : PSTR(" "), false);
  234. oled_write_P(led_usb_state & (1<<USB_LED_SCROLL_LOCK) ? PSTR("SCLK ") : PSTR(" "), false);
  235. }
  236. void oled_task_user(void) {
  237. if (is_keyboard_master())
  238. render_status();
  239. else
  240. render_logo();
  241. }
  242. #endif