Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'qmk new-keyboard' processing of development_board #23996

Merged
merged 2 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions data/templates/keyboard/keyboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
"keyboard_name": "%KEYBOARD%",
"maintainer": "%USER_NAME%",
"manufacturer": "%REAL_NAME%",
"processor": "%MCU%",
"bootloader": "%BOOTLOADER%",
"diode_direction": "COL2ROW",
"matrix_pins": {
"cols": ["C2"],
Expand Down
34 changes: 12 additions & 22 deletions lib/python/qmk/cli/new/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from qmk.json_schema import load_jsonschema
from qmk.path import keyboard
from qmk.json_encoders import InfoJSONEncoder
from qmk.json_schema import deep_update, json_load
from qmk.json_schema import deep_update
from qmk.constants import MCU2BOOTLOADER, QMK_FIRMWARE

COMMUNITY = Path('layouts/default/')
Expand Down Expand Up @@ -78,14 +78,15 @@ def replace_string(src, token, value):
src.write_text(src.read_text().replace(token, value))


def augment_community_info(src, dest):
def augment_community_info(config, src, dest):
"""Splice in any additional data into info.json
"""
info = json.loads(src.read_text())
template = json.loads(dest.read_text())

# merge community with template
deep_update(info, template)
deep_update(info, config)

# avoid assumptions on macro name by using the first available
first_layout = next(iter(info["layouts"].values()))["layout"]
Expand All @@ -105,7 +106,7 @@ def augment_community_info(src, dest):
for item in first_layout:
item["matrix"] = [int(item["y"]), int(item["x"])]

# finally write out the updated info.json
# finally write out the updated json
dest.write_text(json.dumps(info, cls=InfoJSONEncoder, sort_keys=True))


Expand Down Expand Up @@ -212,15 +213,12 @@ def new_keyboard(cli):
default_layout = cli.args.layout if cli.args.layout else prompt_layout()
mcu = cli.args.type if cli.args.type else prompt_mcu()

# Preprocess any development_board presets
config = {}
if mcu in dev_boards:
defaults_map = json_load(Path('data/mappings/defaults.hjson'))
board = defaults_map['development_board'][mcu]

mcu = board['processor']
bootloader = board['bootloader']
config['development_board'] = mcu
else:
bootloader = select_default_bootloader(mcu)
config['processor'] = mcu
config['bootloader'] = select_default_bootloader(mcu)

detach_layout = False
if default_layout == 'none of the above':
Expand All @@ -231,17 +229,9 @@ def new_keyboard(cli):
'YEAR': str(date.today().year),
'KEYBOARD': kb_name,
'USER_NAME': user_name,
'REAL_NAME': real_name,
'LAYOUT': default_layout,
'MCU': mcu,
'BOOTLOADER': bootloader
'REAL_NAME': real_name
}

if cli.config.general.verbose:
cli.log.info("Creating keyboard with:")
for key, value in tokens.items():
cli.echo(f" {key.ljust(10)}: {value}")

# begin with making the deepest folder in the tree
keymaps_path = keyboard(kb_name) / 'keymaps/'
keymaps_path.mkdir(parents=True)
Expand All @@ -256,7 +246,7 @@ def new_keyboard(cli):

# merge in infos
community_info = Path(COMMUNITY / f'{default_layout}/info.json')
augment_community_info(community_info, keyboard(kb_name) / 'keyboard.json')
augment_community_info(config, community_info, keyboard(kb_name) / 'keyboard.json')

# detach community layout and rename to just "LAYOUT"
if detach_layout:
Expand All @@ -265,5 +255,5 @@ def new_keyboard(cli):

cli.log.info(f'{{fg_green}}Created a new keyboard called {{fg_cyan}}{kb_name}{{fg_green}}.{{fg_reset}}')
cli.log.info(f"Build Command: {{fg_yellow}}qmk compile -kb {kb_name} -km default{{fg_reset}}.")
cli.log.info(f'Project Location: {{fg_cyan}}{QMK_FIRMWARE}/{keyboard(kb_name)}{{fg_reset}},')
cli.log.info("{{fg_yellow}}Now update the config files to match the hardware!{{fg_reset}}")
cli.log.info(f'Project Location: {{fg_cyan}}{QMK_FIRMWARE}/{keyboard(kb_name)}{{fg_reset}}.')
cli.log.info("{fg_yellow}Now update the config files to match the hardware!{fg_reset}")
Loading