]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/planck/keymaps/cbbrowne/keymap.c
Merge branch 'master' of https://github.com/jackhumbert/qmk_firmware
[qmk_firmware.git] / keyboards / planck / keymaps / cbbrowne / keymap.c
1 #include "planck.h"
2 #ifdef BACKLIGHT_ENABLE
3 #include "backlight.h"
4 #endif
5 #include "config.h"
6 #include "quantum.h"
7 #include "version.h"
8
9 /* Each layer is given a name to aid in readability, which is then
10    used in the keymap matrix below.  The underscores do not denote 
11    anything - you can have a layer called STUFF or any other name.
12
13    Layer names don't all need to be of the same length, obviously, and
14    you could also skip them entirely and just use numbers, though that
15    means needing to manage the numbers.
16
17    It is preferable to keep the symbols short so that a line worth of
18    key mappings fits compactly onto a line of code. */
19
20 /* This was originally based on planck/keymaps/default/default.c, and
21    then cbbrowne has revised things */
22
23 /* Things I did not like about the default mapping 
24
25    - I found control too hard to get to.  I use it more than Tab, so
26      switched it there.
27    - Having dash on [lower-j] is a bit nonintuitive, but may be OK
28    - I'll bet I should switch ESC/TAB
29    - I'm suspicious that I want to shift M(0) from [4][1] to [4][2],
30      and shift ESC off the first column so KC_LCTL and KC_LALT can
31      be on the first column.
32    - I needed to swap ' and ENTER
33
34    - All of the above are done :-)
35
36    - Dropped out support for Dvorak and friends.  They aren't 
37      improvements to me
38 */
39
40
41 /* Some interesting things implemented
42
43    - There is a macro that writes out "cbbrowne" to show that I could
44    - There is a (somewhat cruddy) linear congruential random number
45      generator.
46      - I would like to be seeding it with clock info to make it look
47        more random
48    - There are two macros that use the random number generators
49      - one, M_RANDDIGIT, generates a random digit based on state
50        of the random number generator
51      - the other, M_RANDLETTER, generates a random letter based on state
52        of the random number generator
53      - in both, note the use of register_code()/unregister_code()
54        to indicate the desired key
55    - I do indeed want a sweet number pad!
56 */
57
58 /* Other things to do...
59
60    - Need to think about what zsh and readline actions I use lots
61    - Ought to ensure that Control-Alt-Delete is convenient enough
62    - How about Alt-F1 thru Alt-F8?
63    - What's the keystroke to get from X to console these days?
64    - A layer for doing console switching would not be a bad idea
65 */
66
67 enum layers {
68   _QWERTY = 0,  /* Qwerty mapping */
69   _LOWER, /* Lower layer, where top line has symbols !@#$%^&*() */
70   _RAISE, /* Raised layer, where top line has digits 1234567890 */
71   _KEYPAD, /* Key pad */
72   _ADJUST, /* Special Adjust layer coming via tri-placement */
73 };
74
75 enum macro_id {
76   M_LED = 0,
77   M_USERNAME,
78   M_RANDDIGIT,
79   M_RANDLETTER,
80   M_VERSION,
81   MACRO_UPPER,
82   MACRO_LOWER,
83 };
84
85 #define M_LOWER M(MACRO_LOWER)
86 #define M_UPPER M(MACRO_UPPER)
87 #define ROT_LED M(M_LED)   /* Rotate LED */
88 #define QWERTY DF(_QWERTY)   /* Switch to QWERTY layout */
89 #define KEYPAD DF(_KEYPAD)   /* Switch to keypad */
90 #define USERNAME M(M_USERNAME) /* shortcut for username */
91 #define RANDDIG M(M_RANDDIGIT)
92 #define RANDALP M(M_RANDLETTER)
93 #define CTLENTER MT(MOD_RCTL, KC_ENT)
94 #define SHIFTQUOTE MT(MOD_RSFT, KC_QUOT)
95 #define ALTRIGHT MT(MOD_LALT, KC_RGHT)
96 #define MVERSION M(M_VERSION)
97 #define ALTSLASH LALT(KC_SLSH)
98
99
100 /* Note that Planck has dimensions 4 rows x 12 columns */
101
102 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
103 [_QWERTY] = { /* Qwerty */
104   {KC_ESC,  KC_Q,    KC_W,    KC_E,    KC_R,    KC_T,    KC_Y,    KC_U,    KC_I,    KC_O,    KC_P,    KC_BSPC},
105   {KC_LCTL, KC_A,    KC_S,    KC_D,    KC_F,    KC_G,    KC_H,    KC_J,    KC_K,    KC_L,    KC_SCLN, CTLENTER},
106   {KC_LSFT, KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_N,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH, SHIFTQUOTE },
107   {KC_TAB,  KC_LALT, ROT_LED, KC_LGUI, M_LOWER, KC_SPC,  KC_SPC,  M_UPPER, KC_LEFT, KC_DOWN, KC_UP,   ALTRIGHT}
108   /* Note that KC_SPC is recorded TWICE, so that either matrix position can activate it */
109 },
110 [_RAISE] = { /* RAISE */
111   {KC_GRV,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    KC_BSPC},
112   {_______, KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_MINS, KC_EQL,  KC_LBRC, KC_RBRC, KC_BSLS},
113   {_______, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  QWERTY,  KEYPAD,  KEYPAD,  ALTSLASH,_______},
114   {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
115 },
116 [_LOWER] = { /* LOWER */
117   {KC_TILD, KC_EXLM, KC_AT,   KC_HASH, KC_DLR,  KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC},
118   {_______, KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE},
119   {_______, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  QWERTY,  KEYPAD,  KEYPAD, ALTSLASH,   _______},
120   {_______, KEYPAD, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
121     },
122 [_KEYPAD] = { /* Key Pad */
123   {KC_ESC,  USERNAME,    MVERSION,   KC_F10,   KC_F11,  KC_F12,   KC_PGUP, KC_KP_ENTER, KC_7, KC_8, KC_9, KC_BSPC},
124   {KC_LCTL, RANDDIG,   KC_F5,   KC_F6,    KC_F7,   KC_F8,    KC_PGDN, KC_KP_MINUS, KC_4, KC_5, KC_6, KC_PIPE},
125   {KC_LSFT, RANDALP,   KC_F1,   KC_F2,    KC_F3,   KC_F4,    KC_DEL,  KC_KP_PLUS,  KC_1, KC_2,  KC_3, KC_ENTER},
126   {KC_TAB,  KC_LALT, ROT_LED, KC_LGUI,  M_LOWER,  KC_SPC,    KC_SPC,  QWERTY,   KC_LEFT, KC_DOWN, KC_UP,  KC_RIGHT}
127 },
128
129 [_ADJUST] = { /* Adjustments - gonna shift the wild tools in here */
130   {ROT_LED,USERNAME,MVERSION, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
131   {_______, RANDDIG, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ },
132   {_______, RANDALP, _______, _______, _______,   RESET,   RESET, _______, _______, _______, _______, _______ },
133   {_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ }
134 }  
135 };
136
137 /* What is fn_actions actually used for??? */
138 const uint16_t PROGMEM fn_actions[] = {
139 };
140
141 /* This bit of logic seeds a wee linear congruential random number generator */
142 /* lots of prime numbers everywhere... */
143 static uint16_t random_value = 157;
144
145 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
146 {
147   uint8_t clockbyte=0;
148   clockbyte = TCNT1 % 256;
149   uint8_t rval;
150   // MACRODOWN only works in this function
151   switch(id) {
152   case M_LED:
153     if (record->event.pressed) {
154       register_code(KC_RSFT);
155 #ifdef BACKLIGHT_ENABLE
156       backlight_step();
157 #endif
158     } else {
159       unregister_code(KC_RSFT);
160     }
161     break;          
162   case M_USERNAME:
163     if (record->event.pressed) {
164       SEND_STRING("cbbrowne");
165     }
166     break;
167   case M_VERSION:
168     if (record->event.pressed) {
169       SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP "@" QMK_VERSION "@" QMK_BUILDDATE);
170     }
171     break;
172   case M_RANDDIGIT:
173     /* Generate, based on random number generator, a keystroke for
174        a numeric digit chosen at random */
175     random_value = ((random_value + randadd) * randmul) % randmod;
176     if (record->event.pressed) {
177       /* Here, we mix the LCRNG with low bits from one of the system
178          clocks via XOR in the theory that this may be more random
179          than either separately */ 
180       rval = (random_value ^ clockbyte) % 10;
181       /* Note that KC_1 thru KC_0 are a contiguous range */
182       register_code (KC_1 + rval);
183       unregister_code (KC_1 + rval);
184     }
185     break;
186   case M_RANDLETTER:
187     /* Generate, based on random number generator, a keystroke for
188        a letter chosen at random */
189     /* Here, we mix the LCRNG with low bits from one of the system
190        clocks via XOR in the theory that this may be more random
191        than either separately */ 
192     random_value = ((random_value + randadd) * randmul) % randmod;
193     if (record->event.pressed) {
194       rval = (random_value ^ clockbyte) % 26;
195       register_code (KC_A + rval);
196       unregister_code (KC_A + rval);
197     }
198     break;
199   case MACRO_UPPER:
200     if (record->event.pressed)
201       {
202         layer_on(_RAISE);
203 #ifdef BACKLIGHT_ENABLE
204         breathing_speed_set(2);
205         breathing_pulse();
206 #endif
207         update_tri_layer(_LOWER, _RAISE, _ADJUST);
208       }
209     else
210       {
211         layer_off(_RAISE);
212         update_tri_layer(_LOWER, _RAISE, _ADJUST);
213       }
214     break;
215   case MACRO_LOWER:
216     if (record->event.pressed)
217       {
218         layer_on(_LOWER);
219 #ifdef BACKLIGHT_ENABLE
220         breathing_speed_set(2);
221         breathing_pulse();
222 #endif
223         update_tri_layer(_LOWER, _RAISE, _ADJUST);
224       }
225     else
226       {
227         layer_off(_LOWER);
228         update_tri_layer(_LOWER, _RAISE, _ADJUST);
229       }
230     break;
231     
232   }
233   return MACRO_NONE;
234 };