diff options
author | Nick Brassel <[email protected]> | 2025-02-26 22:25:41 +1100 |
---|---|---|
committer | GitHub <[email protected]> | 2025-02-26 22:25:41 +1100 |
commit | 1efc82403bebe759272d1ba7a79d9dfa0d5df506 (patch) | |
tree | c356ae7afeb0849926534beb5dd4515f693abf99 /quantum | |
parent | 63b095212b157c4522bdeda3de144fb87213085d (diff) | |
download | qmk_firmware-1efc82403bebe759272d1ba7a79d9dfa0d5df506.tar.gz qmk_firmware-1efc82403bebe759272d1ba7a79d9dfa0d5df506.zip |
Community modules (#24848)
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/action.h | 2 | ||||
-rw-r--r-- | quantum/keyboard.c | 44 | ||||
-rw-r--r-- | quantum/keycodes.h | 3 | ||||
-rw-r--r-- | quantum/keymap_introspection.c | 11 | ||||
-rw-r--r-- | quantum/os_detection.c | 7 | ||||
-rw-r--r-- | quantum/quantum.c | 26 | ||||
-rw-r--r-- | quantum/quantum.h | 4 |
7 files changed, 93 insertions, 4 deletions
diff --git a/quantum/action.h b/quantum/action.h index d5b15c6f17..7596688f31 100644 --- a/quantum/action.h +++ b/quantum/action.h @@ -45,7 +45,7 @@ typedef struct { } tap_t; /* Key event container for recording */ -typedef struct { +typedef struct keyrecord_t { keyevent_t event; #ifndef NO_ACTION_TAPPING tap_t tap; diff --git a/quantum/keyboard.c b/quantum/keyboard.c index d7836cf36e..ad740de4b3 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -289,6 +289,21 @@ __attribute__((weak)) void keyboard_pre_init_kb(void) { keyboard_pre_init_user(); } +/** \brief keyboard_pre_init_modules + * + * FIXME: needs doc + */ +__attribute__((weak)) void keyboard_pre_init_modules(void) {} + +/** \brief keyboard_pre_init_quantum + * + * FIXME: needs doc + */ +void keyboard_pre_init_quantum(void) { + keyboard_pre_init_modules(); + keyboard_pre_init_kb(); +} + /** \brief keyboard_post_init_user * * FIXME: needs doc @@ -305,6 +320,23 @@ __attribute__((weak)) void keyboard_post_init_kb(void) { keyboard_post_init_user(); } +/** \brief keyboard_post_init_modules + * + * FIXME: needs doc + */ + +__attribute__((weak)) void keyboard_post_init_modules(void) {} + +/** \brief keyboard_post_init_quantum + * + * FIXME: needs doc + */ + +void keyboard_post_init_quantum(void) { + keyboard_post_init_modules(); + keyboard_post_init_kb(); +} + /** \brief matrix_can_read * * Allows overriding when matrix scanning operations should be executed. @@ -323,7 +355,7 @@ void keyboard_setup(void) { eeprom_driver_init(); #endif matrix_setup(); - keyboard_pre_init_kb(); + keyboard_pre_init_quantum(); } #ifndef SPLIT_KEYBOARD @@ -355,6 +387,13 @@ __attribute__((weak)) bool should_process_keypress(void) { return is_keyboard_master(); } +/** \brief housekeeping_task_modules + * + * Codegen will override this if community modules are enabled. + * This is specific to keyboard-level functionality. + */ +__attribute__((weak)) void housekeeping_task_modules(void) {} + /** \brief housekeeping_task_kb * * Override this function if you have a need to execute code for every keyboard main loop iteration. @@ -374,6 +413,7 @@ __attribute__((weak)) void housekeeping_task_user(void) {} * Invokes hooks for executing code after QMK is done after each loop iteration. */ void housekeeping_task(void) { + housekeeping_task_modules(); housekeeping_task_kb(); housekeeping_task_user(); } @@ -493,7 +533,7 @@ void keyboard_init(void) { debug_enable = true; #endif - keyboard_post_init_kb(); /* Always keep this last */ + keyboard_post_init_quantum(); /* Always keep this last */ } /** \brief key_event_task diff --git a/quantum/keycodes.h b/quantum/keycodes.h index 5929e35687..b4fc38f5ff 100644 --- a/quantum/keycodes.h +++ b/quantum/keycodes.h @@ -76,6 +76,8 @@ enum qk_keycode_ranges { QK_MACRO_MAX = 0x777F, QK_CONNECTION = 0x7780, QK_CONNECTION_MAX = 0x77BF, + QK_COMMUNITY_MODULE = 0x77C0, + QK_COMMUNITY_MODULE_MAX = 0x77FF, QK_LIGHTING = 0x7800, QK_LIGHTING_MAX = 0x78FF, QK_QUANTUM = 0x7C00, @@ -1476,6 +1478,7 @@ enum qk_keycode_defines { #define IS_QK_STENO(code) ((code) >= QK_STENO && (code) <= QK_STENO_MAX) #define IS_QK_MACRO(code) ((code) >= QK_MACRO && (code) <= QK_MACRO_MAX) #define IS_QK_CONNECTION(code) ((code) >= QK_CONNECTION && (code) <= QK_CONNECTION_MAX) +#define IS_QK_COMMUNITY_MODULE(code) ((code) >= QK_COMMUNITY_MODULE && (code) <= QK_COMMUNITY_MODULE_MAX) #define IS_QK_LIGHTING(code) ((code) >= QK_LIGHTING && (code) <= QK_LIGHTING_MAX) #define IS_QK_QUANTUM(code) ((code) >= QK_QUANTUM && (code) <= QK_QUANTUM_MAX) #define IS_QK_KB(code) ((code) >= QK_KB && (code) <= QK_KB_MAX) diff --git a/quantum/keymap_introspection.c b/quantum/keymap_introspection.c index 236b54ce98..23e842353a 100644 --- a/quantum/keymap_introspection.c +++ b/quantum/keymap_introspection.c @@ -1,6 +1,10 @@ // Copyright 2022 Nick Brassel (@tzarc) // SPDX-License-Identifier: GPL-2.0-or-later +#if defined(COMMUNITY_MODULES_ENABLE) +# include "community_modules_introspection.h" +#endif // defined(COMMUNITY_MODULES_ENABLE) + // Pull the actual keymap code so that we can inspect stuff from it #include KEYMAP_C @@ -171,3 +175,10 @@ __attribute__((weak)) const key_override_t* key_override_get(uint16_t key_overri } #endif // defined(KEY_OVERRIDE_ENABLE) + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// Community modules (must be last in this file!) + +#if defined(COMMUNITY_MODULES_ENABLE) +# include "community_modules_introspection.c" +#endif // defined(COMMUNITY_MODULES_ENABLE) diff --git a/quantum/os_detection.c b/quantum/os_detection.c index 84bbeeed54..9a9f9052f2 100644 --- a/quantum/os_detection.c +++ b/quantum/os_detection.c @@ -72,6 +72,8 @@ static volatile struct usb_device_state maxprev_usb_device_state = {.configure_s static volatile bool debouncing = false; static volatile fast_timer_t last_time = 0; +bool process_detected_host_os_modules(os_variant_t os); + void os_detection_task(void) { #ifdef OS_DETECTION_KEYBOARD_RESET // resetting the keyboard on the USB device state change callback results in instability, so delegate that to this task @@ -96,12 +98,17 @@ void os_detection_task(void) { if (detected_os != reported_os || first_report) { first_report = false; reported_os = detected_os; + process_detected_host_os_modules(detected_os); process_detected_host_os_kb(detected_os); } } } } +__attribute__((weak)) bool process_detected_host_os_modules(os_variant_t os) { + return true; +} + __attribute__((weak)) bool process_detected_host_os_kb(os_variant_t detected_os) { return process_detected_host_os_user(detected_os); } diff --git a/quantum/quantum.c b/quantum/quantum.c index b63300add8..adb14d64b6 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -162,6 +162,10 @@ __attribute__((weak)) void tap_code16(uint16_t code) { tap_code16_delay(code, code == KC_CAPS_LOCK ? TAP_HOLD_CAPS_DELAY : TAP_CODE_DELAY); } +__attribute__((weak)) bool pre_process_record_modules(uint16_t keycode, keyrecord_t *record) { + return true; +} + __attribute__((weak)) bool pre_process_record_kb(uint16_t keycode, keyrecord_t *record) { return pre_process_record_user(keycode, record); } @@ -174,6 +178,10 @@ __attribute__((weak)) bool process_action_kb(keyrecord_t *record) { return true; } +__attribute__((weak)) bool process_record_modules(uint16_t keycode, keyrecord_t *record) { + return true; +} + __attribute__((weak)) bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return process_record_user(keycode, record); } @@ -182,12 +190,22 @@ __attribute__((weak)) bool process_record_user(uint16_t keycode, keyrecord_t *re return true; } +__attribute__((weak)) void post_process_record_modules(uint16_t keycode, keyrecord_t *record) {} + __attribute__((weak)) void post_process_record_kb(uint16_t keycode, keyrecord_t *record) { post_process_record_user(keycode, record); } __attribute__((weak)) void post_process_record_user(uint16_t keycode, keyrecord_t *record) {} +__attribute__((weak)) bool shutdown_modules(bool jump_to_bootloader) { + return true; +} + +__attribute__((weak)) void suspend_power_down_modules(void) {} + +__attribute__((weak)) void suspend_wakeup_init_modules(void) {} + void shutdown_quantum(bool jump_to_bootloader) { clear_keyboard(); #if defined(MIDI_ENABLE) && defined(MIDI_BASIC) @@ -199,11 +217,13 @@ void shutdown_quantum(bool jump_to_bootloader) { # endif uint16_t timer_start = timer_read(); PLAY_SONG(goodbye_song); + shutdown_modules(jump_to_bootloader); shutdown_kb(jump_to_bootloader); while (timer_elapsed(timer_start) < 250) wait_ms(1); stop_all_notes(); #else + shutdown_modules(jump_to_bootloader); shutdown_kb(jump_to_bootloader); wait_ms(250); #endif @@ -258,7 +278,7 @@ uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache) { /* Get keycode, and then process pre tapping functionality */ bool pre_process_record_quantum(keyrecord_t *record) { - return pre_process_record_kb(get_record_keycode(record, true), record) && + return pre_process_record_modules(get_record_keycode(record, true), record) && pre_process_record_kb(get_record_keycode(record, true), record) && #ifdef COMBO_ENABLE process_combo(get_record_keycode(record, true), record) && #endif @@ -268,6 +288,7 @@ bool pre_process_record_quantum(keyrecord_t *record) { /* Get keycode, and then call keyboard function */ void post_process_record_quantum(keyrecord_t *record) { uint16_t keycode = get_record_keycode(record, false); + post_process_record_modules(keycode, record); post_process_record_kb(keycode, record); } @@ -332,6 +353,7 @@ bool process_record_quantum(keyrecord_t *record) { #if defined(POINTING_DEVICE_ENABLE) && defined(POINTING_DEVICE_AUTO_MOUSE_ENABLE) process_auto_mouse(keycode, record) && #endif + process_record_modules(keycode, record) && // modules must run before kb process_record_kb(keycode, record) && #if defined(VIA_ENABLE) process_record_via(keycode, record) && @@ -526,6 +548,7 @@ __attribute__((weak)) bool shutdown_kb(bool jump_to_bootloader) { } void suspend_power_down_quantum(void) { + suspend_power_down_modules(); suspend_power_down_kb(); #ifndef NO_SUSPEND_POWER_DOWN // Turn off backlight @@ -593,6 +616,7 @@ __attribute__((weak)) void suspend_wakeup_init_quantum(void) { #if defined(RGB_MATRIX_ENABLE) rgb_matrix_set_suspend_state(false); #endif + suspend_wakeup_init_modules(); suspend_wakeup_init_kb(); } diff --git a/quantum/quantum.h b/quantum/quantum.h index 9db88a54d4..59a415ead4 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -244,6 +244,10 @@ extern layer_state_t layer_state; # include "layer_lock.h" #endif +#ifdef COMMUNITY_MODULES_ENABLE +# include "community_modules.h" +#endif + void set_single_default_layer(uint8_t default_layer); void set_single_persistent_default_layer(uint8_t default_layer); |