2
0

keymap.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 "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. #define _QWERTY 0
  20. #define _LOWER 1
  21. #define _RAISE 2
  22. #define _ADJUST 3
  23. enum custom_keycodes {
  24. QWERTY = SAFE_RANGE,
  25. LOWER,
  26. RAISE,
  27. ADJUST,
  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 | - |
  34. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  35. * | Tab | Q | W | E | R | T | | Y | U | I | O | P | = |
  36. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  37. * |LShift| A | S | D | F | G | | H | J | K | L | ; | ' |
  38. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  39. * |LCTRL | Z | X | C | V | B |-------.-------. ,---------------| N | M | , | . | / | \ |
  40. * `-----------------------------------------/ Del / / \ \ Bksp \----------------------------------------'
  41. * | LAlt |ADJUST| /-------/ Space / \ Enter \-------\ | [ | ] |
  42. * | | |/ LOWER / / \ \ RAISE \ | | |
  43. * `-----------------------------' '------------------------------'
  44. */
  45. [_QWERTY] = LAYOUT( \
  46. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, \
  47. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_EQL, \
  48. KC_LSFT, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, \
  49. KC_LCTRL, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_DEL, KC_SPC, KC_ENT, KC_BSPC, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_BSLS, \
  50. KC_LALT, ADJUST, LOWER, RAISE, KC_LBRC, KC_RBRC\
  51. ),
  52. /* LOWER
  53. * ,-----------------------------------------. ,-----------------------------------------.
  54. * | ESC | F1 | F2 | F3 | F4 | F5 | | F6 | F7 | F8 | F9 | F10 | F11 |
  55. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  56. * | Tab | / | - | 7 | 8 | 9 | | ! | @ | # | $ | % | F12 |
  57. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  58. * |LShift| * | + | 4 | 5 | 6 | | ^ | & | * | ( | ) | - |
  59. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  60. * |LCTRL | . | 0 | 1 | 2 | 3 |-------.-------. ,---------------| | _ | + | { | } | | |
  61. * `-----------------------------------------/ F11 / / \ \ F12 \----------------------------------------'
  62. * | LAlt | LGUI | /-------/ Space / \ Enter \-------\ | Caps | Num |
  63. * | | |/ LOWER / / \ \ \ | | |
  64. * `-----------------------------' '------------------------------'
  65. */
  66. [_LOWER] = LAYOUT( \
  67. KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, \
  68. _______, KC_PSLS, KC_PMNS, KC_P7, KC_P8, KC_P9, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_F12, \
  69. _______, KC_PAST, KC_PPLS, KC_P4, KC_P5, KC_P6, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_TILD, \
  70. _______, KC_PDOT, KC_P0, KC_P1, KC_P2, KC_P3, _______, _______, _______, _______, XXXXXXX, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, \
  71. _______, KC_LGUI, _______, XXXXXXX, KC_CLCK, KC_NLCK\
  72. ),
  73. /* RAISE
  74. * ,-----------------------------------------. ,-----------------------------------------.
  75. * | | | | | | | | | | | | | |
  76. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  77. * | | 1 | 2 | 3 | 4 | 5 | | 6 | 7 | 8 | 9 | 0 | |
  78. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  79. * | F1 | F2 | F3 | F4 | F5 | F6 | | | �ª | | | | |
  80. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  81. * | F7 | F8 | F9 | F10 | F11 | F12 |-------.-------. ,---------------| �© | �« | �¨ | | | |
  82. * `-----------------------------------------/ / / \ \ \----------------------------------------'
  83. * | | | /-------/ Space / \ Enter \-------\ | | |
  84. * | | |/ / / \ \ RAISE \ | | |
  85. * `-----------------------------' '------------------------------'
  86. */
  87. [_RAISE] = LAYOUT( \
  88. XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
  89. XXXXXXX, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, XXXXXXX, \
  90. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, XXXXXXX, KC_UP, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
  91. KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, XXXXXXX, _______, _______, XXXXXXX, KC_LEFT, KC_DOWN, KC_RGHT, XXXXXXX, XXXXXXX, XXXXXXX, \
  92. XXXXXXX, XXXXXXX, XXXXXXX, _______, XXXXXXX, XXXXXXX \
  93. ),
  94. /* ADJUST
  95. * ,-----------------------------------------. ,-----------------------------------------.
  96. * |RESET | | | | | | | Mute | Vol+ | Play | | | |
  97. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  98. * | | | | PSCR | SLCK | Pause| | Prev | Vol- | Next | | | |
  99. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  100. * | | | |Insert| Home |PageUP| | | |RGB ON| HUE+ | SAT+ | VAL+ |
  101. * |------+------+------+------+------+------| |------+------+------+------+------+------|
  102. * | | | | Del | End |PageDN|-------.-------. ,---------------| |RGB Re| MODE | HUE- | SAT- | VAL- |
  103. * `-----------------------------------------/ / / \ \ \----------------------------------------'
  104. * | |ADJUST| /-------/ Space / \ Enter \-------\ | | |
  105. * | | |/ / / \ \ \ | | |
  106. * `-----------------------------' '------------------------------'
  107. */
  108. [_ADJUST] = LAYOUT( \
  109. RESET, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_MUTE, KC_VOLU, KC_MPLY, XXXXXXX, XXXXXXX, XXXXXXX, \
  110. XXXXXXX, XXXXXXX, XXXXXXX, KC_PSCR, KC_SLCK, KC_PAUS, KC_MPRV, KC_VOLD, KC_MNXT, XXXXXXX, XXXXXXX, XXXXXXX, \
  111. XXXXXXX, XXXXXXX, XXXXXXX, KC_INS, KC_HOME, KC_PGUP, XXXXXXX, XXXXXXX, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, \
  112. XXXXXXX, XXXXXXX, XXXXXXX, KC_DEL, KC_END, KC_PGDN, XXXXXXX, _______, _______, XXXXXXX, XXXXXXX, RGBRST, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD, \
  113. XXXXXXX, _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX \
  114. )
  115. };
  116. int RGB_current_mode;
  117. void persistent_default_layer_set(uint16_t default_layer) {
  118. eeconfig_update_default_layer(default_layer);
  119. default_layer_set(default_layer);
  120. }
  121. // Setting ADJUST layer RGB back to default
  122. void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  123. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  124. layer_on(layer3);
  125. } else {
  126. layer_off(layer3);
  127. }
  128. }
  129. void matrix_init_user(void) {
  130. #ifdef RGBLIGHT_ENABLE
  131. RGB_current_mode = rgblight_config.mode;
  132. #endif
  133. //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h
  134. #ifdef SSD1306OLED
  135. #ifdef SSD1306_128X64
  136. iota_gfx_init(false); // turns on the display
  137. #else
  138. iota_gfx_init(!has_usb()); // turns on the display
  139. #endif
  140. #endif
  141. }
  142. //SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h
  143. #ifdef SSD1306OLED
  144. //assign the right code to your layers for OLED display
  145. #define L_QWERTY 0
  146. #define L_LOWER 2
  147. #define L_RAISE 4
  148. #define L_ADJUST 8
  149. // When add source files to SRC in rules.mk, you can use functions.
  150. const char *read_logo(void);
  151. void matrix_scan_user(void) {
  152. iota_gfx_task();
  153. }
  154. void matrix_render_user(struct CharacterMatrix *matrix) {
  155. if (is_master) {
  156. static char indctr[2][20][5]=
  157. {
  158. // white icon
  159. {
  160. {0x80,0x81,0x82,0x83,0},
  161. {0x88,0x89,0x8A,0x8B,0},
  162. {0x90,0x91,0x92,0x93,0},
  163. {0x98,0x99,0x9A,0x9B,0},
  164. {0x01,0x02,0x03,0x04,0},
  165. {0xA0,0xA1,0xA2,0xA3,0},
  166. {0xA8,0xA9,0xAA,0xAB,0},
  167. {0xB0,0xB1,0xB2,0xB3,0},
  168. {0xB8,0xB9,0xBA,0xBB,0},
  169. {0x21,0x22,0x23,0x24,0},
  170. {0xC0,0xC1,0xC2,0xC3,0},
  171. {0xC8,0xC9,0xCA,0xCB,0},
  172. {0xD0,0xD1,0xD2,0xD3,0},
  173. {0xD8,0xD9,0xDA,0xDB,0},
  174. {0x41,0x42,0x43,0x44,0},
  175. {0xE0,0xE1,0xE2,0xE3,0},
  176. {0xE8,0xE9,0xEA,0xEB,0},
  177. {0xF0,0xF1,0xF2,0xF3,0},
  178. {0xF8,0xF9,0xFA,0xFB,0},
  179. {0x61,0x62,0x63,0x64,0}
  180. },
  181. // Black icon
  182. {
  183. {0x84,0x85,0x86,0x87,0},
  184. {0x8C,0x8D,0x8E,0x8F,0},
  185. {0x94,0x95,0x96,0x97,0},
  186. {0x9C,0x9D,0x9E,0x9F,0},
  187. {0x05,0x06,0x07,0x08,0},
  188. {0xA4,0xA5,0xA6,0xA7,0},
  189. {0xAC,0xAD,0xAE,0xAF,0},
  190. {0xB4,0xB5,0xB6,0xB7,0},
  191. {0xBC,0xBD,0xBE,0xBF,0},
  192. {0x25,0x26,0x27,0x28,0},
  193. {0xC4,0xC5,0xC6,0xC7,0},
  194. {0xCC,0xCD,0xCE,0xCF,0},
  195. {0xD4,0xD5,0xD6,0xD7,0},
  196. {0xDC,0xDD,0xDE,0xDF,0},
  197. {0x45,0x46,0x47,0x48,0},
  198. {0xE4,0xE5,0xE6,0xE7,0},
  199. {0xEC,0xED,0xEE,0xEF,0},
  200. {0xF4,0xF5,0xF6,0xF7,0},
  201. {0xFC,0xFD,0xFE,0xFF,0},
  202. {0x65,0x66,0x67,0x68,0}
  203. }
  204. };
  205. int rown = 0;
  206. int rowc = 0;
  207. int rowl = 0;
  208. int rowr = 0;
  209. int rowa = 0;
  210. //Set Indicator icon
  211. if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) { rown = 1; } else { rown = 0; }
  212. if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) { rowc = 1; } else { rowc = 0; }
  213. if (layer_state == L_LOWER) { rowl = 1; }
  214. if (layer_state == L_RAISE) { rowr = 1; }
  215. if (layer_state == L_ADJUST) { rowa = 1; }
  216. matrix_write(matrix, indctr[rowl] [0]);
  217. matrix_write(matrix, indctr[rowr] [1]);
  218. matrix_write(matrix, indctr[rowa] [2]);
  219. matrix_write(matrix, indctr[rowc] [3]);
  220. matrix_write(matrix, indctr[rown] [4]);
  221. matrix_write_char(matrix, 0x13);
  222. matrix_write(matrix, indctr[rowl] [5]);
  223. matrix_write(matrix, indctr[rowr] [6]);
  224. matrix_write(matrix, indctr[rowa] [7]);
  225. matrix_write(matrix, indctr[rowc] [8]);
  226. matrix_write(matrix, indctr[rown] [9]);
  227. matrix_write_char(matrix, 0x13);
  228. matrix_write(matrix, indctr[rowl] [10]);
  229. matrix_write(matrix, indctr[rowr] [11]);
  230. matrix_write(matrix, indctr[rowa] [12]);
  231. matrix_write(matrix, indctr[rowc] [13]);
  232. matrix_write(matrix, indctr[rown] [14]);
  233. matrix_write_char(matrix, 0x13);
  234. matrix_write(matrix, indctr[rowl] [15]);
  235. matrix_write(matrix, indctr[rowr] [16]);
  236. matrix_write(matrix, indctr[rowa] [17]);
  237. matrix_write(matrix, indctr[rowc] [18]);
  238. matrix_write(matrix, indctr[rown] [19]);
  239. }else{
  240. matrix_write(matrix, read_logo());
  241. }
  242. }
  243. void matrix_update(struct CharacterMatrix *dest, const struct CharacterMatrix *source) {
  244. if (memcmp(dest->display, source->display, sizeof(dest->display))) {
  245. memcpy(dest->display, source->display, sizeof(dest->display));
  246. dest->dirty = true;
  247. }
  248. }
  249. void iota_gfx_task_user(void) {
  250. struct CharacterMatrix matrix;
  251. matrix_clear(&matrix);
  252. matrix_render_user(&matrix);
  253. matrix_update(&display, &matrix);
  254. }
  255. #endif//SSD1306OLED
  256. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  257. switch (keycode) {
  258. case QWERTY:
  259. if (record->event.pressed) {
  260. persistent_default_layer_set(1UL<<_QWERTY);
  261. }
  262. return false;
  263. break;
  264. case LOWER:
  265. if (record->event.pressed) {
  266. layer_on(_LOWER);
  267. } else {
  268. layer_off(_LOWER);
  269. }
  270. return false;
  271. break;
  272. case RAISE:
  273. if (record->event.pressed) {
  274. layer_on(_RAISE);
  275. } else {
  276. layer_off(_RAISE);
  277. }
  278. return false;
  279. break;
  280. case ADJUST:
  281. if (record->event.pressed) {
  282. layer_on(_ADJUST);
  283. } else {
  284. layer_off(_ADJUST);
  285. }
  286. return false;
  287. break;
  288. case RGB_MOD:
  289. #ifdef RGBLIGHT_ENABLE
  290. if (record->event.pressed) {
  291. rgblight_mode(RGB_current_mode);
  292. rgblight_step();
  293. RGB_current_mode = rgblight_config.mode;
  294. }
  295. #endif
  296. return false;
  297. break;
  298. case RGBRST:
  299. #ifdef RGBLIGHT_ENABLE
  300. if (record->event.pressed) {
  301. eeconfig_update_rgblight_default();
  302. rgblight_enable();
  303. RGB_current_mode = rgblight_config.mode;
  304. }
  305. #endif
  306. break;
  307. }
  308. return true;
  309. }