summaryrefslogtreecommitdiff
path: root/docs/feature_userspace.md
diff options
context:
space:
mode:
authorQMK Bot <hello@qmk.fm>2025-09-09 21:51:51 +0000
committerQMK Bot <hello@qmk.fm>2025-09-09 21:51:51 +0000
commitff8db0449edd488ae4440e8c102a0752f76f46c3 (patch)
tree90bc046e8318fdcbff38acd932490d2dcf0ba553 /docs/feature_userspace.md
parent7772f47f04f54cf64db8719a49a225013013aee1 (diff)
parent09ab67c0440d8e5e3faf832d23eb1b754845a573 (diff)
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'docs/feature_userspace.md')
-rw-r--r--docs/feature_userspace.md43
1 files changed, 22 insertions, 21 deletions
diff --git a/docs/feature_userspace.md b/docs/feature_userspace.md
index 0f5c4a5f96..2c8c08b38e 100644
--- a/docs/feature_userspace.md
+++ b/docs/feature_userspace.md
@@ -24,10 +24,10 @@ For example,
24 24
25 make planck:jack 25 make planck:jack
26 26
27Will include the `/users/jack/` folder in the path, along with `/users/jack/rules.mk`. 27Will include the `/users/jack/` folder in the path, along with `/users/jack/rules.mk`.
28 28
29::: warning 29::: warning
30This `name` can be [overridden](#override-default-userspace), if needed. 30This `name` can be [overridden](#override-default-userspace), if needed.
31::: 31:::
32 32
33## `Rules.mk` 33## `Rules.mk`
@@ -38,9 +38,9 @@ It's highly recommended that you use `<name>.c` as the default source file to be
38 38
39 SRC += <name>.c 39 SRC += <name>.c
40 40
41Additional files may be added in the same way - it's recommended you have one named `<name>`.c/.h to start off with, though. 41Additional files may be added in the same way - it's recommended you have one named `<name>`.c/.h to start off with, though.
42 42
43The `/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. 43The `/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.
44 44
45For 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: 45For 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:
46```make 46```make
@@ -82,7 +82,7 @@ You should use the `config.h` for [configuration options](config_options), and t
82 82
83Please include authorship (your name, GitHub username, email), and optionally [a license that's GPL compatible](https://www.gnu.org/licenses/license-list.html#GPLCompatibleLicenses). 83Please include authorship (your name, GitHub username, email), and optionally [a license that's GPL compatible](https://www.gnu.org/licenses/license-list.html#GPLCompatibleLicenses).
84 84
85You can use this as a template: 85You can use this as a template:
86``` 86```
87Copyright <year> <name> <email> @<github_username> 87Copyright <year> <name> <email> @<github_username>
88 88
@@ -100,9 +100,9 @@ You should have received a copy of the GNU General Public License
100along with this program. If not, see <http://www.gnu.org/licenses/>. 100along with this program. If not, see <http://www.gnu.org/licenses/>.
101``` 101```
102 102
103You'd want to replace the year, name, email and GitHub username with your info. 103You'd want to replace the year, name, email and GitHub username with your info.
104 104
105Additionally, this is a good place to document your code, if you wish to share it with others. 105Additionally, this is a good place to document your code, if you wish to share it with others.
106 106
107## Build All Keyboards That Support a Specific Keymap 107## Build All Keyboards That Support a Specific Keymap
108 108
@@ -118,20 +118,21 @@ This is ideal for when you want ensure everything compiles successfully when pre
118 118
119## Examples 119## Examples
120 120
121For a brief example, checkout [`/users/_example/`](https://github.com/qmk/qmk_firmware/tree/master/users/_example). 121For a brief example, checkout [`/users/_example/`](https://github.com/qmk/qmk_firmware/tree/master/users/_example).
122For more complicated examples, checkout the [`awesome-qmk` colletion](https://github.com/qmk/awesome-qmk). 122
123For more complicated examples, checkout the [`awesome-qmk` collection](https://github.com/qmk/awesome-qmk).
123 124
124 125
125### Customized Functions 126### Customized Functions
126 127
127QMK has a bunch of [functions](custom_quantum_functions) that have [`_quantum`, `_kb`, and `_user` versions](custom_quantum_functions#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. 128QMK has a bunch of [functions](custom_quantum_functions) that have [`_quantum`, `_kb`, and `_user` versions](custom_quantum_functions#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.
128 129
129However, you can actually add support for keymap version, so that you can use it in both your userspace and your keymap! 130However, you can actually add support for keymap version, so that you can use it in both your userspace and your keymap!
130 131
131 132
132For instance, let's look at the `layer_state_set_user()` function. You can enable the [Tri Layer State](ref_functions#olkb-tri-layers) functionality on all of your boards, while also retaining the Tri Layer functionality in your `keymap.c` files. 133For instance, let's look at the `layer_state_set_user()` function. You can enable the [Tri Layer State](ref_functions#olkb-tri-layers) functionality on all of your boards, while also retaining the Tri Layer functionality in your `keymap.c` files.
133 134
134In your `<name.c>` file, you'd want to add this: 135In your `<name.c>` file, you'd want to add this:
135```c 136```c
136__attribute__ ((weak)) 137__attribute__ ((weak))
137layer_state_t layer_state_set_keymap (layer_state_t state) { 138layer_state_t layer_state_set_keymap (layer_state_t state) {
@@ -143,7 +144,7 @@ layer_state_t layer_state_set_user (layer_state_t state) {
143 return layer_state_set_keymap (state); 144 return layer_state_set_keymap (state);
144} 145}
145``` 146```
146The `__attribute__ ((weak))` part tells the compiler that this is a placeholder 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. 147The `__attribute__ ((weak))` part tells the compiler that this is a placeholder 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.
147 148
148The `_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. 149The `_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.
149 150
@@ -151,7 +152,7 @@ You can see a list of this and other common functions in [`template.c`](https://
151 152
152### Custom Features 153### Custom Features
153 154
154Since 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. 155Since 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.
155 156
156For 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 157For 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
157```make 158```make
@@ -159,11 +160,11 @@ ifeq ($(strip $(MACROS_ENABLED)), yes)
159 OPT_DEFS += -DMACROS_ENABLED 160 OPT_DEFS += -DMACROS_ENABLED
160endif 161endif
161``` 162```
162The `OPT_DEFS` setting causes `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. 163The `OPT_DEFS` setting causes `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.
163 164
164Then you add `MACROS_ENABLED = yes` to the `rules.mk` for you keymap to enable this feature and the code in your userspace. 165Then you add `MACROS_ENABLED = yes` to the `rules.mk` for you keymap to enable this feature and the code in your userspace.
165 166
166And in your `process_record_user` function, you'd do something like this: 167And in your `process_record_user` function, you'd do something like this:
167```c 168```c
168bool process_record_user(uint16_t keycode, keyrecord_t *record) { 169bool process_record_user(uint16_t keycode, keyrecord_t *record) {
169 switch (keycode) { 170 switch (keycode) {
@@ -187,9 +188,9 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
187 188
188### Consolidated Macros 189### Consolidated Macros
189 190
190If 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. 191If 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.
191 192
192First, 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 193First, 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 won't have any overlapping keycodes
193 194
194Then 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. 195Then 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.
195 196
@@ -245,7 +246,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
245} 246}
246``` 247```
247 248
248For boards that may not have a shift button (such as on a macro pad), we need a way to always include the bootloader option. To do that, add the following to the `rules.mk` in your userspace folder: 249For boards that may not have a shift button (such as on a macro pad), we need a way to always include the bootloader option. To do that, add the following to the `rules.mk` in your userspace folder:
249 250
250```make 251```make
251ifeq ($(strip $(FLASH_BOOTLOADER)), yes) 252ifeq ($(strip $(FLASH_BOOTLOADER)), yes)
@@ -255,7 +256,7 @@ endif
255 256
256This 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. 257This 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.
257 258
258Also, holding Shift will add the flash target (`:flash`) to the command. Holding Control will add some commands that will speed up compiling time by processing multiple files at once. 259Also, holding Shift will add the flash target (`:flash`) to the command. Holding Control will add some commands that will speed up compiling time by processing multiple files at once.
259 260
260And for the boards that lack a shift key, or that you want to always attempt the flashing part, you can add `FLASH_BOOTLOADER = yes` to the `rules.mk` of that keymap. 261And for the boards that lack a shift key, or that you want to always attempt the flashing part, you can add `FLASH_BOOTLOADER = yes` to the `rules.mk` of that keymap.
261 262