]> git.donarmstrong.com Git - qmk_firmware.git/blob - Home.md
split off tmk differences into own page
[qmk_firmware.git] / Home.md
1 # Quantum Mechanical Keyboard Firmware
2
3 You have found the QMK Firmware documentation site. This is a keyboard firmware based on the [tmk_keyboard firmware](http://github.com/tmk/tmk_keyboard) ([view differences](Differences-from-TMK)) with some useful features for Atmel AVR controllers, and more specifically, the [OLKB product line](http://olkb.com), the [ErgoDox EZ](http://www.ergodox-ez.com) keyboard, and the [Clueboard product line](http://clueboard.co/). It has also been ported to ARM chips using ChibiOS. You can use it to power your own hand-wired or custom keyboard PCB.
4
5 # Getting started
6
7 Before you are able to compile, you'll need to install an environment for AVR development. You'll find the instructions for any OS below. If you find another/better way to set things up from scratch, please consider [making a pull request](https://github.com/qmk/qmk_firmware/pulls) with your changes!
8
9 * [Build Environment Setup](Build-Environment-Setup)
10 * [QMK Overview](QMK-Overview)
11
12 # Configuring QMK Firmware
13
14 The QMK Firmware can be configured via the `keymaps` array data.
15
16 For simply generating a [basic keycode](https://github.com/qmk/qmk_firmware/wiki/Keycodes), you add it as an element of your `keymaps` array data.
17
18 For more complicated actions, you add the corresponding **action code** directly as an element of your `keymaps` array data.
19
20 The **action code** is a 16 bit data and organized carefully to represent common operations with the combination of C macros.  It is sometimes called quantum keycode in the QMK source comment.
21
22 For example, the keycode `KC_8` as an element of your `keymaps` array data is for generating keystroke of "8".  The action code `SHFT(KC_8)` an element of your `keymaps` array data is for generating key stroke of "*" which is "8" key shifted.
23
24 > In tmk, only up to 32 **action codes** are usable in `fn_actions` array data which is accessed via 32 special keycodes (`KC_FN0` to `KC_FN31`) in `keymaps` array data.
25
26 For more details of the `keymaps` array, see [Keymap Overview](Keymap) page.
27
28 ## C macros for action code
29
30 Basic "C macros" for layer switching are documented in the [Key Functions](Key-Functions) page.  
31
32 > The keyboard [macros](Macros) are completely different concept from the C macros for action code.  Please don't get confused.
33
34 There are several new standardized support for common operations with new action codes as follows.
35
36 ## Space Cadet Shift: The future, built in
37
38 Steve Losh [described](http://stevelosh.com/blog/2012/10/a-modern-space-cadet/) the Space Cadet Shift quite well. Essentially, you hit the left Shift on its own, and you get an opening parenthesis; hit the right Shift on its own, and you get the closing one. When hit with other keys, the Shift key keeps working as it always does. Yes, it's as cool as it sounds. Head on over to the [Space Cadet Shift](Space-Cadet-Shift) page to read about it.
39
40 ## The Leader key: A new kind of modifier
41
42 Most modifiers have to be held or toggled. But what if you had a key that indicated the start of a sequence? You could press that key and then rapidly press 1-3 more keys to trigger a macro, or enter a special layer, or anything else you might want to do. To learn more about it check out the [Leader Key](Leader-Key) page.
43
44 ## Tap Dance: A single key can do 3, 5, or 100 different things
45
46 Hit the semicolon key once, send a semicolon. Hit it twice, rapidly -- send a colon. Hit it three times, and your keyboard's LEDs do a wild dance. That's just one example of what Tap Dance can do. Read more about it on the [Tap Dance](Tap-Dance) page.
47
48 ## Temporarily setting the default layer
49
50 `DF(layer)` - sets default layer to *layer*. The default layer is the one at the "bottom" of the layer stack - the ultimate fallback layer. This currently does not persist over power loss. When you plug the keyboard back in, layer 0 will always be the default. It is theoretically possible to work around that, but that's not what `DF` does.
51
52 ## Macro shortcuts: Send a whole string when pressing just one key
53
54 How would you like a single keypress to send a whole word, sentence, paragraph, or even document? Head on over to the [Macros](Macros) page to read up on all aspects of Simple and Dynamic Macros.
55
56 ## Additional keycode aliases for software-implemented layouts (Colemak, Dvorak, etc)
57
58 Everything is assuming you're in Qwerty (in software) by default, but there is built-in support for using a Colemak or Dvorak layout by including this at the top of your keymap:
59
60     #include <keymap_colemak.h>
61
62 If you use Dvorak, use `keymap_dvorak.h` instead of `keymap_colemak.h` for this line. After including this line, you will get access to:
63
64  * `CM_*` for all of the Colemak-equivalent characters
65  * `DV_*` for all of the Dvorak-equivalent characters
66
67 These implementations assume you're using Colemak or Dvorak on your OS, not on your keyboard - this is referred to as a software-implemented layout. If your computer is in Qwerty and your keymap is in Colemak or Dvorak, this is referred to as a firmware-implemented layout, and you won't need these features.
68
69 To give an example, if you're using software-implemented Colemak, and want to get an `F`, you would use `CM_F` - `KC_F` under these same circumstances would result in `T`.
70
71 ## Backlight Breathing
72
73 In order to enable backlight breathing, the following line must be added to your config.h file.
74
75     #define BACKLIGHT_BREATHING
76
77 The following function calls are used to control the breathing effect.
78
79 * ```breathing_enable()``` - Enable the free-running breathing effect.
80 * ```breathing_disable()``` - Disable the free-running breathing effect immediately.
81 * ```breathing_self_disable()``` - Disable the free-running breathing effect after the current effect ends.
82 * ```breathing_toggle()``` - Toggle the free-running breathing effect.
83 * ```breathing_defaults()``` - Reset the speed and brightness settings of the breathing effect.
84
85 The following function calls are used to control the maximum brightness of the breathing effect.
86
87 * ```breathing_intensity_set(value)``` - Set the brightness of the breathing effect when it is at its max value.
88 * ```breathing_intensity_default()``` - Reset the brightness of the breathing effect to the default value based on the current backlight intensity.
89
90 The following function calls are used to control the cycling speed of the breathing effect.
91
92 * ```breathing_speed_set(value)``` - Set the speed of the breathing effect - how fast it cycles.
93 * ```breathing_speed_inc(value)``` - Increase the speed of the breathing effect by a fixed value.
94 * ```breathing_speed_dec(value)``` - Decrease the speed of the breathing effect by a fixed value.
95 * ```breathing_speed_default()``` - Reset the speed of the breathing effect to the default value.
96
97 The following example shows how to enable the backlight breathing effect when the FUNCTION layer macro button is pressed:
98
99     case MACRO_FUNCTION:
100         if (record->event.pressed)
101         {
102             breathing_speed_set(3);
103             breathing_enable();
104             layer_on(LAYER_FUNCTION);
105         }
106         else
107         {
108             breathing_speed_set(1);
109             breathing_self_disable();
110             layer_off(LAYER_FUNCTION);
111         }
112         break;
113
114 The following example shows how to pulse the backlight on-off-on when the RAISED layer macro button is pressed:
115
116     case MACRO_RAISED:
117       if (record->event.pressed)
118       {
119         layer_on(LAYER_RAISED);
120         breathing_speed_set(2);
121         breathing_pulse();
122         update_tri_layer(LAYER_LOWER, LAYER_RAISED, LAYER_ADJUST);
123       }
124       else
125       {
126         layer_off(LAYER_RAISED);
127         update_tri_layer(LAYER_LOWER, LAYER_RAISED, LAYER_ADJUST);
128       }
129       break;
130
131 ## Other firmware shortcut keycodes
132
133 * `RESET` - puts the MCU in DFU mode for flashing new firmware (with `make dfu`)
134 * `DEBUG` - the firmware into debug mode - you'll need hid_listen to see things
135 * `BL_ON` - turns the backlight on
136 * `BL_OFF` - turns the backlight off
137 * `BL_<n>` - sets the backlight to level *n*
138 * `BL_INC` - increments the backlight level by one
139 * `BL_DEC` - decrements the backlight level by one
140 * `BL_TOGG` - toggles the backlight
141 * `BL_STEP` - steps through the backlight levels
142
143 Enable the backlight from the Makefile.
144
145 # Custom Quantum functions
146
147 All of these functions are available in the `*_kb()` or `*_user()` variety. `kb` ones should only be used in the `<keyboard>/<keyboard>.c` file, and `user` ones should only be used in the `keymap.c`. The keyboard ones call the user ones - it's necessary to keep these calls to allow the keymap functions to work correctly.
148
149 ## `void matrix_init_*(void)`
150
151 This function gets called when the matrix is initiated, and can contain start-up code for your keyboard/keymap.
152
153 ## `void matrix_scan_*(void)`
154
155 This function gets called at every matrix scan, which is basically as often as the MCU can handle. Be careful what you put here, as it will get run a lot.
156
157 ## `bool process_record_*(uint16_t keycode, keyrecord_t *record)`
158
159 This function gets called on every keypress/release, and is where you can define custom functionality. The return value is whether or not QMK should continue processing the keycode - returning `false` stops the execution.
160
161 The `keycode` variable is whatever is defined in your keymap, eg `MO(1)`, `KC_L`, etc. and can be switch-cased to execute code whenever a particular code is pressed.
162
163 The `record` variable contains infomation about the actual press:
164
165 ```
166 keyrecord_t record {
167   keyevent_t event {
168     keypos_t key {
169       uint8_t col
170       uint8_t row
171     }
172     bool     pressed
173     uint16_t time
174   }
175 }
176 ```
177
178 The conditional `if (record->event.pressed)` can tell if the key is being pressed or released, and you can execute code based on that.
179
180 ## `void led_set_*(uint8_t usb_led)`
181
182 This gets called whenever there is a state change on your host LEDs (eg caps lock, scroll lock, etc). The LEDs are defined as:
183
184 ```
185 #define USB_LED_NUM_LOCK                0
186 #define USB_LED_CAPS_LOCK               1
187 #define USB_LED_SCROLL_LOCK             2
188 #define USB_LED_COMPOSE                 3
189 #define USB_LED_KANA                    4
190 ```
191
192 and can be tested against the `usb_led` with a conditional like `if (usb_led & (1<<USB_LED_CAPS_LOCK))` - if this is true, you can turn your LED on, otherwise turn it off.