keymap.c 15 KB

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