]> git.donarmstrong.com Git - tmk_firmware.git/blob - keyboard/ergodox/keymap.c
Added MicroDox layout
[tmk_firmware.git] / keyboard / ergodox / keymap.c
1 /*
2 Copyright 2013 Oleg Kostyuk <cub.uanic@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include <stdint.h>
18 #include <stdbool.h>
19 #include <avr/pgmspace.h>
20 #include <util/delay.h>
21 #include "keycode.h"
22 #include "action.h"
23 #include "action_code.h"
24 #include "action_macro.h"
25 #include "bootloader.h"
26 #include "report.h"
27 #include "host.h"
28 #include "print.h"
29 #include "debug.h"
30 #include "keymap.h"
31 #include "ergodox.h"
32
33
34 /* ErgoDox keymap definition macro */
35 #define KEYMAP(                                                 \
36                                                                 \
37     /* left hand, spatial positions */                          \
38     k00,k01,k02,k03,k04,k05,k06,                                \
39     k10,k11,k12,k13,k14,k15,k16,                                \
40     k20,k21,k22,k23,k24,k25,                                    \
41     k30,k31,k32,k33,k34,k35,k36,                                \
42     k40,k41,k42,k43,k44,                                        \
43                             k55,k56,                            \
44                                 k54,                            \
45                         k53,k52,k51,                            \
46                                                                 \
47     /* right hand, spatial positions */                         \
48         k07,k08,k09,k0A,k0B,k0C,k0D,                            \
49         k17,k18,k19,k1A,k1B,k1C,k1D,                            \
50             k28,k29,k2A,k2B,k2C,k2D,                            \
51         k37,k38,k39,k3A,k3B,k3C,k3D,                            \
52                 k49,k4A,k4B,k4C,k4D,                            \
53     k57,k58,                                                    \
54     k59,                                                        \
55     k5C,k5B,k5A )                                               \
56                                                                 \
57    /* matrix positions */                                       \
58    {                                                            \
59     { KC_##k00,KC_##k10,KC_##k20,KC_##k30,KC_##k40,KC_NO   },   \
60     { KC_##k01,KC_##k11,KC_##k21,KC_##k31,KC_##k41,KC_##k51},   \
61     { KC_##k02,KC_##k12,KC_##k22,KC_##k32,KC_##k42,KC_##k52},   \
62     { KC_##k03,KC_##k13,KC_##k23,KC_##k33,KC_##k43,KC_##k53},   \
63     { KC_##k04,KC_##k14,KC_##k24,KC_##k34,KC_##k44,KC_##k54},   \
64     { KC_##k05,KC_##k15,KC_##k25,KC_##k35,KC_NO,   KC_##k55},   \
65     { KC_##k06,KC_##k16,KC_NO,   KC_##k36,KC_NO,   KC_##k56},   \
66                                                                 \
67     { KC_##k07,KC_##k17,KC_NO,   KC_##k37,KC_NO,   KC_##k57},   \
68     { KC_##k08,KC_##k18,KC_##k28,KC_##k38,KC_NO,   KC_##k58},   \
69     { KC_##k09,KC_##k19,KC_##k29,KC_##k39,KC_##k49,KC_##k59},   \
70     { KC_##k0A,KC_##k1A,KC_##k2A,KC_##k3A,KC_##k4A,KC_##k5A},   \
71     { KC_##k0B,KC_##k1B,KC_##k2B,KC_##k3B,KC_##k4B,KC_##k5B},   \
72     { KC_##k0C,KC_##k1C,KC_##k2C,KC_##k3C,KC_##k4C,KC_##k5C},   \
73     { KC_##k0D,KC_##k1D,KC_##k2D,KC_##k3D,KC_##k4D,KC_NO   }    \
74    }
75
76 #if defined(KEYMAP_DVORAK)
77 #include "keymap_dvorak.h"
78 #elif defined(KEYMAP_COLEMAK)
79 #include "keymap_colemak.h"
80 #elif defined(KEYMAP_WORKMAN)
81 #include "keymap_workman.h"
82 #elif defined(KEYMAP_MICRO)
83 #include "keymap_micro.h"
84 #elif defined(KEYMAP_CUB)
85 #include "keymap_cub.h"
86 #else
87
88 static const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
89     KEYMAP(  // layer 0 : default
90         // left hand
91         EQL, 1,   2,   3,   4,   5,   ESC,
92         BSLS,Q,   W,   E,   R,   T,   FN2,
93         TAB, A,   S,   D,   F,   G,
94         LSFT,Z,   X,   C,   V,   B,   FN1,
95         LGUI,GRV, BSLS,LEFT,RGHT,
96                                       LCTL,LALT,
97                                            HOME,
98                                  BSPC,DEL, END,
99         // right hand
100              FN3, 6,   7,   8,   9,   0,   MINS,
101              LBRC,Y,   U,   I,   O,   P,   RBRC,
102                   H,   J,   K,   L,   SCLN,QUOT,
103              FN1, N,   M,   COMM,DOT, SLSH,RSFT,
104                        LEFT,DOWN,UP,  RGHT,RGUI,
105         RALT,RCTL,
106         PGUP,
107         PGDN,ENT, SPC
108     ),
109
110     KEYMAP(  // layer 1 : function and symbol keys
111         // left hand
112         TRNS,F1,  F2,  F3,  F4,  F5,  F11,
113         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,FN4,
114         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
115         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
116         TRNS,TRNS,TRNS,TRNS,TRNS,
117                                       TRNS,TRNS,
118                                            TRNS,
119                                  TRNS,TRNS,TRNS,
120         // right hand
121              F12, F6,  F7,  F8,  F9,  F10, TRNS,
122              TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
123                   TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
124              TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
125                        TRNS,TRNS,TRNS,TRNS,TRNS,
126         TRNS,TRNS,
127         TRNS,
128         TRNS,TRNS,TRNS
129     ),
130
131     KEYMAP(  // layer 2 : keyboard functions
132         // left hand
133         FN0, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
134         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
135         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
136         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
137         TRNS,TRNS,TRNS,TRNS,TRNS,
138                                       TRNS,TRNS,
139                                            TRNS,
140                                  TRNS,TRNS,TRNS,
141         // right hand
142              FN4, TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
143              TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
144                   TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
145              TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
146                        TRNS,TRNS,TRNS,TRNS,TRNS,
147         TRNS,TRNS,
148         TRNS,
149         TRNS,TRNS,TRNS
150     ),
151
152     KEYMAP(  // layer 3: numpad
153         // left hand
154         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
155         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
156         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
157         TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,
158         TRNS,TRNS,TRNS,TRNS,TRNS,
159                                       TRNS,TRNS,
160                                            TRNS,
161                                  TRNS,TRNS,TRNS,
162         // right hand
163              SLCK,NLCK,PSLS,PAST,PAST,PMNS,BSPC,
164              TRNS,NO,  P7,  P8,  P9,  PMNS,BSPC,
165                   NO,  P4,  P5,  P6,  PPLS,PENT,
166              TRNS,NO,  P1,  P2,  P3,  PPLS,PENT,
167                        P0,  PDOT,SLSH,PENT,PENT,
168         TRNS,TRNS,
169         TRNS,
170         TRNS,TRNS,TRNS
171     ),
172
173 };
174
175 /* id for user defined functions */
176 enum function_id {
177     TEENSY_KEY,
178 };
179
180 /*
181  * Fn action definition
182  */
183 static const uint16_t PROGMEM fn_actions[] = {
184     ACTION_FUNCTION(TEENSY_KEY),                    // FN0 - Teensy key
185     ACTION_LAYER_MOMENTARY(1),                      // FN1 - switch to Layer1
186     ACTION_LAYER_SET(2, ON_PRESS),                  // FN2 - push Layer2
187     ACTION_LAYER_SET(3, ON_PRESS),                  // FN3 - push Layer3
188     ACTION_LAYER_SET(0, ON_PRESS),                  // FN4 - push Layer0
189 };
190
191 void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
192 {
193     if (id == TEENSY_KEY) {
194         clear_keyboard();
195         print("\n\nJump to bootloader... ");
196         _delay_ms(250);
197         bootloader_jump(); // should not return
198         print("not supported.\n");
199     }
200 }
201
202 #endif
203
204
205 #define KEYMAPS_SIZE    (sizeof(keymaps) / sizeof(keymaps[0]))
206 #define FN_ACTIONS_SIZE (sizeof(fn_actions) / sizeof(fn_actions[0]))
207
208 /* translates key to keycode */
209 uint8_t keymap_key_to_keycode(uint8_t layer, key_t key)
210 {
211     if (layer < KEYMAPS_SIZE) {
212         return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]);
213     } else {
214         // fall back to layer 0
215         return pgm_read_byte(&keymaps[0][(key.row)][(key.col)]);
216     }
217 }
218
219 /* translates Fn keycode to action */
220 action_t keymap_fn_to_action(uint8_t keycode)
221 {
222     action_t action;
223     if (FN_INDEX(keycode) < FN_ACTIONS_SIZE) {
224         action.code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]);
225     } else {
226         action.code = ACTION_NO;
227     }
228     return action;
229 }
230