aboutsummaryrefslogtreecommitdiff
path: root/users/drashna/callbacks.md
diff options
context:
space:
mode:
Diffstat (limited to 'users/drashna/callbacks.md')
-rw-r--r--users/drashna/callbacks.md71
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
3Specifically 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`
7The same goes for `matrix_init`, `layer_state_set`, `led_set`, and a few other functions.
8
9All (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
11This allows for keyboard specific configuration while maintaining the ability to customize the board.
12
13My [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
15You 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) {}
19void matrix_init_user(void) {
20 matrix_init_keymap();
21}
22
23__attribute__((weak)) void keyboard_post_init_keymap(void) {}
24void keyboard_post_init_user(void) {
25 keyboard_post_init_keymap();
26}
27
28__attribute__((weak)) void matrix_scan_keymap(void) {}
29void 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; }
34bool 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; }
40layer_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) {}
46void led_set_user(uint8_t usb_led) {
47 led_set_keymap(usb_led);
48}
49
50__attribute__ ((weak)) void suspend_power_down_keymap(void) {}
51void suspend_power_down_user(void) {
52 suspend_power_down_keymap();
53}
54
55__attribute__ ((weak)) void suspend_wakeup_init_keymap(void) {}
56void suspend_wakeup_init_user(void) {
57 suspend_wakeup_init_keymap();
58}
59
60
61__attribute__ ((weak)) void shutdown_keymap(void) {}
62void shutdown_user (void) {
63 shutdown_keymap();
64}
65
66__attribute__ ((weak)) void eeconfig_init_keymap(void) {}
67void eeconfig_init_user(void) {
68 eeconfig_update_user(0);
69 eeconfig_init_keymap();
70}
71```