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