Skip to content

Commit

Permalink
Fix 'qmk new-keyboard' processing of development_board (qmk#23996)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr authored and pcwa-ahendricks committed Jul 2, 2024
1 parent ae21746 commit e9cca58
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
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}")

0 comments on commit e9cca58

Please sign in to comment.