Drop bs4 dependency, update docs, minor improvements
[jackhill/qmk/firmware.git] / docs / newbs_testing_debugging.md
CommitLineData
08e48eb6 1# Testing and Debugging
2
3Once you've flashed your keyboard with a custom firmware you're ready to test it out. With a little bit of luck everything will work perfectly, but if not this document will help you figure out what's wrong.
4
5## Testing
6
7Testing your keyboard is usually pretty straightforward. Press every single key and make sure it sends the keys you expect. There are even programs that will help you make sure that no key is missed.
8
9Note: These programs are not provided by or endorsed by QMK.
10
feb116c4
DJ
11* [QMK Configurator](https://config.qmk.fm/#/test/) (Web Based)
12* [Switch Hitter](https://web.archive.org/web/20190413233743/https://elitekeyboards.com/switchhitter.php) (Windows Only)
08e48eb6 13* [Keyboard Viewer](https://www.imore.com/how-use-keyboard-viewer-your-mac) (Mac Only)
14* [Keyboard Tester](http://www.keyboardtester.com) (Web Based)
15* [Keyboard Checker](http://keyboardchecker.com) (Web Based)
16
da995d2a 17## Debugging
08e48eb6 18
da995d2a 19Your keyboard will output debug information if you have `CONSOLE_ENABLE = yes` in your `rules.mk`. By default the output is very limited, but you can turn on debug mode to increase the amount of debug output. Use the `DEBUG` keycode in your keymap, use the [Command](feature_command.md) feature to enable debug mode, or add the following code to your keymap.
338ca356 20
21```c
22void keyboard_post_init_user(void) {
23 // Customise these values to desired behaviour
24 debug_enable=true;
25 debug_matrix=true;
26 //debug_keyboard=true;
27 //debug_mouse=true;
28}
29```
08e48eb6 30
da995d2a 31### Debugging With QMK Toolbox
32
33For compatible platforms, [QMK Toolbox](https://github.com/qmk/qmk_toolbox) can be used to display debug messages from your keyboard.
34
35### Debugging With hid_listen
36
37Prefer a terminal based solution? [hid_listen](https://www.pjrc.com/teensy/hid_listen.html), provided by PJRC, can also be used to display debug messages. Prebuilt binaries for Windows,Linux,and MacOS are available.
38
08e48eb6 39<!-- FIXME: Describe the debugging messages here. -->
40
41## Sending Your Own Debug Messages
42
43Sometimes it's useful to print debug messages from within your [custom code](custom_quantum_functions.md). Doing so is pretty simple. Start by including `print.h` at the top of your file:
44
45 #include <print.h>
46
47After that you can use a few different print functions:
48
49* `print("string")`: Print a simple string.
90f9fb4e 50* `uprintf("%s string", var)`: Print a formatted string
08e48eb6 51* `dprint("string")` Print a simple string, but only when debug mode is enabled
52* `dprintf("%s string", var)`: Print a formatted string, but only when debug mode is enabled
da995d2a 53
54## Debug Examples
55
56Below is a collection of real world debugging examples. For additional information, refer to [Debugging/Troubleshooting QMK](faq_debug.md).
57
58### Which matrix position is this keypress?
59
60When porting, or when attempting to diagnose pcb issues, it can be useful to know if a keypress is scanned correctly. To enable logging for this scenario, add the following code to your keymaps `keymap.c`
61
62```c
63bool process_record_user(uint16_t keycode, keyrecord_t *record) {
64 // If console is enabled, it will print the matrix position and status of each key pressed
65#ifdef CONSOLE_ENABLE
66 uprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed);
67#endif
68 return true;
69}
70```
71
72Example output
73```text
74Waiting for device:.......
75Listening:
76KL: kc: 169, col: 0, row: 0, pressed: 1
77KL: kc: 169, col: 0, row: 0, pressed: 0
78KL: kc: 174, col: 1, row: 0, pressed: 1
79KL: kc: 174, col: 1, row: 0, pressed: 0
80KL: kc: 172, col: 2, row: 0, pressed: 1
81KL: kc: 172, col: 2, row: 0, pressed: 0
82```
83
84### How long did it take to scan for a keypress?
85
86When testing performance issues, it can be useful to know the frequency at which the switch matrix is being scanned. To enable logging for this scenario, add the following code to your keymaps `config.h`
87
88```c
89#define DEBUG_MATRIX_SCAN_RATE
90```
91
92Example output
93```text
94 > matrix scan frequency: 315
95 > matrix scan frequency: 313
96 > matrix scan frequency: 316
97 > matrix scan frequency: 316
98 > matrix scan frequency: 316
99 > matrix scan frequency: 316
100```