You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.9 KiB

  1. # Testing and Debugging
  2. Once 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.
  3. ## Testing
  4. Testing 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.
  5. Note: These programs are not provided by or endorsed by QMK.
  6. * [Switch Hitter](https://elitekeyboards.com/switchhitter.php) (Windows Only)
  7. * [Keyboard Viewer](https://www.imore.com/how-use-keyboard-viewer-your-mac) (Mac Only)
  8. * [Keyboard Tester](http://www.keyboardtester.com) (Web Based)
  9. * [Keyboard Checker](http://keyboardchecker.com) (Web Based)
  10. ## Debugging
  11. Your 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.
  12. ```c
  13. void keyboard_post_init_user(void) {
  14. // Customise these values to desired behaviour
  15. debug_enable=true;
  16. debug_matrix=true;
  17. //debug_keyboard=true;
  18. //debug_mouse=true;
  19. }
  20. ```
  21. ### Debugging With QMK Toolbox
  22. For compatible platforms, [QMK Toolbox](https://github.com/qmk/qmk_toolbox) can be used to display debug messages from your keyboard.
  23. ### Debugging With hid_listen
  24. Prefer 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.
  25. <!-- FIXME: Describe the debugging messages here. -->
  26. ## Sending Your Own Debug Messages
  27. Sometimes 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:
  28. #include <print.h>
  29. After that you can use a few different print functions:
  30. * `print("string")`: Print a simple string.
  31. * `uprintf("%s string", var)`: Print a formatted string
  32. * `dprint("string")` Print a simple string, but only when debug mode is enabled
  33. * `dprintf("%s string", var)`: Print a formatted string, but only when debug mode is enabled
  34. ## Debug Examples
  35. Below is a collection of real world debugging examples. For additional information, refer to [Debugging/Troubleshooting QMK](faq_debug.md).
  36. ### Which matrix position is this keypress?
  37. When 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`
  38. ```c
  39. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  40. // If console is enabled, it will print the matrix position and status of each key pressed
  41. #ifdef CONSOLE_ENABLE
  42. uprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed);
  43. #endif
  44. return true;
  45. }
  46. ```
  47. Example output
  48. ```text
  49. Waiting for device:.......
  50. Listening:
  51. KL: kc: 169, col: 0, row: 0, pressed: 1
  52. KL: kc: 169, col: 0, row: 0, pressed: 0
  53. KL: kc: 174, col: 1, row: 0, pressed: 1
  54. KL: kc: 174, col: 1, row: 0, pressed: 0
  55. KL: kc: 172, col: 2, row: 0, pressed: 1
  56. KL: kc: 172, col: 2, row: 0, pressed: 0
  57. ```
  58. ### How long did it take to scan for a keypress?
  59. When 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`
  60. ```c
  61. #define DEBUG_MATRIX_SCAN_RATE
  62. ```
  63. Example output
  64. ```text
  65. > matrix scan frequency: 315
  66. > matrix scan frequency: 313
  67. > matrix scan frequency: 316
  68. > matrix scan frequency: 316
  69. > matrix scan frequency: 316
  70. > matrix scan frequency: 316
  71. ```