diff options
Diffstat (limited to 'lib/python/qmk/info.py')
-rw-r--r-- | lib/python/qmk/info.py | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index d23b3592e..7f9907a50 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py | |||
@@ -9,7 +9,7 @@ from milc import cli | |||
9 | 9 | ||
10 | from qmk.constants import CHIBIOS_PROCESSORS, LUFA_PROCESSORS, VUSB_PROCESSORS | 10 | from qmk.constants import CHIBIOS_PROCESSORS, LUFA_PROCESSORS, VUSB_PROCESSORS |
11 | from qmk.c_parse import find_layouts | 11 | from qmk.c_parse import find_layouts |
12 | from qmk.json_schema import deep_update, json_load, keyboard_validate, keyboard_api_validate | 12 | from qmk.json_schema import deep_update, json_load, validate |
13 | from qmk.keyboard import config_h, rules_mk | 13 | from qmk.keyboard import config_h, rules_mk |
14 | from qmk.keymap import list_keymaps | 14 | from qmk.keymap import list_keymaps |
15 | from qmk.makefile import parse_rules_mk_file | 15 | from qmk.makefile import parse_rules_mk_file |
@@ -64,9 +64,12 @@ def info_json(keyboard): | |||
64 | info_data = _extract_config_h(info_data) | 64 | info_data = _extract_config_h(info_data) |
65 | info_data = _extract_rules_mk(info_data) | 65 | info_data = _extract_rules_mk(info_data) |
66 | 66 | ||
67 | # Ensure that we have matrix row and column counts | ||
68 | info_data = _matrix_size(info_data) | ||
69 | |||
67 | # Validate against the jsonschema | 70 | # Validate against the jsonschema |
68 | try: | 71 | try: |
69 | keyboard_api_validate(info_data) | 72 | validate(info_data, 'qmk.api.keyboard.v1') |
70 | 73 | ||
71 | except jsonschema.ValidationError as e: | 74 | except jsonschema.ValidationError as e: |
72 | json_path = '.'.join([str(p) for p in e.absolute_path]) | 75 | json_path = '.'.join([str(p) for p in e.absolute_path]) |
@@ -90,6 +93,9 @@ def info_json(keyboard): | |||
90 | if layout_name not in info_data.get('layouts', {}) and layout_name not in info_data.get('layout_aliases', {}): | 93 | if layout_name not in info_data.get('layouts', {}) and layout_name not in info_data.get('layout_aliases', {}): |
91 | _log_error(info_data, 'Claims to support community layout %s but no %s() macro found' % (layout, layout_name)) | 94 | _log_error(info_data, 'Claims to support community layout %s but no %s() macro found' % (layout, layout_name)) |
92 | 95 | ||
96 | # Check that the reported matrix size is consistent with the actual matrix size | ||
97 | _check_matrix(info_data) | ||
98 | |||
93 | return info_data | 99 | return info_data |
94 | 100 | ||
95 | 101 | ||
@@ -143,10 +149,7 @@ def _pin_name(pin): | |||
143 | elif pin == 'NO_PIN': | 149 | elif pin == 'NO_PIN': |
144 | return None | 150 | return None |
145 | 151 | ||
146 | elif pin[0] in 'ABCDEFGHIJK' and pin[1].isdigit(): | 152 | return pin |
147 | return pin | ||
148 | |||
149 | raise ValueError(f'Invalid pin: {pin}') | ||
150 | 153 | ||
151 | 154 | ||
152 | def _extract_pins(pins): | 155 | def _extract_pins(pins): |
@@ -341,6 +344,46 @@ def _extract_rules_mk(info_data): | |||
341 | return info_data | 344 | return info_data |
342 | 345 | ||
343 | 346 | ||
347 | def _matrix_size(info_data): | ||
348 | """Add info_data['matrix_size'] if it doesn't exist. | ||
349 | """ | ||
350 | if 'matrix_size' not in info_data and 'matrix_pins' in info_data: | ||
351 | info_data['matrix_size'] = {} | ||
352 | |||
353 | if 'direct' in info_data['matrix_pins']: | ||
354 | info_data['matrix_size']['cols'] = len(info_data['matrix_pins']['direct'][0]) | ||
355 | info_data['matrix_size']['rows'] = len(info_data['matrix_pins']['direct']) | ||
356 | elif 'cols' in info_data['matrix_pins'] and 'rows' in info_data['matrix_pins']: | ||
357 | info_data['matrix_size']['cols'] = len(info_data['matrix_pins']['cols']) | ||
358 | info_data['matrix_size']['rows'] = len(info_data['matrix_pins']['rows']) | ||
359 | |||
360 | return info_data | ||
361 | |||
362 | |||
363 | def _check_matrix(info_data): | ||
364 | """Check the matrix to ensure that row/column count is consistent. | ||
365 | """ | ||
366 | if 'matrix_pins' in info_data and 'matrix_size' in info_data: | ||
367 | actual_col_count = info_data['matrix_size'].get('cols', 0) | ||
368 | actual_row_count = info_data['matrix_size'].get('rows', 0) | ||
369 | col_count = row_count = 0 | ||
370 | |||
371 | if 'direct' in info_data['matrix_pins']: | ||
372 | col_count = len(info_data['matrix_pins']['direct'][0]) | ||
373 | row_count = len(info_data['matrix_pins']['direct']) | ||
374 | elif 'cols' in info_data['matrix_pins'] and 'rows' in info_data['matrix_pins']: | ||
375 | col_count = len(info_data['matrix_pins']['cols']) | ||
376 | row_count = len(info_data['matrix_pins']['rows']) | ||
377 | |||
378 | if col_count != actual_col_count and col_count != (actual_col_count / 2): | ||
379 | # FIXME: once we can we should detect if split is enabled to do the actual_col_count/2 check. | ||
380 | _log_error(info_data, f'MATRIX_COLS is inconsistent with the size of MATRIX_COL_PINS: {col_count} != {actual_col_count}') | ||
381 | |||
382 | if row_count != actual_row_count and row_count != (actual_row_count / 2): | ||
383 | # FIXME: once we can we should detect if split is enabled to do the actual_row_count/2 check. | ||
384 | _log_error(info_data, f'MATRIX_ROWS is inconsistent with the size of MATRIX_ROW_PINS: {row_count} != {actual_row_count}') | ||
385 | |||
386 | |||
344 | def _merge_layouts(info_data, new_info_data): | 387 | def _merge_layouts(info_data, new_info_data): |
345 | """Merge new_info_data into info_data in an intelligent way. | 388 | """Merge new_info_data into info_data in an intelligent way. |
346 | """ | 389 | """ |
@@ -493,7 +536,7 @@ def merge_info_jsons(keyboard, info_data): | |||
493 | continue | 536 | continue |
494 | 537 | ||
495 | try: | 538 | try: |
496 | keyboard_validate(new_info_data) | 539 | validate(new_info_data, 'qmk.keyboard.v1') |
497 | except jsonschema.ValidationError as e: | 540 | except jsonschema.ValidationError as e: |
498 | json_path = '.'.join([str(p) for p in e.absolute_path]) | 541 | json_path = '.'.join([str(p) for p in e.absolute_path]) |
499 | cli.log.error('Not including data from file: %s', info_file) | 542 | cli.log.error('Not including data from file: %s', info_file) |