qmk_firmware/lib/python/qmk/cli/xap/generate_qmk.py
Nick Brassel c2e95c8522
Squashed commit of the following:
commit d614bc5f62f3c2efc5c5cc0f38168a67681e6fb5
Author: Nick Brassel <nick@tzarc.org>
Date:   Sun Oct 16 13:17:03 2022 +1100

    Remove old header generator.

commit 08337b814cfcef57a1f6b41acf06b806ad4bb116
Author: Nick Brassel <nick@tzarc.org>
Date:   Sat Oct 15 11:47:20 2022 +1100

    Restart jinja2 generation for firmware-side output.
2022-10-16 13:19:15 +11:00

80 lines
3.6 KiB
Python
Executable File

"""This script generates the XAP protocol generated sources to be compiled into QMK firmware.
"""
from milc import cli
from qmk.path import normpath
from qmk.keyboard import keyboard_completer, keyboard_folder
from qmk.xap.common import render_xap_output
from qmk.xap.gen_firmware.blob_generator import generate_blob
from qmk.xap.gen_firmware.inline_generator import generate_inline
@cli.argument('-o', '--output', type=normpath, help='File to write to')
@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Name of the keyboard')
@cli.argument('-km', '--keymap', help='The keymap\'s name')
@cli.subcommand('Generates the XAP protocol include.', hidden=False if cli.config.user.developer else True)
def xap_generate_qmk_inc(cli):
"""Generates the XAP protocol inline codegen file, generated during normal build.
"""
# Determine our keyboard/keymap
if not cli.args.keyboard:
cli.log.error('Missing parameter: --keyboard')
cli.subcommands['xap-generate-qmk-inc'].print_help()
return False
if not cli.args.keymap:
cli.log.error('Missing parameter: --keymap')
cli.subcommands['xap-generate-qmk-inc'].print_help()
return False
generate_inline(cli.args.output, cli.args.keyboard, cli.args.keymap)
with open(normpath(str(cli.args.output.resolve()) + '.generated.j2'), 'w', encoding='utf-8') as out_file:
r = render_xap_output('firmware', 'xap_generated.inl.j2', keyboard=cli.args.keyboard, keymap=cli.args.keymap)
while r.find('\n\n\n') != -1:
r = r.replace('\n\n\n', '\n\n')
out_file.write(r)
@cli.argument('-o', '--output', type=normpath, help='File to write to')
@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Name of the keyboard')
@cli.argument('-km', '--keymap', help='The keymap\'s name')
@cli.subcommand('Generates the XAP protocol include.', hidden=False if cli.config.user.developer else True)
def xap_generate_qmk_h(cli):
"""Generates the XAP protocol header file, generated during normal build.
"""
# Determine our keyboard/keymap
if not cli.args.keyboard:
cli.log.error('Missing parameter: --keyboard')
cli.subcommands['xap-generate-qmk-h'].print_help()
return False
if not cli.args.keymap:
cli.log.error('Missing parameter: --keymap')
cli.subcommands['xap-generate-qmk-h'].print_help()
return False
with open(cli.args.output, 'w', encoding='utf-8') as out_file:
r = render_xap_output('firmware', 'xap_generated.h.j2', keyboard=cli.args.keyboard, keymap=cli.args.keymap)
while r.find('\n\n\n') != -1:
r = r.replace('\n\n\n', '\n\n')
out_file.write(r)
@cli.argument('-o', '--output', type=normpath, help='File to write to')
@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Name of the keyboard')
@cli.argument('-km', '--keymap', help='The keymap\'s name')
@cli.subcommand('Generates the XAP config payload include.', hidden=False if cli.config.user.developer else True)
def xap_generate_qmk_blob_h(cli):
"""Generates the XAP config payload header file, generated during normal build.
"""
# Determine our keyboard/keymap
if not cli.args.keyboard:
cli.log.error('Missing parameter: --keyboard')
cli.subcommands['xap-generate-qmk-blob-h'].print_help()
return False
if not cli.args.keymap:
cli.log.error('Missing parameter: --keymap')
cli.subcommands['xap-generate-qmk-blob-h'].print_help()
return False
generate_blob(cli.args.output, cli.args.keyboard, cli.args.keymap)