]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/planck/keymaps/cbbrowne/keymap.c
Merge branch 'master' of http://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   _QW = 0,  /* Qwerty mapping */
69   _LW, /* Lower layer, where top line has symbols !@#$%^&*() */
70   _RS, /* Raised layer, where top line has digits 1234567890 */
71   _KP, /* Key pad */
72 };
73
74 enum macro_id {
75   M_LED = 0,
76   M_USERNAME,
77   M_RANDDIGIT,
78   M_RANDLETTER,
79   M_VERSION
80 };
81
82 /* Note that Planck has dimensions 4 rows x 12 columns */
83
84 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
85 [_QW] = { /* Qwerty */
86   {KC_ESC,  KC_Q,    KC_W,    KC_E,    KC_R,    KC_T,    KC_Y,    KC_U,    KC_I,    KC_O,    KC_P,    KC_BSPC},
87   {KC_LCTL, KC_A,    KC_S,    KC_D,    KC_F,    KC_G,    KC_H,    KC_J,    KC_K,    KC_L,    KC_SCLN, MT(MOD_RSFT, KC_ENT)},
88   {KC_LSFT, KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_N,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH, KC_QUOT },
89   {KC_TAB,  M(M_LED), KC_LALT, KC_LGUI, MO(_LW), KC_SPC,  KC_SPC,  MO(_RS), KC_LEFT, KC_DOWN, KC_UP,   KC_RGHT}
90   /* Note that KC_SPC is recorded TWICE, so that either matrix position can activate it */
91 },
92 [_RS] = { /* RAISE */
93   {KC_GRV,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    KC_BSPC},
94   {_______, KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_MINS, KC_EQL,  KC_LBRC, KC_RBRC, KC_BSLS},
95   {_______, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  DF(_QW), DF(_KP), DF(_KP), RESET,   _______},
96   {_______, _______, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
97 },
98 [_LW] = { /* LOWER */
99   {KC_TILD, KC_EXLM, KC_AT,   KC_HASH, KC_DLR,  KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC},
100   {_______, KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE},
101   {_______, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  DF(_QW), DF(_KP), DF(_KP), RESET,   _______},
102   {_______, DF(_KP), _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
103 },
104 [_KP] = { /* Key Pad */
105   {KC_ESC,  M(M_USERNAME),    M(M_VERSION),   KC_F10,   KC_F11,  KC_F12,   KC_PGUP, KC_KP_ENTER, KC_7, KC_8, KC_9, KC_BSPC},
106   {KC_LCTL, M(M_RANDDIGIT),   KC_F5,   KC_F6,    KC_F7,   KC_F8,    KC_PGDN, KC_KP_MINUS, KC_4, KC_5, KC_6, KC_PIPE},
107   {KC_LSFT, M(M_RANDLETTER),  KC_F1,   KC_F2,    KC_F3,   KC_F4,    KC_DEL,  KC_KP_PLUS,  KC_1, KC_2,  KC_3, KC_ENTER},
108   {BL_STEP, M(M_LED), KC_LALT, KC_LGUI, KC_NO, KC_SPC,  KC_SPC,  DF(_QW),   KC_LEFT, KC_DOWN, KC_UP,  KC_RIGHT}
109 }
110 };
111
112 /* What is fn_actions actually used for??? */
113 const uint16_t PROGMEM fn_actions[] = {
114 };
115
116 /* This bit of logic seeds a wee linear congruential random number generator */
117 /* lots of prime numbers everywhere... */
118 static uint16_t random_value = 157;
119
120 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
121 {
122   uint8_t clockbyte=0;
123   clockbyte = TCNT1 % 256;
124   uint8_t rval;
125   // MACRODOWN only works in this function
126   switch(id) {
127   case M_LED:
128     if (record->event.pressed) {
129       register_code(KC_RSFT);
130 #ifdef BACKLIGHT_ENABLE
131       backlight_step();
132 #endif
133     } else {
134       unregister_code(KC_RSFT);
135     }
136     break;          
137   case M_USERNAME:
138     if (record->event.pressed) {
139       SEND_STRING("cbbrowne");
140     }
141     break;
142   case M_VERSION:
143     if (record->event.pressed) {
144       SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP "@" QMK_VERSION "@" QMK_BUILDDATE);
145     }
146     break;
147   case M_RANDDIGIT:
148     /* Generate, based on random number generator, a keystroke for
149        a numeric digit chosen at random */
150     random_value = ((random_value + randadd) * randmul) % randmod;
151     if (record->event.pressed) {
152       /* Here, we mix the LCRNG with low bits from one of the system
153          clocks via XOR in the theory that this may be more random
154          than either separately */ 
155       rval = (random_value ^ clockbyte) % 10;
156       /* Note that KC_1 thru KC_0 are a contiguous range */
157       register_code (KC_1 + rval);
158       unregister_code (KC_1 + rval);
159     }
160     break;
161   case M_RANDLETTER:
162     /* Generate, based on random number generator, a keystroke for
163        a letter chosen at random */
164     /* Here, we mix the LCRNG with low bits from one of the system
165        clocks via XOR in the theory that this may be more random
166        than either separately */ 
167     random_value = ((random_value + randadd) * randmul) % randmod;
168     if (record->event.pressed) {
169       rval = (random_value ^ clockbyte) % 26;
170       register_code (KC_A + rval);
171       unregister_code (KC_A + rval);
172     }
173     break;
174   }
175   return MACRO_NONE;
176 };