More APIs added, versioning.
This commit is contained in:
parent
11b9ff0c4f
commit
8f79ed1f23
8 changed files with 106 additions and 14 deletions
|
|
@ -18,10 +18,15 @@ class ModuleAPI(AttrDict):
|
|||
MODULE_API_LIST = [
|
||||
ModuleAPI(ret_type='void', name='keyboard_pre_init', args='void', call_params='', ret_val=None),
|
||||
ModuleAPI(ret_type='void', name='keyboard_post_init', args='void', call_params='', ret_val=None),
|
||||
ModuleAPI(ret_type='void', name='housekeeping_task', args='void', call_params='', ret_val=None),
|
||||
ModuleAPI(ret_type='bool', name='pre_process_record', args='uint16_t keycode, keyrecord_t *record', call_params='keycode, record', ret_val='true'),
|
||||
ModuleAPI(ret_type='bool', name='process_record', args='uint16_t keycode, keyrecord_t *record', call_params='keycode, record', ret_val='true'),
|
||||
ModuleAPI(ret_type='void', name='post_process_record', args='uint16_t keycode, keyrecord_t *record', call_params='keycode, record', ret_val=None),
|
||||
ModuleAPI(ret_type='void', name='housekeeping_task', args='void', call_params='', ret_val=None),
|
||||
ModuleAPI(ret_type='bool', name='shutdown', args='bool jump_to_bootloader', call_params='jump_to_bootloader', ret_val='true'),
|
||||
]
|
||||
|
||||
MODULE_API_VERSION = '20250122'
|
||||
|
||||
|
||||
@cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to')
|
||||
@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
|
||||
|
|
@ -33,13 +38,31 @@ def generate_community_modules_h(cli):
|
|||
if cli.args.output and cli.args.output.name == '-':
|
||||
cli.args.output = None
|
||||
|
||||
lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#pragma once', '']
|
||||
lines = [
|
||||
GPL2_HEADER_C_LIKE,
|
||||
GENERATED_HEADER_C_LIKE,
|
||||
'#pragma once',
|
||||
'#include <stdint.h>',
|
||||
'#include <stdbool.h>',
|
||||
'',
|
||||
f'#define COMMUNITY_MODULES_API_VERSION {MODULE_API_VERSION}',
|
||||
f'#define ASSERT_COMMUNITY_MODULES_API_VERSION(x) _Static_assert((x) <= COMMUNITY_MODULES_API_VERSION, "Modules API mismatch, module requires higher version of QMK with API >= {MODULE_API_VERSION}.")',
|
||||
'',
|
||||
'typedef struct keyrecord_t keyrecord_t;',
|
||||
]
|
||||
keymap_json = parse_configurator_json(cli.args.filename)
|
||||
if keymap_json and 'modules' in keymap_json:
|
||||
for module in keymap_json['modules']:
|
||||
lines.append('')
|
||||
lines.append(f'// From module: {module}')
|
||||
for api in MODULE_API_LIST:
|
||||
lines.append(f'{api.ret_type} {api.name}_{module}({api.args});')
|
||||
dump_lines(cli.args.output, lines, cli.args.quiet)
|
||||
lines.append('')
|
||||
|
||||
lines.append(f'// Parent implementation')
|
||||
for api in MODULE_API_LIST:
|
||||
lines.append(f'{api.ret_type} {api.name}_modules({api.args});')
|
||||
dump_lines(cli.args.output, lines, cli.args.quiet, remove_repeated_newlines=True)
|
||||
|
||||
|
||||
@cli.argument('-o', '--output', arg_only=True, type=qmk.path.normpath, help='File to write to')
|
||||
|
|
@ -52,13 +75,14 @@ def generate_community_modules_c(cli):
|
|||
if cli.args.output and cli.args.output.name == '-':
|
||||
cli.args.output = None
|
||||
|
||||
lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#include QMK_KEYBOARD_H', '#include "community_modules.h"']
|
||||
lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '', '#include "community_modules.h"']
|
||||
keymap_json = parse_configurator_json(cli.args.filename)
|
||||
if keymap_json and 'modules' in keymap_json:
|
||||
for module in keymap_json['modules']:
|
||||
lines.append('')
|
||||
for api in MODULE_API_LIST:
|
||||
lines.append('')
|
||||
lines.append(f'__attribute__((weak)) {api.ret_type} {api.name}_{module}({api.args}) {{ ')
|
||||
lines.append(f'__attribute__((weak)) {api.ret_type} {api.name}_{module}({api.args}) {{')
|
||||
if api.ret_val:
|
||||
lines.append(f' return {api.ret_val};')
|
||||
lines.append('}')
|
||||
|
|
@ -76,4 +100,4 @@ def generate_community_modules_c(cli):
|
|||
if api.ret_type == 'bool':
|
||||
lines.append(' ;')
|
||||
lines.append('}')
|
||||
dump_lines(cli.args.output, lines, cli.args.quiet)
|
||||
dump_lines(cli.args.output, lines, cli.args.quiet, remove_repeated_newlines=True)
|
||||
|
|
|
|||
|
|
@ -101,10 +101,12 @@ def generate_rules_mk(cli):
|
|||
rules_mk_lines.append(generate_rule('CONVERT_TO', converter))
|
||||
|
||||
if user_keymap and 'modules' in user_keymap:
|
||||
rules_mk_lines.append('')
|
||||
rules_mk_lines.append('OPT_DEFS += -DCOMMUNITY_MODULES_ENABLED=TRUE')
|
||||
for module in user_keymap['modules']:
|
||||
rules_mk_lines.append('')
|
||||
rules_mk_lines.append(f'COMMUNITY_MODULES += {module}')
|
||||
rules_mk_lines.append(f'OPT_DEFS += -DMODULE_{module.upper()}=TRUE')
|
||||
rules_mk_lines.append(f'OPT_DEFS += -DCOMMUNITY_MODULE_{module.upper()}=TRUE')
|
||||
rules_mk_lines.append(f'VPATH += modules/{module}')
|
||||
rules_mk_lines.append(f'include modules/{module}/rules.mk')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue