2020 February 29 Breaking Changes Update (#8064)
[jackhill/qmk/firmware.git] / keyboards / planck / keymaps / cbbrowne / keymap.c
CommitLineData
26eef35f 1#include QMK_KEYBOARD_H
97817a77 2#include "version.h"
71bd4818 3
5e64f710 4/* Each layer is given a name to aid in readability, which is then
ade22f8e 5 used in the keymap matrix below. The underscores do not denote
5e64f710
CB
6 anything - you can have a layer called STUFF or any other name.
7
8 Layer names don't all need to be of the same length, obviously, and
9 you could also skip them entirely and just use numbers, though that
10 means needing to manage the numbers.
11
12 It is preferable to keep the symbols short so that a line worth of
13 key mappings fits compactly onto a line of code. */
71bd4818 14
9aca1c70
CB
15/* This was originally based on planck/keymaps/default/default.c, and
16 then cbbrowne has revised things */
17
ade22f8e 18/* Things I did not like about the default mapping
9aca1c70 19
49845540
CB
20 - I found control too hard to get to. I use it more than Tab, so
21 switched it there.
22 - Having dash on [lower-j] is a bit nonintuitive, but may be OK
9aca1c70
CB
23 - I'll bet I should switch ESC/TAB
24 - I'm suspicious that I want to shift M(0) from [4][1] to [4][2],
25 and shift ESC off the first column so KC_LCTL and KC_LALT can
26 be on the first column.
49845540 27 - I needed to swap ' and ENTER
9aca1c70 28
5273c73b
CB
29 - All of the above are done :-)
30
ade22f8e 31 - Dropped out support for Dvorak and friends. They aren't
49845540 32 improvements to me
9aca1c70
CB
33*/
34
7919839b
CB
35
36/* Some interesting things implemented
37
a07d1f22
CB
38 - There is a macro that writes out "cbbrowne" just to show that I
39 could
7919839b
CB
40 - There is a (somewhat cruddy) linear congruential random number
41 generator.
a07d1f22 42 - I seed it somewhat with clock info to make it look more random
7919839b
CB
43 - There are two macros that use the random number generators
44 - one, M_RANDDIGIT, generates a random digit based on state
45 of the random number generator
46 - the other, M_RANDLETTER, generates a random letter based on state
47 of the random number generator
0d445444
CB
48 - in both, note the use of register_code()/unregister_code()
49 to indicate the desired key
49845540 50 - I do indeed want a sweet number pad!
7919839b
CB
51*/
52
05d43b06
CB
53/* Other things to do...
54
55 - Need to think about what zsh and readline actions I use lots
05d43b06 56 - Ought to ensure that Control-Alt-Delete is convenient enough
a07d1f22 57 - How about Alt-F1 thru Alt-F8? Not yet...
05d43b06 58 - What's the keystroke to get from X to console these days?
05d43b06 59 - A layer for doing console switching would not be a bad idea
a07d1f22
CB
60
61 - I'm messing with jeremy-dev's keymap that shifts everything
62 outwards. Gotta figure out how to make it sensible...
05d43b06
CB
63*/
64
71bd4818 65enum layers {
344929e0 66 _QWERTY = 0, /* Qwerty mapping */
67 _LOWER, /* Lower layer, where top line has symbols !@#$%^&*() */
68 _RAISE, /* Raised layer, where top line has digits 1234567890 */
fdeaf1d9 69 _KEYPAD, /* Key pad */
6a7ef596 70 _ADJUST, /* Special Adjust layer coming via tri-placement */
a07d1f22
CB
71
72};
73
74enum my_keycodes {
75 MY_ABVE = SAFE_RANGE,
76 MY_BELW,
77 MY_TERM,
78 MY_DEQL, // /=
79 MY_MEQL, // *=
80 MY_SEQL, // -=
81 MY_PEQL, // +=
82 MY_NEQL, // !=
83 MY_LTGT, // <>
84 MY_DPIP, // ||
85 MY_DAMP, // &&
71bd4818
CB
86};
87
674c6273
CB
88enum macro_id {
89 M_LED = 0,
90 M_USERNAME,
7919839b 91 M_RANDDIGIT,
2cf26915 92 M_RANDLETTER,
6a7ef596 93 M_VERSION,
94 MACRO_UPPER,
95 MACRO_LOWER,
674c6273
CB
96};
97
6a7ef596 98#define M_LOWER M(MACRO_LOWER)
99#define M_UPPER M(MACRO_UPPER)
5be2795c 100#define ROT_LED M(M_LED) /* Rotate LED */
101#define QWERTY DF(_QWERTY) /* Switch to QWERTY layout */
102#define KEYPAD DF(_KEYPAD) /* Switch to keypad */
103#define USERNAME M(M_USERNAME) /* shortcut for username */
104#define RANDDIG M(M_RANDDIGIT)
105#define RANDALP M(M_RANDLETTER)
5d643bb7 106#define CTLENTER MT(MOD_RCTL, KC_ENT)
107#define SHIFTQUOTE MT(MOD_RSFT, KC_QUOT)
24e8d01d 108#define ALTRIGHT MT(MOD_LALT, KC_RGHT)
cc7604d1 109#define MVERSION M(M_VERSION)
99ca59ba 110#define ALTSLASH LALT(KC_SLSH)
5be2795c 111
6a7ef596 112
5e64f710 113/* Note that Planck has dimensions 4 rows x 12 columns */
71bd4818
CB
114
115const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
26eef35f
JY
116[_QWERTY] = LAYOUT_planck_grid( /* Qwerty */
117 KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
118 KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, CTLENTER,
119 KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, SHIFTQUOTE ,
120 KC_TAB, KC_LALT, ROT_LED, KC_LGUI, M_LOWER, KC_SPC, KC_SPC, M_UPPER, KC_LEFT, KC_DOWN, KC_UP, ALTRIGHT
28942b3b 121 /* Note that KC_SPC is recorded TWICE, so that either matrix position can activate it */
26eef35f
JY
122),
123[_RAISE] = LAYOUT_planck_grid( /* RAISE */
124 KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
125 _______, KC_4, KC_5, KC_6, _______, _______, _______, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSLS,
126 _______, KC_7, KC_8, KC_9, _______, _______, _______, QWERTY, KEYPAD, KEYPAD, ALTSLASH,_______,
127 _______, KC_0, _______, _______, _______, _______, _______, _______, KC_PGDN, KC_HOME, KC_END, KC_PGUP
128),
129[_LOWER] = LAYOUT_planck_grid( /* LOWER */
130 KC_TILD, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC,
131 _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE,
132 _______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, QWERTY, KEYPAD, KEYPAD, ALTSLASH, _______,
133 _______, KEYPAD, _______, _______, _______, _______, _______, _______, KC_PGDN, KC_HOME, KC_END, KC_PGUP
134 ),
135[_KEYPAD] = LAYOUT_planck_grid( /* Key Pad */
136 KC_ESC, USERNAME, MVERSION, KC_F10, KC_F11, KC_F12, KC_PGUP, KC_KP_ENTER, KC_7, KC_8, KC_9, KC_BSPC,
137 KC_LCTL, RANDDIG, KC_F5, KC_F6, KC_F7, KC_F8, KC_PGDN, KC_KP_MINUS, KC_4, KC_5, KC_6, KC_PIPE,
138 KC_LSFT, RANDALP, KC_F1, KC_F2, KC_F3, KC_F4, KC_DEL, KC_KP_PLUS, KC_1, KC_2, KC_3, KC_ENTER,
139 KC_TAB, KC_LALT, ROT_LED, KC_LGUI, M_LOWER, KC_SPC, KC_SPC, QWERTY, KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT
140),
141
142[_ADJUST] = LAYOUT_planck_grid( /* Adjustments - gonna shift the wild tools in here */
143 ROT_LED,USERNAME,MVERSION, _______, _______, _______, _______, _______, _______, _______, _______, _______ ,
144 _______, RANDDIG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ ,
145 _______, RANDALP, _______, _______, _______, RESET, RESET, _______, _______, _______, _______, _______ ,
146 _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______
147)
71bd4818
CB
148};
149
7919839b 150/* This bit of logic seeds a wee linear congruential random number generator */
49845540 151/* lots of prime numbers everywhere... */
674c6273 152static uint16_t random_value = 157;
674c6273 153
71bd4818
CB
154const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
155{
fe1519de
CB
156 uint8_t clockbyte=0;
157 clockbyte = TCNT1 % 256;
8079dc06 158 uint8_t rval;
71bd4818 159 // MACRODOWN only works in this function
91c46816 160 switch(id) {
674c6273 161 case M_LED:
91c46816
CB
162 if (record->event.pressed) {
163 register_code(KC_RSFT);
164#ifdef BACKLIGHT_ENABLE
165 backlight_step();
166#endif
167 } else {
168 unregister_code(KC_RSFT);
169 }
ade22f8e 170 break;
674c6273
CB
171 case M_USERNAME:
172 if (record->event.pressed) {
49845540 173 SEND_STRING("cbbrowne");
674c6273
CB
174 }
175 break;
2cf26915
CB
176 case M_VERSION:
177 if (record->event.pressed) {
178 SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP "@" QMK_VERSION "@" QMK_BUILDDATE);
179 }
180 break;
674c6273 181 case M_RANDDIGIT:
7919839b
CB
182 /* Generate, based on random number generator, a keystroke for
183 a numeric digit chosen at random */
674c6273 184 random_value = ((random_value + randadd) * randmul) % randmod;
8079dc06 185 if (record->event.pressed) {
fe1519de
CB
186 /* Here, we mix the LCRNG with low bits from one of the system
187 clocks via XOR in the theory that this may be more random
ade22f8e 188 than either separately */
8079dc06
CB
189 rval = (random_value ^ clockbyte) % 10;
190 /* Note that KC_1 thru KC_0 are a contiguous range */
191 register_code (KC_1 + rval);
192 unregister_code (KC_1 + rval);
193 }
7919839b
CB
194 break;
195 case M_RANDLETTER:
196 /* Generate, based on random number generator, a keystroke for
197 a letter chosen at random */
fe1519de
CB
198 /* Here, we mix the LCRNG with low bits from one of the system
199 clocks via XOR in the theory that this may be more random
ade22f8e 200 than either separately */
7919839b 201 random_value = ((random_value + randadd) * randmul) % randmod;
8079dc06
CB
202 if (record->event.pressed) {
203 rval = (random_value ^ clockbyte) % 26;
204 register_code (KC_A + rval);
205 unregister_code (KC_A + rval);
206 }
91c46816 207 break;
6a7ef596 208 case MACRO_UPPER:
209 if (record->event.pressed)
210 {
344929e0 211 layer_on(_RAISE);
4464d90f 212#ifdef BACKLIGHT_BREATHING
4931510a 213 breathing_period_set(2);
cc7604d1 214 breathing_pulse();
215#endif
344929e0 216 update_tri_layer(_LOWER, _RAISE, _ADJUST);
6a7ef596 217 }
218 else
219 {
344929e0 220 layer_off(_RAISE);
221 update_tri_layer(_LOWER, _RAISE, _ADJUST);
6a7ef596 222 }
223 break;
224 case MACRO_LOWER:
225 if (record->event.pressed)
226 {
344929e0 227 layer_on(_LOWER);
4464d90f 228#ifdef BACKLIGHT_BREATHING
4931510a 229 breathing_period_set(2);
cc7604d1 230 breathing_pulse();
231#endif
344929e0 232 update_tri_layer(_LOWER, _RAISE, _ADJUST);
6a7ef596 233 }
234 else
235 {
344929e0 236 layer_off(_LOWER);
237 update_tri_layer(_LOWER, _RAISE, _ADJUST);
6a7ef596 238 }
239 break;
ade22f8e 240
91c46816
CB
241 }
242 return MACRO_NONE;
71bd4818 243};
a07d1f22
CB
244
245void press_key(uint16_t key) {
246 register_code(key);
247 unregister_code(key);
248}
249
250void press_two_keys(uint16_t key1, uint16_t key2) {
251 register_code(key1);
252 register_code(key2);
253 unregister_code(key2);
254 unregister_code(key1);
255}
256
257void press_three_keys(uint16_t key1, uint16_t key2, uint16_t key3) {
258 register_code(key1);
259 register_code(key2);
260 register_code(key3);
261 unregister_code(key3);
262 unregister_code(key2);
263 unregister_code(key1);
264}
265
266bool process_record_user(uint16_t keycode, keyrecord_t *record) {
267 switch (keycode) {
268 case MY_BELW:
269 if (record->event.pressed) {
270 press_two_keys(KC_LGUI, KC_RGHT);
271 press_key(KC_ENT);
272 }
273
274 return false;
275
276 case MY_ABVE:
277 if (record->event.pressed) {
278 press_two_keys(KC_LGUI, KC_LEFT);
279 press_key(KC_ENT);
280 press_key(KC_UP);
281 }
282
283 return false;
284
285 case MY_TERM:
286 if (record->event.pressed) {
287 press_three_keys(KC_LGUI, KC_LSFT, KC_ENT);
288 }
289
290 return false;
291
292 case MY_DEQL: // /=
293 if (record->event.pressed) {
294 press_key(KC_SLSH);
295 press_key(KC_EQL);
296 }
297
298 return false;
299
300 case MY_MEQL: // *=
301 if (record->event.pressed) {
302 press_two_keys(KC_LSFT, KC_ASTR);
303 press_key(KC_EQL);
304 }
305
306 return false;
307
308 case MY_SEQL: // -=
309 if (record->event.pressed) {
310 press_key(KC_MINS);
311 press_key(KC_EQL);
312 }
313
314 return false;
315
316 case MY_PEQL: // +=
317 if (record->event.pressed) {
318 press_two_keys(KC_LSFT, KC_PLUS);
319 press_key(KC_EQL);
320 }
321
322 return false;
323
324 case MY_NEQL: // !=
325 if (record->event.pressed) {
326 press_two_keys(KC_LSFT, KC_EXLM);
327 press_key(KC_EQL);
328 }
329
330 return false;
331
332 case MY_LTGT: // <>
333 if (record->event.pressed) {
334 press_two_keys(KC_LSFT, KC_LABK);
335 press_two_keys(KC_LSFT, KC_RABK);
336 }
337
338 return false;
339
340 case MY_DPIP: // ||
341 if (record->event.pressed) {
342 press_two_keys(KC_LSFT, KC_PIPE);
343 press_two_keys(KC_LSFT, KC_PIPE);
344 }
345
346 return false;
347
348 case MY_DAMP: // &&
349 if (record->event.pressed) {
350 press_two_keys(KC_LSFT, KC_AMPR);
351 press_two_keys(KC_LSFT, KC_AMPR);
352 }
353
354 return false;
355 }
356
357 return true;
358}
ade22f8e 359