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.

231 lines
9.3 KiB

  1. /* Copyright 2020 marksard
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include QMK_KEYBOARD_H
  17. #include "../common/oled_helper.h"
  18. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  19. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  20. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  21. // entirely and just use numbers.
  22. enum layer_number {
  23. _BASE = 0,
  24. _LOWER,
  25. _RAISE,
  26. _ADJUST,
  27. };
  28. enum custom_keycodes {
  29. LOWER = SAFE_RANGE,
  30. RAISE,
  31. ADJUST,
  32. KANJI,
  33. RGBRST
  34. };
  35. #define KC_TBSF LSFT_T(KC_TAB)
  36. #define KC_ALAP LALT_T(KC_APP)
  37. #define KC_ROSF RSFT_T(KC_RO)
  38. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  39. [_BASE] = LAYOUT_base( \
  40. //,--------------------------------------------------------------------------------------------------------------------.
  41. KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,\
  42. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+-----------------|
  43. KC_TBSF, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_ENT,\
  44. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  45. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_UP, \
  46. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  47. KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_BSPC, KC_SPC, RAISE, KC_ALAP, KC_LEFT, KC_DOWN, KC_RGHT,\
  48. //`-------------------------------------------------------------------------------------------------------------------'
  49. KC_ROSF \
  50. // ExtraKey: This key is an extra key. REV1 is a split back space. REV2 is to the right of the arrow-up key.
  51. ),
  52. [_LOWER] = LAYOUT_base( \
  53. //,--------------------------------------------------------------------------------------------------------------------.
  54. _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_MINS, KC_EQL, KC_JYEN, KC_LBRC, KC_RBRC, KC_DEL,\
  55. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+-----------------|
  56. _______, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, XXXXXXX, XXXXXXX, KC_SCLN, KC_QUOT, KC_BSLS, _______,\
  57. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  58. _______, KC_F11, KC_F12, XXXXXXX, XXXXXXX, KANJI, XXXXXXX, KC_COMM, KC_DOT, KC_SLSH, KC_RO, KC_PGUP, \
  59. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  60. _______, _______, _______, _______, KC_DEL, _______, _______, XXXXXXX, KC_HOME, KC_PGDN, KC_END,\
  61. //`-------------------------------------------------------------------------------------------------------------------'
  62. _______ \
  63. // ExtraKey: This key is an extra key. REV1 is a split back space. REV2 is to the right of the arrow-up key.
  64. ),
  65. [_RAISE] = LAYOUT_base( \
  66. //,--------------------------------------------------------------------------------------------------------------------.
  67. _______, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, XXXXXXX,\
  68. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+-----------------|
  69. _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_4, KC_5, KC_6, KC_QUOT, _______,\
  70. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  71. _______, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, KC_1, KC_2, KC_3, KC_RO, XXXXXXX, \
  72. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  73. _______, _______, _______, _______, _______, _______, _______, KC_0, KC_DOT, KC_COMM, KC_SLSH,\
  74. //`-------------------------------------------------------------------------------------------------------------------'
  75. _______ \
  76. // ExtraKey: This key is an extra key. REV1 is a split back space. REV2 is to the right of the arrow-up key.
  77. ),
  78. [_ADJUST] = LAYOUT_base( \
  79. //,--------------------------------------------------------------------------------------------------------------------.
  80. XXXXXXX, RESET, RGBRST, AG_NORM, AG_SWAP, XXXXXXX, XXXXXXX, KC_WH_L, KC_WH_U, KC_HOME, KC_PGUP, XXXXXXX,\
  81. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+-----------------|
  82. XXXXXXX, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, XXXXXXX, XXXXXXX, KC_WH_R, KC_WH_D, KC_END, KC_PGDN, XXXXXXX,\
  83. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  84. _______, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD, XXXXXXX, XXXXXXX, XXXXXXX, KC_BTN1, KC_BTN2, XXXXXXX, KC_MS_U, \
  85. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  86. _______, _______, _______, _______, XXXXXXX, XXXXXXX, _______, XXXXXXX, KC_MS_L, KC_MS_D, KC_MS_R,\
  87. //`-------------------------------------------------------------------------------------------------------------------'
  88. _______ \
  89. // ExtraKey: This key is an extra key. REV1 is a split back space. REV2 is to the right of the arrow-up key.
  90. )
  91. };
  92. #define L_BASE _BASE
  93. #define L_LOWER (1<<_LOWER)
  94. #define L_RAISE (1<<_RAISE)
  95. #define L_ADJUST (1<<_ADJUST)
  96. #define L_ADJUST_TRI (L_ADJUST|L_RAISE|L_LOWER)
  97. #ifdef OLED_ENABLE
  98. #include <stdio.h>
  99. #include <string.h>
  100. typedef struct {
  101. uint8_t state;
  102. char name[8];
  103. }LAYER_DISPLAY_NAME;
  104. #define LAYER_DISPLAY_MAX 5
  105. const LAYER_DISPLAY_NAME layer_display_name[LAYER_DISPLAY_MAX] = {
  106. {L_BASE, "Base"},
  107. {L_BASE + 1, "Base"},
  108. {L_LOWER, "Lower"},
  109. {L_RAISE, "Raise"},
  110. {L_ADJUST_TRI, "Adjust"}
  111. };
  112. static inline const char* get_leyer_status(void) {
  113. for (uint8_t i = 0; i < LAYER_DISPLAY_MAX; ++i) {
  114. if (layer_state == 0 && layer_display_name[i].state == default_layer_state) {
  115. return layer_display_name[i].name;
  116. } else if (layer_state != 0 && layer_display_name[i].state == layer_state) {
  117. return layer_display_name[i].name;
  118. }
  119. }
  120. return "?";
  121. }
  122. static char layer_status_buf[24] = "Layer state ready.\n";
  123. static inline void update_keymap_status(void) {
  124. snprintf(layer_status_buf, sizeof(layer_status_buf) - 1, "OS:%s Layer:%s\n",
  125. keymap_config.swap_lalt_lgui? "win" : "mac", get_leyer_status());
  126. }
  127. static inline void render_keymap_status(void) {
  128. oled_write(layer_status_buf, false);
  129. }
  130. #define UPDATE_KEYMAP_STATUS() update_keymap_status()
  131. static inline void render_status(void) {
  132. UPDATE_LED_STATUS();
  133. RENDER_LED_STATUS();
  134. render_keymap_status();
  135. UPDATE_LOCK_STATUS();
  136. RENDER_LOCK_STATUS();
  137. RENDER_KEY_STATUS();
  138. }
  139. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  140. // if (is_keyboard_master())
  141. // return OLED_ROTATION_180; // flips the display 180 degrees if offhand
  142. return rotation;
  143. }
  144. bool oled_task_user(void) {
  145. if (is_keyboard_master()) {
  146. render_status();
  147. } else {
  148. render_logo();
  149. }
  150. return false;
  151. }
  152. #else
  153. #define UPDATE_KEYMAP_STATUS()
  154. #endif
  155. static inline void update_change_layer(bool pressed, uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  156. pressed ? layer_on(layer1) : layer_off(layer1);
  157. IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2) ? layer_on(layer3) : layer_off(layer3);
  158. }
  159. int RGB_current_mode;
  160. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  161. UPDATE_KEY_STATUS(keycode, record);
  162. bool result = false;
  163. switch (keycode) {
  164. case LOWER:
  165. update_change_layer(record->event.pressed, _LOWER, _RAISE, _ADJUST);
  166. break;
  167. case RAISE:
  168. update_change_layer(record->event.pressed, _RAISE, _LOWER, _ADJUST);
  169. break;
  170. case KANJI:
  171. if (record->event.pressed) {
  172. if (keymap_config.swap_lalt_lgui == false) {
  173. register_code(KC_LANG2);
  174. } else {
  175. SEND_STRING(SS_LALT("`"));
  176. }
  177. } else {
  178. unregister_code(KC_LANG2);
  179. }
  180. break;
  181. #ifdef RGBLIGHT_ENABLE
  182. case RGBRST:
  183. if (record->event.pressed) {
  184. eeconfig_update_rgblight_default();
  185. rgblight_enable();
  186. }
  187. break;
  188. #endif
  189. default:
  190. result = true;
  191. break;
  192. }
  193. UPDATE_KEYMAP_STATUS();
  194. return result;
  195. }