keymap.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 "keymap_jp.h"
  18. #include "../common/oled_helper.h"
  19. #ifdef RGBLIGHT_ENABLE
  20. //Following line allows macro to read current RGB settings
  21. extern rgblight_config_t rgblight_config;
  22. #endif
  23. extern uint8_t is_master;
  24. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  25. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  26. // Layer names don't all need to be of the same length, obviously, and you can also skip them
  27. // entirely and just use numbers.
  28. enum layer_number {
  29. _BASE = 0,
  30. _LOWER,
  31. _RAISE,
  32. _ADJUST,
  33. };
  34. enum custom_keycodes {
  35. LOWER = SAFE_RANGE,
  36. RAISE,
  37. ADJUST,
  38. KANJI,
  39. RGBRST
  40. };
  41. enum tapdances{
  42. TD_SCCL = 0,
  43. TD_SLRO,
  44. };
  45. // Layer Mode aliases
  46. #define _____ KC_TRNS
  47. #define XXXXX KC_NO
  48. #define KC_TBSF LSFT_T(KC_TAB)
  49. // #define KC_SPSF LSFT_T(KC_SPC)
  50. #define KC_ALAP LALT_T(KC_APP)
  51. #define KC_JEQL LSFT(KC_MINS)
  52. #define KC_SCCL TD(TD_SCCL)
  53. #define KC_SLRO TD(TD_SLRO)
  54. qk_tap_dance_action_t tap_dance_actions[] = {
  55. [TD_SCCL] = ACTION_TAP_DANCE_DOUBLE(KC_SCLN, KC_QUOT),
  56. [TD_SLRO] = ACTION_TAP_DANCE_DOUBLE(KC_SLSH, KC_RO),
  57. };
  58. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  59. [_BASE] = LAYOUT_base( \
  60. //,--------------------------------------------------------------------------------------------------------------------.
  61. KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_MINS,\
  62. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+-----------------|
  63. KC_TBSF, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCCL, KC_ENT,\
  64. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  65. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLRO, KC_UP, \
  66. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  67. KC_LCTRL, KC_LALT, KC_LGUI, LOWER, KC_BSPC, KC_SPC, RAISE, KC_ALAP, KC_LEFT, KC_DOWN, KC_RGHT,\
  68. //`-------------------------------------------------------------------------------------------------------------------'
  69. KC_DEL \
  70. // ExtraKey: Split backspace key or it is below the enter key.
  71. ),
  72. [_LOWER] = LAYOUT_base( \
  73. //,--------------------------------------------------------------------------------------------------------------------.
  74. _____, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL,\
  75. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+-----------------|
  76. _____, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, XXXXX, XXXXX, XXXXX, KC_SCLN, KC_QUOT, _____,\
  77. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  78. _____, KC_F11, KC_F12, XXXXX, KANJI, KC_ENT, XXXXX, XXXXX, KC_COMM, KC_DOT, KC_GRV, KC_PGUP, \
  79. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  80. _____, _____, _____, _____, KC_DEL, _____, _____, XXXXX, KC_HOME, KC_PGDN, KC_END,\
  81. //`-------------------------------------------------------------------------------------------------------------------'
  82. XXXXX \
  83. // ExtraKey: Split backspace key or it is below the enter key.
  84. ),
  85. [_RAISE] = LAYOUT_base( \
  86. //,--------------------------------------------------------------------------------------------------------------------.
  87. _____, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, XXXXX,\
  88. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+-----------------|
  89. _____, XXXXX, XXXXX, XXXXX, XXXXX, XXXXX, XXXXX, KC_4, KC_5, KC_6, KC_QUOT, _____,\
  90. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  91. _____, XXXXX, XXXXX, XXXXX, XXXXX, XXXXX, XXXXX, KC_1, KC_2, KC_3, KC_RO, XXXXX, \
  92. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  93. _____, _____, _____, _____, _____, _____, _____, KC_0, KC_DOT, KC_COMM, KC_SLSH,\
  94. //`-------------------------------------------------------------------------------------------------------------------'
  95. XXXXX \
  96. // ExtraKey: Split backspace key or it is below the enter key.
  97. ),
  98. [_ADJUST] = LAYOUT_base( \
  99. //,--------------------------------------------------------------------------------------------------------------------.
  100. XXXXX, RESET, RGBRST, AG_NORM, AG_SWAP, XXXXX, XXXXX, KC_WH_L, KC_WH_U, KC_HOME, KC_PGUP, XXXXX,\
  101. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+-----------------|
  102. XXXXX, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, XXXXX, XXXXX, KC_WH_R, KC_WH_D, KC_END, KC_PGDN, XXXXX,\
  103. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  104. _____, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD, XXXXX, XXXXX, XXXXX, KC_BTN1, KC_BTN2, XXXXX, KC_MS_U, \
  105. //|--------+--------+--------+--------+--------+--------|--------+--------+--------+--------+--------+--------+--------|
  106. _____, _____, _____, _____, XXXXX, XXXXX, _____, XXXXX, KC_MS_L, KC_MS_D, KC_MS_R,\
  107. //`-------------------------------------------------------------------------------------------------------------------'
  108. XXXXX \
  109. // ExtraKey: Split backspace key or it is below the enter key.
  110. )
  111. };
  112. #define L_BASE _BASE
  113. #define L_LOWER (1<<_LOWER)
  114. #define L_RAISE (1<<_RAISE)
  115. #define L_ADJUST (1<<_ADJUST)
  116. #define L_ADJUST_TRI (L_ADJUST|L_RAISE|L_LOWER)
  117. #ifdef OLED_DRIVER_ENABLE
  118. #include <stdio.h>
  119. #include <string.h>
  120. typedef struct {
  121. uint8_t state;
  122. char name[8];
  123. }LAYER_DISPLAY_NAME;
  124. #define LAYER_DISPLAY_MAX 5
  125. const LAYER_DISPLAY_NAME layer_display_name[LAYER_DISPLAY_MAX] = {
  126. {L_BASE, "Base"},
  127. {L_BASE + 1, "Base"},
  128. {L_LOWER, "Lower"},
  129. {L_RAISE, "Raise"},
  130. {L_ADJUST_TRI, "Adjust"}
  131. };
  132. static inline const char* get_leyer_status(void) {
  133. for (uint8_t i = 0; i < LAYER_DISPLAY_MAX; ++i) {
  134. if (layer_state == 0 && layer_display_name[i].state == default_layer_state) {
  135. return layer_display_name[i].name;
  136. } else if (layer_state != 0 && layer_display_name[i].state == layer_state) {
  137. return layer_display_name[i].name;
  138. }
  139. }
  140. return "?";
  141. }
  142. static char layer_status_buf[24] = "Layer state ready.\n";
  143. static inline void update_keymap_status(void) {
  144. snprintf(layer_status_buf, sizeof(layer_status_buf) - 1, "OS:%s Layer:%s\n",
  145. keymap_config.swap_lalt_lgui? "win" : "mac", get_leyer_status());
  146. }
  147. static inline void render_keymap_status(void) {
  148. oled_write(layer_status_buf, false);
  149. }
  150. #define UPDATE_KEYMAP_STATUS() update_keymap_status()
  151. static inline void render_status(void) {
  152. UPDATE_LED_STATUS();
  153. RENDER_LED_STATUS();
  154. render_keymap_status();
  155. UPDATE_LOCK_STATUS();
  156. RENDER_LOCK_STATUS();
  157. RENDER_KEY_STATUS();
  158. }
  159. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  160. // if (is_keyboard_master())
  161. // return OLED_ROTATION_180; // flips the display 180 degrees if offhand
  162. return rotation;
  163. }
  164. void oled_task_user(void) {
  165. if (is_keyboard_master()) {
  166. render_status();
  167. } else {
  168. render_logo();
  169. }
  170. }
  171. #else
  172. #define UPDATE_KEYMAP_STATUS()
  173. #endif
  174. static inline void update_change_layer(bool pressed, uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  175. pressed ? layer_on(layer1) : layer_off(layer1);
  176. IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2) ? layer_on(layer3) : layer_off(layer3);
  177. }
  178. int RGB_current_mode;
  179. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  180. UPDATE_KEY_STATUS(keycode, record);
  181. bool result = false;
  182. switch (keycode) {
  183. case LOWER:
  184. update_change_layer(record->event.pressed, _LOWER, _RAISE, _ADJUST);
  185. break;
  186. case RAISE:
  187. update_change_layer(record->event.pressed, _RAISE, _LOWER, _ADJUST);
  188. break;
  189. case KANJI:
  190. if (record->event.pressed) {
  191. if (keymap_config.swap_lalt_lgui == false) {
  192. register_code(KC_LANG2);
  193. } else {
  194. SEND_STRING(SS_LALT("`"));
  195. }
  196. } else {
  197. unregister_code(KC_LANG2);
  198. }
  199. break;
  200. #ifdef RGBLIGHT_ENABLE
  201. case RGBRST:
  202. if (record->event.pressed) {
  203. eeconfig_update_rgblight_default();
  204. rgblight_enable();
  205. }
  206. break;
  207. #endif
  208. default:
  209. result = true;
  210. break;
  211. }
  212. UPDATE_KEYMAP_STATUS();
  213. return result;
  214. }