2
0

keymap.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. #include QMK_KEYBOARD_H
  2. #include "bootloader.h"
  3. #ifdef PROTOCOL_LUFA
  4. #include "lufa.h"
  5. #include "split_util.h"
  6. #endif
  7. #ifdef SSD1306OLED
  8. #include "common/ssd1306.h"
  9. #endif
  10. extern keymap_config_t keymap_config;
  11. #ifdef RGBLIGHT_ENABLE
  12. //Following line allows macro to read current RGB settings
  13. extern rgblight_config_t rgblight_config;
  14. #endif
  15. extern uint8_t is_master;
  16. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  17. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  18. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  19. // entirely and just use numbers.
  20. enum layer_number {
  21. _QWERTY = 0,
  22. _COLEMAK,
  23. _FN,
  24. _ADJ
  25. };
  26. enum custom_keycodes {
  27. QWERTY = SAFE_RANGE,
  28. COLEMAK,
  29. FN,
  30. ADJ,
  31. BACKLIT,
  32. RGBRST
  33. };
  34. enum macro_keycodes {
  35. KC_SAMPLEMACRO,
  36. };
  37. #define FN_ESC LT(_FN, KC_ESC)
  38. #define FN_CAPS LT(_FN, KC_CAPS)
  39. // Define your non-alpha grouping in this define's LAYOUT, and all your BASE_LAYERS will share the same mod/macro columns
  40. /* Base Layout
  41. * ,------------------------------------------------. ,------------------------------------------------.
  42. * | GESC | | | | | | - | | = | | | | | | BkSp |
  43. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  44. * | Tab | | | | | | [ | | ] | | | | | | \ |
  45. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  46. * |FN(CAPS)| | | | | | ( | | ) | | | | | | ' |
  47. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  48. * |Shift | | | | | | { | | } | | | | | |Shift |
  49. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  50. * | Ctrl | Win | Alt | RGB | ADJ | Space| DEL | | Enter| Space| FN | Left | Down | Up |Right |
  51. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------'
  52. * | Space| DEL | | Enter| Space|
  53. * `-------------' `-------------'
  54. */
  55. #define BASE_LAYOUT( \
  56. _00, _01, _02, _03, _04, _05, _06, _07, _08, _09, \
  57. _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, \
  58. _20, _21, _22, _23, _24, _25, _26, _27, _28, _29 \
  59. ) \
  60. LAYOUT( \
  61. 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, \
  62. KC_TAB, _00, _01, _02, _03, _04, KC_LBRC, KC_RBRC, _05, _06, _07, _08, _09, KC_BSLS, \
  63. FN_CAPS, _10, _11, _12, _13, _14, KC_LPRN, KC_RPRN, _15, _16, _17, _18, _19, KC_QUOT, \
  64. KC_LSFT, _20, _21, _22, _23, _24, KC_LCBR, KC_RCBR, _25, _26, _27, _28, _29, KC_ENT, \
  65. 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, \
  66. KC_VOLU, KC_VOLD, KC_SPC, KC_DEL, KC_ENT, KC_SPC, KC_VOLU, KC_VOLD \
  67. )
  68. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  69. /* Qwerty
  70. * ,------------------------------------------------. ,------------------------------------------------.
  71. * | | | | | | | | | | | | | | | |
  72. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  73. * | | Q | W | E | R | T | | | | Y | U | I | O | P | |
  74. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  75. * | | A | S | D | F | G | | | | H | J | K | L | ; | |
  76. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  77. * | | Z | X | C | V | B | | | | N | M | , | . | / | |
  78. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  79. * | | | | | | | | | | | | | | | |
  80. * `------+------+------+------+------+------+------| |------+------+------+------+------+------+------'
  81. * | | | | | |
  82. * `-------------' `--------=----'
  83. */
  84. [_QWERTY] = BASE_LAYOUT( \
  85. KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, \
  86. KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, \
  87. KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH \
  88. ),
  89. /* Colemak
  90. * ,------------------------------------------------. ,------------------------------------------------.
  91. * | | | | | | | | | | | | | | | |
  92. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  93. * | | Q | W | F | P | G | | | | J | L | U | Y | ; | |
  94. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  95. * | | A | R | S | T | D | | | | H | N | E | I | O | |
  96. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  97. * | | Z | X | C | V | B | | | | K | M | , | . | / | |
  98. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  99. * | | | | | | | | | | | | | | | |
  100. * `------+------+------+------+------+------+------| |------+------+------+------+------+------+------'
  101. * | | | | | |
  102. * `-------------' `--------=----'
  103. */
  104. [_COLEMAK] = BASE_LAYOUT( \
  105. KC_Q, KC_W, KC_F, KC_P, KC_B, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, \
  106. KC_A, KC_R, KC_S, KC_T, KC_G, KC_K, KC_N, KC_E, KC_I, KC_O, \
  107. KC_Z, KC_X, KC_C, KC_D, KC_V, KC_M, KC_H, KC_COMM, KC_DOT, KC_SLSH \
  108. ),
  109. /* FN
  110. * ,------------------------------------------------. ,------------------------------------------------.
  111. * | F1 | F2 | F3 | F4 | F5 | F6 | | | | F7 | F8 | F9 | F10 | F11 | F12 |
  112. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  113. * | | PGDN | UP | PGUP | | | | | | | PGDN | UP | PGUP | PRINT| HOME |
  114. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  115. * | | LEFT | DOWN | RIGHT| | | | | | | LEFT | DOWN | RIGHT|INSERT| END |
  116. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  117. * | | | | | | | | | | | | | | | |
  118. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  119. * | | | |RGBMOD| | | | | | | PLAY | NEXT | MUTE | VOL- | VOL+ |
  120. * `------+------+------+------+------+------+------| |------+------+------+------+------+------+------'
  121. * | | | | | |
  122. * `-------------' `-------------'
  123. */
  124. [_FN] = LAYOUT( \
  125. 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, \
  126. _______, KC_PGDN, KC_UP, KC_PGUP, _______, _______, _______, _______, _______, KC_PGDN, KC_UP, KC_PGUP, KC_PSCR, KC_HOME, \
  127. _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, _______, KC_LEFT, KC_DOWN, KC_RGHT, KC_INS, KC_END, \
  128. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  129. _______, _______, _______, RGB_MOD, _______, _______, _______, _______, _______, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, \
  130. KC_VOLU, KC_VOLD, _______, _______, _______, _______, KC_VOLU, KC_VOLD \
  131. ),
  132. /* ADJ
  133. * ,------------------------------------------------. ,------------------------------------------------.
  134. * | F1 | F2 | F3 | F4 | F5 | F6 | | | | F7 | F8 | F9 | F10 | F11 | F12 |
  135. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  136. * | | SAD | VAI | SAI | RESET| | | | | | | | | | |
  137. * |------+------+------+------+------+------|------| |------|------+------+------+------+------+------|
  138. * | | HUD | VAD | HUI |RGBRST| | | | | |QWERTY|COLEMK| | | |
  139. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  140. * | | | | | | | | | | | |RGBTOG| HUI | SAI | VAI |
  141. * |------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  142. * | | | |RGBMOD(| | | | | | | |RGBRMOD| HUD | SAD | VAD |
  143. * `------+------+------+------+------+------+------| |------+------+------+------+------+------+------'
  144. * | | | | | |
  145. * `-------------' `-------------'
  146. */
  147. [_ADJ] = LAYOUT( \
  148. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, _______, _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \
  149. _______, RGB_SAD, RGB_VAI, RGB_SAI, RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
  150. _______, RGB_HUD, RGB_VAD, RGB_HUI, RGBRST, _______, _______, _______, _______, QWERTY, COLEMAK, _______, _______, _______, \
  151. _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, \
  152. _______, _______, _______, RGB_MOD, _______, _______, _______, _______, _______, _______, RGB_RMOD,RGB_HUD, RGB_SAD, RGB_VAD, \
  153. KC_VOLU, KC_VOLD, _______, _______, _______, _______, KC_VOLU, KC_VOLD \
  154. )
  155. };
  156. // define variables for reactive RGB
  157. bool TOG_STATUS = false;
  158. int RGB_current_mode;
  159. // Setting ADJ layer RGB back to default
  160. void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  161. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  162. #ifdef RGBLIGHT_ENABLE
  163. //rgblight_mode(RGB_current_mode);
  164. #endif
  165. layer_on(layer3);
  166. } else {
  167. layer_off(layer3);
  168. }
  169. }
  170. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  171. //uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
  172. switch (keycode) {
  173. case QWERTY:
  174. if (record->event.pressed) {
  175. set_single_persistent_default_layer(_QWERTY);
  176. }
  177. return false;
  178. break;
  179. case COLEMAK:
  180. if(record->event.pressed) {
  181. set_single_persistent_default_layer(_COLEMAK);
  182. }
  183. return false;
  184. break;
  185. case FN:
  186. if (record->event.pressed) {
  187. //not sure how to have keyboard check mode and set it to a variable, so my work around
  188. //uses another variable that would be set to true after the first time a reactive key is pressed.
  189. if (TOG_STATUS) { //TOG_STATUS checks is another reactive key currently pressed, only changes RGB mode if returns false
  190. } else {
  191. TOG_STATUS = !TOG_STATUS;
  192. #ifdef RGBLIGHT_ENABLE
  193. //rgblight_mode(15);
  194. #endif
  195. }
  196. layer_on(_FN);
  197. } else {
  198. #ifdef RGBLIGHT_ENABLE
  199. //rgblight_mode(RGB_current_mode); // revert RGB to initial mode prior to RGB mode change
  200. #endif
  201. layer_off(_FN);
  202. TOG_STATUS = false;
  203. }
  204. return false;
  205. break;
  206. case ADJ:
  207. if (record->event.pressed) {
  208. layer_on(_ADJ);
  209. } else {
  210. layer_off(_ADJ);
  211. }
  212. return false;
  213. break;
  214. //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
  215. case RGBRST:
  216. #ifdef RGBLIGHT_ENABLE
  217. if (record->event.pressed) {
  218. eeconfig_update_rgblight_default();
  219. rgblight_enable();
  220. RGB_current_mode = rgblight_config.mode;
  221. }
  222. #endif
  223. break;
  224. }
  225. return true;
  226. }
  227. void matrix_init_user(void) {
  228. #ifdef RGBLIGHT_ENABLE
  229. RGB_current_mode = rgblight_config.mode;
  230. #endif
  231. //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h
  232. #ifdef SSD1306OLED
  233. iota_gfx_init(!has_usb()); // turns on the display
  234. #endif
  235. }
  236. //SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h
  237. #ifdef SSD1306OLED
  238. // hook point for 'led_test' keymap
  239. // 'default' keymap's led_test_init() is empty function, do nothing
  240. // 'led_test' keymap's led_test_init() force rgblight_mode_noeeprom(35);
  241. __attribute__ ((weak))
  242. void led_test_init(void) {}
  243. void matrix_scan_user(void) {
  244. led_test_init();
  245. iota_gfx_task(); // this is what updates the display continuously
  246. }
  247. void matrix_update(struct CharacterMatrix *dest,
  248. const struct CharacterMatrix *source) {
  249. if (memcmp(dest->display, source->display, sizeof(dest->display))) {
  250. memcpy(dest->display, source->display, sizeof(dest->display));
  251. dest->dirty = true;
  252. }
  253. }
  254. //assign the right code to your layers for OLED display
  255. #define L_BASE 0
  256. #define L_FN (1<<_FN)
  257. #define L_ADJ (1<<_ADJ)
  258. static void render_logo(struct CharacterMatrix *matrix) {
  259. static char logo[]={
  260. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
  261. 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
  262. 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,
  263. 0};
  264. matrix_write(matrix, logo);
  265. //matrix_write_P(&matrix, PSTR(" Split keyboard kit"));
  266. }
  267. void render_status(struct CharacterMatrix *matrix) {
  268. // Render to mode icon
  269. static char logo[][2][3]={{{0x95,0x96,0},{0xb5,0xb6,0}},{{0x97,0x98,0},{0xb7,0xb8,0}}};
  270. if(keymap_config.swap_lalt_lgui==false){
  271. matrix_write(matrix, logo[0][0]);
  272. matrix_write_P(matrix, PSTR("\n"));
  273. matrix_write(matrix, logo[0][1]);
  274. }else{
  275. matrix_write(matrix, logo[1][0]);
  276. matrix_write_P(matrix, PSTR("\n"));
  277. matrix_write(matrix, logo[1][1]);
  278. }
  279. // 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
  280. char buf[40];
  281. snprintf(buf,sizeof(buf), "Undef-%ld", layer_state);
  282. matrix_write_P(matrix, PSTR("\nLayer: "));
  283. switch (layer_state) {
  284. case L_BASE:
  285. matrix_write_P(matrix, PSTR("Default"));
  286. break;
  287. case L_FN:
  288. matrix_write_P(matrix, PSTR("FN"));
  289. break;
  290. case L_ADJ:
  291. case L_ADJ_TRI:
  292. matrix_write_P(matrix, PSTR("ADJ"));
  293. break;
  294. default:
  295. matrix_write(matrix, buf);
  296. }
  297. // Host Keyboard LED Status
  298. char led[40];
  299. snprintf(led, sizeof(led), "\n%s %s %s",
  300. (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : " ",
  301. (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ",
  302. (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " ");
  303. matrix_write(matrix, led);
  304. }
  305. void iota_gfx_task_user(void) {
  306. struct CharacterMatrix matrix;
  307. #if DEBUG_TO_SCREEN
  308. if (debug_enable) {
  309. return;
  310. }
  311. #endif
  312. matrix_clear(&matrix);
  313. if(is_master){
  314. render_status(&matrix);
  315. }else{
  316. render_logo(&matrix);
  317. }
  318. matrix_update(&display, &matrix);
  319. }
  320. #endif