diff options
author | James Young <18669334+noroadsleft@users.noreply.github.com> | 2020-10-17 09:50:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-18 03:50:32 +1100 |
commit | de68d294ec6fdae37e41f515407f324bcc4611ae (patch) | |
tree | 36de783fa1c9ce8baa1271f2fbdcaf38a8ebf0c0 /docs/configurator_default_keymaps.md | |
parent | f0a1ab5488425857987e94c883fd13cc661a92a8 (diff) | |
download | qmk_firmware-de68d294ec6fdae37e41f515407f324bcc4611ae.tar.gz qmk_firmware-de68d294ec6fdae37e41f515407f324bcc4611ae.zip |
[Docs] add "Adding Default Keymaps to QMK Configurator" doc (#10049)
Diffstat (limited to 'docs/configurator_default_keymaps.md')
-rw-r--r-- | docs/configurator_default_keymaps.md | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/docs/configurator_default_keymaps.md b/docs/configurator_default_keymaps.md new file mode 100644 index 000000000..30f9fa72f --- /dev/null +++ b/docs/configurator_default_keymaps.md | |||
@@ -0,0 +1,193 @@ | |||
1 | # Adding Default Keymaps to QMK Configurator :id=adding-default-keymaps | ||
2 | |||
3 | This page covers how to add a default keymap for a keyboard to QMK Configurator. | ||
4 | |||
5 | |||
6 | ## Technical Information :id=technical-information | ||
7 | |||
8 | QMK Configurator uses JSON as its native file format for keymaps. As much as possible, these should be kept such that they behave the same as running `make <keyboard>:default` from `qmk_firmware`. | ||
9 | |||
10 | Keymaps in this directory require four key-value pairs: | ||
11 | |||
12 | * `keyboard` (string) | ||
13 | * This is the name of the keyboard, the same as would be used when running a compile job through `make` (e.g. `make 1upkeyboards/1up60rgb:default`). | ||
14 | * `keymap` (string) | ||
15 | * Should be set to `default`. | ||
16 | * `layout` (string) | ||
17 | * This is the layout macro used by the default keymap. | ||
18 | * `layers` (array) | ||
19 | * The keymap itself. This key should contain one array per layer, which themselves should contain the keycodes that make up that layer. | ||
20 | |||
21 | Additionally, most keymaps contain a `commit` key. This key is not consumed by the API that back-stops QMK Configurator, but is used by Configurator's maintainers to tell which version of a keymap was used to create the JSON keymap in this repository. The value is the SHA of the last commit to modify a board's default `keymap.c` in the `qmk_firmware` repository. The SHA is found by checking out [the `master` branch of the `qmk/qmk_firmware` repository](https://github.com/qmk/qmk_firmware/tree/master/) and running `git log -1 --pretty=oneline -- keyboards/<keyboard>/keymaps/default/keymap.c` (use `keymap.json` if the keyboard in question has this file instead), which should return something similar to: | ||
22 | |||
23 | ```shell | ||
24 | f14629ed1cd7c7ec9089604d64f29a99981558e8 Remove/migrate action_get_macro()s from default keymaps (#5625) | ||
25 | ``` | ||
26 | |||
27 | In this example, `f14629ed1cd7c7ec9089604d64f29a99981558e8` is the value that should be used for `commit`. | ||
28 | |||
29 | |||
30 | ## Example :id=example | ||
31 | |||
32 | If one wished to add a default keymap for the H87a by Hineybush, one would run the `git log` command above against the H87a's default keymap in `qmk_firmware`: | ||
33 | |||
34 | ```shell | ||
35 | user ~/qmk_firmware (master) | ||
36 | $ git log -1 --pretty=oneline master -- keyboards/hineybush/h87a/keymaps/default/keymap.c | ||
37 | ef8878fba5d3786e3f9c66436da63a560cd36ac9 Hineybush h87a lock indicators (#8237) | ||
38 | ``` | ||
39 | |||
40 | Now that we have the commit hash, we need the keymap (edited for readability): | ||
41 | |||
42 | ```c | ||
43 | ... | ||
44 | #include QMK_KEYBOARD_H | ||
45 | |||
46 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
47 | |||
48 | [0] = LAYOUT_all( | ||
49 | KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_SLCK, KC_PAUS, | ||
50 | KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_BSPC, KC_INS, KC_HOME, KC_PGUP, | ||
51 | KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_END, KC_PGDN, | ||
52 | KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_NUHS, KC_ENT, | ||
53 | KC_LSFT, KC_NUBS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_TRNS, KC_UP, | ||
54 | KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_RGUI, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT), | ||
55 | |||
56 | [1] = LAYOUT_all( | ||
57 | KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RGB_TOG, RGB_MOD, RGB_HUD, RGB_HUI, RGB_SAD, RGB_SAI, RGB_VAD, RGB_VAI, BL_TOGG, BL_DEC, BL_INC, | ||
58 | 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_VOLU, | ||
59 | KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RESET, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_MPLY, KC_MNXT, KC_VOLD, | ||
60 | 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, | ||
61 | 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, | ||
62 | KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS), | ||
63 | |||
64 | }; | ||
65 | ``` | ||
66 | |||
67 | The default keymap uses the `LAYOUT_all` macro, so that will be the value of the `layout` key. Compiled to a QMK Configurator JSON keymap, our resulting file should be: | ||
68 | |||
69 | ```json | ||
70 | { | ||
71 | "keyboard": "hineybush/h87a", | ||
72 | "keymap": "default", | ||
73 | "commit": "ef8878fba5d3786e3f9c66436da63a560cd36ac9", | ||
74 | "layout": "LAYOUT_all", | ||
75 | "layers": [ | ||
76 | [ | ||
77 | "KC_ESC", "KC_F1", "KC_F2", "KC_F3", "KC_F4", "KC_F5", "KC_F6", "KC_F7", "KC_F8", "KC_F9", "KC_F10", "KC_F11", "KC_F12", "KC_PSCR", "KC_SLCK", "KC_PAUS", | ||
78 | "KC_GRV", "KC_1", "KC_2", "KC_3", "KC_4", "KC_5", "KC_6", "KC_7", "KC_8", "KC_9", "KC_0", "KC_MINS", "KC_EQL", "KC_BSPC", "KC_BSPC", "KC_INS", "KC_HOME", "KC_PGUP", | ||
79 | "KC_TAB", "KC_Q", "KC_W", "KC_E", "KC_R", "KC_T", "KC_Y", "KC_U", "KC_I", "KC_O", "KC_P", "KC_LBRC", "KC_RBRC", "KC_BSLS", "KC_DEL", "KC_END", "KC_PGDN", | ||
80 | "KC_CAPS", "KC_A", "KC_S", "KC_D", "KC_F", "KC_G", "KC_H", "KC_J", "KC_K", "KC_L", "KC_SCLN", "KC_QUOT", "KC_NUHS", "KC_ENT", | ||
81 | "KC_LSFT", "KC_NUBS", "KC_Z", "KC_X", "KC_C", "KC_V", "KC_B", "KC_N", "KC_M", "KC_COMM", "KC_DOT", "KC_SLSH", "KC_RSFT", "KC_TRNS", "KC_UP", | ||
82 | "KC_LCTL", "KC_LGUI", "KC_LALT", "KC_SPC", "KC_RALT", "MO(1)", "KC_RGUI", "KC_RCTL", "KC_LEFT", "KC_DOWN", "KC_RGHT" | ||
83 | ], | ||
84 | [ | ||
85 | "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "RGB_TOG", "RGB_MOD", "RGB_HUD", "RGB_HUI", "RGB_SAD", "RGB_SAI", "RGB_VAD", "RGB_VAI", "BL_TOGG", "BL_DEC", "BL_INC", | ||
86 | "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_VOLU", | ||
87 | "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "RESET", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_MPLY", "KC_MNXT", "KC_VOLD", | ||
88 | "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", | ||
89 | "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", | ||
90 | "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS", "KC_TRNS" | ||
91 | ] | ||
92 | ] | ||
93 | } | ||
94 | ``` | ||
95 | |||
96 | The white space in the `layers` arrays have no effect on the functionality of the keymap, but are used to make these files easier for humans to read. | ||
97 | |||
98 | |||
99 | ## Caveats :id=caveats | ||
100 | |||
101 | ### Layers can only be referenced by number :id=layer-references | ||
102 | |||
103 | A common QMK convention is to name layers using a series of `#define`s, or an `enum` statement: | ||
104 | |||
105 | ```c | ||
106 | enum layer_names { | ||
107 | _BASE, | ||
108 | _MEDIA, | ||
109 | _FN | ||
110 | }; | ||
111 | ``` | ||
112 | |||
113 | This works in C, but for Configurator, you *must* use the layer's numeric index – `MO(_FN)` would need to be `MO(2)` in the above example. | ||
114 | |||
115 | ### No support for custom code of any kind :id=custom-code | ||
116 | |||
117 | Features that require adding functions to the keymap.c file, such as Tap Dance or Unicode, can not be compiled in Configurator **at all**. Even setting `TAP_DANCE_ENABLE = yes` in the `qmk_firmware` repository at the keyboard level will prevent Configurator from compiling **any** firmware for that keyboard. This is limited both by the API and the current spec of our JSON keymap format. | ||
118 | |||
119 | ### Limited Support for Custom keycodes :id=custom-keycodes | ||
120 | |||
121 | There is a way to support custom keycodes: if the logic for a custom keycode is implemented at the keyboard level instead of the keymap level in qmk_firmware, that keycode *can* be used in Configurator and it *will* compile and work. Instead of using the following in your `keymap.c`: | ||
122 | |||
123 | ```c | ||
124 | enum custom_keycodes { | ||
125 | MACRO_1 = SAFE_RANGE, | ||
126 | MACRO_2, | ||
127 | MACRO_3 | ||
128 | }; | ||
129 | ... | ||
130 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
131 | switch(keycode) { | ||
132 | case MACRO_1: | ||
133 | if (record->event.pressed) { | ||
134 | SEND_STRING("This is macro #1."); | ||
135 | } | ||
136 | return false; | ||
137 | case MACRO_2: | ||
138 | if (record->event.pressed) { | ||
139 | SEND_STRING("This is macro #2."); | ||
140 | } | ||
141 | return false; | ||
142 | case MACRO_3: | ||
143 | if (record->event.pressed) { | ||
144 | SEND_STRING("This is macro #3."); | ||
145 | } | ||
146 | return false; | ||
147 | } | ||
148 | return true; | ||
149 | }; | ||
150 | ``` | ||
151 | |||
152 | ... add the keycode `enum` block to your keyboard's header file (`<keyboard>.h`) as follows (note that the `enum` is named `keyboard_keycodes` here): | ||
153 | |||
154 | ```c | ||
155 | enum keyboard_keycodes { | ||
156 | MACRO_1 = SAFE_RANGE, | ||
157 | MACRO_2, | ||
158 | MACRO_3, | ||
159 | NEW_SAFE_RANGE // Important! | ||
160 | }; | ||
161 | ``` | ||
162 | |||
163 | ... then the logic to your `<keyboard>.c` through `process_record_kb()`: | ||
164 | |||
165 | ```c | ||
166 | bool process_record_kb(uint16_t keycode, keyrecord_t *record) { | ||
167 | switch(keycode) { | ||
168 | case MACRO_1: | ||
169 | if (record->event.pressed) { | ||
170 | SEND_STRING("This is macro #1."); | ||
171 | } | ||
172 | return false; | ||
173 | case MACRO_2: | ||
174 | if (record->event.pressed) { | ||
175 | SEND_STRING("This is macro #2."); | ||
176 | } | ||
177 | return false; | ||
178 | case MACRO_3: | ||
179 | if (record->event.pressed) { | ||
180 | SEND_STRING("This is macro #3."); | ||
181 | } | ||
182 | return false; | ||
183 | } | ||
184 | return process_record_user(keycode, record); | ||
185 | }; | ||
186 | ``` | ||
187 | |||
188 | Note the call to `process_record_user()` at the end. Additionally, users of the keyboard will need to use `NEW_SAFE_RANGE` instead of `SAFE_RANGE` if they wish to add their own custom keycodes at keymap level, beyond what is provided by the keyboard. | ||
189 | |||
190 | |||
191 | ## Additional Reading :id=additional-reading | ||
192 | |||
193 | For QMK Configurator to support your keyboard, your keyboard must be present in the `master` branch of the `qmk_firmware` repository. For instructions on this, please see [Supporting Your Keyboard in QMK Configurator](reference_configurator_support.md). | ||