summaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/cli')
-rw-r--r--lib/python/qmk/cli/__init__.py3
-rw-r--r--lib/python/qmk/cli/doctor/macos.py2
-rw-r--r--lib/python/qmk/cli/flash.py2
-rwxr-xr-xlib/python/qmk/cli/generate/api.py37
-rwxr-xr-xlib/python/qmk/cli/generate/config_h.py36
-rwxr-xr-xlib/python/qmk/cli/generate/info_json.py8
-rw-r--r--lib/python/qmk/cli/import/__init__.py0
-rw-r--r--lib/python/qmk/cli/import/kbfirmware.py25
-rw-r--r--lib/python/qmk/cli/import/keyboard.py23
-rw-r--r--lib/python/qmk/cli/import/keymap.py23
10 files changed, 140 insertions, 19 deletions
diff --git a/lib/python/qmk/cli/__init__.py b/lib/python/qmk/cli/__init__.py
index 02c6d1cbf4..8a507677ef 100644
--- a/lib/python/qmk/cli/__init__.py
+++ b/lib/python/qmk/cli/__init__.py
@@ -59,6 +59,9 @@ subcommands = [
'qmk.cli.generate.rules_mk',
'qmk.cli.generate.version_h',
'qmk.cli.hello',
+ 'qmk.cli.import.kbfirmware',
+ 'qmk.cli.import.keyboard',
+ 'qmk.cli.import.keymap',
'qmk.cli.info',
'qmk.cli.json2c',
'qmk.cli.lint',
diff --git a/lib/python/qmk/cli/doctor/macos.py b/lib/python/qmk/cli/doctor/macos.py
index 00fb272858..5d088c9492 100644
--- a/lib/python/qmk/cli/doctor/macos.py
+++ b/lib/python/qmk/cli/doctor/macos.py
@@ -8,6 +8,6 @@ from .check import CheckStatus
def os_test_macos():
"""Run the Mac specific tests.
"""
- cli.log.info("Detected {fg_cyan}macOS %s{fg_reset}.", platform.mac_ver()[0])
+ cli.log.info("Detected {fg_cyan}macOS %s (%s){fg_reset}.", platform.mac_ver()[0], 'Apple Silicon' if platform.processor() == 'arm' else 'Intel')
return CheckStatus.OK
diff --git a/lib/python/qmk/cli/flash.py b/lib/python/qmk/cli/flash.py
index 216896b974..ebe739c50e 100644
--- a/lib/python/qmk/cli/flash.py
+++ b/lib/python/qmk/cli/flash.py
@@ -33,6 +33,8 @@ def print_bootloader_help():
cli.echo('\tdfu-split-right')
cli.echo('\tdfu-util-split-left')
cli.echo('\tdfu-util-split-right')
+ cli.echo('\tuf2-split-left')
+ cli.echo('\tuf2-split-right')
cli.echo('For more info, visit https://docs.qmk.fm/#/flashing')
diff --git a/lib/python/qmk/cli/generate/api.py b/lib/python/qmk/cli/generate/api.py
index 0596b3f22b..8d8ca3cd41 100755
--- a/lib/python/qmk/cli/generate/api.py
+++ b/lib/python/qmk/cli/generate/api.py
@@ -12,21 +12,30 @@ from qmk.json_encoders import InfoJSONEncoder
from qmk.json_schema import json_load
from qmk.keyboard import find_readme, list_keyboards
-TEMPLATE_PATH = Path('data/templates/api/')
+DATA_PATH = Path('data')
+TEMPLATE_PATH = DATA_PATH / 'templates/api/'
BUILD_API_PATH = Path('.build/api_data/')
+def _filtered_keyboard_list():
+ """Perform basic filtering of list_keyboards
+ """
+ keyboard_list = list_keyboards()
+ if cli.args.filter:
+ kb_list = []
+ for keyboard_name in keyboard_list:
+ if any(i in keyboard_name for i in cli.args.filter):
+ kb_list.append(keyboard_name)
+ keyboard_list = kb_list
+ return keyboard_list
+
+
@cli.argument('-n', '--dry-run', arg_only=True, action='store_true', help="Don't write the data to disk.")
@cli.argument('-f', '--filter', arg_only=True, action='append', default=[], help="Filter the list of keyboards based on partial name matches the supplied value. May be passed multiple times.")
-@cli.subcommand('Creates a new keymap for the keyboard of your choosing', hidden=False if cli.config.user.developer else True)
+@cli.subcommand('Generate QMK API data', hidden=False if cli.config.user.developer else True)
def generate_api(cli):
"""Generates the QMK API data.
"""
- if BUILD_API_PATH.exists():
- shutil.rmtree(BUILD_API_PATH)
-
- shutil.copytree(TEMPLATE_PATH, BUILD_API_PATH)
-
v1_dir = BUILD_API_PATH / 'v1'
keyboard_all_file = v1_dir / 'keyboards.json' # A massive JSON containing everything
keyboard_list_file = v1_dir / 'keyboard_list.json' # A simple list of keyboard targets
@@ -34,14 +43,14 @@ def generate_api(cli):
keyboard_metadata_file = v1_dir / 'keyboard_metadata.json' # All the data configurator/via needs for initialization
usb_file = v1_dir / 'usb.json' # A mapping of USB VID/PID -> keyboard target
+ if BUILD_API_PATH.exists():
+ shutil.rmtree(BUILD_API_PATH)
+
+ shutil.copytree(TEMPLATE_PATH, BUILD_API_PATH)
+ shutil.copytree(DATA_PATH, v1_dir)
+
# Filter down when required
- keyboard_list = list_keyboards()
- if cli.args.filter:
- kb_list = []
- for keyboard_name in keyboard_list:
- if any(i in keyboard_name for i in cli.args.filter):
- kb_list.append(keyboard_name)
- keyboard_list = kb_list
+ keyboard_list = _filtered_keyboard_list()
kb_all = {}
usb_list = {}
diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py
index 893892c479..a26dcdf7d7 100755
--- a/lib/python/qmk/cli/generate/config_h.py
+++ b/lib/python/qmk/cli/generate/config_h.py
@@ -134,6 +134,36 @@ def generate_config_items(kb_info_json, config_h_lines):
config_h_lines.append(f'#endif // {config_key}')
+def generate_encoder_config(encoder_json, config_h_lines, postfix=''):
+ """Generate the config.h lines for encoders."""
+ a_pads = []
+ b_pads = []
+ resolutions = []
+ for encoder in encoder_json.get("rotary", []):
+ a_pads.append(encoder["pin_a"])
+ b_pads.append(encoder["pin_b"])
+ resolutions.append(encoder.get("resolution", None))
+
+ config_h_lines.append(f'#ifndef ENCODERS_PAD_A{postfix}')
+ config_h_lines.append(f'# define ENCODERS_PAD_A{postfix} {{ { ", ".join(a_pads) } }}')
+ config_h_lines.append(f'#endif // ENCODERS_PAD_A{postfix}')
+
+ config_h_lines.append(f'#ifndef ENCODERS_PAD_B{postfix}')
+ config_h_lines.append(f'# define ENCODERS_PAD_B{postfix} {{ { ", ".join(b_pads) } }}')
+ config_h_lines.append(f'#endif // ENCODERS_PAD_B{postfix}')
+
+ if None in resolutions:
+ cli.log.debug("Unable to generate ENCODER_RESOLUTION configuration")
+ elif len(set(resolutions)) == 1:
+ config_h_lines.append(f'#ifndef ENCODER_RESOLUTION{postfix}')
+ config_h_lines.append(f'# define ENCODER_RESOLUTION{postfix} { resolutions[0] }')
+ config_h_lines.append(f'#endif // ENCODER_RESOLUTION{postfix}')
+ else:
+ config_h_lines.append(f'#ifndef ENCODER_RESOLUTIONS{postfix}')
+ config_h_lines.append(f'# define ENCODER_RESOLUTIONS{postfix} {{ { ", ".join(map(str,resolutions)) } }}')
+ config_h_lines.append(f'#endif // ENCODER_RESOLUTIONS{postfix}')
+
+
def generate_split_config(kb_info_json, config_h_lines):
"""Generate the config.h lines for split boards."""
if 'primary' in kb_info_json['split']:
@@ -173,6 +203,9 @@ def generate_split_config(kb_info_json, config_h_lines):
if 'right' in kb_info_json['split'].get('matrix_pins', {}):
config_h_lines.append(matrix_pins(kb_info_json['split']['matrix_pins']['right'], '_RIGHT'))
+ if 'right' in kb_info_json['split'].get('encoder', {}):
+ generate_encoder_config(kb_info_json['split']['encoder']['right'], config_h_lines, '_RIGHT')
+
@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
@@ -198,6 +231,9 @@ def generate_config_h(cli):
if 'matrix_pins' in kb_info_json:
config_h_lines.append(matrix_pins(kb_info_json['matrix_pins']))
+ if 'encoder' in kb_info_json:
+ generate_encoder_config(kb_info_json['encoder'], config_h_lines)
+
if 'split' in kb_info_json:
generate_split_config(kb_info_json, config_h_lines)
diff --git a/lib/python/qmk/cli/generate/info_json.py b/lib/python/qmk/cli/generate/info_json.py
index 284d1a8510..0dc80f10cc 100755
--- a/lib/python/qmk/cli/generate/info_json.py
+++ b/lib/python/qmk/cli/generate/info_json.py
@@ -5,7 +5,7 @@ Compile an info.json for a particular keyboard and pretty-print it.
import json
from argcomplete.completers import FilesCompleter
-from jsonschema import Draft7Validator, RefResolver, validators
+from jsonschema import Draft202012Validator, RefResolver, validators
from milc import cli
from pathlib import Path
@@ -18,7 +18,7 @@ from qmk.path import is_keyboard, normpath
def pruning_validator(validator_class):
- """Extends Draft7Validator to remove properties that aren't specified in the schema.
+ """Extends Draft202012Validator to remove properties that aren't specified in the schema.
"""
validate_properties = validator_class.VALIDATORS["properties"]
@@ -37,10 +37,10 @@ def strip_info_json(kb_info_json):
"""Remove the API-only properties from the info.json.
"""
schema_store = compile_schema_store()
- pruning_draft_7_validator = pruning_validator(Draft7Validator)
+ pruning_draft_validator = pruning_validator(Draft202012Validator)
schema = schema_store['qmk.keyboard.v1']
resolver = RefResolver.from_schema(schema_store['qmk.keyboard.v1'], store=schema_store)
- validator = pruning_draft_7_validator(schema, resolver=resolver).validate
+ validator = pruning_draft_validator(schema, resolver=resolver).validate
return validator(kb_info_json)
diff --git a/lib/python/qmk/cli/import/__init__.py b/lib/python/qmk/cli/import/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/lib/python/qmk/cli/import/__init__.py
diff --git a/lib/python/qmk/cli/import/kbfirmware.py b/lib/python/qmk/cli/import/kbfirmware.py
new file mode 100644
index 0000000000..9c03737378
--- /dev/null
+++ b/lib/python/qmk/cli/import/kbfirmware.py
@@ -0,0 +1,25 @@
+from milc import cli
+
+from qmk.importers import import_kbfirmware as _import_kbfirmware
+from qmk.path import FileType
+from qmk.json_schema import json_load
+
+
+@cli.argument('filename', type=FileType('r'), nargs='+', arg_only=True, help='file')
+@cli.subcommand('Import kbfirmware json export')
+def import_kbfirmware(cli):
+ filename = cli.args.filename[0]
+
+ data = json_load(filename)
+
+ cli.log.info(f'{{style_bright}}Importing {filename.name}.{{style_normal}}')
+ cli.echo('')
+
+ cli.log.warn("Support here is basic - Consider using 'qmk new-keyboard' instead")
+
+ kb_name = _import_kbfirmware(data)
+
+ cli.log.info(f'{{fg_green}}Imported a new keyboard named {{fg_cyan}}{kb_name}{{fg_green}}.{{fg_reset}}')
+ cli.log.info(f'To start working on things, `cd` into {{fg_cyan}}keyboards/{kb_name}{{fg_reset}},')
+ cli.log.info('or open the directory in your preferred text editor.')
+ cli.log.info(f"And build with {{fg_yellow}}qmk compile -kb {kb_name} -km default{{fg_reset}}.")
diff --git a/lib/python/qmk/cli/import/keyboard.py b/lib/python/qmk/cli/import/keyboard.py
new file mode 100644
index 0000000000..3a5ed37dee
--- /dev/null
+++ b/lib/python/qmk/cli/import/keyboard.py
@@ -0,0 +1,23 @@
+from milc import cli
+
+from qmk.importers import import_keyboard as _import_keyboard
+from qmk.path import FileType
+from qmk.json_schema import json_load
+
+
+@cli.argument('filename', type=FileType('r'), nargs='+', arg_only=True, help='file')
+@cli.subcommand('Import data-driven keyboard')
+def import_keyboard(cli):
+ filename = cli.args.filename[0]
+
+ data = json_load(filename)
+
+ cli.log.info(f'{{style_bright}}Importing {filename.name}.{{style_normal}}')
+ cli.echo('')
+
+ kb_name = _import_keyboard(data)
+
+ cli.log.info(f'{{fg_green}}Imported a new keyboard named {{fg_cyan}}{kb_name}{{fg_green}}.{{fg_reset}}')
+ cli.log.info(f'To start working on things, `cd` into {{fg_cyan}}keyboards/{kb_name}{{fg_reset}},')
+ cli.log.info('or open the directory in your preferred text editor.')
+ cli.log.info(f"And build with {{fg_yellow}}qmk compile -kb {kb_name} -km default{{fg_reset}}.")
diff --git a/lib/python/qmk/cli/import/keymap.py b/lib/python/qmk/cli/import/keymap.py
new file mode 100644
index 0000000000..a499c93480
--- /dev/null
+++ b/lib/python/qmk/cli/import/keymap.py
@@ -0,0 +1,23 @@
+from milc import cli
+
+from qmk.importers import import_keymap as _import_keymap
+from qmk.path import FileType
+from qmk.json_schema import json_load
+
+
+@cli.argument('filename', type=FileType('r'), nargs='+', arg_only=True, help='file')
+@cli.subcommand('Import data-driven keymap')
+def import_keymap(cli):
+ filename = cli.args.filename[0]
+
+ data = json_load(filename)
+
+ cli.log.info(f'{{style_bright}}Importing {filename.name}.{{style_normal}}')
+ cli.echo('')
+
+ kb_name, km_name = _import_keymap(data)
+
+ cli.log.info(f'{{fg_green}}Imported a new keymap named {{fg_cyan}}{km_name}{{fg_green}}.{{fg_reset}}')
+ cli.log.info(f'To start working on things, `cd` into {{fg_cyan}}keyboards/{kb_name}/keymaps/{km_name}{{fg_reset}},')
+ cli.log.info('or open the directory in your preferred text editor.')
+ cli.log.info(f"And build with {{fg_yellow}}qmk compile -kb {kb_name} -km {km_name}{{fg_reset}}.")