You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
7.4 KiB

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