]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/planck/keymaps/skug/keymap.c
Merge branch 'master' of https://github.com/qmk/qmk_firmware
[qmk_firmware.git] / keyboards / planck / keymaps / skug / keymap.c
1 /* Copyright 2015-2017 Jack Humbert, Christoffer Holmberg
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
17 #include QMK_KEYBOARD_H
18 #include "keymap_swedish.h"
19 #include "muse.h"
20
21 extern keymap_config_t keymap_config;
22
23 enum planck_layers {
24   _DEFAULT,
25   _LOWER,
26   _RAISE,
27   _UTILITY,
28   _ADJUST
29 };
30
31 enum planck_keycodes {
32   DEFAULT = SAFE_RANGE,
33   RAISE,
34   LOWER,
35   UTILITY,
36   BACKLIT,
37   S1, S2, S3, S4, S5, S6, S7, S8, S9
38 };
39
40 #define ESC_LOW LT(_LOWER, KC_ESC)
41 #define BSP_RAI LT(_RAISE, KC_BSPC)
42 #define LFT_CTR CTL_T(NO_APOS)
43 #define RGT_CTR CTL_T(KC_TILD)
44 #define UTILITY MO(_UTILITY)
45
46 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
47
48 /* Qwerty
49  * ,-----------------------------------------------------------------------------------.
50  * | Tab  |   Q  |   W  |   E  |   R  |   T  |   Y  |   U  |   I  |   O  |   P  |  Å   |
51  * |------+------+------+------+------+-------------+------+------+------+------+------|
52  * | Fn   |   A  |   S  |   D  |   F  |   G  |   H  |   J  |   K  |   L  |   Ö  |  Ä   |
53  * |------+------+------+------+------+------|------+------+------+------+------+------|
54  * | Shift|   Z  |   X  |   C  |   V  |   B  |   N  |   M  |   ,  |   .  |   -  |Shift |
55  * |------+------+------+------+------+------+------+------+------+------+------+------|
56  * | Ctrl | Super| Alt  |      |L/Esc | Ret  | Space|R/Bspc|      |AltGr |   *  |  ¨   |
57  * `-----------------------------------------------------------------------------------'
58  */
59 [_DEFAULT] = LAYOUT_planck_grid(
60     KC_TAB , KC_Q   , KC_W   , KC_E   , KC_R   , KC_T   , KC_Y    , KC_U   , KC_I   , KC_O   , KC_P   , NO_AA  ,
61     UTILITY, KC_A   , KC_S   , KC_D   , KC_F   , KC_G   , KC_H    , KC_J   , KC_K   , KC_L   , NO_OSLH, NO_AE  ,
62     KC_LSPO, KC_Z   , KC_X   , KC_C   , KC_V   , KC_B   , KC_N    , KC_M   , KC_COMM, KC_DOT , NO_MINS, KC_RSPC,
63     LFT_CTR, KC_LALT, KC_LGUI, NO_AT  , ESC_LOW, KC_ENT , KC_SPC  , BSP_RAI, _______, KC_ALGR, NO_ASTR, RGT_CTR
64 ),
65
66 /* Raise
67  * ,-----------------------------------------------------------------------------------.
68  * |   `  |   1  |   2  |   3  |   4  |   5  |   6  |   7  |   8  |   9  |   0  |   +  |
69  * |------+------+------+------+------+-------------+------+------+------+------+------|
70  * |      |      |      |      |      |      |      |      |      |      |      |      |
71  * |------+------+------+------+------+------|------+------+------+------+------+------|
72  * |      |      |      |      |      |      |      |      |      |      |      |      |
73  * |------+------+------+------+------+------+------+------+------+------+------+------|
74  * |      |      |      |      |      |      |      |      |      |      |      |      |
75  * `-----------------------------------------------------------------------------------'
76  */
77 [_RAISE] = LAYOUT_planck_grid(
78     KC_GRV,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    KC_PLUS,
79     _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
80     _______, NO_GRTR, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
81     _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
82 ),
83
84 /* Lower
85  * ,-----------------------------------------------------------------------------------.
86  * |      |      |      |      |      |      |      |      |      |      |      |      |
87  * |------+------+------+------+------+-------------+------+------+------+------+------|
88  * |      |      |      |      |      |      |      |      |      |      |      |      |
89  * |------+------+------+------+------+------|------+------+------+------+------+------|
90  * |      |      |      |      |      |      |      |      |      |      |      |      |
91  * |------+------+------+------+------+------+------+------+------+------+------+------|
92  * |      |      |      |      |      |      |      |      |      |      |      |      |
93  * `-----------------------------------------------------------------------------------'
94  */
95 [_LOWER] = LAYOUT_planck_grid(
96     NO_HALF, LSFT(KC_1), NO_QUO2, LSFT(KC_3), NO_BULT, LSFT(KC_5), NO_AMPR, NO_SLSH, NO_LPRN, NO_RPRN, NO_EQL , NO_QUES,
97     _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
98     _______, NO_LESS, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
99     _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
100 ),
101
102 /* Utility layer
103  * ,-----------------------------------------------------------------------------------.
104  * |      |      |  up  |      |      |      |      |      |  S1  |  S2  |  S3  |      |
105  * |------+------+------+------+------+-------------+------+------+------+------+------|
106  * |      | left | down | right|      |      |      |      |  S4  |  S5  |  S6  |      |
107  * |------+------+------+------+------+------|------+------+------+------+------+------|
108  * |      |      |      |      |      |      |      |      |  S7  |  S8  |  S9  |      |
109  * |------+------+------+------+------+------+------+------+------+------+------+------|
110  * |      |      |      |      |      |      |      | Del  |      |      |      |      |
111  * `-----------------------------------------------------------------------------------'
112  */
113
114 [_UTILITY] = LAYOUT_planck_grid(
115     _______, _______, KC_UP  , _______, _______, _______, _______, _______, S1     , S2     , S3     , _______,
116     _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, S4     , S5     , S6     , _______,
117     _______, _______, _______, _______, _______, _______, _______, _______, S7     , S8     , S9     , _______,
118     _______, _______, _______, _______, _______, _______, _______, KC_DEL , _______, _______, _______, _______
119 ),
120
121 /* Adjust (Lower + Raise)
122  * ,-----------------------------------------------------------------------------------.
123  * |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |  F7  |  F8  |  F9  |  F10 |  F11 | F12  |
124  * |------+------+------+------+------+-------------+------+------+------+------+------|
125  * |      |Reset |      |Aud on|Audoff|AGnorm|AGswap|Qwerty|      |      |Utilit|      |
126  * |------+------+------+------+------+------|------+------+------+------+------+------|
127  * |      |      |      |      |      |      |      |      |      |      |      |      |
128  * |------+------+------+------+------+------+------+------+------+------+------+------|
129  * |      |      |      |      |      |      |      |      |      |      |      |      |
130  * `-----------------------------------------------------------------------------------'
131  */
132 [_ADJUST] = LAYOUT_planck_grid(
133     KC_F1  , KC_F2  , KC_F3  , KC_F4  , KC_F5  , KC_F6  , KC_F7  , KC_F8  , KC_F9   , KC_F10 , KC_F11 , KC_F12 ,
134     _______, RESET  , MU_MOD , AU_ON  , AU_OFF , AG_NORM, AG_SWAP, DEFAULT, XXXXXXX , XXXXXXX, UTILITY, _______,
135     _______, NO_PIPE, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
136     _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
137 )
138
139
140 };
141
142 #ifdef AUDIO_ENABLE
143   float plover_song[][2]     = SONG(PLOVER_SOUND);
144   float plover_gb_song[][2]  = SONG(PLOVER_GOODBYE_SOUND);
145   float s1[][2]              = SONG(NUMBER_ONE);
146   float s2[][2]              = SONG(ZELDA_PUZZLE);
147   float s3[][2]              = SONG(ZELDA_TREASURE);
148   float s4[][2]              = SONG(OVERWATCH_THEME);
149   float s5[][2]              = SONG(IMPERIAL_MARCH);
150   float s6[][2]              = SONG(E1M1_DOOM);
151   float s7[][2]              = SONG(COIN_SOUND);
152   float s8[][2]              = SONG(ONE_UP_SOUND);
153   float s9[][2]              = SONG(SONIC_RING);
154 #endif
155
156 uint32_t layer_state_set_user(uint32_t state) {
157   return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
158 }
159
160 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
161   switch (keycode) {
162     case DEFAULT:
163       if (record->event.pressed) {
164         set_single_persistent_default_layer(_DEFAULT);
165       }
166       return false;
167       break;
168     case BACKLIT:
169       if (record->event.pressed) {
170         register_code(KC_RSFT);
171         #ifdef BACKLIGHT_ENABLE
172           backlight_step();
173         #endif
174         #ifdef KEYBOARD_planck_rev5
175           PORTE &= ~(1<<6);
176         #endif
177       } else {
178         unregister_code(KC_RSFT);
179         #ifdef KEYBOARD_planck_rev5
180           PORTE |= (1<<6);
181         #endif
182       }
183       return false;
184       break;
185     case S1:
186       if (record->event.pressed) {
187         #ifdef AUDIO_ENABLE
188             PLAY_SONG(s1);
189         #endif //AUDIO_ENABLE
190       }
191       return false;
192       break;
193     case S2:
194       if (record->event.pressed) {
195         #ifdef AUDIO_ENABLE
196             PLAY_SONG(s2);
197         #endif //AUDIO_ENABLE
198       }
199       return false;
200       break;
201     case S3:
202       if (record->event.pressed) {
203         #ifdef AUDIO_ENABLE
204             PLAY_SONG(s3);
205         #endif //AUDIO_ENABLE
206       }
207       return false;
208       break;
209     case S4:
210       if (record->event.pressed) {
211         #ifdef AUDIO_ENABLE
212             PLAY_SONG(s4);
213         #endif //AUDIO_ENABLE
214       }
215       return false;
216       break;
217     case S5:
218       if (record->event.pressed) {
219         #ifdef AUDIO_ENABLE
220             PLAY_SONG(s5);
221         #endif //AUDIO_ENABLE
222       }
223       return false;
224       break;
225     case S6:
226       if (record->event.pressed) {
227         #ifdef AUDIO_ENABLE
228             PLAY_SONG(s6);
229         #endif //AUDIO_ENABLE
230       }
231       return false;
232       break;
233     case S7:
234       if (record->event.pressed) {
235         #ifdef AUDIO_ENABLE
236             PLAY_SONG(s7);
237         #endif //AUDIO_ENABLE
238       }
239       return false;
240       break;
241     case S8:
242       if (record->event.pressed) {
243         #ifdef AUDIO_ENABLE
244             PLAY_SONG(s8);
245         #endif //AUDIO_ENABLE
246       }
247       return false;
248       break;
249     case S9:
250       if (record->event.pressed) {
251         #ifdef AUDIO_ENABLE
252             PLAY_SONG(s9);
253         #endif //AUDIO_ENABLE
254       }
255       return false;
256       break;
257   }
258   return true;
259 }
260
261 bool muse_mode = false;
262 uint8_t last_muse_note = 0;
263 uint16_t muse_counter = 0;
264 uint8_t muse_offset = 70;
265 uint16_t muse_tempo = 50;
266
267 void encoder_update(bool clockwise) {
268   if (muse_mode) {
269     if (IS_LAYER_ON(_RAISE)) {
270       if (clockwise) {
271         muse_offset++;
272       } else {
273         muse_offset--;
274       }
275     } else {
276       if (clockwise) {
277         muse_tempo+=1;
278       } else {
279         muse_tempo-=1;
280       }
281     }
282   } else {
283     if (clockwise) {
284       register_code(KC_PGDN);
285       unregister_code(KC_PGDN);
286     } else {
287       register_code(KC_PGUP);
288       unregister_code(KC_PGUP);
289     }
290   }
291 }
292
293 void dip_update(uint8_t index, bool active) {
294   switch (index) {
295     case 0:
296       if (active) {
297         #ifdef AUDIO_ENABLE
298           PLAY_SONG(plover_song);
299         #endif
300         layer_on(_ADJUST);
301       } else {
302         #ifdef AUDIO_ENABLE
303           PLAY_SONG(plover_gb_song);
304         #endif
305         layer_off(_ADJUST);
306       }
307       break;
308     case 1:
309       if (active) {
310         muse_mode = true;
311       } else {
312         muse_mode = false;
313         #ifdef AUDIO_ENABLE
314           stop_all_notes();
315         #endif
316       }
317    }
318 }
319
320 void matrix_scan_user(void) {
321   #ifdef AUDIO_ENABLE
322     if (muse_mode) {
323       if (muse_counter == 0) {
324         uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
325         if (muse_note != last_muse_note) {
326           stop_note(compute_freq_for_midi_note(last_muse_note));
327           play_note(compute_freq_for_midi_note(muse_note), 0xF);
328           last_muse_note = muse_note;
329         }
330       }
331       muse_counter = (muse_counter + 1) % muse_tempo;
332     }
333   #endif
334 }
335
336 bool music_mask_user(uint16_t keycode) {
337   switch (keycode) {
338     case RAISE:
339     case LOWER:
340       return false;
341     default:
342       return true;
343   }
344 }