]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/planck/keymaps/tom/keymap.c
[Keymap] Add custom Planck Light keymap (#5464)
[qmk_firmware.git] / keyboards / planck / keymaps / tom / keymap.c
1 /* Copyright 2015-2017 Jack Humbert
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 "muse.h"
19
20 extern keymap_config_t keymap_config;
21
22 enum planck_layers {
23   _QWERTY,
24   _COLEMAK,
25   _DVORAK,
26   _LOWER,
27   _RAISE,
28   _PLOVER,
29   _ADJUST
30 };
31
32 enum planck_keycodes {
33   QWERTY = SAFE_RANGE,
34   COLEMAK,
35   DVORAK,
36   PLOVER,
37   BACKLIT,
38   EXT_PLV
39 };
40
41 #define LOWER MO(_LOWER)
42 #define RAISE MO(_RAISE)
43
44 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
45
46 /* Qwerty
47  * ,-----------------------------------------------------------------------------------.
48  * | Esc  |   Q  |   W  |   E  |   R  |   T  |   Y  |   U  |   I  |   O  |   P  | Bksp |
49  * |------+------+------+------+------+-------------+------+------+------+------+------|
50  * | Tab  |   A  |   S  |   D  |   F  |   G  |   H  |   J  |   K  |   L  |   ;  |Enter |
51  * |------+------+------+------+------+------|------+------+------+------+------+------|
52  * | Shift|   Z  |   X  |   C  |   V  |   B  |   N  |   M  |   ,  |   .  |  Up  |Shift |
53  * |------+------+------+------+------+------+------+------+------+------+------+------|
54  * | Brite| Ctrl | Alt  | GUI  |Lower |    Space    |Raise |   /  | Left | Down |Right |
55  * `-----------------------------------------------------------------------------------'
56  */
57 [_QWERTY] = LAYOUT_planck_grid(
58     KC_ESC,  KC_Q,    KC_W,    KC_E,    KC_R,    KC_T,    KC_Y,    KC_U,    KC_I,    KC_O,    KC_P,    KC_BSPC,
59     KC_TAB,  KC_A,    KC_S,    KC_D,    KC_F,    KC_G,    KC_H,    KC_J,    KC_K,    KC_L,    KC_SCLN, KC_ENT,
60     KC_LSFT, KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_N,    KC_M,    KC_COMM, KC_DOT,  KC_UP,   KC_RSFT,
61     BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER,   KC_SPC,  KC_SPC,  RAISE,   KC_SLSH, KC_LEFT, KC_DOWN, KC_RGHT
62 ),
63
64
65 /* Lower
66  * ,-----------------------------------------------------------------------------------.
67  * |   ~  |   !  |   @  |   #  |   $  |   %  |   ^  |   &  |   *  |   (  |   )  |  |   |
68  * |------+------+------+------+------+-------------+------+------+------+------+------|
69  * | Del  |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |   _  |   +  |   {  |   }  |  '   |
70  * |------+------+------+------+------+------|------+------+------+------+------+------|
71  * |      |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |ISO ~ |ISO | | Home |  End |      |
72  * |------+------+------+------+------+------+------+------+------+------+------+------|
73  * |      |      |      |      |      |             |      | Vol- | Vol+ |Brite-|Brite+|
74  * `-----------------------------------------------------------------------------------'
75  */
76 [_LOWER] = LAYOUT_planck_grid(
77     KC_TILD, KC_EXLM, KC_AT,   KC_HASH, KC_DLR,  KC_PERC, KC_CIRC, KC_AMPR,    KC_ASTR,    KC_LPRN, KC_RPRN, KC_PIPE,
78     KC_DEL,  KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_UNDS,    KC_PLUS,    KC_LCBR, KC_RCBR, KC_QUOT,
79     _______, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  S(KC_NUHS), S(KC_NUBS), KC_HOME, KC_END,  _______,
80     _______, _______, _______, _______, _______, _______, _______, _______,    KC_VOLD,    KC_VOLU, KC_BRMD, KC_BRMU
81 ),
82
83 /* Raise
84  * ,-----------------------------------------------------------------------------------.
85  * |   `  |   1  |   2  |   3  |   4  |   5  |   6  |   7  |   8  |   9  |   0  |  \   |
86  * |------+------+------+------+------+-------------+------+------+------+------+------|
87  * | Del  |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |   -  |   =  |   [  |   ]  |  '   |
88  * |------+------+------+------+------+------|------+------+------+------+------+------|
89  * |      |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |ISO # |ISO / |Pg Up |Pg Dn |      |
90  * |------+------+------+------+------+------+------+------+------+------+------+------|
91  * |      |      |      |      |      |             |      | Vol- | Vol+ |Brite-|Brite+|
92  * `-----------------------------------------------------------------------------------'
93  */
94 [_RAISE] = LAYOUT_planck_grid(
95     KC_GRV,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    KC_BSLS,
96     KC_DEL,  KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_MINS, KC_EQL,  KC_LBRC, KC_RBRC, KC_QUOT,
97     _______, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  KC_NUHS, KC_NUBS, KC_PGUP, KC_PGDN, _______,
98     _______, _______, _______, _______, _______, _______, _______, _______, KC_VOLD, KC_VOLU, KC_BRMD, KC_BRMU
99 ),
100
101 /* Adjust (Lower + Raise)
102  * ,-----------------------------------------------------------------------------------.
103  * |      | Reset|      |      |      |      |      |      |      |      |      |  Del |
104  * |------+------+------+------+------+-------------+------+------+------+------+------|
105  * |      |      |      |Aud on|Audoff|AGnorm|AGswap|Qwerty|      |      |      |      |
106  * |------+------+------+------+------+------|------+------+------+------+------+------|
107  * |      |Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof|      |      |      |      |      |
108  * |------+------+------+------+------+------+------+------+------+------+------+------|
109  * |      |      |      |      |      |             |      |      |      |      |      |
110  * `-----------------------------------------------------------------------------------'
111  */
112 [_ADJUST] = LAYOUT_planck_grid(
113     _______, RESET,   DEBUG,   RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD,  RGB_VAI, RGB_VAD, KC_DEL ,
114     _______, _______, MU_MOD,  AU_ON,   AU_OFF,  AG_NORM, AG_SWAP, QWERTY,  _______,  _______, _______, _______,
115     _______, MUV_DE,  MUV_IN,  MU_ON,   MU_OFF,  MI_ON,   MI_OFF,  TERM_ON, TERM_OFF, _______, _______, _______,
116     _______, _______, _______, _______, _______, _______, _______, _______, _______,  _______, _______, _______
117 )
118
119 };
120
121 #ifdef AUDIO_ENABLE
122   float plover_song[][2]     = SONG(PLOVER_SOUND);
123   float plover_gb_song[][2]  = SONG(PLOVER_GOODBYE_SOUND);
124 #endif
125
126 uint32_t layer_state_set_user(uint32_t state) {
127   return update_tri_layer_state(state, _LOWER, _RAISE, _ADJUST);
128 }
129
130 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
131   switch (keycode) {
132     case QWERTY:
133       if (record->event.pressed) {
134         print("mode just switched to qwerty and this is a huge string\n");
135         set_single_persistent_default_layer(_QWERTY);
136       }
137       return false;
138       break;
139     case BACKLIT:
140       if (record->event.pressed) {
141         register_code(KC_RSFT);
142         #ifdef BACKLIGHT_ENABLE
143           backlight_step();
144         #endif
145         #ifdef KEYBOARD_planck_rev5
146           PORTE &= ~(1<<6);
147         #endif
148       } else {
149         unregister_code(KC_RSFT);
150         #ifdef KEYBOARD_planck_rev5
151           PORTE |= (1<<6);
152         #endif
153       }
154       return false;
155       break;
156     case EXT_PLV:
157       if (record->event.pressed) {
158         #ifdef AUDIO_ENABLE
159           PLAY_SONG(plover_gb_song);
160         #endif
161         layer_off(_PLOVER);
162       }
163       return false;
164       break;
165   }
166   return true;
167 }
168
169 bool muse_mode = false;
170 uint8_t last_muse_note = 0;
171 uint16_t muse_counter = 0;
172 uint8_t muse_offset = 70;
173 uint16_t muse_tempo = 50;
174
175 void encoder_update(bool clockwise) {
176   if (muse_mode) {
177     if (IS_LAYER_ON(_RAISE)) {
178       if (clockwise) {
179         muse_offset++;
180       } else {
181         muse_offset--;
182       }
183     } else {
184       if (clockwise) {
185         muse_tempo+=1;
186       } else {
187         muse_tempo-=1;
188       }
189     }
190   } else {
191     if (clockwise) {
192       #ifdef MOUSEKEY_ENABLE
193         tap_code(KC_MS_WH_DOWN);
194       #else
195         tap_code(KC_PGDN);
196       #endif
197     } else {
198       #ifdef MOUSEKEY_ENABLE
199         tap_code(KC_MS_WH_UP);
200       #else
201         tap_code(KC_PGUP);
202       #endif
203     }
204   }
205 }
206
207 void dip_update(uint8_t index, bool active) {
208   switch (index) {
209     case 0:
210       if (active) {
211         #ifdef AUDIO_ENABLE
212           PLAY_SONG(plover_song);
213         #endif
214         layer_on(_ADJUST);
215       } else {
216         #ifdef AUDIO_ENABLE
217           PLAY_SONG(plover_gb_song);
218         #endif
219         layer_off(_ADJUST);
220       }
221       break;
222     case 1:
223       if (active) {
224         muse_mode = true;
225       } else {
226         muse_mode = false;
227         #ifdef AUDIO_ENABLE
228           stop_all_notes();
229         #endif
230       }
231    }
232 }
233
234 void matrix_scan_user(void) {
235   #ifdef AUDIO_ENABLE
236     if (muse_mode) {
237       if (muse_counter == 0) {
238         uint8_t muse_note = muse_offset + SCALE[muse_clock_pulse()];
239         if (muse_note != last_muse_note) {
240           stop_note(compute_freq_for_midi_note(last_muse_note));
241           play_note(compute_freq_for_midi_note(muse_note), 0xF);
242           last_muse_note = muse_note;
243         }
244       }
245       muse_counter = (muse_counter + 1) % muse_tempo;
246     }
247   #endif
248 }
249
250 bool music_mask_user(uint16_t keycode) {
251   switch (keycode) {
252     case RAISE:
253     case LOWER:
254       return false;
255     default:
256       return true;
257   }
258 }
259
260 void rgb_matrix_indicators_user(void) {
261   #ifdef RGB_MATRIX_ENABLE
262   rgb_led led;
263   switch (biton32(layer_state)) {
264     case _RAISE:
265       for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
266         led = g_rgb_leds[i];
267         if ( led.modifier ) {
268           rgb_matrix_set_color(i, 0x6B, 0x00, 0x80);
269         } else {
270           rgb_matrix_set_color(i, 0x00, 0xFF, 0x00);
271         }
272       }
273       break;
274
275     case _LOWER:
276       for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
277         led = g_rgb_leds[i];
278         if ( led.modifier ) {
279           rgb_matrix_set_color(i, 0xFF, 0xA5, 0x00);
280         } else {
281           rgb_matrix_set_color(i, 0x00, 0x67, 0xC7);
282         }
283       }
284       break;
285
286     case _ADJUST:
287       for (int i = 0; i < DRIVER_LED_TOTAL; i++) {
288         rgb_matrix_set_color(i, 0xFF, 0x99, 0x00);
289       }
290       rgb_matrix_set_color(1, 0xFF, 0x00, 0x00);
291       break;
292
293     default:
294       break;
295   }
296   #endif
297 }