keymap.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #include QMK_KEYBOARD_H
  2. #include "hvp.c"
  3. #ifdef SSD1306OLED
  4. # include "ssd1306.h"
  5. # include <string.h>
  6. #endif
  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. #define _QWERTY 0
  16. #define _LOWER 1
  17. #define _RAISE 2
  18. #define _ADJUST 3
  19. enum custom_keycodes {
  20. QWERTY = SAFE_RANGE,
  21. LOWER,
  22. RAISE,
  23. ADJUST
  24. };
  25. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  26. [_QWERTY] = LAYOUT_split_3x6_3(
  27. //,-----------------------------------------. ,-----------------------------------------.
  28. LT(_ADJUST,KC_TAB), KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P,KC_BSPC,
  29. //|------+------+------+------+------+------| |------+------+------+------+------+------|
  30. LSFT_T(KC_ESC), KC_A, KC_S, KC_D, LT(3,KC_F), KC_G, KC_H, KC_J, KC_K, KC_L,TD(TD1),TD(TD2),
  31. //|------+------+------+------+------+------| |------+------+------+------+------+------|
  32. KC_LCTL, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M,KC_COMM,KC_DOT,TD(TD3),KC_SFTENT,
  33. //|------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  34. KC_LGUI, LT(1,KC_SPC),MT(MOD_LSFT, KC_SPC), MT(MOD_LSFT,KC_ENT), LT(2,KC_SPC),KC_LALT
  35. //`--------------------' `--------------------'
  36. ),
  37. [_RAISE] = LAYOUT_split_3x6_3(
  38. //,-----------------------------------------. ,-----------------------------------------.
  39. KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0,KC_BSPC,
  40. //|------+------+------+------+------+------| |------+------+------+------+------+------|
  41. KC_DEL, _______, _______, _______, _______, _______, _______,KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS,
  42. //|------+------+------+------+------+------| |------+------+------+------+------+------|
  43. KC_LCTL, _______, _______, _______, _______, _______, _______, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE,
  44. //|------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  45. _______, _______, _______, _______, _______, _______
  46. //`--------------------' `--------------------'
  47. ),
  48. [_LOWER] = LAYOUT_split_3x6_3(
  49. //,-----------------------------------------. ,-----------------------------------------.
  50. KC_TAB,KC_EXLM,KC_AT,KC_HASH,KC_DLR,KC_PERC, KC_CIRC,KC_AMPR,KC_ASTR,KC_LPRN,KC_RPRN,KC_BSPC,
  51. //|------+------+------+------+------+------| |------+------+------+------+------+------|
  52. KC_DEL, _______, _______, _______, _______, _______, _______,KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_BSLS,
  53. //|------+------+------+------+------+------| |------+------+------+------+------+------|
  54. KC_LCTL, _______, _______, _______, _______, _______, _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_TILD,
  55. //|------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  56. _______, _______, _______, _______, _______, _______
  57. //`--------------------' `--------------------'
  58. ),
  59. [_ADJUST] = LAYOUT_split_3x6_3(
  60. //,-----------------------------------------. ,-----------------------------------------.
  61. _______,KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,
  62. //|------+------+------+------+------+------| |------+------+------+------+------+------|
  63. KC_F1,_______,_______,D_NAVI,_______,_______, KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT, _______, _______,
  64. //|------+------+------+------+------+------| |------+------+------+------+------+------|
  65. RESET,KC_PSCR,_______,_______,_______,_______, KC_HOME, KC_PGDN, KC_PGUP, KC_END, _______, _______,
  66. //|------+------+------+------+------+------+------| |------+------+------+------+------+------+------|
  67. _______, KC_VOLD,KC_MPLY, KC_MNXT, KC_VOLU,_______
  68. //`--------------------' `--------------------'
  69. )
  70. };
  71. int RGB_current_mode;
  72. // Setting ADJUST layer RGB back to default
  73. void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  74. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  75. layer_on(layer3);
  76. } else {
  77. layer_off(layer3);
  78. }
  79. }
  80. void matrix_init_user(void) {
  81. #ifdef RGBLIGHT_ENABLE
  82. RGB_current_mode = rgblight_config.mode;
  83. #endif
  84. //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h
  85. #ifdef SSD1306OLED
  86. iota_gfx_init(); // turns on the display
  87. #endif
  88. }
  89. //SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h
  90. #ifdef SSD1306OLED
  91. // When add source files to SRC in rules.mk, you can use functions.
  92. const char *read_layer_state(void);
  93. const char *read_logo(void);
  94. void set_keylog(uint16_t keycode, keyrecord_t *record);
  95. const char *read_keylog(void);
  96. const char *read_keylogs(void);
  97. // const char *read_mode_icon(bool swap);
  98. // const char *read_host_led_state(void);
  99. // void set_timelog(void);
  100. // const char *read_timelog(void);
  101. void matrix_scan_user(void) {
  102. iota_gfx_task();
  103. }
  104. void matrix_render_user(struct CharacterMatrix *matrix) {
  105. if (is_keyboard_master()) {
  106. // If you want to change the display of OLED, you need to change here
  107. matrix_write(matrix, read_layer_state());
  108. matrix_write(matrix, read_keylog());
  109. //matrix_write_ln(matrix, read_keylogs());
  110. //matrix_write_ln(matrix, read_mode_icon(keymap_config.swap_lalt_lgui));
  111. //matrix_write_ln(matrix, read_host_led_state());
  112. //matrix_write_ln(matrix, read_timelog());
  113. } else {
  114. matrix_write(matrix, read_logo());
  115. }
  116. }
  117. void matrix_update(struct CharacterMatrix *dest, const struct CharacterMatrix *source) {
  118. if (memcmp(dest->display, source->display, sizeof(dest->display))) {
  119. memcpy(dest->display, source->display, sizeof(dest->display));
  120. dest->dirty = true;
  121. }
  122. }
  123. void iota_gfx_task_user(void) {
  124. struct CharacterMatrix matrix;
  125. matrix_clear(&matrix);
  126. matrix_render_user(&matrix);
  127. matrix_update(&display, &matrix);
  128. }
  129. #endif//SSD1306OLED
  130. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  131. if (record->event.pressed) {
  132. #ifdef SSD1306OLED
  133. set_keylog(keycode, record);
  134. #endif
  135. // set_timelog();
  136. }
  137. switch (keycode) {
  138. case LOWER:
  139. if (record->event.pressed) {
  140. layer_on(_LOWER);
  141. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  142. } else {
  143. layer_off(_LOWER);
  144. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  145. }
  146. return false;
  147. case RAISE:
  148. if (record->event.pressed) {
  149. layer_on(_RAISE);
  150. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  151. } else {
  152. layer_off(_RAISE);
  153. update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
  154. }
  155. return false;
  156. case ADJUST:
  157. if (record->event.pressed) {
  158. layer_on(_ADJUST);
  159. } else {
  160. layer_off(_ADJUST);
  161. }
  162. return false;
  163. break;
  164. }
  165. return true;
  166. }