keymap.c 15 KB

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