summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/constants/module_hooks/1.1.0.hjson55
-rw-r--r--docs/features/community_modules.md33
-rw-r--r--lib/python/qmk/cli/generate/community_modules.py10
-rw-r--r--quantum/action_layer.c19
-rw-r--r--quantum/action_layer.h3
-rw-r--r--quantum/led_matrix/led_matrix.c10
-rw-r--r--quantum/pointing_device/pointing_device.c9
-rw-r--r--quantum/pointing_device/pointing_device.h1
-rw-r--r--quantum/rgb_matrix/rgb_matrix.c10
9 files changed, 137 insertions, 13 deletions
diff --git a/data/constants/module_hooks/1.1.0.hjson b/data/constants/module_hooks/1.1.0.hjson
new file mode 100644
index 0000000000..b50dad6a66
--- /dev/null
+++ b/data/constants/module_hooks/1.1.0.hjson
@@ -0,0 +1,55 @@
1{
2 pointing_device_init: {
3 ret_type: void
4 args: void
5 guard: defined(POINTING_DEVICE_ENABLE)
6 }
7 pointing_device_task: {
8 ret_type: report_mouse_t
9 args: report_mouse_t mouse_report
10 call_params: mouse_report
11 guard: defined(POINTING_DEVICE_ENABLE)
12 header: report.h
13 }
14 rgb_matrix_indicators: {
15 ret_type: bool
16 args: void
17 guard: defined(RGB_MATRIX_ENABLE)
18 header: rgb_matrix.h
19 }
20 rgb_matrix_indicators_advanced: {
21 ret_type: bool
22 args: uint8_t led_min, uint8_t led_max
23 call_params: led_min, led_max
24 guard: defined(RGB_MATRIX_ENABLE)
25 header: rgb_matrix.h
26 }
27 led_matrix_indicators: {
28 ret_type: bool
29 args: void
30 guard: defined(LED_MATRIX_ENABLE)
31 header: led_matrix.h
32 }
33 led_matrix_indicators_advanced: {
34 ret_type: bool
35 args: uint8_t led_min, uint8_t led_max
36 call_params: led_min, led_max
37 guard: defined(LED_MATRIX_ENABLE)
38 header: led_matrix.h
39 }
40 default_layer_state_set: {
41 ret_type: layer_state_t
42 args: layer_state_t state
43 call_params: state
44 guard: !defined(NO_ACTION_LAYER)
45 header: action_layer.h
46 }
47 layer_state_set: {
48 ret_type: layer_state_t
49 args: layer_state_t state
50 call_params: state
51 guard: !defined(NO_ACTION_LAYER)
52 header: action_layer.h
53 }
54
55}
diff --git a/docs/features/community_modules.md b/docs/features/community_modules.md
index 52526c9fe8..69fc47f617 100644
--- a/docs/features/community_modules.md
+++ b/docs/features/community_modules.md
@@ -127,18 +127,27 @@ Introspection is a relatively advanced topic within QMK, and existing patterns s
127 127
128Community Modules may provide specializations for the following APIs: 128Community Modules may provide specializations for the following APIs:
129 129
130| Base API | API Format | Example (`hello_world` module) | API Version | 130| Base API | API Format | Example (`hello_world` module) | API Version |
131|----------------------------|-------------------------------------|----------------------------------------|-------------| 131|----------------------------------|-------------------------------------------|---------------------------------------------|-------------|
132| `keyboard_pre_init` | `keyboard_pre_init_<module>` | `keyboard_pre_init_hello_world` | `0.1.0` | 132| `keyboard_pre_init` | `keyboard_pre_init_<module>` | `keyboard_pre_init_hello_world` | `0.1.0` |
133| `keyboard_post_init` | `keyboard_post_init_<module>` | `keyboard_post_init_hello_world` | `0.1.0` | 133| `keyboard_post_init` | `keyboard_post_init_<module>` | `keyboard_post_init_hello_world` | `0.1.0` |
134| `pre_process_record` | `pre_process_record_<module>` | `pre_process_record_hello_world` | `0.1.0` | 134| `pre_process_record` | `pre_process_record_<module>` | `pre_process_record_hello_world` | `0.1.0` |
135| `process_record` | `process_record_<module>` | `process_record_hello_world` | `0.1.0` | 135| `process_record` | `process_record_<module>` | `process_record_hello_world` | `0.1.0` |
136| `post_process_record` | `post_process_record_<module>` | `post_process_record_hello_world` | `0.1.0` | 136| `post_process_record` | `post_process_record_<module>` | `post_process_record_hello_world` | `0.1.0` |
137| `housekeeping_task` | `housekeeping_task_<module>` | `housekeeping_task_hello_world` | `1.0.0` | 137| `housekeeping_task` | `housekeeping_task_<module>` | `housekeeping_task_hello_world` | `1.0.0` |
138| `suspend_power_down` | `suspend_power_down_<module>` | `suspend_power_down_hello_world` | `1.0.0` | 138| `suspend_power_down` | `suspend_power_down_<module>` | `suspend_power_down_hello_world` | `1.0.0` |
139| `suspend_wakeup_init` | `suspend_wakeup_init_<module>` | `suspend_wakeup_init_hello_world` | `1.0.0` | 139| `suspend_wakeup_init` | `suspend_wakeup_init_<module>` | `suspend_wakeup_init_hello_world` | `1.0.0` |
140| `shutdown` | `shutdown_<module>` | `shutdown_hello_world` | `1.0.0` | 140| `shutdown` | `shutdown_<module>` | `shutdown_hello_world` | `1.0.0` |
141| `process_detected_host_os` | `process_detected_host_os_<module>` | `process_detected_host_os_hello_world` | `1.0.0` | 141| `process_detected_host_os` | `process_detected_host_os_<module>` | `process_detected_host_os_hello_world` | `1.0.0` |
142| `default_layer_state_set` | `default_layer_state_set_<module>` | `default_layer_state_set_hello_world` | `1.1.0` |
143| `layer_state_set` | `layer_state_set_<module>` | `layer_state_set_hello_world` | `1.1.0` |
144| `led_matrix_indicators` | `led_matrix_indicators_<module>` | `led_matrix_indicators_hello_word` | `1.1.0` |
145| `led_matrix_indicators_advanced` | `led_matrix_indicators_advanced_<module>` | `led_matrix_indicators_advanced_hello_word` | `1.1.0` |
146| `rgb_matrix_indicators` | `rgb_matrix_indicators_<module>` | `rgb_matrix_indicators_hello_word` | `1.1.0` |
147| `rgb_matrix_indicators_advanced` | `rgb_matrix_indicators_advanced_<module>` | `rgb_matrix_indicators_advanced_hello_word` | `1.1.0` |
148| `pointing_device_init` | `pointing_device_init_<module>` | `pointing_device_init_hello_word` | `1.1.0` |
149| `pointing_device_task` | `pointing_device_task_<module>` | `pointing_device_task_hello_word` | `1.1.0` |
150
142 151
143::: info 152::: info
144An unspecified API is disregarded if a Community Module does not provide a specialization for it. 153An unspecified API is disregarded if a Community Module does not provide a specialization for it.
diff --git a/lib/python/qmk/cli/generate/community_modules.py b/lib/python/qmk/cli/generate/community_modules.py
index e12daccf1c..61e24077d3 100644
--- a/lib/python/qmk/cli/generate/community_modules.py
+++ b/lib/python/qmk/cli/generate/community_modules.py
@@ -76,6 +76,8 @@ def _render_api_implementations(api, module):
76 lines.append(f'__attribute__((weak)) {api.ret_type} {api.name}_{module_name}_user({api.args}) {{') 76 lines.append(f'__attribute__((weak)) {api.ret_type} {api.name}_{module_name}_user({api.args}) {{')
77 if api.ret_type == 'bool': 77 if api.ret_type == 'bool':
78 lines.append(' return true;') 78 lines.append(' return true;')
79 elif api.ret_type in ['layer_state_t', 'report_mouse_t']:
80 lines.append(f' return {api.call_params};')
79 else: 81 else:
80 pass 82 pass
81 lines.append('}') 83 lines.append('}')
@@ -86,6 +88,8 @@ def _render_api_implementations(api, module):
86 if api.ret_type == 'bool': 88 if api.ret_type == 'bool':
87 lines.append(f' if(!{api.name}_{module_name}_user({api.call_params})) {{ return false; }}') 89 lines.append(f' if(!{api.name}_{module_name}_user({api.call_params})) {{ return false; }}')
88 lines.append(' return true;') 90 lines.append(' return true;')
91 elif api.ret_type in ['layer_state_t', 'report_mouse_t']:
92 lines.append(f' return {api.name}_{module_name}_user({api.call_params});')
89 else: 93 else:
90 lines.append(f' {api.name}_{module_name}_user({api.call_params});') 94 lines.append(f' {api.name}_{module_name}_user({api.call_params});')
91 lines.append('}') 95 lines.append('}')
@@ -96,6 +100,8 @@ def _render_api_implementations(api, module):
96 if api.ret_type == 'bool': 100 if api.ret_type == 'bool':
97 lines.append(f' if(!{api.name}_{module_name}_kb({api.call_params})) {{ return false; }}') 101 lines.append(f' if(!{api.name}_{module_name}_kb({api.call_params})) {{ return false; }}')
98 lines.append(' return true;') 102 lines.append(' return true;')
103 elif api.ret_type in ['layer_state_t', 'report_mouse_t']:
104 lines.append(f' return {api.name}_{module_name}_kb({api.call_params});')
99 else: 105 else:
100 lines.append(f' {api.name}_{module_name}_kb({api.call_params});') 106 lines.append(f' {api.name}_{module_name}_kb({api.call_params});')
101 lines.append('}') 107 lines.append('}')
@@ -113,10 +119,14 @@ def _render_core_implementation(api, modules):
113 module_name = Path(module).name 119 module_name = Path(module).name
114 if api.ret_type == 'bool': 120 if api.ret_type == 'bool':
115 lines.append(f' && {api.name}_{module_name}({api.call_params})') 121 lines.append(f' && {api.name}_{module_name}({api.call_params})')
122 elif api.ret_type in ['layer_state_t', 'report_mouse_t']:
123 lines.append(f' {api.call_params} = {api.name}_{module_name}({api.call_params});')
116 else: 124 else:
117 lines.append(f' {api.name}_{module_name}({api.call_params});') 125 lines.append(f' {api.name}_{module_name}({api.call_params});')
118 if api.ret_type == 'bool': 126 if api.ret_type == 'bool':
119 lines.append(' ;') 127 lines.append(' ;')
128 elif api.ret_type in ['layer_state_t', 'report_mouse_t']:
129 lines.append(f' return {api.call_params};')
120 lines.append('}') 130 lines.append('}')
121 return lines 131 return lines
122 132
diff --git a/quantum/action_layer.c b/quantum/action_layer.c
index 7c09a5bd1e..5828dcb824 100644
--- a/quantum/action_layer.c
+++ b/quantum/action_layer.c
@@ -27,11 +27,20 @@ __attribute__((weak)) layer_state_t default_layer_state_set_kb(layer_state_t sta
27 return default_layer_state_set_user(state); 27 return default_layer_state_set_user(state);
28} 28}
29 29
30/** \brief Default Layer State Set At Module Level
31 *
32 * Run module code on default layer state change
33 */
34__attribute__((weak)) layer_state_t default_layer_state_set_modules(layer_state_t state) {
35 return state;
36}
37
30/** \brief Default Layer State Set 38/** \brief Default Layer State Set
31 * 39 *
32 * Static function to set the default layer state, prints debug info and clears keys 40 * Static function to set the default layer state, prints debug info and clears keys
33 */ 41 */
34static void default_layer_state_set(layer_state_t state) { 42static void default_layer_state_set(layer_state_t state) {
43 state = default_layer_state_set_modules(state);
35 state = default_layer_state_set_kb(state); 44 state = default_layer_state_set_kb(state);
36 ac_dprintf("default_layer_state: "); 45 ac_dprintf("default_layer_state: ");
37 default_layer_debug(); 46 default_layer_debug();
@@ -107,11 +116,21 @@ __attribute__((weak)) layer_state_t layer_state_set_kb(layer_state_t state) {
107 return layer_state_set_user(state); 116 return layer_state_set_user(state);
108} 117}
109 118
119/** \brief Layer state set modules
120 *
121 * Runs module code on layer state change
122 */
123
124__attribute__((weak)) layer_state_t layer_state_set_modules(layer_state_t state) {
125 return state;
126}
127
110/** \brief Layer state set 128/** \brief Layer state set
111 * 129 *
112 * Sets the layer to match the specified state (a bitmask) 130 * Sets the layer to match the specified state (a bitmask)
113 */ 131 */
114void layer_state_set(layer_state_t state) { 132void layer_state_set(layer_state_t state) {
133 state = layer_state_set_modules(state);
115 state = layer_state_set_kb(state); 134 state = layer_state_set_kb(state);
116 ac_dprintf("layer_state: "); 135 ac_dprintf("layer_state: ");
117 layer_debug(); 136 layer_debug();
diff --git a/quantum/action_layer.h b/quantum/action_layer.h
index a2410d49a5..067e33cdb5 100644
--- a/quantum/action_layer.h
+++ b/quantum/action_layer.h
@@ -78,6 +78,7 @@ extern layer_state_t default_layer_state;
78void default_layer_debug(void); 78void default_layer_debug(void);
79void default_layer_set(layer_state_t state); 79void default_layer_set(layer_state_t state);
80 80
81__attribute__((weak)) layer_state_t default_layer_state_set_modules(layer_state_t state);
81__attribute__((weak)) layer_state_t default_layer_state_set_kb(layer_state_t state); 82__attribute__((weak)) layer_state_t default_layer_state_set_kb(layer_state_t state);
82__attribute__((weak)) layer_state_t default_layer_state_set_user(layer_state_t state); 83__attribute__((weak)) layer_state_t default_layer_state_set_user(layer_state_t state);
83 84
@@ -114,6 +115,7 @@ void layer_and(layer_state_t state);
114void layer_xor(layer_state_t state); 115void layer_xor(layer_state_t state);
115layer_state_t layer_state_set_user(layer_state_t state); 116layer_state_t layer_state_set_user(layer_state_t state);
116layer_state_t layer_state_set_kb(layer_state_t state); 117layer_state_t layer_state_set_kb(layer_state_t state);
118layer_state_t layer_state_set_modules(layer_state_t state);
117 119
118/** 120/**
119 * @brief Applies the tri layer to global layer state. Not be used in layer_state_set_(kb|user) functions. 121 * @brief Applies the tri layer to global layer state. Not be used in layer_state_set_(kb|user) functions.
@@ -149,6 +151,7 @@ layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_
149# define layer_or(state) (void)state 151# define layer_or(state) (void)state
150# define layer_and(state) (void)state 152# define layer_and(state) (void)state
151# define layer_xor(state) (void)state 153# define layer_xor(state) (void)state
154# define layer_state_set_modules(state) (void)state
152# define layer_state_set_kb(state) (void)state 155# define layer_state_set_kb(state) (void)state
153# define layer_state_set_user(state) (void)state 156# define layer_state_set_user(state) (void)state
154# define update_tri_layer(layer1, layer2, layer3) 157# define update_tri_layer(layer1, layer2, layer3)
diff --git a/quantum/led_matrix/led_matrix.c b/quantum/led_matrix/led_matrix.c
index f9d76e2776..00bc199ecf 100644
--- a/quantum/led_matrix/led_matrix.c
+++ b/quantum/led_matrix/led_matrix.c
@@ -358,7 +358,12 @@ void led_matrix_task(void) {
358 } 358 }
359} 359}
360 360
361__attribute__((weak)) bool led_matrix_indicators_modules(void) {
362 return true;
363}
364
361void led_matrix_indicators(void) { 365void led_matrix_indicators(void) {
366 led_matrix_indicators_modules();
362 led_matrix_indicators_kb(); 367 led_matrix_indicators_kb();
363} 368}
364 369
@@ -370,6 +375,10 @@ __attribute__((weak)) bool led_matrix_indicators_user(void) {
370 return true; 375 return true;
371} 376}
372 377
378__attribute__((weak)) bool led_matrix_indicators_advanced_modules(uint8_t led_min, uint8_t led_max) {
379 return true;
380}
381
373void led_matrix_indicators_advanced(effect_params_t *params) { 382void led_matrix_indicators_advanced(effect_params_t *params) {
374 /* special handling is needed for "params->iter", since it's already been incremented. 383 /* special handling is needed for "params->iter", since it's already been incremented.
375 * Could move the invocations to led_task_render, but then it's missing a few checks 384 * Could move the invocations to led_task_render, but then it's missing a few checks
@@ -377,6 +386,7 @@ void led_matrix_indicators_advanced(effect_params_t *params) {
377 * led_task_render, right before the iter++ line. 386 * led_task_render, right before the iter++ line.
378 */ 387 */
379 LED_MATRIX_USE_LIMITS_ITER(min, max, params->iter - 1); 388 LED_MATRIX_USE_LIMITS_ITER(min, max, params->iter - 1);
389 led_matrix_indicators_advanced_modules(min, max);
380 led_matrix_indicators_advanced_kb(min, max); 390 led_matrix_indicators_advanced_kb(min, max);
381} 391}
382 392
diff --git a/quantum/pointing_device/pointing_device.c b/quantum/pointing_device/pointing_device.c
index 5ee65c9c61..564c2d294c 100644
--- a/quantum/pointing_device/pointing_device.c
+++ b/quantum/pointing_device/pointing_device.c
@@ -109,6 +109,11 @@ const pointing_device_driver_t custom_pointing_device_driver = {
109 109
110const pointing_device_driver_t *pointing_device_driver = &POINTING_DEVICE_DRIVER(POINTING_DEVICE_DRIVER_NAME); 110const pointing_device_driver_t *pointing_device_driver = &POINTING_DEVICE_DRIVER(POINTING_DEVICE_DRIVER_NAME);
111 111
112__attribute__((weak)) void pointing_device_init_modules(void) {}
113__attribute__((weak)) report_mouse_t pointing_device_task_modules(report_mouse_t mouse_report) {
114 return mouse_report;
115}
116
112/** 117/**
113 * @brief Keyboard level code pointing device initialisation 118 * @brief Keyboard level code pointing device initialisation
114 * 119 *
@@ -190,6 +195,7 @@ __attribute__((weak)) void pointing_device_init(void) {
190 } 195 }
191#endif 196#endif
192 197
198 pointing_device_init_modules();
193 pointing_device_init_kb(); 199 pointing_device_init_kb();
194 pointing_device_init_user(); 200 pointing_device_init_user();
195} 201}
@@ -319,8 +325,9 @@ __attribute__((weak)) bool pointing_device_task(void) {
319 local_mouse_report = is_keyboard_left() ? pointing_device_task_combined_kb(local_mouse_report, shared_mouse_report) : pointing_device_task_combined_kb(shared_mouse_report, local_mouse_report); 325 local_mouse_report = is_keyboard_left() ? pointing_device_task_combined_kb(local_mouse_report, shared_mouse_report) : pointing_device_task_combined_kb(shared_mouse_report, local_mouse_report);
320#else 326#else
321 local_mouse_report = pointing_device_adjust_by_defines(local_mouse_report); 327 local_mouse_report = pointing_device_adjust_by_defines(local_mouse_report);
322 local_mouse_report = pointing_device_task_kb(local_mouse_report);
323#endif 328#endif
329 local_mouse_report = pointing_device_task_modules(local_mouse_report);
330 local_mouse_report = pointing_device_task_kb(local_mouse_report);
324 // automatic mouse layer function 331 // automatic mouse layer function
325#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE 332#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
326 pointing_device_task_auto_mouse(local_mouse_report); 333 pointing_device_task_auto_mouse(local_mouse_report);
diff --git a/quantum/pointing_device/pointing_device.h b/quantum/pointing_device/pointing_device.h
index d8b583c87e..e7a0819ed9 100644
--- a/quantum/pointing_device/pointing_device.h
+++ b/quantum/pointing_device/pointing_device.h
@@ -17,6 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18#pragma once 18#pragma once
19 19
20#include <stdbool.h>
20#include <stdint.h> 21#include <stdint.h>
21#include "host.h" 22#include "host.h"
22#include "report.h" 23#include "report.h"
diff --git a/quantum/rgb_matrix/rgb_matrix.c b/quantum/rgb_matrix/rgb_matrix.c
index 3fc9085f06..94852e3520 100644
--- a/quantum/rgb_matrix/rgb_matrix.c
+++ b/quantum/rgb_matrix/rgb_matrix.c
@@ -393,7 +393,12 @@ void rgb_matrix_task(void) {
393 } 393 }
394} 394}
395 395
396__attribute__((weak)) bool rgb_matrix_indicators_modules(void) {
397 return true;
398}
399
396void rgb_matrix_indicators(void) { 400void rgb_matrix_indicators(void) {
401 rgb_matrix_indicators_modules();
397 rgb_matrix_indicators_kb(); 402 rgb_matrix_indicators_kb();
398} 403}
399 404
@@ -433,6 +438,10 @@ struct rgb_matrix_limits_t rgb_matrix_get_limits(uint8_t iter) {
433 return limits; 438 return limits;
434} 439}
435 440
441__attribute__((weak)) bool rgb_matrix_indicators_advanced_modules(uint8_t led_min, uint8_t led_max) {
442 return true;
443}
444
436void rgb_matrix_indicators_advanced(effect_params_t *params) { 445void rgb_matrix_indicators_advanced(effect_params_t *params) {
437 /* special handling is needed for "params->iter", since it's already been incremented. 446 /* special handling is needed for "params->iter", since it's already been incremented.
438 * Could move the invocations to rgb_task_render, but then it's missing a few checks 447 * Could move the invocations to rgb_task_render, but then it's missing a few checks
@@ -440,6 +449,7 @@ void rgb_matrix_indicators_advanced(effect_params_t *params) {
440 * rgb_task_render, right before the iter++ line. 449 * rgb_task_render, right before the iter++ line.
441 */ 450 */
442 RGB_MATRIX_USE_LIMITS_ITER(min, max, params->iter - 1); 451 RGB_MATRIX_USE_LIMITS_ITER(min, max, params->iter - 1);
452 rgb_matrix_indicators_advanced_modules(min, max);
443 rgb_matrix_indicators_advanced_kb(min, max); 453 rgb_matrix_indicators_advanced_kb(min, max);
444} 454}
445 455