keymap.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #include "atomic.h"
  2. #include "action_layer.h"
  3. #ifdef AUDIO_ENABLE
  4. #include "audio.h"
  5. #endif
  6. #define _QW 0
  7. #define _LW 1
  8. #define _RS 2
  9. #define _AD 3
  10. #define _FN 4
  11. #define M_QW 0
  12. #define M_LW 1
  13. #define M_RS 2
  14. #define M_FN 3
  15. #define _______ KC_TRNS
  16. #define ___T___ KC_TRNS
  17. #define XXXXXXX KC_NO
  18. /*
  19. * .---------------------------------------------------------------------------------------------------------------------- 2u ------------.
  20. * | ESC | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | = | XXXXXX . BACKSP |
  21. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+-----------------|
  22. * | TAB | Q | W | E | R | T | Y | U | I | O | P | [ | ] | \ | DEL |
  23. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+- 2u ------------+--------|
  24. * | CAPS | A | S | D | F | G | H | J | K | L | ; | ' | XXXXXX . ENTER | PG UP |
  25. * |--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+- 2u ---------------------+--------|
  26. * | LSHIFT | Z | X | C | V | B | N | M | , | . | / | XXXXXX . RSHIFT | UP | PG DN |
  27. * |--------+--------+--------+--------+--------+- 2u ------------+--------+--------+--------+--------+-----------------+--------+--------|
  28. * | LCTRL | LWIN | FN | LALT | RAISED | XXXXXX . SPACE | LOWER | RALT | HOME | END | RCTRL | LEFT | DOWN | RIGHT |
  29. * '--------------------------------------------------------------------------------------------------------------------------------------'
  30. */
  31. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  32. [_QW] = { /* QWERTY */
  33. { KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, XXXXXXX },
  34. { KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL },
  35. { KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, XXXXXXX, KC_PGUP },
  36. { KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, XXXXXXX, KC_UP, KC_PGDN },
  37. { KC_LCTL, KC_LGUI, M(M_FN), KC_LALT, M(M_RS), KC_SPC, XXXXXXX, M(M_LW), KC_RALT, KC_HOME, KC_END, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT },
  38. },
  39. [_LW] = { /* LOWERED */
  40. { KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, ___T___, ___T___ },
  41. { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_INS },
  42. { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, ___T___, ___T___, _______ },
  43. { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, ___T___, ___T___, _______, _______ },
  44. { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
  45. },
  46. [_RS] = { /* RAISED */
  47. { KC_TILD, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, ___T___, ___T___ },
  48. { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_INS },
  49. { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, ___T___, ___T___, _______ },
  50. { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, ___T___, ___T___, _______, _______ },
  51. { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
  52. },
  53. [_FN] = { /* FUNCTION */
  54. { KC_NLCK, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, ___T___, ___T___ },
  55. { KC_SLCK, KC_F13, KC_F14, KC_F15, KC_F16, KC_F17, KC_F18, KC_F19, KC_F20, KC_F21, KC_F22, KC_F23, KC_F24, KC_PAUS, KC_PSCR },
  56. { KC_CAPS, KC_BTN5, KC_BTN4, KC_BTN3, KC_BTN2, KC_ACL0, KC_ACL2, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY, _______, ___T___, ___T___, KC_WH_U },
  57. { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, ___T___, ___T___, KC_MS_U, KC_WH_D },
  58. { _______, _______, _______, _______, _______, KC_BTN1, KC_BTN1, _______, _______, _______, _______, _______, KC_MS_L, KC_MS_D, KC_MS_R },
  59. },
  60. [_AD] = { /* ADJUST */
  61. { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, ___T___, ___T___ },
  62. { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
  63. { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, ___T___, ___T___, _______ },
  64. { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, ___T___, ___T___, _______, _______ },
  65. { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
  66. },
  67. };
  68. #define IS_LAYER_ON(layer) (layer_state & (1UL << (layer)))
  69. #define IS_LAYER_OFF(layer) (!IS_LAYER_ON(layer))
  70. #ifdef AUDIO_ENABLE
  71. float tone_lw[][2] = {
  72. {440.0*pow(2.0,(59)/12.0), 8},
  73. {440.0*pow(2.0,(60)/12.0), 8},
  74. {0, 4},
  75. {440.0*pow(2.0,(67)/12.0), 16}
  76. };
  77. float tone_rs[][2] = {
  78. {440.0*pow(2.0,(59)/12.0), 8},
  79. {440.0*pow(2.0,(60)/12.0), 8},
  80. {0, 4},
  81. {440.0*pow(2.0,(67)/12.0), 16},
  82. {0, 4},
  83. {440.0*pow(2.0,(71)/12.0), 16}
  84. };
  85. float tone_fn[][2] = {
  86. {440.0*pow(2.0,(59)/12.0), 8},
  87. {440.0*pow(2.0,(60)/12.0), 8},
  88. {0, 4},
  89. {440.0*pow(2.0,(67)/12.0), 16},
  90. {0, 4},
  91. {440.0*pow(2.0,(69)/12.0), 16},
  92. {0, 4},
  93. {440.0*pow(2.0,(67)/12.0), 16}
  94. };
  95. #endif
  96. void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3)
  97. {
  98. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2))
  99. {
  100. #ifdef AUDIO_ENABLE
  101. println("PlayNotes FN");
  102. play_notes(&tone_fn, 8, false);
  103. #endif
  104. layer_on(layer3);
  105. }
  106. else
  107. {
  108. layer_off(layer3);
  109. }
  110. }
  111. void update_quad_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3, uint8_t layer4, bool order)
  112. {
  113. if (order)
  114. {
  115. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2))
  116. {
  117. layer_on(layer3);
  118. }
  119. else
  120. {
  121. layer_off(layer3);
  122. layer_off(layer4);
  123. }
  124. }
  125. else
  126. {
  127. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2))
  128. {
  129. layer_on(layer4);
  130. }
  131. else
  132. {
  133. layer_off(layer3);
  134. layer_off(layer4);
  135. }
  136. }
  137. }
  138. const uint16_t PROGMEM fn_actions[] = {
  139. };
  140. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  141. {
  142. // MACRODOWN only works in this function
  143. switch(id) {
  144. case M_LW:
  145. if (record->event.pressed) {
  146. #ifdef AUDIO_ENABLE
  147. println("PlayNotes LW");
  148. play_notes(&tone_lw, 4, false);
  149. #endif
  150. layer_on(_LW);
  151. update_tri_layer(_LW, _RS, _FN);
  152. } else {
  153. layer_off(_LW);
  154. update_tri_layer(_LW, _RS, _FN);
  155. }
  156. break;
  157. case M_RS:
  158. if (record->event.pressed) {
  159. #ifdef AUDIO_ENABLE
  160. println("PlayNotes RS");
  161. play_notes(&tone_rs, 6, false);
  162. #endif
  163. layer_on(_RS);
  164. update_tri_layer(_LW, _RS, _FN);
  165. } else {
  166. layer_off(_RS);
  167. update_tri_layer(_LW, _RS, _FN);
  168. }
  169. break;
  170. default:
  171. break;
  172. }
  173. return MACRO_NONE;
  174. };
  175. #ifdef AUDIO_ENABLE
  176. float start_up[][2] = {
  177. {440.0*pow(2.0,(67)/12.0), 12},
  178. {440.0*pow(2.0,(64)/12.0), 8},
  179. {440.0*pow(2.0,(55)/12.0), 8},
  180. {440.0*pow(2.0,(60)/12.0), 8},
  181. {440.0*pow(2.0,(64)/12.0), 20}
  182. };
  183. #endif
  184. void matrix_init_user(void) {
  185. #ifdef AUDIO_ENABLE
  186. init_notes();
  187. play_notes(&start_up, 5, false);
  188. println("Matrix Init");
  189. #endif
  190. }