]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/keymap_common.h
[Jack & Erez] Comments + tiny updates and cleanup
[qmk_firmware.git] / quantum / keymap_common.h
1 /*
2 Copyright 2012,2013 Jun Wako <wakojun@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
18 #ifndef KEYMAP_H
19 #define KEYMAP_H
20
21 #include <stdint.h>
22 #include <stdbool.h>
23 #include "action.h"
24 #include <avr/pgmspace.h>
25 #include "keycode.h"
26 #include "keymap.h"
27 #include "action_macro.h"
28 #include "report.h"
29 #include "host.h"
30 // #include "print.h"
31 #include "debug.h"
32
33 #ifdef BOOTMAGIC_ENABLE
34 /* NOTE: Not portable. Bit field order depends on implementation */
35 typedef union {
36     uint16_t raw;
37     struct {
38         bool swap_control_capslock:1;
39         bool capslock_to_control:1;
40         bool swap_lalt_lgui:1;
41         bool swap_ralt_rgui:1;
42         bool no_gui:1;
43         bool swap_grave_esc:1;
44         bool swap_backslash_backspace:1;
45         bool nkro:1;
46     };
47 } keymap_config_t;
48 keymap_config_t keymap_config;
49 #endif
50
51
52 /* translates key to keycode */
53 uint16_t keymap_key_to_keycode(uint8_t layer, keypos_t key);
54
55 /* translates Fn keycode to action */
56 action_t keymap_fn_to_action(uint16_t keycode);
57
58 /* translates Fn keycode to action */
59 action_t keymap_func_to_action(uint16_t keycode);
60
61 extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS];
62 extern const uint16_t fn_actions[];
63
64 // Ability to use mods in layouts
65 #define LCTL(kc) kc | 0x0100
66 #define LSFT(kc) kc | 0x0200
67 #define LALT(kc) kc | 0x0400
68 #define LGUI(kc) kc | 0x0800
69 #define RCTL(kc) kc | 0x1100
70 #define RSFT(kc) kc | 0x1200
71 #define RALT(kc) kc | 0x1400
72 #define RGUI(kc) kc | 0x1800
73
74 // Aliases for shifted symbols
75 // Each key has a 4-letter code, and some have longer aliases too.
76 // While the long aliases are descriptive, the 4-letter codes
77 // make for nicer grid layouts (everything lines up), and are
78 // the preferred style for Quantum.
79 #define KC_TILD LSFT(KC_GRV)    // ~
80 #define KC_TILDE    KC_TILD
81
82 #define KC_EXLM LSFT(KC_1)      // !
83 #define KC_EXCLAIM  KC_EXLM
84
85 #define KC_AT   LSFT(KC_2)      // @
86 #define KC_HASH LSFT(KC_3)      // #
87
88 #define KC_DLR  LSFT(KC_4)      // $
89 #define KC_DOLLAR   KC_DLR
90
91 #define KC_PERC LSFT(KC_5)      // %
92 #define KC_PERCENT  KC_PERC
93
94 #define KC_CIRC LSFT(KC_6)      // ^
95 #define KC_CIRCUMFLEX   KC_CIRC
96
97 #define KC_AMPR LSFT(KC_7)      // &
98 #define KC_AMPERSAND    KC_AMPR
99
100 #define KC_ASTR LSFT(KC_8)      // *
101 #define KC_ASTERISK KC_ASTR
102
103 #define KC_LPRN LSFT(KC_9)      // (
104 #define KC_LEFT_PAREN   KC_LPRN
105
106 #define KC_RPRN LSFT(KC_0)      // )
107 #define KC_RIGHT_PAREN  KC_RPRN
108
109 #define KC_UNDS LSFT(KC_MINS)   // _
110 #define KC_UNDERSCORE   KC_UNDS
111
112 #define KC_PLUS LSFT(KC_EQL)    // +
113
114 #define KC_LCBR LSFT(KC_LBRC)   // {
115 #define KC_LEFT_CURLY_BRACE KC_LCBR
116
117 #define KC_RCBR LSFT(KC_RBRC)   // }
118 #define KC_RIGHT_CURLY_BRACE    KC_RCBR
119
120 #define KC_PIPE LSFT(KC_SLSH)   // |
121
122 // Alias for function layers than expand past FN31
123 #define FUNC(kc) kc | 0x2000
124
125 // Aliases
126 #define S(kc) LSFT(kc)
127 #define F(kc) FUNC(kc)
128
129 #define M(kc) kc | 0x3000
130
131 #define MACRODOWN(...) (record->event.pressed ? MACRO(__VA_ARGS__) : MACRO_NONE)
132
133 // These affect the backlight (if your keyboard has one).
134 // We don't need to comment them out if your keyboard doesn't have a backlight,
135 // since they don't take up any space.
136 #define BL_ON 0x4009
137 #define BL_OFF 0x4000
138 #define BL_0 0x4000
139 #define BL_1 0x4001
140 #define BL_2 0x4002
141 #define BL_3 0x4003
142 #define BL_4 0x4004
143 #define BL_5 0x4005
144 #define BL_6 0x4006
145 #define BL_7 0x4007
146 #define BL_8 0x4008
147 #define BL_9 0x4009
148 #define BL_10 0x400A
149 #define BL_11 0x400B
150 #define BL_12 0x400C
151 #define BL_13 0x400D
152 #define BL_14 0x400E
153 #define BL_15 0x400F
154 #define BL_DEC 0x4010
155 #define BL_INC 0x4011
156 #define BL_TOGG 0x4012
157 #define BL_STEP 0x4013
158
159 #define RESET 0x5000
160 #define DEBUG 0x5001
161
162 // GOTO layer - 16 layers max
163 // when:
164 // ON_PRESS    = 1
165 // ON_RELEASE  = 2
166 // Unless you have a good reason not to do so, prefer  ON_PRESS (1) as your default.
167 #define TO(layer, when) (layer | 0x5100 | (when << 0x4))
168
169 // Momentary switch layer - 256 layer max
170 #define MO(layer) (layer | 0x5200)
171
172 // Set default layer - 256 layer max
173 #define DF(layer) (layer | 0x5300)
174
175 #define MIDI(n) (n | 0x6000)
176
177 // For sending unicode codes.
178 // You may not send codes over 1FFF -- this supports most of UTF8.
179 // To have a key that sends out Œ, go UC(0x0152)
180 #define UNICODE(n) (n | 0x8000)
181 #define UC(n) UNICODE(n)
182
183
184 #endif