2021-08-11 11:08:32 +00:00
|
|
|
"""This script generates the XAP protocol documentation.
|
|
|
|
"""
|
2022-02-15 23:53:35 +00:00
|
|
|
import hjson
|
2022-10-16 19:24:37 +00:00
|
|
|
|
|
|
|
from milc import cli
|
|
|
|
|
2022-02-15 23:53:35 +00:00
|
|
|
from qmk.constants import QMK_FIRMWARE
|
|
|
|
from qmk.xap.common import get_xap_definition_files, update_xap_definitions, render_xap_output
|
2021-08-11 11:08:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
@cli.subcommand('Generates the XAP protocol documentation.', hidden=False if cli.config.user.developer else True)
|
|
|
|
def xap_generate_docs(cli):
|
|
|
|
"""Generates the XAP protocol documentation by merging the definitions files, and producing the corresponding Markdown document under `/docs/`.
|
|
|
|
"""
|
2022-10-16 19:24:37 +00:00
|
|
|
versions = []
|
2022-02-15 23:53:35 +00:00
|
|
|
|
|
|
|
overall = None
|
|
|
|
for file in get_xap_definition_files():
|
|
|
|
overall = update_xap_definitions(overall, hjson.load(file.open(encoding='utf-8')))
|
|
|
|
|
|
|
|
# Inject dummy bits for unspecified response flags
|
|
|
|
for n in range(0, 8):
|
|
|
|
if str(n) not in overall['response_flags']['bits']:
|
|
|
|
overall['response_flags']['bits'][str(n)] = {'name': '', 'description': '', 'define': '-'}
|
|
|
|
|
|
|
|
output_doc = QMK_FIRMWARE / "docs" / f"{file.stem}.md"
|
2022-10-16 19:24:37 +00:00
|
|
|
versions.append(overall['version'])
|
2022-02-15 23:53:35 +00:00
|
|
|
output = render_xap_output('docs', 'docs.md.j2', overall)
|
|
|
|
with open(output_doc, "w", encoding='utf-8') as out_file:
|
|
|
|
out_file.write(output)
|
|
|
|
|
2022-03-16 00:10:30 +00:00
|
|
|
output_doc = QMK_FIRMWARE / "docs" / "xap_protocol.md"
|
2022-10-16 19:24:37 +00:00
|
|
|
output = render_xap_output('docs', 'versions.md.j2', overall, versions=versions)
|
2022-02-15 23:53:35 +00:00
|
|
|
with open(output_doc, "w", encoding='utf-8') as out_file:
|
2022-10-16 19:24:37 +00:00
|
|
|
out_file.write(output)
|