]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - keyboard/ergodox/keymap_cub.c
aba7c79a81d106b9b8f7d5ea5b62b44dad3e6755
[max/tmk_keyboard.git] / keyboard / ergodox / keymap_cub.c
1 #include <util/delay.h>
2 #include "action_layer.h"
3 #include "action_util.h"
4 #include "bootloader.h"
5 #include "keymap_common.h"
6
7
8 const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
9     /*
10      * Keymap: Default Layer in QWERTY
11      *
12      * ,--------------------------------------------------.           ,--------------------------------------------------.
13      * |   ~    |   1  |   2  |   3  |   4  |   5  |   \  |           |   -  |   6  |   7  |   8  |   9  |   0  |   =    |
14      * |--------+------+------+------+------+-------------|           |------+------+------+------+------+------+--------|
15      * | Tab    |   Q  |   W  |   E  |   R  |   T  | ~L5  |           | ~L6  |   Y  |   U  |   I  |   O  |   P  |   [    |
16      * |--------+------+------+------+------+------|      |           |      |------+------+------+------+------+--------|
17      * | Tab/Shf|   A  |   S  |   D  |   F  |   G  |------|           |------|   H  |   J  |   K  |   L  |   ;  |   '    |
18      * |--------+------+------+------+------+------|  L0  |           | ~L7  |------+------+------+------+------+--------|
19      * | LCtrl  |   Z  |   X  |   C  |   V  |   B  |      |           |      |   N  |   M  |   ,  |   .  |   /  |   ]    |
20      * `--------+------+------+------+------+-------------'           `-------------+------+------+------+------+--------'
21      *   | ~L5  | ~L2  | Caps | LAlt | LGui |                                       |  Lft |  Up  |  Dn  | Rght | ~L6  |
22      *   `----------------------------------'                                       `----------------------------------'
23      *                                        ,-------------.       ,-------------.
24      *                                        | +L2  | Home |       | PgUp | Del  |
25      *                                 ,------|------|------|       |------+------+------.
26      *                                 |      |      |  End |       | PgDn |      |      |
27      *                                 | BkSp |  ESC |------|       |------| Enter| Space|
28      *                                 |      |      |  Spc |       | Ins  |      |      |
29      *                                 `--------------------'       `--------------------'
30      *
31      *
32      *
33      ****************************************************************************************************
34      *
35      * Under XOrg, I use my own mapping from QWERTY to "Workman for Programmers"
36      * See XOrg files in ./addons/ subdirectory.
37      *
38      * I have to do so, because of two things:
39      * 1) my native language is Russian, and XOrg keymap for it is based on QWERTY layout
40      * 2) I want to have non-standart shifted keys, like $ (as normal) and @ (as shifted), or _ and -
41      *
42      * And even if (2) could be solved using FN* keys (but there is limit in firmware for only 32 such
43      * keys), then (1) can't be solved at firmware level at all.
44      *
45      * So, I have to stick with QWERTY as my main layout + my own XOrg keyboard layout for English.
46      * But sometimes I have to input something when XOrg is not active - for example, in Linux console,
47      * or in firmware console (while debugging firmware), or when keyboard is connected to not my computer.
48      *
49      * For such cases I have Layer1 :)
50      * // hint: switch to Layer1 is only at Layer6
51      *
52      ****************************************************************************************************
53      *
54      *
55      *
56      * Keymap: Default Layer in Workman
57      *
58      * ,--------------------------------------------------.           ,--------------------------------------------------.
59      * |  ~     |   ;  |   !  |   #  |   {  |   }  |   '  |           |   ^  |   [  |   ]  |   *  |   (  |   )  |   =    |
60      * |--------+------+------+------+------+-------------|           |------+------+------+------+------+------+--------|
61      * | Tab    |   Q  |   D  |   R  |   W  |   B  |  NO  |           | ~L7  |   J  |   F  |   U  |   P  |   $  |   :    |
62      * |--------+------+------+------+------+------|      |           |      |------+------+------+------+------+--------|
63      * | Tab/Shf|   A  |   S  |   H  |   T  |   G  |------|           |------|   Y  |   N  |   E  |   O  |   I  |   -    |
64      * |--------+------+------+------+------+------| Home |           | End  |------+------+------+------+------+--------|
65      * | LCtrl  |   Z  |   X  |   M  |   C  |   V  |      |           |      |   K  |   L  |   ,  |   .  |   /  |   |    |
66      * `--------+------+------+------+------+-------------'           `-------------+------+------+------+------+--------'
67      *   | ~L5  | ~L2  | Caps | LAlt | LGui |                                       |  Lft |  Up  |  Dn  | Rght | ~L6  |
68      *   `----------------------------------'                                       `----------------------------------'
69      *                                        ,-------------.       ,-------------.
70      *                                        |  L0  |  +L2 |       | PgUp | Del  |
71      *                                 ,------|------|------|       |------+------+------.
72      *                                 |      |      |  NO  |       | PgDn |      |      |
73      *                                 | BkSp |  ESC |------|       |------| Enter| Space|
74      *                                 |      |      |  Spc |       | Ins  |      |      |
75      *                                 `--------------------'       `--------------------'
76      *
77      * Keymap: Default Layer in Workman / with Shift
78      *
79      * ,--------------------------------------------------.           ,--------------------------------------------------.
80      * |  `     |   1  |   2  |   3  |   4  |   5  |   "  |           |   \  |   6  |   7  |   8  |   9  |   0  |   +    |
81      * |--------+------+------+------+------+-------------|           |------+------+------+------+------+------+--------|
82      * | Tab    |   Q  |   D  |   R  |   W  |   B  |  NO  |           | ~L7  |   J  |   F  |   U  |   P  |   @  |   %    |
83      * |--------+------+------+------+------+------|      |           |      |------+------+------+------+------+--------|
84      * | Tab/Shf|   A  |   S  |   H  |   T  |   G  |------|           |------|   Y  |   N  |   E  |   O  |   I  |   _    |
85      * |--------+------+------+------+------+------| Home |           | End  |------+------+------+------+------+--------|
86      * | LCtrl  |   Z  |   X  |   M  |   C  |   V  |      |           |      |   K  |   L  |   ,  |   .  |   /  |   &    |
87      * `--------+------+------+------+------+-------------'           `-------------+------+------+------+------+--------'
88      *   | ~L5  | ~L2  | Caps | LAlt | LGui |                                       |  Lft |  Up  |  Dn  | Rght | ~L6  |
89      *   `----------------------------------'                                       `----------------------------------'
90      *                                        ,-------------.       ,-------------.
91      *                                        |  L0  |  +L2 |       | PgUp | Del  |
92      *                                 ,------|------|------|       |------+------+------.
93      *                                 |      |      |  NO  |       | PgDn |      |      |
94      *                                 | BkSp |  ESC |------|       |------| Enter| Space|
95      *                                 |      |      |  Spc |       | Ins  |      |      |
96      *                                 `--------------------'       `--------------------'
97      *
98      */
99
100     KEYMAP(  // Layer0: default, leftled:none
101         // left hand
102         GRV, 1,   2,   3,   4,   5,   BSLS,
103         FN2, Q,   W,   E,   R,   T,   FN23,
104         FN11,FN28,FN29,FN30,FN31,G,
105         FN12,FN24,FN25,FN26,FN27,B,   HOME,
106         FN21,FN20,CAPS,FN13,FN14,
107                                       FN17,FN19,
108                                            NO,
109                                  FN5, FN6, FN7,
110         // right hand
111              MINS,6,   7,   8,   9,   0,   EQL,
112              FN23,Y,   U,   I,   O,   P,   LBRC,
113                   H,   J,   K,   L,   SCLN,FN15,
114              END, N,   M,   COMM,DOT, SLSH,FN16,
115                        LEFT,UP,  DOWN,RGHT,FN22,
116         PGUP,DEL,
117         PGDN,
118         FN8, FN9, FN10
119     ),
120
121     KEYMAP(  // Layer1: Workman layout, leftled:all
122         // left hand
123         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
124         TRNS,Q,   D,   R,   W,   B,   TRNS,
125         TRNS,A,   S,   H,   T,   G,
126         TRNS,Z,   X,   M,   C,   V,   TRNS,
127         TRNS,TRNS,FN17,TRNS,TRNS,
128                                       TRNS,TRNS,
129                                            TRNS,
130                                  TRNS,TRNS,TRNS,
131         // right hand
132              TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
133              TRNS,J,   F,   U,   P,   4,   TRNS,
134                   Y,   N,   E,   O,   I,   TRNS,
135              TRNS,K,   L,   TRNS,TRNS,TRNS,TRNS,
136                        TRNS,TRNS,TRNS,TRNS,TRNS,
137         TRNS,TRNS,
138         TRNS,
139         TRNS,TRNS,TRNS
140     ),
141
142     KEYMAP(  // Layer2: numpad, leftled:mid/blue
143         // left hand
144         TRNS,NO,  NO,  NO,  NO,  PAUS,PSCR,
145         TRNS,NO,  NO,  NO,  NO,  NO,  TRNS,
146         TRNS,NO,  NO,  NO,  TRNS,NO,
147         TRNS,NO,  NO,  NO,  TRNS,NO,  TRNS,
148         TRNS,TRNS,FN17,TRNS,TRNS,
149                                       TRNS,TRNS,
150                                            TRNS,
151                                  TRNS,TRNS,TRNS,
152         // right hand
153              SLCK,NLCK,PSLS,PAST,PAST,PMNS,BSPC,
154              TRNS,NO,  P7,  P8,  P9,  PMNS,PGUP,
155                   NO,  P4,  P5,  P6,  PPLS,PGDN,
156              TRNS,NO,  P1,  P2,  P3,  PPLS,PENT,
157                        P0,  PDOT,SLSH,PENT,PENT,
158         TRNS,TRNS,
159         TRNS,
160         TRNS,TRNS,TRNS
161     ),
162
163     KEYMAP(  // Layer3: F-keys + PgUp/PgDn on right hand, leftled:bot/green
164         // left hand
165         TRNS,NO,  NO,  NO,  NO,  NO,  NO,
166         TRNS,NO,  NO,  NO,  NO,  NO,  TRNS,
167         TRNS,NO,  TRNS,NO,  NO,  NO,
168         TRNS,NO,  TRNS,NO,  NO,  NO,  TRNS,
169         TRNS,TRNS,TRNS,LALT,LGUI,
170                                       TRNS,TRNS,
171                                            TRNS,
172                                  LCTL,LSFT,TRNS,
173         // right hand
174              NO,  NO,  NO,  NO,  NO,  NO,  TRNS,
175              TRNS,NO,  F1,  F2,  F3,  F4,  PGUP,
176                   NO,  F5,  F6,  F7,  F8,  PGDN,
177              TRNS,NO,  F9,  F10, F11, F12, APP,
178                        RGUI,RALT,TRNS,TRNS,TRNS,
179         TRNS,TRNS,
180         TRNS,
181         TRNS,RSFT,RCTL
182     ),
183
184     KEYMAP(  // Layer4: unconvenient keys on right hand, leftled:top/white
185         // left hand
186         TRNS,NO,  NO,  NO,  NO,  NO,  NO,
187         TRNS,NO,  NO,  NO,  NO,  NO,  TRNS,
188         TRNS,TRNS,NO,  NO,  NO,  NO,
189         TRNS,TRNS,NO,  NO,  NO,  NO,  TRNS,
190         TRNS,TRNS,TRNS,LALT,LGUI,
191                                       TRNS,TRNS,
192                                            TRNS,
193                                  TRNS,TRNS,TRNS,
194
195         /* in Workman right hand will be:
196                 { } ( ) +
197               ^ ! ?     =
198               ' ! $ " ; \
199               # [ < > ] \
200         */
201
202         // right hand
203              NO,  NO,  4,   5,   9,   0,   PPLS,
204              TRNS,MINS,2,   FN5, 9,   0,   EQL,
205                   BSLS,2,   P,   FN1, 1,   FN2,
206              TRNS,3,   6,   FN3, FN4, 7,   FN2,
207                        TRNS,TRNS,TRNS,TRNS,TRNS,
208         TRNS,TRNS,
209         TRNS,
210         TRNS,TRNS,TRNS
211     ),
212
213     KEYMAP(  // Layer5: F-keys instead of numbers, leftled:top/white
214         // left hand
215         TRNS,F1,  F2,  F3,  F4,  F5,  F6,
216         TRNS,P1,  P2,  P3,  P4,  P5,  TRNS,
217         TRNS,TRNS,TRNS,E,   TRNS,TRNS,
218         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
219         TRNS,TRNS,TRNS,TRNS,TRNS,
220                                       TRNS,TRNS,
221                                            TRNS,
222                                  TRNS,TRNS,TRNS,
223         // right hand
224              F7,  F8,  F9,  F10, F11, F12, TRNS,
225              TRNS,P6,  P7,  P8,  P9,  P0,  TRNS,
226                   TRNS,U,   TRNS,TRNS,TRNS,TRNS,
227              TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
228                        TRNS,TRNS,TRNS,TRNS,TRNS,
229         TRNS,TRNS,
230         TRNS,
231         TRNS,TRNS,TRNS
232     ),
233
234     KEYMAP(  // Layer6: F-keys + utils(Teensy, Workman-layer switch), leftled:top/white+onboard
235         // left hand
236         FN0, F1,  F2,  F3,  F4,  F5,  F6,
237         TRNS,P1,  P2,  P3,  P4,  P5,  TRNS,
238         TRNS,TRNS,TRNS,E,   TRNS,TRNS,
239         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
240         FN18,TRNS,TRNS,TRNS,TRNS,
241                                       TRNS,TRNS,
242                                            TRNS,
243                                  TRNS,TRNS,TRNS,
244         // right hand
245              F7,  F8,  F9,  F10, F11, F12, FN0,
246              TRNS,P6,  P7,  P8,  P9,  P0,  TRNS,
247                   TRNS,U,   TRNS,TRNS,TRNS,TRNS,
248              TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
249                        TRNS,TRNS,TRNS,TRNS,TRNS,
250         TRNS,TRNS,
251         TRNS,
252         TRNS,TRNS,TRNS
253     ),
254
255     //
256     // rarely used
257     //
258
259     KEYMAP(  // Layer7: F-keys only, leftled:top/white
260         // left hand
261         FN0, NO,  NO,  NO,  NO,  NO,  NO,
262         FN1, F13, F14, F15, F16, NO,  TRNS,
263         TRNS,F17, F18, F19, F20, NO,
264         TRNS,F21, F22, F23, F24, NO,  TRNS,
265         TRNS,TRNS,TRNS,TRNS,TRNS,
266                                       TRNS,TRNS,
267                                            TRNS,
268                                  TRNS,TRNS,TRNS,
269         // right hand
270              NO,  NO,  NO,  NO,  NO,  NO,  TRNS,
271              TRNS,NO,  F1,  F2,  F3,  F4,  TRNS,
272                   NO,  F5,  F6,  F7,  F8,  TRNS,
273              TRNS,NO,  F9,  F10, F11, F12, TRNS,
274                        TRNS,TRNS,TRNS,TRNS,TRNS,
275         TRNS,TRNS,
276         TRNS,
277         SLEP,TRNS,TRNS
278     ),
279
280     KEYMAP(  // Layer8: mouse and navigation, leftled:mid/blue+bot/green
281         // left hand
282         TRNS,NO,  NO,  NO,  NO,  NO,  NO,
283         TRNS,NO,  NO,  NO,  ACL0,NO,  TRNS,
284         TRNS,NO,  NO,  TRNS,ACL1,NO,
285         TRNS,NO,  NO,  TRNS,ACL2,NO,  TRNS,
286         TRNS,TRNS,TRNS,TRNS,TRNS,
287                                       TRNS,TRNS,
288                                            TRNS,
289                                  TRNS,TRNS,TRNS,
290
291         // right hand
292              F16, MPLY,MPRV,MNXT,VOLD,VOLU,MUTE,
293              F14, BTN2,WH_L,WH_U,WH_D,WH_R,PGUP,
294                   BTN1,MS_L,MS_U,MS_D,MS_R,PGDN,
295              F15, BTN3,HOME,END, DEL, INS, NO,
296                        TRNS,TRNS,TRNS,TRNS,TRNS,
297         TRNS,TRNS,
298         TRNS,
299         TRNS,TRNS,TRNS
300     ),
301
302     KEYMAP(  // Layer9: application-specific shortcuts (mostly browser), leftled:top/white+bot/green
303         // left hand
304         TRNS,NO,  NO,  NO,  NO,  NO,  NO,
305         TRNS,NO,  NO,  NO,  NO,  NO,  TRNS,
306         TRNS,NO,  NO,  NO,  NO,  NO,
307         TRNS,NO,  NO,  NO,  TRNS,NO,  TRNS,
308         TRNS,TRNS,TRNS,TRNS,TRNS,
309                                       TRNS,TRNS,
310                                            TRNS,
311                                  TRNS,TRNS,TRNS,
312         // right hand
313              NO,  NO,  NO,  NO,  NO,  NO,  TRNS,
314              TRNS,NO,  FN12,FN13,FN14,FN15,FN10,
315                   FN1, FN2, FN3, FN4, FN5, FN11,
316              TRNS,TRNS,FN6, FN7, FN8, FN9, FN0,
317                        TRNS,TRNS,TRNS,TRNS,TRNS,
318         TRNS,TRNS,
319         TRNS,
320         TRNS,TRNS,TRNS
321     ),
322
323 /*
324     // templates to copy from
325
326     KEYMAP(  // LayerN: transparent on edges + hard-defined thumb keys, all others are empty
327         // left hand
328         TRNS,NO,  NO,  NO,  NO,  NO,  NO,
329         TRNS,NO,  NO,  NO,  NO,  NO,  TRNS,
330         TRNS,NO,  NO,  NO,  NO,  NO,
331         TRNS,NO,  NO,  NO,  NO,  NO,  TRNS,
332         TRNS,TRNS,TRNS,LALT,LGUI,
333                                       TRNS,TRNS,
334                                            TRNS,
335                                  LCTL,LSFT,TRNS,
336         // right hand
337              NO,  NO,  NO,  NO,  NO,  NO,  TRNS,
338              TRNS,NO,  NO,  NO,  NO,  NO,  TRNS,
339                   NO,  NO,  NO,  NO,  NO,  TRNS,
340              TRNS,NO,  NO,  NO,  NO,  NO,  TRNS,
341                        RGUI,RALT,TRNS,TRNS,TRNS,
342         TRNS,TRNS,
343         TRNS,
344         TRNS,RSFT,RCTL
345     ),
346     KEYMAP(  // LayerN: fully transparent
347         // left hand
348         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
349         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
350         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
351         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
352         TRNS,TRNS,TRNS,TRNS,TRNS,
353                                       TRNS,TRNS,
354                                            TRNS,
355                                  TRNS,TRNS,TRNS,
356         // right hand
357              TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
358              TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
359                   TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
360              TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
361                        TRNS,TRNS,TRNS,TRNS,TRNS,
362         TRNS,TRNS,
363         TRNS,
364         TRNS,TRNS,TRNS
365     ),
366 */
367
368 };
369
370 /* id for user defined functions & macros */
371 enum function_id {
372     TEENSY_KEY,
373     CUSTOM_KEY,
374     L_CTRL_ALT_ENT,
375     R_CTRL_ALT_ENT,
376 };
377
378 enum macro_id {
379     XMONAD_RESET,
380     PASSWORD1,
381     PASSWORD2,
382     PASSWORD3,
383 };
384
385 /*
386  * Fn action definition
387  */
388 const uint16_t PROGMEM fn_actions[] = {
389     [0] =   ACTION_FUNCTION(TEENSY_KEY),                    // FN0  - Teensy key
390
391     [1] =   ACTION_MODS_KEY(MOD_LSFT, KC_BSLS),             // FN1  = Shifted BackSlash // " in Workman
392     [2] =   ACTION_MODS_KEY(MOD_LSFT, KC_MINS),             // FN2  = Shifted Minus     // \ in Workman
393     [3] =   ACTION_MODS_KEY(MOD_LSFT, KC_COMM),             // FN3  = Shifted comma     // < in Workman
394     [4] =   ACTION_MODS_KEY(MOD_LSFT, KC_DOT),              // FN4  = Shifted dot       // > in Workman
395
396     [5] =   ACTION_MODS_TAP_KEY(MOD_LCTL, KC_BSPC),         // FN5  = LShift with tap BackSpace
397     [6] =   ACTION_MODS_TAP_KEY(MOD_LSFT, KC_DEL),          // FN6  = LCtrl  with tap Delete
398     [7] =   ACTION_MODS_TAP_KEY(MOD_LALT, KC_ESC),          // FN7  = LAlt   with tap Escape
399     [8] =   ACTION_MODS_TAP_KEY(MOD_RGUI, KC_INS),          // FN8  = RGui   with tap Ins
400     [9] =   ACTION_MODS_TAP_KEY(MOD_RSFT, KC_ENT),          // FN9  = RShift with tap Enter
401     [10] =  ACTION_MODS_TAP_KEY(MOD_RCTL, KC_SPC),          // FN10 = RCtrl  with tap Space
402
403     [11] =  ACTION_MODS_TAP_KEY(MOD_LSFT, KC_TAB),          // FN11 = LShift with tap Tab
404     [12] =  ACTION_MODS_TAP_KEY(MOD_LCTL, KC_GRV),          // FN12 = LCtrl  with tap Tilda
405     [13] =  ACTION_MODS_TAP_KEY(MOD_LALT, KC_SPC),          // FN13 = LAlt   with tap Space
406     [14] =  ACTION_MODS_TAP_KEY(MOD_LGUI, KC_ESC),          // FN14 = LGui   with tap Escape
407     [15] =  ACTION_MODS_TAP_KEY(MOD_RSFT, KC_QUOT),         // FN15 = RShift with tap quotes
408     [16] =  ACTION_MODS_TAP_KEY(MOD_RCTL, KC_RBRC),         // FN16 = RCtrl  with tap ]
409
410     [17] =  ACTION_LAYER_SET(0, ON_BOTH),                   // FN17 - set Layer0
411     [18] =  ACTION_LAYER_SET(1, ON_BOTH),                   // FN18 - set Layer1, to use Workman layout at firmware level
412     [19] =  ACTION_LAYER_SET(2, ON_BOTH),                   // FN19 - set Layer2, to use with Numpad keys
413
414     [21] =  ACTION_FUNCTION_TAP(L_CTRL_ALT_ENT),            // FN21 - momentary Layer5+CTRL+ALT on Enter, to use with F* keys on top row
415     [22] =  ACTION_FUNCTION_TAP(R_CTRL_ALT_ENT),            // FN22 - momentary Layer6+CTRL+ALT on Enter, to use with F* keys on top row + utils
416
417     [28] =  ACTION_LAYER_TAP_KEY(4, KC_A),                  // FN28 = momentary Layer4 on A key, to use with unconvenient keys
418     [29] =  ACTION_LAYER_TAP_KEY(3, KC_S),                  // FN29 = momentary Layer3 on S key, to use with F* keys
419     [30] =  ACTION_LAYER_TAP_KEY(8, KC_D),                  // FN30 = momentary Layer8 on D key, to use with mouse and navigation keys
420     [31] =  ACTION_LAYER_TAP_KEY(2, KC_F),                  // FN31 = momentary Layer2 on F key, to use with Numpad keys
421
422     // i'd like to remove this - will try to get used to live without this and convert them to usual keys
423     [20] =  ACTION_LAYER_MOMENTARY(2),                      // FN20 - momentary Layer2, to use with Numpad keys
424 // or
425 //  [20] =  ACTION_FUNCTION_TAP(CUSTOM_KEY),                // FN20 - use custom key, with tapping support
426
427     [23] =  ACTION_LAYER_TAP_KEY(7, KC_BSLS),               // FN23 - momentary Layer7 on ' , to use with F* keys (F1-F24)
428
429     [24] =  ACTION_LAYER_TAP_KEY(4, KC_Z),                  // FN24 = momentary Layer4 on Z key, to use with unconvenient keys
430     [25] =  ACTION_LAYER_TAP_KEY(3, KC_X),                  // FN25 = momentary Layer3 on X key, to use with F* keys
431     [26] =  ACTION_LAYER_TAP_KEY(8, KC_C),                  // FN26 = momentary Layer8 on C key, to use with mouse and navigation keys
432     [27] =  ACTION_LAYER_TAP_KEY(9, KC_V),                  // FN27 = momentary Layer9 on V key, to use with application-specific shortcuts
433 };
434
435 const uint16_t PROGMEM fn_actions_4[] = {
436     [1]  =  ACTION_MODS_KEY(MOD_LSFT, KC_BSLS),             // FN1  = Shifted BackSlash // " in Workman
437     [2]  =  ACTION_MODS_KEY(MOD_LSFT, KC_MINS),             // FN2  = Shifted Minus     // \ in Workman
438     [3]  =  ACTION_MODS_KEY(MOD_LSFT, KC_COMM),             // FN3  = Shifted comma     // < in Workman
439     [4]  =  ACTION_MODS_KEY(MOD_LSFT, KC_DOT),              // FN4  = Shifted dot       // > in Workman
440     [5]  =  ACTION_MODS_KEY(MOD_LSFT, KC_SLSH),             // FN5  = Shifted slash     // ? in Workman
441 };
442
443 const uint16_t PROGMEM fn_actions_7[] = {
444     [0]  =  ACTION_MACRO(XMONAD_RESET),                     // FN0  = xmonad-reanimator
445     [1]  =  ACTION_MACRO(PASSWORD1),                        // FN1  = default password
446     [2]  =  ACTION_MACRO(PASSWORD1),                        // FN2  = other password
447     [3]  =  ACTION_MACRO(PASSWORD1),                        // FN3  = mega password
448 };
449
450 const uint16_t PROGMEM fn_actions_9[] = {
451     [0]  =  ACTION_MODS_KEY(MOD_LCTL,          KC_P0),      // FN0  = Ctrl+0
452     [1]  =  ACTION_MODS_KEY(MOD_LALT,          KC_P1),      // FN1  = Alt+1
453     [2]  =  ACTION_MODS_KEY(MOD_LALT,          KC_P2),      // FN2  = Alt+2
454     [3]  =  ACTION_MODS_KEY(MOD_LALT,          KC_P3),      // FN3  = Alt+3
455     [4]  =  ACTION_MODS_KEY(MOD_LALT,          KC_P4),      // FN4  = Alt+4
456     [5]  =  ACTION_MODS_KEY(MOD_LALT,          KC_P5),      // FN5  = Alt+5
457     [6]  =  ACTION_MODS_KEY(MOD_LALT,          KC_P6),      // FN6  = Alt+6
458     [7]  =  ACTION_MODS_KEY(MOD_LALT,          KC_P7),      // FN7  = Alt+7
459     [8]  =  ACTION_MODS_KEY(MOD_LALT,          KC_P8),      // FN8  = Alt+8
460     [9]  =  ACTION_MODS_KEY(MOD_LALT,          KC_P9),      // FN9  = Alt+9
461     [10] =  ACTION_MODS_KEY(MOD_LCTL|MOD_LSFT, KC_TAB),     // FN10 = Ctrl+Shift+Tab
462     [11] =  ACTION_MODS_KEY(MOD_LCTL,          KC_TAB),     // FN11 = Ctrl+Tab
463     [12] =  ACTION_MODS_KEY(MOD_LCTL|MOD_LSFT, KC_PGUP),    // FN12 = Ctrl+Shift+PgUp
464     [13] =  ACTION_MODS_KEY(MOD_LCTL|MOD_LSFT, KC_PGDN),    // FN13 = Ctrl+Shift+PgDn
465     [14] =  ACTION_MODS_KEY(MOD_LCTL,          KC_PMNS),    // FN14 = Ctrl+Pad Minus
466     [15] =  ACTION_MODS_KEY(MOD_LCTL,          KC_PPLS),    // FN15 = Ctrl+Pad Plus
467 };
468
469 void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
470 {
471     // print("action_function called\n");
472     // print("id  = "); phex(id); print("\n");
473     // print("opt = "); phex(opt); print("\n");
474
475     if (id == TEENSY_KEY) {
476         clear_keyboard();
477         print("\n\nJump to bootloader... ");
478         _delay_ms(50);
479         bootloader_jump(); // should not return
480         print("not supported.\n");
481     }
482
483     if (id == L_CTRL_ALT_ENT || id == R_CTRL_ALT_ENT) {
484         if (record->tap.count == 0 || record->tap.interrupted) {
485             uint8_t weak_mods;
486             uint8_t layer;
487
488             if (id == L_CTRL_ALT_ENT) {
489                 weak_mods = MOD_BIT(KC_LCTL) | MOD_BIT(KC_LALT);
490                 layer     = 5;
491             } else {
492                 weak_mods = MOD_BIT(KC_RCTL) | MOD_BIT(KC_RALT);
493                 layer     = 6;
494             }
495
496             if (record->event.pressed) {
497                 layer_on(layer);
498                 add_weak_mods(weak_mods);
499             } else {
500                 del_weak_mods(weak_mods);
501                 layer_off(layer);
502             }
503         } else {
504             if (record->event.pressed) {
505                 add_key(KC_ENT);
506                 send_keyboard_report();
507             } else {
508                 del_key(KC_ENT);
509                 send_keyboard_report();
510             }
511         }
512     }
513
514
515 /*
516  * just an example of custom key implementation
517  * not really needed with custom keymap_fn_to_action(),
518  * because it will allow you to have 32 FN** keys on EACH layer
519  */
520
521 /*
522     keyevent_t event = record->event;
523
524     if (id == CUSTOM_KEY) {
525         uint8_t layer = biton32(layer_state);
526         uint8_t col = event.key.col;
527         uint8_t row = event.key.row;
528         uint8_t handled = 0;
529
530         if (event.pressed) {
531             if (layer == XXX && col == XXX && row == XXX) {
532                     action_macro_play(
533                         MACRO(
534                             ...........
535                         END)
536                     );
537                     handled++;
538                 }
539             }
540         }
541
542         if (!handled) {
543             print("custom key not handled");
544             print(": layer "); pdec(layer);
545             print(", col "); pdec(col);
546             print(", row "); pdec(row);
547             print("\n");
548         }
549     }
550 */
551
552 }
553
554 #include "keymap_passwords.h"
555 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) {
556     if (record->event.pressed) {
557         switch (id) {
558             case XMONAD_RESET:  return MACRO_XMONAD_RESET;
559             case PASSWORD1:     return MACRO_PASSWORD1;
560         }
561     }
562     return MACRO_NONE;
563 }
564
565 #define FN_ACTIONS_SIZE     (sizeof(fn_actions)   / sizeof(fn_actions[0]))
566 #define FN_ACTIONS_4_SIZE   (sizeof(fn_actions_4) / sizeof(fn_actions_4[0]))
567 #define FN_ACTIONS_7_SIZE   (sizeof(fn_actions_7) / sizeof(fn_actions_7[0]))
568 #define FN_ACTIONS_9_SIZE   (sizeof(fn_actions_9) / sizeof(fn_actions_9[0]))
569
570 /*
571  * translates Fn keycode to action
572  * for some layers, use different translation table
573  */
574 action_t keymap_fn_to_action(uint8_t keycode)
575 {
576     uint8_t layer = biton32(layer_state);
577
578     action_t action;
579     action.code = ACTION_NO;
580
581     if (layer == 4 && FN_INDEX(keycode) < FN_ACTIONS_4_SIZE) {
582         action.code = pgm_read_word(&fn_actions_4[FN_INDEX(keycode)]);
583     }
584
585     if (layer == 7 && FN_INDEX(keycode) < FN_ACTIONS_7_SIZE) {
586         action.code = pgm_read_word(&fn_actions_7[FN_INDEX(keycode)]);
587     }
588
589     if (layer == 9 && FN_INDEX(keycode) < FN_ACTIONS_9_SIZE) {
590         action.code = pgm_read_word(&fn_actions_9[FN_INDEX(keycode)]);
591     }
592
593     // by default, use fn_actions from default layer 0
594     // this is needed to get mapping for same key, that was used switch to some layer,
595     // to have possibility to switch layers back
596     if (action.code == ACTION_NO && FN_INDEX(keycode) < FN_ACTIONS_SIZE) {
597         action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
598     }
599
600     return action;
601 }
602