You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

894 lines
33 KiB

Add a lot more data to info.json (#13366) * add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
Add a lot more data to info.json (#13366) * add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
Add a lot more data to info.json (#13366) * add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
Add a lot more data to info.json (#13366) * add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
Add a lot more data to info.json (#13366) * add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
Add a lot more data to info.json (#13366) * add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
Add a lot more data to info.json (#13366) * add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
Add a lot more data to info.json (#13366) * add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
Add a lot more data to info.json (#13366) * add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
Add a lot more data to info.json (#13366) * add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
Add a lot more data to info.json (#13366) * add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
Add a lot more data to info.json (#13366) * add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
Add a lot more data to info.json (#13366) * add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
Add a lot more data to info.json (#13366) * add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
Add a lot more data to info.json (#13366) * add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
2 years ago
  1. """Functions that help us generate and use info.json files.
  2. """
  3. from pathlib import Path
  4. import jsonschema
  5. from dotty_dict import dotty
  6. from milc import cli
  7. from qmk.constants import CHIBIOS_PROCESSORS, LUFA_PROCESSORS, VUSB_PROCESSORS
  8. from qmk.c_parse import find_layouts, parse_config_h_file, find_led_config
  9. from qmk.json_schema import deep_update, json_load, validate
  10. from qmk.keyboard import config_h, rules_mk
  11. from qmk.keymap import list_keymaps, locate_keymap
  12. from qmk.commands import parse_configurator_json
  13. from qmk.makefile import parse_rules_mk_file
  14. from qmk.math import compute
  15. true_values = ['1', 'on', 'yes']
  16. false_values = ['0', 'off', 'no']
  17. # TODO: reduce this list down
  18. SAFE_LAYOUT_TOKENS = {
  19. 'ansi',
  20. 'iso',
  21. 'wkl',
  22. 'tkl',
  23. 'preonic',
  24. 'planck',
  25. }
  26. def _valid_community_layout(layout):
  27. """Validate that a declared community list exists
  28. """
  29. return (Path('layouts/default') / layout).exists()
  30. def _validate(keyboard, info_data):
  31. """Perform various validation on the provided info.json data
  32. """
  33. # First validate against the jsonschema
  34. try:
  35. validate(info_data, 'qmk.api.keyboard.v1')
  36. except jsonschema.ValidationError as e:
  37. json_path = '.'.join([str(p) for p in e.absolute_path])
  38. cli.log.error('Invalid API data: %s: %s: %s', keyboard, json_path, e.message)
  39. exit(1)
  40. layouts = info_data.get('layouts', {})
  41. layout_aliases = info_data.get('layout_aliases', {})
  42. community_layouts = info_data.get('community_layouts', [])
  43. community_layouts_names = list(map(lambda layout: f'LAYOUT_{layout}', community_layouts))
  44. # Make sure we have at least one layout
  45. if len(layouts) == 0:
  46. _log_error(info_data, 'No LAYOUTs defined! Need at least one layout defined in info.json.')
  47. # Providing only LAYOUT_all "because I define my layouts in a 3rd party tool"
  48. if len(layouts) == 1 and 'LAYOUT_all' in layouts:
  49. _log_warning(info_data, '"LAYOUT_all" should be "LAYOUT" unless additional layouts are provided.')
  50. # Extended layout name checks - ignoring community_layouts and "safe" values
  51. name_fragments = set(keyboard.split('/')) - SAFE_LAYOUT_TOKENS
  52. potential_layouts = set(layouts.keys()) - set(community_layouts_names)
  53. for layout in potential_layouts:
  54. if any(fragment in layout for fragment in name_fragments):
  55. _log_warning(info_data, f'Layout "{layout}" should not contain name of keyboard.')
  56. # Filter out any non-existing community layouts
  57. for layout in community_layouts:
  58. if not _valid_community_layout(layout):
  59. # Ignore layout from future checks
  60. info_data['community_layouts'].remove(layout)
  61. _log_error(info_data, 'Claims to support a community layout that does not exist: %s' % (layout))
  62. # Make sure we supply layout macros for the community layouts we claim to support
  63. for layout_name in community_layouts_names:
  64. if layout_name not in layouts and layout_name not in layout_aliases:
  65. _log_error(info_data, 'Claims to support community layout %s but no %s() macro found' % (layout, layout_name))
  66. def info_json(keyboard):
  67. """Generate the info.json data for a specific keyboard.
  68. """
  69. cur_dir = Path('keyboards')
  70. root_rules_mk = parse_rules_mk_file(cur_dir / keyboard / 'rules.mk')
  71. if 'DEFAULT_FOLDER' in root_rules_mk:
  72. keyboard = root_rules_mk['DEFAULT_FOLDER']
  73. info_data = {
  74. 'keyboard_name': str(keyboard),
  75. 'keyboard_folder': str(keyboard),
  76. 'keymaps': {},
  77. 'layouts': {},
  78. 'parse_errors': [],
  79. 'parse_warnings': [],
  80. 'maintainer': 'qmk',
  81. }
  82. # Populate the list of JSON keymaps
  83. for keymap in list_keymaps(keyboard, c=False, fullpath=True):
  84. info_data['keymaps'][keymap.name] = {'url': f'https://raw.githubusercontent.com/qmk/qmk_firmware/master/{keymap}/keymap.json'}
  85. # Populate layout data
  86. layouts, aliases = _search_keyboard_h(keyboard)
  87. if aliases:
  88. info_data['layout_aliases'] = aliases
  89. for layout_name, layout_json in layouts.items():
  90. if not layout_name.startswith('LAYOUT_kc'):
  91. layout_json['c_macro'] = True
  92. info_data['layouts'][layout_name] = layout_json
  93. # Merge in the data from info.json, config.h, and rules.mk
  94. info_data = merge_info_jsons(keyboard, info_data)
  95. info_data = _process_defaults(info_data)
  96. info_data = _extract_rules_mk(info_data, rules_mk(str(keyboard)))
  97. info_data = _extract_config_h(info_data, config_h(str(keyboard)))
  98. # Ensure that we have matrix row and column counts
  99. info_data = _matrix_size(info_data)
  100. # Merge in data from <keyboard.c>
  101. info_data = _extract_led_config(info_data, str(keyboard))
  102. # Validate
  103. _validate(keyboard, info_data)
  104. # Check that the reported matrix size is consistent with the actual matrix size
  105. _check_matrix(info_data)
  106. return info_data
  107. def _extract_features(info_data, rules):
  108. """Find all the features enabled in rules.mk.
  109. """
  110. # Process booleans rules
  111. for key, value in rules.items():
  112. if key.endswith('_ENABLE'):
  113. key = '_'.join(key.split('_')[:-1]).lower()
  114. value = True if value.lower() in true_values else False if value.lower() in false_values else value
  115. if 'config_h_features' not in info_data:
  116. info_data['config_h_features'] = {}
  117. if 'features' not in info_data:
  118. info_data['features'] = {}
  119. if key in info_data['features']:
  120. _log_warning(info_data, 'Feature %s is specified in both info.json and rules.mk, the rules.mk value wins.' % (key,))
  121. info_data['features'][key] = value
  122. info_data['config_h_features'][key] = value
  123. return info_data
  124. def _pin_name(pin):
  125. """Returns the proper representation for a pin.
  126. """
  127. pin = pin.strip()
  128. if not pin:
  129. return None
  130. elif pin.isdigit():
  131. return int(pin)
  132. elif pin == 'NO_PIN':
  133. return None
  134. return pin
  135. def _extract_pins(pins):
  136. """Returns a list of pins from a comma separated string of pins.
  137. """
  138. return [_pin_name(pin) for pin in pins.split(',')]
  139. def _extract_2d_array(raw):
  140. """Return a 2d array of strings
  141. """
  142. out_array = []
  143. while raw[-1] != '}':
  144. raw = raw[:-1]
  145. for row in raw.split('},{'):
  146. if row.startswith('{'):
  147. row = row[1:]
  148. if row.endswith('}'):
  149. row = row[:-1]
  150. out_array.append([])
  151. for val in row.split(','):
  152. out_array[-1].append(val)
  153. return out_array
  154. def _extract_2d_int_array(raw):
  155. """Return a 2d array of ints
  156. """
  157. ret = _extract_2d_array(raw)
  158. return [list(map(int, x)) for x in ret]
  159. def _extract_direct_matrix(direct_pins):
  160. """extract direct_matrix
  161. """
  162. direct_pin_array = _extract_2d_array(direct_pins)
  163. for i in range(len(direct_pin_array)):
  164. for j in range(len(direct_pin_array[i])):
  165. if direct_pin_array[i][j] == 'NO_PIN':
  166. direct_pin_array[i][j] = None
  167. return direct_pin_array
  168. def _extract_audio(info_data, config_c):
  169. """Populate data about the audio configuration
  170. """
  171. audio_pins = []
  172. for pin in 'B5', 'B6', 'B7', 'C4', 'C5', 'C6':
  173. if config_c.get(f'{pin}_AUDIO'):
  174. audio_pins.append(pin)
  175. if audio_pins:
  176. info_data['audio'] = {'pins': audio_pins}
  177. def _extract_encoders_values(config_c, postfix=''):
  178. """Common encoder extraction logic
  179. """
  180. a_pad = config_c.get(f'ENCODERS_PAD_A{postfix}', '').replace(' ', '')[1:-1]
  181. b_pad = config_c.get(f'ENCODERS_PAD_B{postfix}', '').replace(' ', '')[1:-1]
  182. resolutions = config_c.get(f'ENCODER_RESOLUTIONS{postfix}', '').replace(' ', '')[1:-1]
  183. default_resolution = config_c.get('ENCODER_RESOLUTION', None)
  184. if a_pad and b_pad:
  185. a_pad = list(filter(None, a_pad.split(',')))
  186. b_pad = list(filter(None, b_pad.split(',')))
  187. resolutions = list(filter(None, resolutions.split(',')))
  188. if default_resolution:
  189. resolutions += [default_resolution] * (len(a_pad) - len(resolutions))
  190. encoders = []
  191. for index in range(len(a_pad)):
  192. encoder = {'pin_a': a_pad[index], 'pin_b': b_pad[index]}
  193. if index < len(resolutions):
  194. encoder['resolution'] = int(resolutions[index])
  195. encoders.append(encoder)
  196. return encoders
  197. def _extract_encoders(info_data, config_c):
  198. """Populate data about encoder pins
  199. """
  200. encoders = _extract_encoders_values(config_c)
  201. if encoders:
  202. if 'encoder' not in info_data:
  203. info_data['encoder'] = {}
  204. if 'rotary' in info_data['encoder']:
  205. _log_warning(info_data, 'Encoder config is specified in both config.h and info.json (encoder.rotary) (Value: %s), the config.h value wins.' % info_data['encoder']['rotary'])
  206. info_data['encoder']['rotary'] = encoders
  207. def _extract_split_encoders(info_data, config_c):
  208. """Populate data about split encoder pins
  209. """
  210. encoders = _extract_encoders_values(config_c, '_RIGHT')
  211. if encoders:
  212. if 'split' not in info_data:
  213. info_data['split'] = {}
  214. if 'encoder' not in info_data['split']:
  215. info_data['split']['encoder'] = {}
  216. if 'right' not in info_data['split']['encoder']:
  217. info_data['split']['encoder']['right'] = {}
  218. if 'rotary' in info_data['split']['encoder']['right']:
  219. _log_warning(info_data, 'Encoder config is specified in both config.h and info.json (encoder.rotary) (Value: %s), the config.h value wins.' % info_data['split']['encoder']['right']['rotary'])
  220. info_data['split']['encoder']['right']['rotary'] = encoders
  221. def _extract_secure_unlock(info_data, config_c):
  222. """Populate data about the secure unlock sequence
  223. """
  224. unlock = config_c.get('SECURE_UNLOCK_SEQUENCE', '').replace(' ', '')[1:-1]
  225. if unlock:
  226. unlock_array = _extract_2d_int_array(unlock)
  227. if 'secure' not in info_data:
  228. info_data['secure'] = {}
  229. if 'unlock_sequence' in info_data['secure']:
  230. _log_warning(info_data, 'Secure unlock sequence is specified in both config.h (SECURE_UNLOCK_SEQUENCE) and info.json (secure.unlock_sequence) (Value: %s), the config.h value wins.' % info_data['secure']['unlock_sequence'])
  231. info_data['secure']['unlock_sequence'] = unlock_array
  232. def _extract_split_main(info_data, config_c):
  233. """Populate data about the split configuration
  234. """
  235. # Figure out how the main half is determined
  236. if config_c.get('SPLIT_HAND_PIN') is True:
  237. if 'split' not in info_data:
  238. info_data['split'] = {}
  239. if 'main' in info_data['split']:
  240. _log_warning(info_data, 'Split main hand is specified in both config.h (SPLIT_HAND_PIN) and info.json (split.main) (Value: %s), the config.h value wins.' % info_data['split']['main'])
  241. info_data['split']['main'] = 'pin'
  242. if config_c.get('SPLIT_HAND_MATRIX_GRID'):
  243. if 'split' not in info_data:
  244. info_data['split'] = {}
  245. if 'main' in info_data['split']:
  246. _log_warning(info_data, 'Split main hand is specified in both config.h (SPLIT_HAND_MATRIX_GRID) and info.json (split.main) (Value: %s), the config.h value wins.' % info_data['split']['main'])
  247. info_data['split']['main'] = 'matrix_grid'
  248. info_data['split']['matrix_grid'] = _extract_pins(config_c['SPLIT_HAND_MATRIX_GRID'])
  249. if config_c.get('EE_HANDS') is True:
  250. if 'split' not in info_data:
  251. info_data['split'] = {}
  252. if 'main' in info_data['split']:
  253. _log_warning(info_data, 'Split main hand is specified in both config.h (EE_HANDS) and info.json (split.main) (Value: %s), the config.h value wins.' % info_data['split']['main'])
  254. info_data['split']['main'] = 'eeprom'
  255. if config_c.get('MASTER_RIGHT') is True:
  256. if 'split' not in info_data:
  257. info_data['split'] = {}
  258. if 'main' in info_data['split']:
  259. _log_warning(info_data, 'Split main hand is specified in both config.h (MASTER_RIGHT) and info.json (split.main) (Value: %s), the config.h value wins.' % info_data['split']['main'])
  260. info_data['split']['main'] = 'right'
  261. if config_c.get('MASTER_LEFT') is True:
  262. if 'split' not in info_data:
  263. info_data['split'] = {}
  264. if 'main' in info_data['split']:
  265. _log_warning(info_data, 'Split main hand is specified in both config.h (MASTER_LEFT) and info.json (split.main) (Value: %s), the config.h value wins.' % info_data['split']['main'])
  266. info_data['split']['main'] = 'left'
  267. def _extract_split_transport(info_data, config_c):
  268. # Figure out the transport method
  269. if config_c.get('USE_I2C') is True:
  270. if 'split' not in info_data:
  271. info_data['split'] = {}
  272. if 'transport' not in info_data['split']:
  273. info_data['split']['transport'] = {}
  274. if 'protocol' in info_data['split']['transport']:
  275. _log_warning(info_data, 'Split transport is specified in both config.h (USE_I2C) and info.json (split.transport.protocol) (Value: %s), the config.h value wins.' % info_data['split']['transport'])
  276. info_data['split']['transport']['protocol'] = 'i2c'
  277. # Ignore transport defaults if "SPLIT_KEYBOARD" is unset
  278. elif 'enabled' in info_data.get('split', {}):
  279. if 'split' not in info_data:
  280. info_data['split'] = {}
  281. if 'transport' not in info_data['split']:
  282. info_data['split']['transport'] = {}
  283. if 'protocol' not in info_data['split']['transport']:
  284. info_data['split']['transport']['protocol'] = 'serial'
  285. def _extract_split_right_pins(info_data, config_c):
  286. # Figure out the right half matrix pins
  287. row_pins = config_c.get('MATRIX_ROW_PINS_RIGHT', '').replace('{', '').replace('}', '').strip()
  288. col_pins = config_c.get('MATRIX_COL_PINS_RIGHT', '').replace('{', '').replace('}', '').strip()
  289. direct_pins = config_c.get('DIRECT_PINS_RIGHT', '').replace(' ', '')[1:-1]
  290. if row_pins or col_pins or direct_pins:
  291. if info_data.get('split', {}).get('matrix_pins', {}).get('right', None):
  292. _log_warning(info_data, 'Right hand matrix data is specified in both info.json and config.h, the config.h values win.')
  293. if 'split' not in info_data:
  294. info_data['split'] = {}
  295. if 'matrix_pins' not in info_data['split']:
  296. info_data['split']['matrix_pins'] = {}
  297. if 'right' not in info_data['split']['matrix_pins']:
  298. info_data['split']['matrix_pins']['right'] = {}
  299. if col_pins:
  300. info_data['split']['matrix_pins']['right']['cols'] = _extract_pins(col_pins)
  301. if row_pins:
  302. info_data['split']['matrix_pins']['right']['rows'] = _extract_pins(row_pins)
  303. if direct_pins:
  304. info_data['split']['matrix_pins']['right']['direct'] = _extract_direct_matrix(direct_pins)
  305. def _extract_matrix_info(info_data, config_c):
  306. """Populate the matrix information.
  307. """
  308. row_pins = config_c.get('MATRIX_ROW_PINS', '').replace('{', '').replace('}', '').strip()
  309. col_pins = config_c.get('MATRIX_COL_PINS', '').replace('{', '').replace('}', '').strip()
  310. direct_pins = config_c.get('DIRECT_PINS', '').replace(' ', '')[1:-1]
  311. info_snippet = {}
  312. if 'MATRIX_ROWS' in config_c and 'MATRIX_COLS' in config_c:
  313. if 'matrix_size' in info_data:
  314. _log_warning(info_data, 'Matrix size is specified in both info.json and config.h, the config.h values win.')
  315. info_data['matrix_size'] = {
  316. 'cols': compute(config_c.get('MATRIX_COLS', '0')),
  317. 'rows': compute(config_c.get('MATRIX_ROWS', '0')),
  318. }
  319. if row_pins and col_pins:
  320. if 'matrix_pins' in info_data and 'cols' in info_data['matrix_pins'] and 'rows' in info_data['matrix_pins']:
  321. _log_warning(info_data, 'Matrix pins are specified in both info.json and config.h, the config.h values win.')
  322. info_snippet['cols'] = _extract_pins(col_pins)
  323. info_snippet['rows'] = _extract_pins(row_pins)
  324. if direct_pins:
  325. if 'matrix_pins' in info_data and 'direct' in info_data['matrix_pins']:
  326. _log_warning(info_data, 'Direct pins are specified in both info.json and config.h, the config.h values win.')
  327. info_snippet['direct'] = _extract_direct_matrix(direct_pins)
  328. if config_c.get('CUSTOM_MATRIX', 'no') != 'no':
  329. if 'matrix_pins' in info_data and 'custom' in info_data['matrix_pins']:
  330. _log_warning(info_data, 'Custom Matrix is specified in both info.json and config.h, the config.h values win.')
  331. info_snippet['custom'] = True
  332. if config_c['CUSTOM_MATRIX'] == 'lite':
  333. info_snippet['custom_lite'] = True
  334. if info_snippet:
  335. info_data['matrix_pins'] = info_snippet
  336. return info_data
  337. def _config_to_json(key_type, config_value):
  338. """Convert config value using spec
  339. """
  340. if key_type.startswith('array'):
  341. if '.' in key_type:
  342. key_type, array_type = key_type.split('.', 1)
  343. else:
  344. array_type = None
  345. config_value = config_value.replace('{', '').replace('}', '').strip()
  346. if array_type == 'int':
  347. return list(map(int, config_value.split(',')))
  348. else:
  349. return list(map(str.strip, config_value.split(',')))
  350. elif key_type == 'bool':
  351. return config_value in true_values
  352. elif key_type == 'hex':
  353. return '0x' + config_value[2:].upper()
  354. elif key_type == 'list':
  355. return config_value.split()
  356. elif key_type == 'int':
  357. return int(config_value)
  358. elif key_type == 'str':
  359. return config_value.strip('"').replace('\\"', '"').replace('\\\\', '\\')
  360. elif key_type == 'bcd_version':
  361. major = int(config_value[2:4])
  362. minor = int(config_value[4])
  363. revision = int(config_value[5])
  364. return f'{major}.{minor}.{revision}'
  365. return config_value
  366. def _extract_config_h(info_data, config_c):
  367. """Pull some keyboard information from existing config.h files
  368. """
  369. # Pull in data from the json map
  370. dotty_info = dotty(info_data)
  371. info_config_map = json_load(Path('data/mappings/info_config.hjson'))
  372. for config_key, info_dict in info_config_map.items():
  373. info_key = info_dict['info_key']
  374. key_type = info_dict.get('value_type', 'raw')
  375. try:
  376. replace_with = info_dict.get('replace_with')
  377. if config_key in config_c and info_dict.get('invalid', False):
  378. if replace_with:
  379. _log_error(info_data, '%s in config.h is no longer a valid option and should be replaced with %s' % (config_key, replace_with))
  380. else:
  381. _log_error(info_data, '%s in config.h is no longer a valid option and should be removed' % config_key)
  382. elif config_key in config_c and info_dict.get('deprecated', False):
  383. if replace_with:
  384. _log_warning(info_data, '%s in config.h is deprecated in favor of %s and will be removed at a later date' % (config_key, replace_with))
  385. else:
  386. _log_warning(info_data, '%s in config.h is deprecated and will be removed at a later date' % config_key)
  387. if config_key in config_c and info_dict.get('to_json', True):
  388. if dotty_info.get(info_key) and info_dict.get('warn_duplicate', True):
  389. _log_warning(info_data, '%s in config.h is overwriting %s in info.json' % (config_key, info_key))
  390. dotty_info[info_key] = _config_to_json(key_type, config_c[config_key])
  391. except Exception as e:
  392. _log_warning(info_data, f'{config_key}->{info_key}: {e}')
  393. info_data.update(dotty_info)
  394. # Pull data that easily can't be mapped in json
  395. _extract_matrix_info(info_data, config_c)
  396. _extract_audio(info_data, config_c)
  397. _extract_secure_unlock(info_data, config_c)
  398. _extract_split_main(info_data, config_c)
  399. _extract_split_transport(info_data, config_c)
  400. _extract_split_right_pins(info_data, config_c)
  401. _extract_encoders(info_data, config_c)
  402. _extract_split_encoders(info_data, config_c)
  403. return info_data
  404. def _process_defaults(info_data):
  405. """Process any additional defaults based on currently discovered information
  406. """
  407. defaults_map = json_load(Path('data/mappings/defaults.hjson'))
  408. for default_type in defaults_map.keys():
  409. thing_map = defaults_map[default_type]
  410. if default_type in info_data:
  411. for key, value in thing_map.get(info_data[default_type], {}).items():
  412. info_data[key] = value
  413. return info_data
  414. def _extract_rules_mk(info_data, rules):
  415. """Pull some keyboard information from existing rules.mk files
  416. """
  417. info_data['processor'] = rules.get('MCU', info_data.get('processor', 'atmega32u4'))
  418. if info_data['processor'] in CHIBIOS_PROCESSORS:
  419. arm_processor_rules(info_data, rules)
  420. elif info_data['processor'] in LUFA_PROCESSORS + VUSB_PROCESSORS:
  421. avr_processor_rules(info_data, rules)
  422. else:
  423. cli.log.warning("%s: Unknown MCU: %s" % (info_data['keyboard_folder'], info_data['processor']))
  424. unknown_processor_rules(info_data, rules)
  425. # Pull in data from the json map
  426. dotty_info = dotty(info_data)
  427. info_rules_map = json_load(Path('data/mappings/info_rules.hjson'))
  428. for rules_key, info_dict in info_rules_map.items():
  429. info_key = info_dict['info_key']
  430. key_type = info_dict.get('value_type', 'raw')
  431. try:
  432. replace_with = info_dict.get('replace_with')
  433. if rules_key in rules and info_dict.get('invalid', False):
  434. if replace_with:
  435. _log_error(info_data, '%s in rules.mk is no longer a valid option and should be replaced with %s' % (rules_key, replace_with))
  436. else:
  437. _log_error(info_data, '%s in rules.mk is no longer a valid option and should be removed' % rules_key)
  438. elif rules_key in rules and info_dict.get('deprecated', False):
  439. if replace_with:
  440. _log_warning(info_data, '%s in rules.mk is deprecated in favor of %s and will be removed at a later date' % (rules_key, replace_with))
  441. else:
  442. _log_warning(info_data, '%s in rules.mk is deprecated and will be removed at a later date' % rules_key)
  443. if rules_key in rules and info_dict.get('to_json', True):
  444. if dotty_info.get(info_key) and info_dict.get('warn_duplicate', True):
  445. _log_warning(info_data, '%s in rules.mk is overwriting %s in info.json' % (rules_key, info_key))
  446. dotty_info[info_key] = _config_to_json(key_type, rules[rules_key])
  447. except Exception as e:
  448. _log_warning(info_data, f'{rules_key}->{info_key}: {e}')
  449. info_data.update(dotty_info)
  450. # Merge in config values that can't be easily mapped
  451. _extract_features(info_data, rules)
  452. return info_data
  453. def find_keyboard_c(keyboard):
  454. """Find all <keyboard>.c files
  455. """
  456. keyboard = Path(keyboard)
  457. current_path = Path('keyboards/')
  458. files = []
  459. for directory in keyboard.parts:
  460. current_path = current_path / directory
  461. keyboard_c_path = current_path / f'{directory}.c'
  462. if keyboard_c_path.exists():
  463. files.append(keyboard_c_path)
  464. return files
  465. def _extract_led_config(info_data, keyboard):
  466. """Scan all <keyboard>.c files for led config
  467. """
  468. cols = info_data['matrix_size']['cols']
  469. rows = info_data['matrix_size']['rows']
  470. # Determine what feature owns g_led_config
  471. features = info_data.get("features", {})
  472. feature = None
  473. if features.get("rgb_matrix", False):
  474. feature = "rgb_matrix"
  475. elif features.get("led_matrix", False):
  476. feature = "led_matrix"
  477. if feature:
  478. # Process
  479. for file in find_keyboard_c(keyboard):
  480. try:
  481. ret = find_led_config(file, cols, rows)
  482. if ret:
  483. info_data[feature] = info_data.get(feature, {})
  484. info_data[feature]["layout"] = ret
  485. except Exception as e:
  486. _log_warning(info_data, f'led_config: {file.name}: {e}')
  487. return info_data
  488. def _matrix_size(info_data):
  489. """Add info_data['matrix_size'] if it doesn't exist.
  490. """
  491. if 'matrix_size' not in info_data and 'matrix_pins' in info_data:
  492. info_data['matrix_size'] = {}
  493. if 'direct' in info_data['matrix_pins']:
  494. info_data['matrix_size']['cols'] = len(info_data['matrix_pins']['direct'][0])
  495. info_data['matrix_size']['rows'] = len(info_data['matrix_pins']['direct'])
  496. elif 'cols' in info_data['matrix_pins'] and 'rows' in info_data['matrix_pins']:
  497. info_data['matrix_size']['cols'] = len(info_data['matrix_pins']['cols'])
  498. info_data['matrix_size']['rows'] = len(info_data['matrix_pins']['rows'])
  499. # Assumption of split common
  500. if 'split' in info_data:
  501. if info_data['split'].get('enabled', False):
  502. info_data['matrix_size']['rows'] *= 2
  503. return info_data
  504. def _check_matrix(info_data):
  505. """Check the matrix to ensure that row/column count is consistent.
  506. """
  507. if 'matrix_pins' in info_data and 'matrix_size' in info_data:
  508. actual_col_count = info_data['matrix_size'].get('cols', 0)
  509. actual_row_count = info_data['matrix_size'].get('rows', 0)
  510. col_count = row_count = 0
  511. if 'direct' in info_data['matrix_pins']:
  512. col_count = len(info_data['matrix_pins']['direct'][0])
  513. row_count = len(info_data['matrix_pins']['direct'])
  514. elif 'cols' in info_data['matrix_pins'] and 'rows' in info_data['matrix_pins']:
  515. col_count = len(info_data['matrix_pins']['cols'])
  516. row_count = len(info_data['matrix_pins']['rows'])
  517. if col_count != actual_col_count and col_count != (actual_col_count / 2):
  518. # FIXME: once we can we should detect if split is enabled to do the actual_col_count/2 check.
  519. _log_error(info_data, f'MATRIX_COLS is inconsistent with the size of MATRIX_COL_PINS: {col_count} != {actual_col_count}')
  520. if row_count != actual_row_count and row_count != (actual_row_count / 2):
  521. # FIXME: once we can we should detect if split is enabled to do the actual_row_count/2 check.
  522. _log_error(info_data, f'MATRIX_ROWS is inconsistent with the size of MATRIX_ROW_PINS: {row_count} != {actual_row_count}')
  523. def _search_keyboard_h(keyboard):
  524. keyboard = Path(keyboard)
  525. current_path = Path('keyboards/')
  526. aliases = {}
  527. layouts = {}
  528. for directory in keyboard.parts:
  529. current_path = current_path / directory
  530. keyboard_h = '%s.h' % (directory,)
  531. keyboard_h_path = current_path / keyboard_h
  532. if keyboard_h_path.exists():
  533. new_layouts, new_aliases = find_layouts(keyboard_h_path)
  534. layouts.update(new_layouts)
  535. for alias, alias_text in new_aliases.items():
  536. if alias_text in layouts:
  537. aliases[alias] = alias_text
  538. return layouts, aliases
  539. def _log_error(info_data, message):
  540. """Send an error message to both JSON and the log.
  541. """
  542. info_data['parse_errors'].append(message)
  543. cli.log.error('%s: %s', info_data.get('keyboard_folder', 'Unknown Keyboard!'), message)
  544. def _log_warning(info_data, message):
  545. """Send a warning message to both JSON and the log.
  546. """
  547. info_data['parse_warnings'].append(message)
  548. cli.log.warning('%s: %s', info_data.get('keyboard_folder', 'Unknown Keyboard!'), message)
  549. def arm_processor_rules(info_data, rules):
  550. """Setup the default info for an ARM board.
  551. """
  552. info_data['processor_type'] = 'arm'
  553. info_data['protocol'] = 'ChibiOS'
  554. if 'STM32' in info_data['processor']:
  555. info_data['platform'] = 'STM32'
  556. elif 'MCU_SERIES' in rules:
  557. info_data['platform'] = rules['MCU_SERIES']
  558. elif 'ARM_ATSAM' in rules:
  559. info_data['platform'] = 'ARM_ATSAM'
  560. return info_data
  561. def avr_processor_rules(info_data, rules):
  562. """Setup the default info for an AVR board.
  563. """
  564. info_data['processor_type'] = 'avr'
  565. info_data['platform'] = rules['ARCH'] if 'ARCH' in rules else 'unknown'
  566. info_data['protocol'] = 'V-USB' if info_data['processor'] in VUSB_PROCESSORS else 'LUFA'
  567. # FIXME(fauxpark/anyone): Eventually we should detect the protocol by looking at PROTOCOL inherited from mcu_selection.mk:
  568. # info_data['protocol'] = 'V-USB' if rules.get('PROTOCOL') == 'VUSB' else 'LUFA'
  569. return info_data
  570. def unknown_processor_rules(info_data, rules):
  571. """Setup the default keyboard info for unknown boards.
  572. """
  573. info_data['bootloader'] = 'unknown'
  574. info_data['platform'] = 'unknown'
  575. info_data['processor'] = 'unknown'
  576. info_data['processor_type'] = 'unknown'
  577. info_data['protocol'] = 'unknown'
  578. return info_data
  579. def merge_info_jsons(keyboard, info_data):
  580. """Return a merged copy of all the info.json files for a keyboard.
  581. """
  582. for info_file in find_info_json(keyboard):
  583. # Load and validate the JSON data
  584. new_info_data = json_load(info_file)
  585. if not isinstance(new_info_data, dict):
  586. _log_error(info_data, "Invalid file %s, root object should be a dictionary." % (str(info_file),))
  587. continue
  588. try:
  589. validate(new_info_data, 'qmk.keyboard.v1')
  590. except jsonschema.ValidationError as e:
  591. json_path = '.'.join([str(p) for p in e.absolute_path])
  592. cli.log.error('Not including data from file: %s', info_file)
  593. cli.log.error('\t%s: %s', json_path, e.message)
  594. continue
  595. # Merge layout data in
  596. if 'layout_aliases' in new_info_data:
  597. info_data['layout_aliases'] = {**info_data.get('layout_aliases', {}), **new_info_data['layout_aliases']}
  598. del new_info_data['layout_aliases']
  599. for layout_name, layout in new_info_data.get('layouts', {}).items():
  600. if layout_name in info_data.get('layout_aliases', {}):
  601. _log_warning(info_data, f"info.json uses alias name {layout_name} instead of {info_data['layout_aliases'][layout_name]}")
  602. layout_name = info_data['layout_aliases'][layout_name]
  603. if layout_name in info_data['layouts']:
  604. if len(info_data['layouts'][layout_name]['layout']) != len(layout['layout']):
  605. msg = 'Number of keys for %s does not match! info.json specifies %d keys, C macro specifies %d'
  606. _log_error(info_data, msg % (layout_name, len(layout['layout']), len(info_data['layouts'][layout_name]['layout'])))
  607. else:
  608. for new_key, existing_key in zip(layout['layout'], info_data['layouts'][layout_name]['layout']):
  609. existing_key.update(new_key)
  610. else:
  611. if not all('matrix' in key_data.keys() for key_data in layout['layout']):
  612. _log_error(info_data, f'Layout "{layout_name}" has no "matrix" definition in either "info.json" or "<keyboard>.h"!')
  613. else:
  614. layout['c_macro'] = False
  615. info_data['layouts'][layout_name] = layout
  616. # Update info_data with the new data
  617. if 'layouts' in new_info_data:
  618. del new_info_data['layouts']
  619. deep_update(info_data, new_info_data)
  620. return info_data
  621. def find_info_json(keyboard):
  622. """Finds all the info.json files associated with a keyboard.
  623. """
  624. # Find the most specific first
  625. base_path = Path('keyboards')
  626. keyboard_path = base_path / keyboard
  627. keyboard_parent = keyboard_path.parent
  628. info_jsons = [keyboard_path / 'info.json']
  629. # Add DEFAULT_FOLDER before parents, if present
  630. rules = rules_mk(keyboard)
  631. if 'DEFAULT_FOLDER' in rules:
  632. info_jsons.append(Path(rules['DEFAULT_FOLDER']) / 'info.json')
  633. # Add in parent folders for least specific
  634. for _ in range(5):
  635. if keyboard_parent == base_path:
  636. break
  637. info_jsons.append(keyboard_parent / 'info.json')
  638. keyboard_parent = keyboard_parent.parent
  639. # Return a list of the info.json files that actually exist
  640. return [info_json for info_json in info_jsons if info_json.exists()]
  641. def keymap_json_config(keyboard, keymap):
  642. """Extract keymap level config
  643. """
  644. keymap_folder = locate_keymap(keyboard, keymap).parent
  645. km_info_json = parse_configurator_json(keymap_folder / 'keymap.json')
  646. return km_info_json.get('config', {})
  647. def keymap_json(keyboard, keymap):
  648. """Generate the info.json data for a specific keymap.
  649. """
  650. keymap_folder = locate_keymap(keyboard, keymap).parent
  651. # Files to scan
  652. keymap_config = keymap_folder / 'config.h'
  653. keymap_rules = keymap_folder / 'rules.mk'
  654. keymap_file = keymap_folder / 'keymap.json'
  655. # Build the info.json file
  656. kb_info_json = info_json(keyboard)
  657. # Merge in the data from keymap.json
  658. km_info_json = keymap_json_config(keyboard, keymap) if keymap_file.exists() else {}
  659. deep_update(kb_info_json, km_info_json)
  660. # Merge in the data from config.h, and rules.mk
  661. _extract_rules_mk(kb_info_json, parse_rules_mk_file(keymap_rules))
  662. _extract_config_h(kb_info_json, parse_config_h_file(keymap_config))
  663. return kb_info_json