hardware_keyboard_guidelines.md (14928B)
1 # QMK Keyboard Guidelines 2 3 Since starting, QMK has grown by leaps and bounds thanks to people like you who contribute to creating and maintaining our community keyboards. As we've grown we've discovered some patterns that work well, and ask that you conform to them to make it easier for other people to benefit from your hard work. 4 5 6 ## Use QMK Lint 7 8 We have provided a tool, `qmk lint`, which will let you check over your keyboard for problems. We suggest using it frequently while working on your keyboard and keymap. 9 10 Example passing check: 11 12 ``` 13 $ qmk lint -kb rominronin/katana60/rev2 14 Ψ Lint check passed! 15 ``` 16 17 Example failing check: 18 19 ``` 20 $ qmk lint -kb clueboard/66/rev3 21 ☒ Missing keyboards/clueboard/66/rev3/readme.md 22 ☒ Lint check failed! 23 ``` 24 25 ## Naming Your Keyboard/Project 26 27 All keyboard names are in lower case, consisting only of letters, numbers, and underscore (`_`). Names may not begin with an underscore. Forward slash (`/`) is used as a sub-folder separation character. 28 29 The names `test`, `keyboard`, and `all` are reserved for make commands and may not be used as a keyboard or subfolder name. 30 31 Valid Examples: 32 33 * `412_64` 34 * `chimera_ortho` 35 * `clueboard/66/rev3` 36 * `planck` 37 * `v60_type_r` 38 39 ## Sub-folders 40 41 QMK uses sub-folders both for organization and to share code between revisions of the same keyboard. You can nest folders up to 4 levels deep: 42 43 ``` 44 qmk_firmware/keyboards/top_folder/sub_1/sub_2/sub_3/sub_4 45 ``` 46 47 If a sub-folder has a `keyboard.json` file it will be considered a compilable keyboard. It will be available in QMK Configurator and tested with `make all`. If you are using a folder to organize several keyboards from the same maker you should not have a `keyboard.json` file. 48 49 ::: tip 50 When configuring a keyboard with multiple revisions (like the `clueboard/66` example below), an `info.json` file at the top keyboard level (eg. `clueboard/66`) should be used for configuration shared between revisions. Then `keyboard.json` in each revision directory containing revision-specific configuration, and indicating a buildable keyboard. 51 ::: 52 53 Example: 54 55 Clueboard uses sub-folders for both purposes, organization and keyboard revisions. 56 57 * [`qmk_firmware`](https://github.com/qmk/qmk_firmware/tree/master) 58 * [`keyboards`](https://github.com/qmk/qmk_firmware/tree/master/keyboards) 59 * [`clueboard`](https://github.com/qmk/qmk_firmware/tree/master/keyboards/clueboard) ← This is the organization folder, there's no `keyboard.json` file 60 * [`60`](https://github.com/qmk/qmk_firmware/tree/master/keyboards/clueboard/60) ← This is a compilable keyboard - it has a `keyboard.json` file 61 * [`66`](https://github.com/qmk/qmk_firmware/tree/master/keyboards/clueboard/66) ← This is not a compilable keyboard - a revision must be specified 62 * [`rev1`](https://github.com/qmk/qmk_firmware/tree/master/keyboards/clueboard/66/rev1) ← compilable: `make clueboard/66/rev1` 63 * [`rev2`](https://github.com/qmk/qmk_firmware/tree/master/keyboards/clueboard/66/rev2) ← compilable: `make clueboard/66/rev2` 64 * [`rev3`](https://github.com/qmk/qmk_firmware/tree/master/keyboards/clueboard/66/rev3) ← compilable: `make clueboard/66/rev3` 65 66 ## Keyboard Folder Structure 67 68 Your keyboard should be located in `qmk_firmware/keyboards/` and the folder name should be your keyboard's name as described in the previous section. Inside this folder should be several files, some of which are optional: 69 70 * `readme.md` 71 * `keyboard.json` (or `info.json`) 72 * `config.h` 73 * `rules.mk` 74 * `<keyboard>.c` 75 * `<keyboard>.h` 76 77 ### `readme.md` 78 79 All projects need to have a `readme.md` file that explains what the keyboard is, who made it and where it's available. If applicable, it should also contain links to more information, such as the maker's website. Please follow the [published template](documentation_templates#keyboard-readmemd-template). 80 81 ### `keyboard.json`/`info.json` 82 83 The `keyboard.json` file is necessary for your keyboard (or keyboard revision) to be considered a buildable keyboard. The same content is valid in both `info.json` and `keyboard.json`. For the available configuration options of this file, see the [reference page](reference_info_json). This file is also used by the [QMK API](https://github.com/qmk/qmk_api), and by the [QMK Configurator](https://config.qmk.fm/) to display a representation of the available layouts of your keyboard. 84 85 Additionally, this is where layouts available on your keyboard are defined. If you only have a single layout, it should be named `LAYOUT`. When defining multiple layouts, you should have a base layout, named `LAYOUT_all`, that supports all possible switch positions in your matrix, even if that layout is impossible to build physically. This is the layout that should be used in the `default` keymap. You should then have additional keymaps named `default_<layout>` that configure keymaps for the other layouts. Layout macro names are entirely lowercase, except for the prefix of `LAYOUT`. 86 87 As an example, if you have a 60% PCB that supports ANSI and ISO, you might define the following layouts and keymaps: 88 89 | Layout Name | Keymap Name | Description | 90 |-------------|--------------|------------------------------------------| 91 | LAYOUT_all | default | A layout that supports both ISO and ANSI | 92 | LAYOUT_ansi | default_ansi | An ANSI layout | 93 | LAYOUT_iso | default_iso | An ISO layout | 94 95 ::: tip 96 Providing only `LAYOUT_all` is invalid, as is providing a `LAYOUT` when multiple layouts are present. 97 ::: 98 99 ### `config.h` 100 101 Some projects will need to have a `config.h` that configures parameters that are not possible to be set in `keyboard.json`. This is not a required file. 102 103 The `config.h` files can also be placed in sub-folders, and the order in which they are read is as follows: 104 105 * `keyboards/top_folder/config.h` 106 * `keyboards/top_folder/sub_1/config.h` 107 * `keyboards/top_folder/sub_1/sub_2/config.h` 108 * `keyboards/top_folder/sub_1/sub_2/sub_3/config.h` 109 * `keyboards/top_folder/sub_1/sub_2/sub_3/sub_4/config.h` 110 * [`.build/objs_<keyboard>/src/info_config.h`](data_driven_config#add-code-to-generate-it) see [Data Driven Configuration](data_driven_config) 111 * `users/a_user_folder/config.h` 112 * `keyboards/top_folder/keymaps/a_keymap/config.h` 113 * `keyboards/top_folder/sub_1/sub_2/sub_3/sub_4/post_config.h` 114 * `keyboards/top_folder/sub_1/sub_2/sub_3/post_config.h` 115 * `keyboards/top_folder/sub_1/sub_2/post_config.h` 116 * `keyboards/top_folder/sub_1/post_config.h` 117 * `keyboards/top_folder/post_config.h` 118 119 The `post_config.h` file can be used for additional post-processing, depending on what is specified in the `config.h` file. For example, if you define the `IOS_DEVICE_ENABLE` macro in your keymap-level `config.h` file as follows, you can configure more detailed settings accordingly in the `post_config.h` file: 120 121 * `keyboards/top_folder/keymaps/a_keymap/config.h` 122 ```c 123 #define IOS_DEVICE_ENABLE 124 ``` 125 * `keyboards/top_folder/post_config.h` 126 ```c 127 #ifndef IOS_DEVICE_ENABLE 128 // USB_MAX_POWER_CONSUMPTION value for this keyboard 129 #define USB_MAX_POWER_CONSUMPTION 400 130 #else 131 // fix iPhone and iPad power adapter issue 132 // iOS devices need less than 100 133 #define USB_MAX_POWER_CONSUMPTION 100 134 #endif 135 136 #ifdef RGBLIGHT_ENABLE 137 #ifndef IOS_DEVICE_ENABLE 138 #define RGBLIGHT_LIMIT_VAL 200 139 #define RGBLIGHT_VAL_STEP 17 140 #else 141 #define RGBLIGHT_LIMIT_VAL 35 142 #define RGBLIGHT_VAL_STEP 4 143 #endif 144 #ifndef RGBLIGHT_HUE_STEP 145 #define RGBLIGHT_HUE_STEP 10 146 #endif 147 #ifndef RGBLIGHT_SAT_STEP 148 #define RGBLIGHT_SAT_STEP 17 149 #endif 150 #endif 151 ``` 152 153 ::: tip 154 If you define options using `post_config.h` as in the above example, you should not define the same options in the keyboard- or user-level `config.h`. 155 ::: 156 157 ### `rules.mk` 158 159 This file is typically used to configure hardware drivers (eg. pointing device), or to include additional C files in compilation. This is not a required file. 160 161 The `rules.mk` file can also be placed in a sub-folder, and its reading order is as follows: 162 163 * `keyboards/top_folder/rules.mk` 164 * `keyboards/top_folder/sub_1/rules.mk` 165 * `keyboards/top_folder/sub_1/sub_2/rules.mk` 166 * `keyboards/top_folder/sub_1/sub_2/sub_3/rules.mk` 167 * `keyboards/top_folder/sub_1/sub_2/sub_3/sub_4/rules.mk` 168 * `keyboards/top_folder/keymaps/a_keymap/rules.mk` 169 * `users/a_user_folder/rules.mk` 170 * `keyboards/top_folder/sub_1/sub_2/sub_3/sub_4/post_rules.mk` 171 * `keyboards/top_folder/sub_1/sub_2/sub_3/post_rules.mk` 172 * `keyboards/top_folder/sub_1/sub_2/post_rules.mk` 173 * `keyboards/top_folder/sub_1/post_rules.mk` 174 * `keyboards/top_folder/post_rules.mk` 175 * `common_features.mk` 176 177 Many of the settings written in the `rules.mk` file are interpreted by `common_features.mk`, which sets the necessary source files and compiler options. 178 179 The `post_rules.mk` file can interpret `features` of a keyboard-level before `common_features.mk`. For example, when your designed keyboard has the option to implement backlighting or underglow using rgblight.c, writing the following in the `post_rules.mk` makes it easier for the user to configure the `rules.mk`. 180 181 * `keyboards/top_folder/keymaps/a_keymap/rules.mk` 182 ```make 183 # Please set the following according to the selection of the hardware implementation option. 184 RGBLED_OPTION_TYPE = backlight ## none, backlight or underglow 185 ``` 186 * `keyboards/top_folder/post_rules.mk` 187 ```make 188 ifeq ($(filter $(strip $(RGBLED_OPTION_TYPE))x, nonex backlightx underglowx x),) 189 $(error unknown RGBLED_OPTION_TYPE value "$(RGBLED_OPTION_TYPE)") 190 endif 191 192 ifeq ($(strip $(RGBLED_OPTION_TYPE)),backlight) 193 RGBLIGHT_ENABLE = yes 194 OPT_DEFS += -DRGBLIGHT_LED_COUNT=30 195 endif 196 ifeq ($(strip $(RGBLED_OPTION_TYPE)),underglow) 197 RGBLIGHT_ENABLE = yes 198 OPT_DEFS += -DRGBLIGHT_LED_COUNT=6 199 endif 200 ``` 201 202 ::: tip 203 See `build_keyboard.mk` and `common_features.mk` for more details. 204 ::: 205 206 ### `<keyboard>.c` 207 208 This file should contain C code required for the functionality of your keyboard, for example hardware initialisation code, OLED display code, and so on. This file should only contain code necessary for the keyboard to work, and *not* things that should be left to the end user to configure in their keymap. This file is automatically included in compilation if it exists. This is not a required file. 209 210 The following functions are typically defined in this file: 211 212 * `void matrix_init_kb(void)` 213 * `void matrix_scan_kb(void)` 214 * `bool process_record_kb(uint16_t keycode, keyrecord_t *record)` 215 * `bool led_update_kb(led_t led_state)` 216 217 ### `<keyboard>.h` 218 219 This file can contain function prototypes for custom functions and other header file code utilised by `<keyboard>.c`. The `<keyboard>.c` file should include this file. This is not a required file. 220 221 ## Image/Hardware Files 222 223 In an effort to keep the repo size down we do not accept binary files of any format, with few exceptions. Hosting them elsewhere (such as <https://imgur.com>) and linking them in the `readme.md` is preferred. Hardware files such as plates, cases, and PCBs can be published in a personal repository or elsewhere, and linked to by your keyboard's `readme.md` file. 224 225 ## Keyboard Defaults 226 227 Given the amount of functionality that QMK exposes it's very easy to confuse new users. When putting together the default firmware for your keyboard we recommend limiting your enabled features and options to the minimal set needed to support your hardware. Recommendations for specific features follow. 228 229 ### Magic Keycodes and Command 230 231 [Magic Keycodes](keycodes_magic) and [Command](features/command) are two related features that allow a user to control their keyboard in non-obvious ways. We recommend you think long and hard about if you're going to enable either feature, and how you will expose this functionality. Keep in mind that users who want this functionality can enable it in their personal keymaps without affecting all the novice users who may be using your keyboard as their first programmable board. 232 233 If your keyboard does not have 2 shift keys you should provide a working default for `IS_COMMAND`, even when you have set `COMMAND_ENABLE = no`. This will give your users a default to conform to if they do enable Command. 234 235 ## Custom Keyboard Programming 236 237 As documented on [Customizing Functionality](custom_quantum_functions) you can define custom functions for your keyboard. Please keep in mind that your users may want to customize that behavior as well, and make it possible for them to do that. If you are providing a custom function, for example `process_record_kb()`, make sure that your function calls the `_user()` version of the call too. You should also take into account the return value of the `_user()` version, and only run your custom code if the user returns `true`. 238 239 ## Non-Production/Handwired Projects 240 241 We're happy to accept any project that uses QMK, including handwired ones, but we have a separate `/keyboards/handwired/` folder for them, so the main `/keyboards/` folder doesn't get overcrowded. If a prototype project becomes a production project at some point in the future, we'd be happy to move it to the main `/keyboards/` folder! 242 243 ## Warnings as Errors 244 245 When developing your keyboard, keep in mind that all warnings will be treated as errors - these small warnings can build-up and cause larger errors down the road (and keeping them is generally a bad practice). 246 247 ## Copyright Blurb 248 249 If you're adapting your keyboard's setup from another project, but not using the same code, be sure to update the copyright header at the top of the files to show your name, in this format: 250 251 ```c 252 Copyright 2017 Your Name <your@email.com> 253 ``` 254 255 If you are modifying someone else's code and have made only trivial changes you should leave their name in the copyright statement. If you have done significant work on the file you should add your name to theirs, like so: 256 257 ```c 258 Copyright 2017 Their Name <original_author@example.com> Your Name <you@example.com> 259 ``` 260 261 The year should be the first year the file is created. If work was done to that file in later years you can reflect that by appending the second year to the first, like so: 262 263 ```c 264 Copyright 2015-2017 Your Name <you@example.com> 265 ``` 266 267 ## License 268 269 The core of QMK is licensed under the [GNU General Public License](https://www.gnu.org/licenses/licenses.en.html). If you are shipping binaries for AVR processors you may choose either [GPLv2](https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) or [GPLv3](https://www.gnu.org/licenses/gpl.html). If you are shipping binaries for ARM processors you must choose [GPL Version 3](https://www.gnu.org/licenses/gpl.html) to comply with the [ChibiOS](https://www.chibios.org) GPLv3 license.