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.

71 lines
2.7 KiB

  1. # Custom Userspace Callback Functions
  2. Specifically QMK works by using customized callback functions for everything. This allows for multiple levels of customization.
  3. `matrix_scan` calls `matrix_scan_quantum`, which calls `matrix_scan_kb`, which calls `matrix_scan_user`.
  4. `process_record` calls a bunch of stuff, but eventually calls `process_record_kb` which calls `process_record_user`
  5. The same goes for `matrix_init`, `layer_state_set`, `led_set`, and a few other functions.
  6. All (most) `_user` functions are handled here, in the userspace instead. To allow keyboard specific configuration, I've created `_keymap` functions that can be called by the keymap.c files instead.
  7. This allows for keyboard specific configuration while maintaining the ability to customize the board.
  8. My [Ergodox EZ Keymap](https://github.com/qmk/qmk_firmware/blob/master/layouts/community/ergodox/drashna/keymap.c) is a good example of this, as it uses the LEDs as modifier indicators.
  9. You can see a list of these files in [callbacks.c](callbacks.c), or a shortend list here
  10. ```c
  11. __attribute__((weak)) void matrix_init_keymap(void) {}
  12. void matrix_init_user(void) {
  13. matrix_init_keymap();
  14. }
  15. __attribute__((weak)) void keyboard_post_init_keymap(void) {}
  16. void keyboard_post_init_user(void) {
  17. keyboard_post_init_keymap();
  18. }
  19. __attribute__((weak)) void matrix_scan_keymap(void) {}
  20. void matrix_scan_user(void) {
  21. matrix_scan_keymap();
  22. }
  23. __attribute__ ((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { return true; }
  24. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  25. if (!process_record_keymap(keycode, record)) { return false; }
  26. return true;
  27. }
  28. __attribute__((weak)) layer_state_t layer_state_set_keymap(layer_state_t state) { return state; }
  29. layer_state_t layer_state_set_user(layer_state_t state) {
  30. state = layer_state_set_keymap(state);
  31. return state;
  32. }
  33. __attribute__ ((weak)) void led_set_keymap(uint8_t usb_led) {}
  34. void led_set_user(uint8_t usb_led) {
  35. led_set_keymap(usb_led);
  36. }
  37. __attribute__ ((weak)) void suspend_power_down_keymap(void) {}
  38. void suspend_power_down_user(void) {
  39. suspend_power_down_keymap();
  40. }
  41. __attribute__ ((weak)) void suspend_wakeup_init_keymap(void) {}
  42. void suspend_wakeup_init_user(void) {
  43. suspend_wakeup_init_keymap();
  44. }
  45. __attribute__ ((weak)) void shutdown_keymap(void) {}
  46. void shutdown_user (void) {
  47. shutdown_keymap();
  48. }
  49. __attribute__ ((weak)) void eeconfig_init_keymap(void) {}
  50. void eeconfig_init_user(void) {
  51. eeconfig_update_user(0);
  52. eeconfig_init_keymap();
  53. }
  54. ```