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.

94 lines
3.6 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. You can use [QMK Configurator](https://config.qmk.fm/#/test/)'s test mode to check your keyboard, even if it doesn't run QMK.
  5. ## Debugging :id=debugging
  6. 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.
  7. ```c
  8. void keyboard_post_init_user(void) {
  9. // Customise these values to desired behaviour
  10. debug_enable=true;
  11. debug_matrix=true;
  12. //debug_keyboard=true;
  13. //debug_mouse=true;
  14. }
  15. ```
  16. ## Debugging Tools
  17. There are two different tools you can use to debug your keyboard.
  18. ### Debugging With QMK Toolbox
  19. For compatible platforms, [QMK Toolbox](https://github.com/qmk/qmk_toolbox) can be used to display debug messages from your keyboard.
  20. ### Debugging With hid_listen
  21. 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.
  22. ## Sending Your Own Debug Messages
  23. 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:
  24. #include <print.h>
  25. After that you can use a few different print functions:
  26. * `print("string")`: Print a simple string.
  27. * `uprintf("%s string", var)`: Print a formatted string
  28. * `dprint("string")` Print a simple string, but only when debug mode is enabled
  29. * `dprintf("%s string", var)`: Print a formatted string, but only when debug mode is enabled
  30. ## Debug Examples
  31. Below is a collection of real world debugging examples. For additional information, refer to [Debugging/Troubleshooting QMK](faq_debug.md).
  32. ### Which matrix position is this keypress?
  33. 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`
  34. ```c
  35. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  36. // If console is enabled, it will print the matrix position and status of each key pressed
  37. #ifdef CONSOLE_ENABLE
  38. uprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed);
  39. #endif
  40. return true;
  41. }
  42. ```
  43. Example output
  44. ```text
  45. Waiting for device:.......
  46. Listening:
  47. KL: kc: 169, col: 0, row: 0, pressed: 1
  48. KL: kc: 169, col: 0, row: 0, pressed: 0
  49. KL: kc: 174, col: 1, row: 0, pressed: 1
  50. KL: kc: 174, col: 1, row: 0, pressed: 0
  51. KL: kc: 172, col: 2, row: 0, pressed: 1
  52. KL: kc: 172, col: 2, row: 0, pressed: 0
  53. ```
  54. ### How long did it take to scan for a keypress?
  55. 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`
  56. ```c
  57. #define DEBUG_MATRIX_SCAN_RATE
  58. ```
  59. Example output
  60. ```text
  61. > matrix scan frequency: 315
  62. > matrix scan frequency: 313
  63. > matrix scan frequency: 316
  64. > matrix scan frequency: 316
  65. > matrix scan frequency: 316
  66. > matrix scan frequency: 316
  67. ```