]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/planck/keymaps/cbbrowne/keymap.c
Merge pull request #433 from algernon/ergodox-ez/algernon
[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
8 /* Each layer is given a name to aid in readability, which is then
9    used in the keymap matrix below.  The underscores do not denote 
10    anything - you can have a layer called STUFF or any other name.
11
12    Layer names don't all need to be of the same length, obviously, and
13    you could also skip them entirely and just use numbers, though that
14    means needing to manage the numbers.
15
16    It is preferable to keep the symbols short so that a line worth of
17    key mappings fits compactly onto a line of code. */
18
19 /* This was originally based on planck/keymaps/default/default.c, and
20    then cbbrowne has revised things */
21
22 /* Things I did not like about the default mapping 
23
24    - I found control too hard to get to.  I use it more than Tab, so
25      switched it there.
26    - Having dash on [lower-j] is a bit nonintuitive, but may be OK
27    - I'll bet I should switch ESC/TAB
28    - I'm suspicious that I want to shift M(0) from [4][1] to [4][2],
29      and shift ESC off the first column so KC_LCTL and KC_LALT can
30      be on the first column.
31    - I needed to swap ' and ENTER
32
33    - All of the above are done :-)
34
35    - Dropped out support for Dvorak and friends.  They aren't 
36      improvements to me
37 */
38
39
40 /* Some interesting things implemented
41
42    - There is a macro that writes out "cbbrowne" to show that I could
43    - There is a (somewhat cruddy) linear congruential random number
44      generator.
45      - I would like to be seeding it with clock info to make it look
46        more random
47    - There are two macros that use the random number generators
48      - one, M_RANDDIGIT, generates a random digit based on state
49        of the random number generator
50      - the other, M_RANDLETTER, generates a random letter based on state
51        of the random number generator
52      - in both, note the use of register_code()/unregister_code()
53        to indicate the desired key
54    - I do indeed want a sweet number pad!
55 */
56
57 /* Other things to do...
58
59    - Need to think about what zsh and readline actions I use lots
60    - Ought to ensure that Control-Alt-Delete is convenient enough
61    - How about Alt-F1 thru Alt-F8?
62    - What's the keystroke to get from X to console these days?
63    - A layer for doing console switching would not be a bad idea
64 */
65
66 enum layers {
67   _QW = 0,  /* Qwerty mapping */
68   _LW, /* Lower layer, where top line has symbols !@#$%^&*() */
69   _RS, /* Raised layer, where top line has digits 1234567890 */
70   _KP, /* Key pad */
71 };
72
73 enum macro_id {
74   M_LED = 0,
75   M_USERNAME,
76   M_RANDDIGIT,
77   M_RANDLETTER,
78   M_VERSION
79 };
80
81 /* Note that Planck has dimensions 4 rows x 12 columns */
82
83 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
84 [_QW] = { /* Qwerty */
85   {KC_ESC,  KC_Q,    KC_W,    KC_E,    KC_R,    KC_T,    KC_Y,    KC_U,    KC_I,    KC_O,    KC_P,    KC_BSPC},
86   {KC_LCTL, KC_A,    KC_S,    KC_D,    KC_F,    KC_G,    KC_H,    KC_J,    KC_K,    KC_L,    KC_SCLN, KC_ENT},
87   {KC_LSFT, KC_Z,    KC_X,    KC_C,    KC_V,    KC_B,    KC_N,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH, KC_QUOT },
88   {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}
89 },
90 [_RS] = { /* RAISE */
91   {KC_GRV,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,    KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    KC_BSPC},
92   {KC_TRNS, KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_MINS, KC_EQL,  KC_LBRC, KC_RBRC, KC_BSLS},
93   {KC_TRNS, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  DF(_QW), DF(_KP), DF(_KP), RESET,   KC_TRNS},
94   {KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
95 },
96 [_LW] = { /* LOWER */
97   {KC_TILD, KC_EXLM, KC_AT,   KC_HASH, KC_DLR,  KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC},
98   {KC_TRNS, KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,   KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE},
99   {KC_TRNS, KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,  DF(_QW), DF(_KP), DF(_KP), RESET,   KC_TRNS},
100   {KC_TRNS, DF(_KP), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY}
101 },
102 [_KP] = { /* Key Pad */
103   {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},
104   {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},
105   {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},
106   {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}
107 }
108 };
109
110 const uint16_t PROGMEM fn_actions[] = {
111 };
112
113 /* This bit of logic seeds a wee linear congruential random number generator */
114 /* lots of prime numbers everywhere... */
115 static uint16_t random_value = 157;
116
117 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
118 {
119   uint8_t clockbyte=0;
120   clockbyte = TCNT1 % 256;
121   uint8_t rval;
122   // MACRODOWN only works in this function
123   switch(id) {
124   case M_LED:
125     if (record->event.pressed) {
126       register_code(KC_RSFT);
127 #ifdef BACKLIGHT_ENABLE
128       backlight_step();
129 #endif
130     } else {
131       unregister_code(KC_RSFT);
132     }
133     break;          
134   case M_USERNAME:
135     if (record->event.pressed) {
136       SEND_STRING("cbbrowne");
137     }
138     break;
139   case M_VERSION:
140     if (record->event.pressed) {
141       SEND_STRING(QMK_KEYBOARD "/" QMK_KEYMAP "@" QMK_VERSION "@" QMK_BUILDDATE);
142     }
143     break;
144   case M_RANDDIGIT:
145     /* Generate, based on random number generator, a keystroke for
146        a numeric digit chosen at random */
147     random_value = ((random_value + randadd) * randmul) % randmod;
148     if (record->event.pressed) {
149       /* Here, we mix the LCRNG with low bits from one of the system
150          clocks via XOR in the theory that this may be more random
151          than either separately */ 
152       rval = (random_value ^ clockbyte) % 10;
153       /* Note that KC_1 thru KC_0 are a contiguous range */
154       register_code (KC_1 + rval);
155       unregister_code (KC_1 + rval);
156     }
157     break;
158   case M_RANDLETTER:
159     /* Generate, based on random number generator, a keystroke for
160        a letter chosen at random */
161     /* Here, we mix the LCRNG with low bits from one of the system
162        clocks via XOR in the theory that this may be more random
163        than either separately */ 
164     random_value = ((random_value + randadd) * randmul) % randmod;
165     if (record->event.pressed) {
166       rval = (random_value ^ clockbyte) % 26;
167       register_code (KC_A + rval);
168       unregister_code (KC_A + rval);
169     }
170     break;
171   }
172   return MACRO_NONE;
173 };