]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/handwired/frenchdev/keymaps/default/keymap.c
Update handwired/frenchdev keyboard (#5443)
[qmk_firmware.git] / keyboards / handwired / frenchdev / keymaps / default / keymap.c
1 #include QMK_KEYBOARD_H
2 #include "keymap_bepo.h"
3
4
5 // Each layer gets a name for readability, which is then used in the keymap matrix below.
6 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
7 #define _BASE 0
8 #define _SYMBOLS 1
9 #define _MEDIA 2
10 #define _TRNS 8
11
12 #define PEDAL_DELAY 250
13 #define KEY_DELAY 130
14
15 enum macros {
16     M_LP = SAFE_RANGE,   // left pedal
17     M_RP,   // right pedal
18     M_SF,   // shift
19     M_SFS,  // shift and space
20     M_L1E,  // L1 and space
21     L2INS,  // L2 and insert
22     L2LOC,  // Lock L2
23     M_UN,   // undo
24     M_CUT,  // cut
25     M_CP,   // copy
26     M_PS,   // paste
27     M_SE,   // search
28     M_SFU,  // shift and underscore
29 };
30
31 static uint16_t key_timer_left_pedal;
32 static uint16_t key_timer_right_pedal;
33 static uint16_t key_timer_shift;
34 static uint16_t key_timer_1;
35 static uint16_t key_timer_2;
36
37 static uint16_t shift_count = 0; //this is used to keep track of shift state and avoid inserting non breakable space
38 static uint16_t l2_locked = 0; //this indicate wether L2 is locked
39
40 #define BP_CBSP  CTL_T(KC_BSPC)
41 #define BP_CDEL  CTL_T(KC_DEL)
42
43 //layout : http://www.keyboard-layout-editor.com/#/gists/4480e3ab8026eb7c710a7e22203ef4aa
44 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
45 /* base
46  *   left foot clicked is right click
47  *   left foot pressed is layer 2
48  *   right foot clicked is left click
49  *   right foot pressed is layer 1 + scroll lock (used with autohotkey for easier scrolling with trackballs)
50  *                      ,------.                                    ..                                    ,------.                      *
51  *               ,------|  F3  |-------------.                      ..                      ,-------------|  F10 |------.               *
52  *        ,------|  F2  |------|  F4  |  F5  |------.               ..               ,------|  F8  |  F9  |------| F11  |------.        *
53  *        |  F1  |------| »/3  |------|------|  F6  |               ..               |  F7  |------|------| -/8  |------|  F12 |        *
54  * ,------+------| «/2  |------|  (/4 | )/5  |------|               ..               |------| @/6  | +/7  |------| //9  |------+------. *
55  * |  ESC | "/1  |------|  O   |------|------|  ¨   |               ..               |  ^   |------|------|  D   |------| * /0 |BCKSP | *
56  * |------+------|  É   |------|  P   |  È   |------|               ..               |------|  K   |  V   |------|  L   |------+------| *
57  * | TAB  |  B   |------|  E   |------|------|  _   |               ..               | =/°  |------|------|  S   |------|  J   |ENTER | *
58  * |------+------|  U   |------|  I   |  F   |------|               ..               |------|  C   |  T   |------|  R   |------+------| *
59  * | `    |  A   |------|  Y   |------|------|  ;   |               ..               |  !   |------|------|  UP  |------|  N   |  '/? | *
60  * |------+------|  À   |------|  X   |  W   |------|-------------. .. .-------------|------|  M   |  G   |------|  H   |------+------| *
61  * | SHIFT|  Z   |------|  .   |------|------|sp/sh |bsp/ct|L2/ins| .. |L2lock|del/CT|sp/sh |------|------| DOWN |------|  Q   |SHIFT | *
62  * |------+------|  /   |------|  ,   | space|------|------|------  ..  ------|------|------| L1/sp| LEFT |------|  UP  |------+------| *
63  * | CTRL | win  |------/      \-------------| L1   | alt  |        ..        | CAPS | L1   |-------------/      \------| :    | CTRL | *
64  * `-------------/                           \-------------/        ..        \-------------/                           \-------------/ *
65  */
66 [_BASE] = LAYOUT(
67            KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,                                          KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,     \
68   KC_ESC,  BP_DQOT, BP_LGIL, BP_RGIL, BP_LPRN, BP_RPRN, BP_DTRM,                                        BP_DCRC, BP_AT,   BP_PLUS, BP_MINS, BP_SLSH, BP_ASTR, KC_BSPC, \
69   KC_TAB,  BP_B,    BP_ECUT, BP_O,    BP_P,    BP_EGRV, BP_UNDS,                                        BP_EQL,  BP_K,    BP_V,    BP_D,    BP_L,    BP_J,    KC_ENT,  \
70   BP_GRV,  BP_A,    BP_U,    BP_E,    BP_I,    BP_F,    BP_SCLN,                                        BP_EXLM, BP_C,    BP_T,    BP_S,    BP_R,    BP_N,    BP_APOS, \
71   M_SF,    BP_Z,    BP_AGRV, BP_Y,    BP_X,    KC_RBRC, M_SFS,   BP_CBSP, L2INS,        L2LOC, BP_CDEL, M_SFS,   BP_M,    BP_G,    KC_UP,   BP_H,    BP_Q,    M_SF, \
72   KC_LCTL, KC_LGUI, KC_PSLS, BP_DOT,  BP_COMM, KC_SPACE,M_L1E,   KC_LALT,                     KC_CAPS, M_L1E,  KC_SPACE,  KC_LEFT, KC_DOWN, KC_RIGHT,BP_COLN, KC_RCTL,   \
73   //left pedals
74   M_LP, M_RP, KC_TRNS, \
75   //right pedals
76   M_LP, M_RP, KC_TRNS \
77 ),
78
79  /* Larer 1 for symbols.
80  *   left foot is middle click
81   *                      ,------.                                    ..                                    ,------.                      *
82   *               ,------|      |-------------.                      ..                      ,-------------|      |------.               *
83   *        ,------|      |------|      |      |------.               ..               ,------|      |      |------|      |------.        *
84   *        |      |------|  §   |------|------|      |               ..               |      |------|------|  ±   |------|      |        *
85   * ,------+------|  ¶   |------|  µ   |      |------|               ..               |------|  ≤   |  ≥   |------|  ÷   |------+------. *
86   * |      |  ¤   |------|  {   |------|------|  ~   |               ..               |  ˇ   |------|------|  ]   |------|  ×   |      | *
87   * |------+------|  *   |------|  }   |  `   |------|               ..               |------|  #   |  [   |------|  %   |------+------| *
88   * |      |  \   |------|  (   |------|------|      |               ..               |  ≠   |------|------|  >   |------|  ‰  |      | *
89   * |------+------|  Ù   |------|  )   |  +   |------|               ..               |------|  Ç   |  <   |------|  &   |------+------| *
90   * |      |  =   |------| copy |------|------|  :   |               ..               |  ?   |------|------| PGUP |------|  _   |      | *
91   * |------+------|  cut |------| paste|search|------|-------------. .. .-------------|------|  $   |  =   |------|  |   |------+------| *
92   * |      | undo |------|  \   |------|------|      |      |      | .. |      |      |      |------|------| PGDN |------|  /   |      | *
93   * |------+------|      |------|      |      |------|------|------  ..  ------|------|------|      | HOME |------| PGDN |------+------| *
94   * |      |      |------/      \-------------|      |      |        ..        |      |      |-------------/      \------|      |      | *
95   * `-------------/                           \-------------/        ..        \-------------/                           \-------------/ *
96   *
97   */
98 [_SYMBOLS] = LAYOUT(
99            KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                                       KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,          \
100   KC_TRNS, BP_DCUR, BP_PARG, BP_SECT, BP_DGRK, KC_TRNS, BP_TILD,                                       BP_DCAR, BP_LEQL, BP_GEQL, BP_PSMS, BP_OBEL, BP_TIMS, KC_TRNS, \
101   KC_TRNS, BP_BSLS, BP_ASTR, BP_LCBR, BP_RCBR, BP_GRV,  KC_TRNS,                                       BP_DIFF, BP_HASH, BP_LBRC, BP_RBRC, BP_PERC, BP_PMIL, KC_TRNS, \
102   KC_TRNS, BP_EQL,  BP_UGRV, BP_LPRN, BP_RPRN, BP_PLUS, BP_COLN,                                       BP_QEST, BP_CCED, BP_LESS, BP_GRTR, BP_AMPR, BP_UNDS, KC_TRNS, \
103   KC_TRNS, M_UN,    M_CUT,   M_CP,    M_PS,    M_SE,    KC_TRNS, KC_TRNS, KC_TRNS,   KC_TRNS, KC_TRNS, KC_TRNS, BP_DLR,  BP_EQL,  KC_PGUP, BP_PIPE, BP_SLSH, KC_TRNS, \
104   KC_TRNS, KC_TRNS, BP_BSLS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                     KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGDN, KC_END,  KC_TRNS, KC_TRNS,  \
105   //left pedals
106   KC_TRNS, KC_BTN1, KC_TRNS, \
107   //right pedals
108   KC_TRNS, KC_BTN1, KC_TRNS  \
109 ),
110
111  /* MEDIA, mouse and numpad.
112   * right pedal is left clic
113   *                      ,------.                                    ..                                    ,------.                      *
114   *               ,------|PAUSE |-------------.                      ..                      ,-------------| PRINT|------.               *
115   *        ,------|SCROLL|------|MUTE  |VOLUD |------.               ..               ,------| pre  | next |------| calc |------.        *
116   *        |RESET |------| stop |------|------|VOLDU |               ..               | play |------|------| stop |------| num  |        *
117   * ,------+------|      |------| pre  | next |------|               ..               |------| pre  | next |------|      |------+------. *
118   * |      |      |------|scrolu|------|------| play |               ..               | play |------|------|  8   |------|  -   |      | *
119   * |------+------|      |------|      | bt4  |------|               ..               |------| next |  7   |------|  9   |------+------| *
120   * |      |      |------|scrold|------|------| bt5  |               ..               | pre  |------|------|  5   |------|  +   |      | *
121   * |------+------|      |------|mclic | rclic|------|               ..               |------| rclic|  4   |------|  6   |------+------| *
122   * |      |      |------|      |------|------| lclic|               ..               | lclic|------|------|  2   |------|  *   |      | *
123   * |------+------|      |------|      | mclck|------|-------------. .. .-------------|------| mclic|  1   |------|  3   |------+------| *
124   * |      |      |------|      |------|------|      |      |      | .. |      |      |      |------|------| num. |------|  /   |      | *
125   * |------+------|      |------|      |      |------|------|------  ..  ------|------|------|      |  0   |------|  .   |------+------| *
126   * |      |      |------/      \-------------|      |      |        ..        |      |      |-------------/      \------|  ,   |      | *
127   * `-------------/                           \-------------/        ..        \-------------/                           \-------------/ *
128   *
129   */
130 [_MEDIA] = LAYOUT(
131            RESET,   KC_SLCK, KC_PAUS, KC_MUTE, KC_VOLD, KC_VOLU,                                     KC_MUTE, KC_VOLD, KC_VOLU, KC_PSCR, KC_CALC, KC_NLCK,          \
132   KC_TRNS, KC_TRNS, KC_TRNS, KC_MSTP, KC_MPRV, KC_MNXT, KC_MPLY,                                     KC_MPLY, KC_MPRV, KC_MNXT, KC_MSTP, KC_TRNS, KC_PMNS, KC_TRNS, \
133   KC_TRNS, KC_TRNS, KC_TRNS, KC_WH_U, KC_TRNS, KC_BTN4, KC_BTN5,                                     KC_BTN4, KC_BTN5, KC_KP_7, KC_KP_8, KC_KP_9, KC_PPLS, KC_TRNS, \
134   KC_TRNS, KC_TRNS, KC_TRNS, KC_WH_D, KC_BTN3, KC_BTN2, KC_BTN1,                                     KC_BTN1, KC_BTN2, KC_KP_4, KC_KP_5, KC_KP_6, KC_PAST, KC_TRNS, \
135   KC_TRNS, M_UN,    M_CUT,   M_CP,    M_PS,    KC_BTN3, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN3, KC_KP_1, KC_KP_2, KC_KP_3, KC_PSLS, KC_TRNS, \
136   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                   KC_TRNS, KC_TRNS, KC_TRNS, KC_KP_0, KC_PDOT, BP_DOT,  BP_COMM, KC_TRNS,  \
137   //left pedals
138   KC_BTN3, M_RP,    KC_TRNS, \
139   //right pedals
140   KC_BTN3, M_RP,    KC_TRNS  \
141 ),
142
143 /* TRNS - skeleton for laters
144  *                      ,------.                                    ..                                    ,------.                      *
145  *               ,------|      |-------------.                      ..                      ,-------------|      |------.               *
146  *        ,------|      |------|      |      |------.               ..               ,------|      |      |------|      |------.        *
147  *        |      |------|      |------|------|      |               ..               |      |------|------|      |------|      |        *
148  * ,------+------|      |------|      |      |------|               ..               |------|      |      |------|      |------+------. *
149  * |      |      |------|      |------|------|      |               ..               |      |------|------|      |------|      |      | *
150  * |------+------|      |------|      |      |------|               ..               |------|      |      |------|      |------+------| *
151  * |      |      |------|      |------|------|      |               ..               |      |------|------|      |------|      |      | *
152  * |------+------|      |------|      |      |------|               ..               |------|      |      |------|      |------+------| *
153  * |      |      |------|      |------|------|      |               ..               |      |------|------|      |------|      |      | *
154  * |------+------|      |------|      |      |------|-------------. .. .-------------|------|      |      |------|      |------+------| *
155  * |      |      |------|      |------|------|      |      |      | .. |      |      |      |------|------|      |------|      |      | *
156  * |------+------|      |------|      |      |------|------|------  ..  ------|------|------|      |      |------|      |------+------| *
157  * |      |      |------/      \-------------|      |      |        ..        |      |      |-------------/      \------|      |      | *
158  * `-------------/                           \-------------/        ..        \-------------/                           \-------------/ *
159  *
160  */
161
162 [_TRNS] = LAYOUT(
163            KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                                     KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,          \
164   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                                     KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
165   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                                     KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
166   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                                     KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
167   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
168   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
169   //left pedals
170   KC_BTN3, M_RP,    KC_TRNS, \
171   //right pedals
172   KC_BTN3, M_RP,    KC_TRNS  \
173 ),
174
175 };
176
177 void hold_shift(void) {
178   shift_count = shift_count + 1;
179   register_code(KC_LSHIFT);
180 }
181
182 void release_shift(void) {
183   shift_count = shift_count - 1;
184   if(shift_count <= 0){
185     unregister_code(KC_LSHIFT);
186     shift_count = 0;
187   }
188 }
189
190 void press_space(void) {
191   if(shift_count > 0) unregister_code (KC_LSHIFT);
192   tap_code(KC_SPACE);
193   if(shift_count > 0) register_code (KC_LSHIFT);
194 }
195
196 void press_enter(void) {
197   if(shift_count > 0) unregister_code (KC_LSHIFT);
198   tap_code (KC_ENT);
199   if(shift_count > 0) register_code (KC_LSHIFT);
200 }
201
202 void press_underscore(void) {
203   if(shift_count > 0) unregister_code (KC_LSHIFT);
204   tap_code ((unsigned char) BP_UNDS);
205   if(shift_count > 0) register_code (KC_LSHIFT);
206 }
207
208 void matrix_init_user(void) {
209 }
210
211 // Bleah globals need to be initialized.
212 uint8_t old_layer=_BASE;
213
214 void matrix_scan_user(void) {
215     uint8_t layer = biton32(layer_state);
216
217     frenchdev_led_1_off();
218     frenchdev_led_2_off();
219     switch (layer) {
220         case _BASE:
221             frenchdev_led_2_on();
222             break;
223         case _SYMBOLS:
224             frenchdev_led_1_on();
225             break;
226         case _MEDIA:
227            frenchdev_led_1_on();
228            frenchdev_led_2_on();
229         default:
230             // none
231             break;
232     }
233 }
234
235
236 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
237   switch(keycode) {
238     case M_LP: //left pedal
239       if (record->event.pressed) {
240         layer_on(1);
241         register_code (KC_SLCK);
242         key_timer_left_pedal = timer_read(); // if the key is being pressed, we start the timer.
243       } else {
244         if (timer_elapsed(key_timer_left_pedal) < KEY_DELAY) {
245            tap_code (KC_BTN2);
246         }
247         unregister_code (KC_SLCK);
248         layer_off(1);
249       }
250       break;
251     case M_RP: //right pedal
252       if (record->event.pressed) {
253         layer_on(2);
254         key_timer_right_pedal = timer_read(); // if the key is being pressed, we start the timer.
255       } else {
256         if (timer_elapsed(key_timer_right_pedal) < PEDAL_DELAY) {
257            tap_code (KC_BTN1);
258         }
259         layer_off(2);
260       }
261       break;
262     case M_SF: // shift, using macro to keep track of shift state and avoid inserting nbsp by mistake
263       if (record->event.pressed) {
264         hold_shift();
265       } else {
266         release_shift();
267       }
268       break;
269     case M_SFS: // shift when held, space when tapped
270       if (record->event.pressed) {
271         hold_shift();
272         key_timer_shift = timer_read(); // if the key is being pressed, we start the timer.
273       } else {
274         if (timer_elapsed(key_timer_shift) < KEY_DELAY) {
275           press_space();
276         }
277         release_shift();
278       }
279       break;
280     case M_SFU: // shift when held, _ when tapped
281       if (record->event.pressed) {
282         hold_shift();
283         key_timer_shift = timer_read(); // if the key is being pressed, we start the timer.
284       } else {
285         if (timer_elapsed(key_timer_shift) < KEY_DELAY) {
286           press_space();
287         }
288         release_shift();
289       }
290       break;
291     case M_L1E: // L1 when held, space when tapped
292       if (record->event.pressed) {
293         layer_on(1);
294         key_timer_1 = timer_read(); // if the key is being pressed, we start the timer.
295       } else {
296         if (timer_elapsed(key_timer_1) < KEY_DELAY) {
297           press_enter();
298         }
299         layer_off(1);
300       }
301       break;
302     case L2INS: //activate layer 2, if released before 100ms trigger INS. basicaly equivalent to LT(2, KC_INS) but without delay for activation of layer 2
303       if (record->event.pressed) {
304         layer_on(2);
305         key_timer_2 = timer_read(); // if the key is being pressed, we start the timer.
306       } else {
307         if (timer_elapsed(key_timer_2) < KEY_DELAY) {
308            tap_code (KC_INS);
309         }
310         l2_locked = 0;
311         layer_off(2);
312       }
313       break;
314     case L2LOC: //lock L2
315       if (record->event.pressed) {
316         key_timer_2 = timer_read(); // if the key is being pressed, we start the timer.
317         layer_on(2);
318       } else {
319         if (timer_elapsed(key_timer_2) < KEY_DELAY && l2_locked == 0) {
320           l2_locked = 1;
321           layer_on(2);
322         } else {
323           l2_locked = 0;
324           layer_off(2);
325         }
326       }
327       break;
328     case M_UN: // undo
329       if (record->event.pressed) {
330         tap_code16(C(BP_Z));
331       }
332       break;
333     case M_CUT: // cut
334       if (record->event.pressed) {
335         tap_code16(C(BP_X));
336       }
337       break;
338     case M_CP: // copy
339       if (record->event.pressed) {
340         tap_code16(C(BP_C));
341       }
342       break;
343     case M_PS: // paste
344       if (record->event.pressed) {
345         tap_code16(C(BP_V));
346       }
347       break;
348     case M_SE: // search
349       if (record->event.pressed) {
350         tap_code16(C(BP_F));
351       }
352       break;
353   }
354   return true;
355 }
356
357 void led_set_user(uint8_t usb_led) {
358   if (usb_led & (1<<USB_LED_CAPS_LOCK)){
359     frenchdev_led_3_on();
360   } else {
361     frenchdev_led_3_off();
362   }
363   return ;
364 }