aboutsummaryrefslogtreecommitdiff
path: root/lib/python
diff options
context:
space:
mode:
authorZach White <skullydazed@gmail.com>2021-07-11 09:43:58 -0700
committerGitHub <noreply@github.com>2021-07-11 09:43:58 -0700
commit0b06452d00dcd967bfcaffe89e88a4758c878e74 (patch)
tree7fb602ad2fe6c3be373f8d962e88635c9c75131d /lib/python
parentfd284c43a598061afeb30e8edb4fb239f0196ac3 (diff)
downloadqmk_firmware-0b06452d00dcd967bfcaffe89e88a4758c878e74.tar.gz
qmk_firmware-0b06452d00dcd967bfcaffe89e88a4758c878e74.zip
Matrix consistency check (#13470)
* Add a check to make sure the matrix sizes match the actual matrix size * make flake8 happy
Diffstat (limited to 'lib/python')
-rw-r--r--lib/python/qmk/info.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py
index 5525f0fe6..bcb4d81ef 100644
--- a/lib/python/qmk/info.py
+++ b/lib/python/qmk/info.py
@@ -64,6 +64,9 @@ 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 validate(info_data, 'qmk.api.keyboard.v1') 72 validate(info_data, 'qmk.api.keyboard.v1')
@@ -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
@@ -338,6 +344,46 @@ def _extract_rules_mk(info_data):
338 return info_data 344 return info_data
339 345
340 346
347def _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
363def _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
341def _merge_layouts(info_data, new_info_data): 387def _merge_layouts(info_data, new_info_data):
342 """Merge new_info_data into info_data in an intelligent way. 388 """Merge new_info_data into info_data in an intelligent way.
343 """ 389 """