aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2018-09-28 09:27:51 -0700
committerJack Humbert <jack.humb@gmail.com>2018-09-28 12:27:51 -0400
commitfa47f5fb15cca3bea9ab4de1001fcfecd43dac19 (patch)
tree45d67170d2f853eb27d1a887e21b0591659ec24d
parent8454fa5e9faab3a969168447d42369828f8ade91 (diff)
downloadqmk_firmware-fa47f5fb15cca3bea9ab4de1001fcfecd43dac19.tar.gz
qmk_firmware-fa47f5fb15cca3bea9ab4de1001fcfecd43dac19.zip
Update to the Userspace documentation (#4005)
* Overhaul to Userspace Documentation * Formatting issues * Additionaly formatting fixes * Add Readme info * Additionaly Readme info * Formatting fixes
-rw-r--r--docs/feature_userspace.md178
1 files changed, 133 insertions, 45 deletions
diff --git a/docs/feature_userspace.md b/docs/feature_userspace.md
index 5f7c05b83..b7fc9d809 100644
--- a/docs/feature_userspace.md
+++ b/docs/feature_userspace.md
@@ -5,15 +5,12 @@ If you use more than one keyboard with a similar keymap, you might see the benef
5* `/users/<name>/` (added to the path automatically) 5* `/users/<name>/` (added to the path automatically)
6 * `readme.md` (optional, recommended) 6 * `readme.md` (optional, recommended)
7 * `rules.mk` (included automatically) 7 * `rules.mk` (included automatically)
8 * `config.h` (included automatically)
8 * `<name>.h` (optional) 9 * `<name>.h` (optional)
9 * `<name>.c` (optional) 10 * `<name>.c` (optional)
10 * `config.h` (optional) 11 * `cool_rgb_stuff.c` (optional)
12 * `cool_rgb_stuff.h` (optional)
11 13
12`<name>.c` will need to be added to the SRC in `rules.mk` like this:
13
14 SRC += <name>.c
15
16Additional files may be added in the same way - it's recommended you have one named `<name>`.c/.h though.
17 14
18All this only happens when you build a keymap named `<name>`, like this: 15All this only happens when you build a keymap named `<name>`, like this:
19 16
@@ -23,82 +20,179 @@ For example,
23 20
24 make planck:jack 21 make planck:jack
25 22
26Will include the `/users/jack/` folder in the path, along with `/users/jack/rules.mk`. 23Will include the `/users/jack/` folder in the path, along with `/users/jack/rules.mk`.
27 24
28Additionally, `config.h` here will be processed like the same file in your keymap folder. This is handled separately from the `<name>.h` file. 25!> This `name` can be [overridden](#override-default-userspace), if needed.
29 26
30The reason for this, is that `<name>.h` won't be added in time to add settings (such as `#define TAPPING_TERM 100`), and including the `<name.h>` file in any `config.h` files will result in compile issues. 27## `Rules.mk`
28
29The `rules.mk` is one of the two files that gets processed automatically. This is how you add additional source files (such as `<name>.c`) will be added when compiling.
31 30
32So you should use the `config.h` for QMK settings, and the `<name>.h` file for user or keymap specific settings. 31It's highly recommended that you use `<name>.c` as the default source file to be added. And to add it, you need to add it the SRC in `rules.mk` like this:
33 32
34`/users/<name>/rules.mk` will be included in the build _after_ the `rules.mk` from your keymap. This allows you to have features in your userspace `rules.mk` that depend on individual QMK features that may or may not be available on a specific keyboard. For example, if you have RGB control features shared between all your keyboards that support RGB lighting, you can `define RGB_ENABLE` in your keymap `rules.mk` and then check for the variable in your userspace `rules.mk` like this: 33 SRC += <name>.c
34
35Additional files may be added in the same way - it's recommended you have one named `<name>`.c/.h to start off with, though.
36
37The `/users/<name>/rules.mk` file will be included in the build _after_ the `rules.mk` from your keymap. This allows you to have features in your userspace `rules.mk` that depend on individual QMK features that may or may not be available on a specific keyboard.
38
39For example, if you have RGB control features shared between all your keyboards that support RGB lighting, you can add support for that if the RGBLIGHT feature is enabled:
35```make 40```make
36ifdef RGB_ENABLE 41ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
37 # Include my fancy rgb functions source here 42 # Include my fancy rgb functions source here
43 SRC += cool_rgb_stuff.c
38endif 44endif
39``` 45```
40Because of this, any time you turn on QMK features in your `users/<name>/rules.mk`, you should conditionally enable them only if the flag isn't already defined, like this: 46
47Alternatively, you can `define RGB_ENABLE` in your keymap's `rules.mk` and then check for the variable in your userspace's `rules.mk` like this:
41```make 48```make
42ifndef TAP_DANCE_ENABLE 49ifdef RGB_ENABLE
43 TAP_DANCE_ENABLE = yes 50 # Include my fancy rgb functions source here
51 SRC += cool_rgb_stuff.c
44endif 52endif
45``` 53```
46This will ensure that you can explicitly turn off features for an individual keymap.
47 54
48## Readme 55### Override default userspace
56
57By default the userspace used will be the same as the keymap name. In some situations this isn't desirable. For instance, if you use the [layout](feature_layouts.md) feature you can't use the same name for different keymaps (e.g. ANSI and ISO). You can name your layouts `mylayout-ansi` and `mylayout-iso` and add the following line to your layout's `rules.mk`:
58
59```
60USER_NAME := mylayout
61```
62
63This is also useful if you have multiple different keyboards with different features physically present on the board (such as one with RGB Lights, and one with Audio, or different number of LEDs, or connected to a different PIN on the controller).
64
65## Configuration Options (`config.h`)
66
67Additionally, `config.h` here will be processed like the same file in your keymap folder. This is handled separately from the `<name>.h` file.
68
69The reason for this, is that `<name>.h` won't be added in time to add settings (such as `#define TAPPING_TERM 100`), and including the `<name.h>` file in any `config.h` files will result in compile issues.
70
71!>You should use the `config.h` for [configuration options](config_options.md), and the `<name>.h` file for user or keymap specific settings (such as the enum for layer or keycodes)
72
73
74## Readme (`readme.md`)
49 75
50Please include authorship (your name, github username, email), and optionally [a license that's GPL compatible](https://www.gnu.org/licenses/license-list.html#GPLCompatibleLicenses). 76Please include authorship (your name, github username, email), and optionally [a license that's GPL compatible](https://www.gnu.org/licenses/license-list.html#GPLCompatibleLicenses).
51 77
52## `Config.h` 78You can use this as a template:
79```
80Copyright <year> <name> <email> @<github_username>
81
82This program is free software: you can redistribute it and/or modify
83it under the terms of the GNU General Public License as published by
84the Free Software Foundation, either version 2 of the License, or
85(at your option) any later version.
86
87This program is distributed in the hope that it will be useful,
88but WITHOUT ANY WARRANTY; without even the implied warranty of
89MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90GNU General Public License for more details.
91
92You should have received a copy of the GNU General Public License
93along with this program. If not, see <http://www.gnu.org/licenses/>.
94```
95
96You'd want to replace the year, name, email and github username with your info.
97
98Additionally, this is a good place to document your code, if you wish to share it with others.
99
100# Examples
101
102For a brief example, checkout [`/users/_example/`](https://github.com/qmk/qmk_firmware/tree/master/users/drashna).
103For a more complicaed example, checkout [`/users/drashna/`](https://github.com/qmk/qmk_firmware/tree/master/users/drashna)'s userspace.
104
105
106## Customized Functions
107
108QMK has a bunch of [functions](custom_quantum_functions.md) that have [`_quantum`, `_kb`, and `_user` versions](custom_quantum_functions.md#a-word-on-core-vs-keyboards-vs-keymap) that you can use. You will pretty much always want to use the user version of these functions. But the problem is that if you use them in your userspace, then you don't have a version that you can use in your keymap.
109
110However, you can actually add support for keymap version, so that you can use it in both your userspace and your keymap!
53 111
54If you do add a `config,h` file, you want to make sure that it only gets processed once. So you may want to start off with something like this:
55 112
113For instance, lets looks at the `layer_state_set_user` function. Lets enable the [Tri Layer State](ref_functions.md#olkb-tri-layers) functionalitly to all of our boards, and then still have your `keymap.c` still able to use this functionality.
114
115In your `<name.c>` file, you'd want to add this:
56```c 116```c
57#ifndef USERSPACE_CONFIG_H 117__attribute__ ((weak))
58#define USERSPACE_CONFIG_H 118uint32_t layer_state_set_keymap (uint32_t state) {
119 return state;
120}
121
122uint32_t layer_state_set_user (uint32_t state) {
123 state = update_tri_layer_state(state, 2, 3, 5);
124 return layer_state_set_keymap (state);
125}
126```
127The `__attribute__ ((weak))` part tells the compiler that this is a placce holder function that can then be replaced by a version in your `keymap.c`. That way, you don't need to add it to your `keymap.c`, but if you do, you won't get any conflicts because the function is the same name.
59 128
60// Put normal config.h settings here: 129The `_keymap` part here doesn't matter, it just needs to be something other than `_quantum`, `_kb`, or `_user`, since those are already in use. So you could use `layer_state_set_mine`, `layer_state_set_fn`, or anything else.
61 130
62#endif // !USERSPACE_CONFIG_H 131You can see a list of this and other common functions in [`template.c`](https://github.com/qmk/qmk_firmware/blob/master/users/drashna/template.c) in [`users/drashna`](https://github.com/qmk/qmk_firmware/tree/master/users/drashna).
132
133## Custom Features
134
135Since the Userspace feature can support a staggering number of boards, you may have boards that you want to enable certain functionality for, but not for others. And you can actually create "features" that you can enable or disable in your own userspace.
136
137For instance, if you wanted to have a bunch of macros available, but only on certain boards (to save space), you could "hide" them being a `#ifdef MACROS_ENABLED`, and then enable it per board. To do this, add this to your rules.mk
138```make
139ifeq ($(strip $(MACROS_ENABLED)), yes)
140 OPT_DEFS += -DMACROS_ENABLED
141endif
63``` 142```
143The `OPT_DEFS` setting causee `MACROS_ENABLED` to be defined for your keyboards (note the `-D` in front of the name), and you could use `#ifdef MACROS_ENABLED` to check the status in your c/h files, and handle that code based on that.
64 144
65You can use any option hre that you could use in your keymap's `config.h` file. You can find a list of vales [here](config_options.md). 145Then you add `MACROS_ENABLED = yes` to the `rules.mk` for you keymap to enable this feature and the code in your userspace.
66 146
67## Example 147And in your `process_record_user` function, you'd do something like this:
148```c
149bool process_record_user(uint16_t keycode, keyrecord_t *record) {
150 switch (keycode) {
151#ifdef MACROS_ENABLED
152 case MACRO1:
153 if (!record->event.pressed) {
154 SEND_STRING("This is macro 1!");
155 }
156 break;
157 case MACRO2:
158 if (!record->event.pressed) {
159 SEND_STRING("This is macro 2!");
160 }
161 break;
162#endif
163 }
164 return true;
165}
166```
68 167
69For a brief example, checkout `/users/_example/` , or for a more detailed examples check out [`template.h`](https://github.com/qmk/qmk_firmware/blob/master/users/drashna/template.h) and [`template.c`](https://github.com/qmk/qmk_firmware/blob/master/users/drashna/template.c) in `/users/drashna/` .
70 168
71### Consolidated Macros 169## Consolidated Macros
72 170
73If you wanted to consolidate macros and other functions into your userspace for all of your keymaps, you can do that. The issue is that you then cannot call any function defined in your userspace, or it gets complicated. To better handle this, you can call the functions here and create new functions to use in individual keymaps. 171If you wanted to consolidate macros and other functions into your userspace for all of your keymaps, you can do that. This builds upon the [Customized Functions](#customized-functions) example above. This lets you maintain a bunch of macros that are shared between the different keyboards, and allow for keyboard specific macros, too.
74 172
75First, you'd want to go through all of your `keymap.c` files and replace `process_record_user` with `process_record_keymap` instead. This way, you can still use keyboard specific codes on those boards, and use your custom "global" keycodes as well. You'll also want to replace `SAFE_RANGE` with `NEW_SAFE_RANGE` so that you wont have any overlapping keycodes 173First, you'd want to go through all of your `keymap.c` files and replace `process_record_user` with `process_record_keymap` instead. This way, you can still use keyboard specific codes on those boards, and use your custom "global" keycodes as well. You'll also want to replace `SAFE_RANGE` with `NEW_SAFE_RANGE` so that you wont have any overlapping keycodes
76 174
77Then add `#include <name.h>` to all of your keymap.c files. This allows you to use these new keycodes without having to redefine them in each keymap. 175Then add `#include <name.h>` to all of your keymap.c files. This allows you to use these new keycodes without having to redefine them in each keymap.
78 176
79Once you've done that, you'll want to set the keycode definitions that you need to the `<name>.h` file. For instance: 177Once you've done that, you'll want to set the keycode definitions that you need to the `<name>.h` file. For instance:
80``` 178```c
81#ifndef USERSPACE 179#pragma once
82#define USERSPACE
83 180
84#include "quantum.h" 181#include "quantum.h"
182#include "action.h"
183#include "version.h"
85 184
86// Define all of 185// Define all of
87enum custom_keycodes { 186enum custom_keycodes {
88 KC_MAKE = SAFE_RANGE, 187 KC_MAKE = SAFE_RANGE,
89 NEW_SAFE_RANGE //use "NEW_SAFE_RANGE" for keymap specific codes 188 NEW_SAFE_RANGE //use "NEW_SAFE_RANGE" for keymap specific codes
90}; 189};
91
92#endif
93``` 190```
94 191
95Now you want to create the `<name>.c` file, and add this content to it: 192Now you want to create the `<name>.c` file, and add this content to it:
96 193
97``` 194```c
98#include "<name>.h" 195#include "<name>.h"
99#include "quantum.h"
100#include "action.h"
101#include "version.h"
102 196
103__attribute__ ((weak)) 197__attribute__ ((weak))
104bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { 198bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
@@ -126,14 +220,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
126} 220}
127``` 221```
128 222
129This will add a new `KC_MAKE` keycode that can be used in any of your keymaps. And this keycode will output `make <keyboard>:<keymap">`, making frequent compiling easier. And this will work with any keyboard and any keymap as it will output the current boards info, so that you don't have to type this out every time. 223This will add a new `KC_MAKE` keycode that can be used in any of your keymaps. And this keycode will output `make <keyboard>:<keymap">`, making frequent compiling easier. And this will work with any keyboard and any keymap as it will output the current boards info, so that you don't have to type this out every time.
130 224
131Additionally, this should flash the newly compiled firmware automatically, using the correct utility, based on the bootloader settings (or default to just generating the HEX file). However, it should be noted that this may not work on all systems. AVRDUDE doesn't work on WSL, namely (and will dump the HEX in the ".build" folder instead). 225Additionally, this should flash the newly compiled firmware automatically, using the correct utility, based on the bootloader settings (or default to just generating the HEX file). However, it should be noted that this may not work on all systems. AVRDUDE doesn't work on WSL, namely (and will dump the HEX in the ".build" folder instead).
132 226
133## Override default userspace
134 227
135By default the userspace used will be the same as the keymap name. In some situations this isn't desirable. For instance, if you use the [layout](feature_layouts.md) feature you can't use the same name for different keymaps (e.g. ANSI and ISO). You can name your layouts `mylayout-ansi` and `mylayout-iso` and add the following line to your layout's `rules.mk`:
136
137```
138USER_NAME := mylayout
139```