-
-
Notifications
You must be signed in to change notification settings - Fork 40.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make parameters from info.json available to the build system
- Loading branch information
1 parent
c3221d4
commit 21983f4
Showing
15 changed files
with
592 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
from . import api | ||
from . import config_h | ||
from . import info_json | ||
from . import layouts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
"""Used by the make system to generate info_config.h from info.json. | ||
""" | ||
from milc import cli | ||
|
||
from qmk.decorators import automagic_keyboard, automagic_keymap | ||
from qmk.info import info_json | ||
from qmk.path import is_keyboard, normpath | ||
|
||
usb_properties = { | ||
'vid': 'VENDOR_ID', | ||
'pid': 'PRODUCT_ID', | ||
'device_ver': 'DEVICE_VER', | ||
} | ||
|
||
|
||
@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") | ||
@cli.argument('-kb', '--keyboard', help='Keyboard to generate config.h for.') | ||
@cli.subcommand('Used by the make system to generate info_config.h from info.json', hidden=True) | ||
@automagic_keyboard | ||
@automagic_keymap | ||
def generate_config_h(cli): | ||
"""Generates the info_config.h file. | ||
""" | ||
# Determine our keyboard(s) | ||
if not cli.config.generate_config_h.keyboard: | ||
cli.log.error('Missing paramater: --keyboard') | ||
cli.subcommands['info'].print_help() | ||
return False | ||
|
||
if not is_keyboard(cli.config.generate_config_h.keyboard): | ||
cli.log.error('Invalid keyboard: "%s"', cli.config.generate_config_h.keyboard) | ||
return False | ||
|
||
# Build the info.json file | ||
kb_info_json = info_json(cli.config.generate_config_h.keyboard) | ||
|
||
# Build the info_config.h file. | ||
config_h_lines = ['/* This file was generated by `qmk generate-config-h`. Do not edit or copy.' ' */', '', '#pragma once'] | ||
|
||
if 'diode_direction' in kb_info_json: | ||
config_h_lines.append('') | ||
config_h_lines.append('#ifndef DIODE_DIRECTION') | ||
config_h_lines.append('# define DIODE_DIRECTION ' + kb_info_json['diode_direction']) | ||
config_h_lines.append('#endif // DIODE_DIRECTION') | ||
|
||
if 'keyboard_name' in kb_info_json: | ||
config_h_lines.append('') | ||
config_h_lines.append('#ifndef DESCRIPTION') | ||
config_h_lines.append('# define DESCRIPTION ' + kb_info_json['keyboard_name']) | ||
config_h_lines.append('#endif // DESCRIPTION') | ||
config_h_lines.append('') | ||
config_h_lines.append('#ifndef PRODUCT') | ||
config_h_lines.append('# define PRODUCT ' + kb_info_json['keyboard_name']) | ||
config_h_lines.append('#endif // PRODUCT') | ||
|
||
if 'manufacturer' in kb_info_json: | ||
config_h_lines.append('') | ||
config_h_lines.append('#ifndef MANUFACTURER') | ||
config_h_lines.append('# define MANUFACTURER ' + kb_info_json['manufacturer']) | ||
config_h_lines.append('#endif // MANUFACTURER') | ||
|
||
if 'matrix_pins' in kb_info_json: | ||
if 'cols' in kb_info_json['matrix_pins']: | ||
cols = ','.join(kb_info_json['matrix_pins']['cols']) | ||
col_num = len(kb_info_json['matrix_pins']['cols']) | ||
|
||
config_h_lines.append('') | ||
config_h_lines.append('#ifndef MATRIX_COLS') | ||
config_h_lines.append('# define MATRIX_COLS ' + str(col_num)) | ||
config_h_lines.append('#endif // MATRIX_COLS') | ||
config_h_lines.append('') | ||
config_h_lines.append('#ifndef MATRIX_COL_PINS') | ||
config_h_lines.append('# define MATRIX_COL_PINS { %s }' % (cols,)) | ||
config_h_lines.append('#endif // MATRIX_COL_PINS') | ||
|
||
if 'rows' in kb_info_json['matrix_pins']: | ||
rows = ','.join(kb_info_json['matrix_pins']['rows']) | ||
row_num = len(kb_info_json['matrix_pins']['rows']) | ||
|
||
config_h_lines.append('') | ||
config_h_lines.append('#ifndef MATRIX_ROWS') | ||
config_h_lines.append('# define MATRIX_ROWS ' + str(row_num)) | ||
config_h_lines.append('#endif // MATRIX_ROWS') | ||
config_h_lines.append('') | ||
config_h_lines.append('#ifndef MATRIX_ROW_PINS') | ||
config_h_lines.append('# define MATRIX_ROW_PINS { %s }' % (rows,)) | ||
config_h_lines.append('#endif // MATRIX_ROW_PINS') | ||
|
||
if 'usb' in kb_info_json: | ||
for info_name, config_name in usb_properties.items(): | ||
if info_name in kb_info_json['usb']: | ||
config_h_lines.append('') | ||
config_h_lines.append('#ifndef ' + config_name) | ||
config_h_lines.append('# define %s %s' % (config_name, kb_info_json['usb'][info_name])) | ||
config_h_lines.append('#endif // ' + config_name) | ||
|
||
# Show the results | ||
config_h = '\n'.join(config_h_lines) | ||
|
||
if cli.args.output: | ||
cli.args.output.parent.mkdir(parents=True, exist_ok=True) | ||
if cli.args.output.exists(): | ||
cli.args.output.replace(cli.args.output.name + '.bak') | ||
cli.args.output.write_text(config_h) | ||
|
||
if not cli.args.quiet: | ||
cli.log.info('Wrote info_config.h to %s.', cli.args.output) | ||
|
||
else: | ||
print(config_h) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Keyboard information script. | ||
Compile an info.json for a particular keyboard and pretty-print it. | ||
""" | ||
import json | ||
|
||
from milc import cli | ||
|
||
from qmk.info_json_encoder import InfoJSONEncoder | ||
from qmk.decorators import automagic_keyboard, automagic_keymap | ||
from qmk.info import info_json | ||
from qmk.path import is_keyboard | ||
|
||
|
||
@cli.argument('-kb', '--keyboard', help='Keyboard to show info for.') | ||
@cli.argument('-km', '--keymap', help='Show the layers for a JSON keymap too.') | ||
@cli.subcommand('Generate an info.json file for a keyboard.', hidden=False if cli.config.user.developer else True) | ||
@automagic_keyboard | ||
@automagic_keymap | ||
def generate_info_json(cli): | ||
"""Generate an info.json file for a keyboard | ||
""" | ||
# Determine our keyboard(s) | ||
if not cli.config.generate_info_json.keyboard: | ||
cli.log.error('Missing paramater: --keyboard') | ||
cli.subcommands['info'].print_help() | ||
return False | ||
|
||
if not is_keyboard(cli.config.generate_info_json.keyboard): | ||
cli.log.error('Invalid keyboard: "%s"', cli.config.generate_info_json.keyboard) | ||
return False | ||
|
||
# Build the info.json file | ||
kb_info_json = info_json(cli.config.generate_info_json.keyboard) | ||
pared_down_json = {} | ||
|
||
for key in ('manufacturer', 'maintainer', 'usb', 'keyboard_name', 'width', 'height', 'diode_direction', 'matrix_pins', 'url'): | ||
if key in kb_info_json: | ||
pared_down_json[key] = kb_info_json[key] | ||
|
||
pared_down_json['layouts'] = {} | ||
if 'layouts' in pared_down_json: | ||
for layout_name, layout in kb_info_json['layouts'].items(): | ||
pared_down_json['layouts'][layout_name] = {} | ||
pared_down_json['layouts'][layout_name]['key_count'] = layout.get('key_count', len(layout['layout'])) | ||
pared_down_json['layouts'][layout_name]['layout'] = layout['layout'] | ||
|
||
# Display the results | ||
print(json.dumps(pared_down_json, indent=2, cls=InfoJSONEncoder)) |
Oops, something went wrong.