From 779c7debcfff1a4a3ad578a0c12bdd50cba11039 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 27 Feb 2022 12:39:24 +0000 Subject: Fix issues with data driven split keyboards (#16457) --- lib/python/qmk/cli/generate/config_h.py | 36 ++++++++++++++++++--------------- lib/python/qmk/cli/generate/layouts.py | 16 ++++++--------- lib/python/qmk/cli/generate/rules_mk.py | 2 +- lib/python/qmk/info.py | 5 +++++ 4 files changed, 32 insertions(+), 27 deletions(-) (limited to 'lib/python') diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py index 6b1012fae7..24bbbdf517 100755 --- a/lib/python/qmk/cli/generate/config_h.py +++ b/lib/python/qmk/cli/generate/config_h.py @@ -21,18 +21,7 @@ def direct_pins(direct_pins, postfix): cols = ','.join(map(str, [col or 'NO_PIN' for col in row])) rows.append('{' + cols + '}') - col_count = len(direct_pins[0]) - row_count = len(direct_pins) - return f""" -#ifndef MATRIX_COLS{postfix} -# define MATRIX_COLS{postfix} {col_count} -#endif // MATRIX_COLS{postfix} - -#ifndef MATRIX_ROWS{postfix} -# define MATRIX_ROWS{postfix} {row_count} -#endif // MATRIX_ROWS{postfix} - #ifndef DIRECT_PINS{postfix} # define DIRECT_PINS{postfix} {{ {", ".join(rows)} }} #endif // DIRECT_PINS{postfix} @@ -42,14 +31,9 @@ def direct_pins(direct_pins, postfix): def pin_array(define, pins, postfix): """Return the config.h lines that set a pin array. """ - pin_num = len(pins) pin_array = ', '.join(map(str, [pin or 'NO_PIN' for pin in pins])) return f""" -#ifndef {define}S{postfix} -# define {define}S{postfix} {pin_num} -#endif // {define}S{postfix} - #ifndef {define}_PINS{postfix} # define {define}_PINS{postfix} {{ {pin_array} }} #endif // {define}_PINS{postfix} @@ -73,6 +57,24 @@ def matrix_pins(matrix_pins, postfix=''): return '\n'.join(pins) +def generate_matrix_size(kb_info_json, config_h_lines): + """Add the matrix size to the config.h. + """ + if 'matrix_pins' in kb_info_json: + col_count = kb_info_json['matrix_size']['cols'] + row_count = kb_info_json['matrix_size']['rows'] + + config_h_lines.append(f""" +#ifndef MATRIX_COLS +# define MATRIX_COLS {col_count} +#endif // MATRIX_COLS + +#ifndef MATRIX_ROWS +# define MATRIX_ROWS {row_count} +#endif // MATRIX_ROWS +""") + + def generate_config_items(kb_info_json, config_h_lines): """Iterate through the info_config map to generate basic config values. """ @@ -183,6 +185,8 @@ def generate_config_h(cli): generate_config_items(kb_info_json, config_h_lines) + generate_matrix_size(kb_info_json, config_h_lines) + if 'matrix_pins' in kb_info_json: config_h_lines.append(matrix_pins(kb_info_json['matrix_pins'])) diff --git a/lib/python/qmk/cli/generate/layouts.py b/lib/python/qmk/cli/generate/layouts.py index e44266e1c8..a21311bd49 100755 --- a/lib/python/qmk/cli/generate/layouts.py +++ b/lib/python/qmk/cli/generate/layouts.py @@ -40,16 +40,12 @@ def generate_layouts(cli): # Build the layouts.h file. layouts_h_lines = ['/* This file was generated by `qmk generate-layouts`. Do not edit or copy.', ' */', '', '#pragma once'] - if 'matrix_pins' in kb_info_json: - if 'direct' in kb_info_json['matrix_pins']: - col_num = len(kb_info_json['matrix_pins']['direct'][0]) - row_num = len(kb_info_json['matrix_pins']['direct']) - elif 'cols' in kb_info_json['matrix_pins'] and 'rows' in kb_info_json['matrix_pins']: - col_num = len(kb_info_json['matrix_pins']['cols']) - row_num = len(kb_info_json['matrix_pins']['rows']) - else: - cli.log.error('%s: Invalid matrix config.', cli.config.generate_layouts.keyboard) - return False + if 'matrix_size' not in kb_info_json: + cli.log.error('%s: Invalid matrix config.', cli.config.generate_layouts.keyboard) + return False + + col_num = kb_info_json['matrix_size']['cols'] + row_num = kb_info_json['matrix_size']['rows'] for layout_name in kb_info_json['layouts']: if kb_info_json['layouts'][layout_name]['c_macro']: diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py index 5d8d7cc8a7..ce824f6378 100755 --- a/lib/python/qmk/cli/generate/rules_mk.py +++ b/lib/python/qmk/cli/generate/rules_mk.py @@ -29,7 +29,7 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict): if key_type in ['array', 'list']: return f'{rules_key} ?= {" ".join(rules_value)}' elif key_type == 'bool': - return f'{rules_key} ?= {"on" if rules_value else "off"}' + return f'{rules_key} ?= {"yes" if rules_value else "no"}' elif key_type == 'mapping': return '\n'.join([f'{key} ?= {value}' for key, value in rules_value.items()]) diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index 905f10ecc2..b86eaa059f 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -550,6 +550,11 @@ def _matrix_size(info_data): info_data['matrix_size']['cols'] = len(info_data['matrix_pins']['cols']) info_data['matrix_size']['rows'] = len(info_data['matrix_pins']['rows']) + # Assumption of split common + if 'split' in info_data: + if info_data['split'].get('enabled', False): + info_data['matrix_size']['rows'] *= 2 + return info_data -- cgit v1.2.1