diff options
Diffstat (limited to 'users/drashna/callbacks.md')
| -rw-r--r-- | users/drashna/callbacks.md | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/users/drashna/callbacks.md b/users/drashna/callbacks.md new file mode 100644 index 000000000..a0f0d9fda --- /dev/null +++ b/users/drashna/callbacks.md | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | # Custom Userspace Callback Functions | ||
| 2 | |||
| 3 | Specifically QMK works by using customized callback functions for everything. This allows for multiple levels of customization. | ||
| 4 | |||
| 5 | `matrix_scan` calls `matrix_scan_quantum`, which calls `matrix_scan_kb`, which calls `matrix_scan_user`. | ||
| 6 | `process_record` calls a bunch of stuff, but eventually calls `process_record_kb` which calls `process_record_user` | ||
| 7 | The same goes for `matrix_init`, `layer_state_set`, `led_set`, and a few other functions. | ||
| 8 | |||
| 9 | 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. | ||
| 10 | |||
| 11 | This allows for keyboard specific configuration while maintaining the ability to customize the board. | ||
| 12 | |||
| 13 | 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. | ||
| 14 | |||
| 15 | You can see a list of these files in [callbacks.c](callbacks.c), or a shortend list here | ||
| 16 | |||
| 17 | ```c | ||
| 18 | __attribute__((weak)) void matrix_init_keymap(void) {} | ||
| 19 | void matrix_init_user(void) { | ||
| 20 | matrix_init_keymap(); | ||
| 21 | } | ||
| 22 | |||
| 23 | __attribute__((weak)) void keyboard_post_init_keymap(void) {} | ||
| 24 | void keyboard_post_init_user(void) { | ||
| 25 | keyboard_post_init_keymap(); | ||
| 26 | } | ||
| 27 | |||
| 28 | __attribute__((weak)) void matrix_scan_keymap(void) {} | ||
| 29 | void matrix_scan_user(void) { | ||
| 30 | matrix_scan_keymap(); | ||
| 31 | } | ||
| 32 | |||
| 33 | __attribute__ ((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { return true; } | ||
| 34 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
| 35 | if (!process_record_keymap(keycode, record)) { return false; } | ||
| 36 | return true; | ||
| 37 | } | ||
| 38 | |||
| 39 | __attribute__((weak)) layer_state_t layer_state_set_keymap(layer_state_t state) { return state; } | ||
| 40 | layer_state_t layer_state_set_user(layer_state_t state) { | ||
| 41 | state = layer_state_set_keymap(state); | ||
| 42 | return state; | ||
| 43 | } | ||
| 44 | |||
| 45 | __attribute__ ((weak)) void led_set_keymap(uint8_t usb_led) {} | ||
| 46 | void led_set_user(uint8_t usb_led) { | ||
| 47 | led_set_keymap(usb_led); | ||
| 48 | } | ||
| 49 | |||
| 50 | __attribute__ ((weak)) void suspend_power_down_keymap(void) {} | ||
| 51 | void suspend_power_down_user(void) { | ||
| 52 | suspend_power_down_keymap(); | ||
| 53 | } | ||
| 54 | |||
| 55 | __attribute__ ((weak)) void suspend_wakeup_init_keymap(void) {} | ||
| 56 | void suspend_wakeup_init_user(void) { | ||
| 57 | suspend_wakeup_init_keymap(); | ||
| 58 | } | ||
| 59 | |||
| 60 | |||
| 61 | __attribute__ ((weak)) void shutdown_keymap(void) {} | ||
| 62 | void shutdown_user (void) { | ||
| 63 | shutdown_keymap(); | ||
| 64 | } | ||
| 65 | |||
| 66 | __attribute__ ((weak)) void eeconfig_init_keymap(void) {} | ||
| 67 | void eeconfig_init_user(void) { | ||
| 68 | eeconfig_update_user(0); | ||
| 69 | eeconfig_init_keymap(); | ||
| 70 | } | ||
| 71 | ``` | ||
