1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
// An Ergodox EZ keymap meant to be used with a bépo layout (FR ergonomic
// layout, dvorak style). The overall design is slightly inspired by the
// TypeMatrix keyboard. Switching between a TypeMatrix and an Ergodox with this
// layout should be relatively easy.
//
// See the README.md file for an image of this keymap.
#include QMK_KEYBOARD_H
#include "keymap_bepo.h"
// The layers that we are defining for this keyboards.
#define BASE 0
#define FN 1
#define MOUSE 2
#define NUMS 3
#define SWAP 4
#define SYSLEDS 5
// The Tap Dance identifiers, used in the TD keycode and tap_dance_actions array.
#define TAP_MACRO 0
// A 'transparent' key code (that falls back to the layers below it).
#define ___ KC_TRANSPARENT
// A 'blocking' key code. Does nothing but prevent falling back to another layer.
#define XXX KC_NO
// Some combined keys (one normal keycode when tapped and one modifier or layer
// toggle when held).
#define ESC_FN LT(FN, KC_ESC) // ESC key and FN layer toggle.
#define M_RSFT MT(MOD_RSFT, BP_M) // 'M' key and right shift modifier.
#define W_RCTL MT(MOD_RCTL, BP_W) // 'W' key and right control modifier.
#define SPC_RALT MT(MOD_RALT, KC_SPC) // SPACE key and right alt modifier.
#define PERC_FN LT(FN, BP_PERC) // '%' key and FN layer toggle.
// The most portable copy/paste keys (windows (mostly), linux, and some terminal emulators).
#define MK_CUT LSFT(KC_DEL) // shift + delete
#define MK_COPY LCTL(KC_INS) // ctrl + insert
#define MK_PASTE LSFT(KC_INS) // shift + insert
// Custom keycodes
enum {
// SAFE_RANGE must be used to tag the first element of the enum.
// DYNAMIC_MACRO_RANGE must always be the last element of the enum if other
// values are added (as its value is used to create a couple of other keycodes
// after it).
DYNAMIC_MACRO_RANGE = SAFE_RANGE,
};
// This file must be included after DYNAMIC_MACRO_RANGE is defined...
#include "dynamic_macro.h"
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// Layer 0: basic keys.
[BASE] = LAYOUT_ergodox(
/* left hand */
BP_DLR, BP_DQUO, BP_LDAQ, BP_RDAQ, BP_LPRN, BP_RPRN, KC_DEL,
KC_TAB, BP_B, BP_EACU, BP_P, BP_O, BP_EGRV, KC_BSPC,
KC_LSFT, BP_A, BP_U, BP_I, BP_E, BP_COMM,
KC_LCTL, BP_AGRV, BP_Y, BP_X, BP_DOT, BP_K, KC_ENT,
ESC_FN, BP_ECIR, KC_LGUI, KC_LALT, SPC_RALT,
TT(SWAP), KC_MNXT,
KC_MPLY,
TT(FN), TT(NUMS), KC_MPRV,
/* right hand */
KC_DEL, BP_AT, BP_PLUS, BP_MINS, BP_SLSH, BP_ASTR, BP_EQL,
KC_BSPC, BP_DCIR, BP_V, BP_D, BP_L, BP_J, BP_Z,
BP_C, BP_T, BP_S, BP_R, BP_N, M_RSFT,
KC_ENT, BP_QUOT, BP_Q, BP_G, BP_H, BP_F, W_RCTL,
SPC_RALT, KC_LALT, TT(SYSLEDS), BP_CCED, PERC_FN,
KC_LEFT, KC_RIGHT,
KC_UP,
KC_DOWN, TD(TAP_MACRO), TT(MOUSE)),
// Layer 1: function and media keys.
[FN] = LAYOUT_ergodox(
/* left hand */
KC_SLEP, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, KC_LSFT,
___, ___, MK_CUT, MK_COPY, MK_PASTE, KC_LCTL, ___,
___, ___, ___, ___, ___,
___, KC_VOLU,
KC_VOLD,
___, ___, KC_MUTE,
/* right hand */
___, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11,
___, ___, KC_HOME, KC_UP, KC_END, KC_PGUP, KC_F12,
___, KC_LEFT, KC_DOWN, KC_RIGHT, KC_PGDN, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___,
KC_HOME, KC_END,
KC_PGUP,
KC_PGDN, ___, ___),
// Note that any change to the FN layer above must be added to
// the MOUSE layer below (except for the arrow keys).
// Layer 2: Mouse control.
[MOUSE] = LAYOUT_ergodox(
/* left hand */
KC_SLEP, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, ___,
___, ___, KC_BTN4, KC_MS_U, KC_BTN5, ___, ___,
___, ___, KC_MS_L, KC_MS_D, KC_MS_R, KC_LSFT,
___, ___, MK_CUT, MK_COPY, MK_PASTE, KC_LCTL, ___,
___, ___, ___, ___, ___,
___, KC_VOLU,
KC_VOLD,
___, ___, KC_MUTE,
/* right hand */
___, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11,
___, ___, XXX, KC_WH_U, XXX, XXX, KC_F12,
___, KC_WH_L, KC_WH_D, KC_WH_R, XXX, ___,
___, ___, KC_ACL0, KC_ACL1, KC_ACL2, ___, ___,
KC_BTN1, KC_BTN2, KC_BTN3, ___, ___,
___, ___,
___,
___, ___, ___),
// Layer 3: Numeric keypad and system keys.
[NUMS] = LAYOUT_ergodox(
/* left hand */
KC_PSCR, KC_INS, KC_PAUS, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___,
___, ___, MK_CUT, MK_COPY, MK_PASTE, ___, ___,
___, ___, ___, ___, ___,
___, ___,
___,
___, ___, ___,
/* right hand */
___, ___, ___, ___, ___, ___, KC_NUM,
___, KC_PEQL, KC_P7, KC_P8, KC_P9, KC_PMNS, KC_SCRL,
KC_PCMM, KC_P4, KC_P5, KC_P6, KC_PPLS, ___,
KC_PENT, KC_P0, KC_P1, KC_P2, KC_P3, KC_PAST, ___,
___, ___, ___, KC_PSLS, ___,
___, ___,
___,
___, ___, ___),
// Layer 4: hand swap, all keys are mirrored to the other side of the keyboard
// except for the layer toggle itself (so there is no right arrow when this
// layer is activated).
[SWAP] = LAYOUT_ergodox(
/* left hand */
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___,
TT(SWAP), ___,
___,
___, ___, ___,
/* right hand */
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___,
___, TT(SWAP),
___,
___, ___, ___),
// Layer 5: The LEDs are showing the "standard" caps/num/scroll lock indicator
// instead of their default which shows the currently active layers (FN, NUMS,
// and MOUSE in that order).
[SYSLEDS] = LAYOUT_ergodox(
/* left hand */
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___,
___, ___,
___,
___, ___, ___,
/* right hand */
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___,
___, ___, TT(SYSLEDS), ___, ___,
___, ___,
___,
___, ___, ___),
};
// Whether the macro 1 is currently being recorded.
static bool is_macro1_recording = false;
// The current set of active layers (as a bitmask).
// There is a global 'layer_state' variable but it is set after the call
// to layer_state_set_user().
static layer_state_t current_layer_state = 0;
layer_state_t layer_state_set_user(layer_state_t state);
// Method called at the end of the tap dance on the TAP_MACRO key. That key is
// used to start recording a macro (double tap or more), to stop recording (any
// number of tap), or to play the recorded macro (1 tap).
void macro_tapdance_fn(tap_dance_state_t *state, void *user_data) {
uint16_t keycode;
keyrecord_t record;
dprintf("macro_tap_dance_fn %d\n", state->count);
if (is_macro1_recording) {
keycode = DM_RSTP;
is_macro1_recording = false;
layer_state_set_user(current_layer_state);
} else if (state->count == 1) {
keycode = DM_PLY1;
} else {
keycode = DM_REC1;
is_macro1_recording = true;
layer_state_set_user(current_layer_state);
}
record.event.pressed = true;
process_record_dynamic_macro(keycode, &record);
record.event.pressed = false;
process_record_dynamic_macro(keycode, &record);
}
// The definition of the tap dance actions:
tap_dance_action_t tap_dance_actions[] = {
// This Tap dance plays the macro 1 on TAP and records it on double tap.
[TAP_MACRO] = ACTION_TAP_DANCE_FN(macro_tapdance_fn),
};
// Runs for each key down or up event.
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (keycode != TD(TAP_MACRO)) {
// That key is processed by the macro_tapdance_fn. Not ignoring it here is
// mostly a no-op except that it is recorded in the macros (and uses space).
// We can't just return false when the key is a tap dance, because
// process_record_user, is called before the tap dance processing (and
// returning false would eat the tap dance).
if (!process_record_dynamic_macro(keycode, record)) {
return false;
}
}
return true; // Let QMK send the enter press/release events
}
// Runs just one time when the keyboard initializes.
void matrix_init_user(void) {
ergodox_right_led_1_off();
ergodox_right_led_2_off();
ergodox_right_led_3_off();
};
// Runs constantly in the background, in a loop.
void matrix_scan_user(void) {
};
// The state of the LEDs requested by the system, as a bitmask.
static uint8_t sys_led_state = 0;
// Use these masks to read the system LEDs state.
static const uint8_t sys_led_mask_num_lock = 1 << USB_LED_NUM_LOCK;
static const uint8_t sys_led_mask_caps_lock = 1 << USB_LED_CAPS_LOCK;
static const uint8_t sys_led_mask_scroll_lock = 1 << USB_LED_SCROLL_LOCK;
// Value to use to switch LEDs on. The default value of 255 is far too bright.
static const uint8_t max_led_value = 20;
// Whether the given layer (one of the constant defined at the top) is active.
#define LAYER_ON(layer) (current_layer_state & (1<<layer))
void led_1_on(void) {
ergodox_right_led_1_on();
ergodox_right_led_1_set(max_led_value);
}
void led_2_on(void) {
ergodox_right_led_2_on();
ergodox_right_led_2_set(max_led_value);
}
void led_3_on(void) {
ergodox_right_led_3_on();
ergodox_right_led_3_set(max_led_value);
}
void led_1_off(void) {
ergodox_right_led_1_off();
}
void led_2_off(void) {
ergodox_right_led_2_off();
}
void led_3_off(void) {
ergodox_right_led_3_off();
}
// Called when the computer wants to change the state of the keyboard LEDs.
void led_set_user(uint8_t usb_led) {
sys_led_state = usb_led;
if (LAYER_ON(SYSLEDS)) {
if (sys_led_state & sys_led_mask_caps_lock) {
led_1_on();
} else {
led_1_off();
}
if (sys_led_state & sys_led_mask_num_lock) {
led_2_on();
} else {
led_2_off();
}
if (sys_led_state & sys_led_mask_scroll_lock) {
led_3_on();
} else {
led_3_off();
}
}
}
layer_state_t layer_state_set_user(layer_state_t state) {
current_layer_state = state;
swap_hands = LAYER_ON(SWAP);
if (is_macro1_recording) {
led_1_on();
led_2_on();
led_3_on();
return state;
}
if (LAYER_ON(SYSLEDS)) {
led_set_user(sys_led_state);
return state;
}
if (LAYER_ON(FN)) {
led_1_on();
} else {
led_1_off();
}
if (LAYER_ON(NUMS)) {
led_2_on();
} else {
led_2_off();
}
if (LAYER_ON(MOUSE)) {
led_3_on();
} else {
led_3_off();
}
return state;
};
|