Fix issues with data driven split keyboards (#16457)
parent
e884414e1e
commit
779c7debcf
|
@ -21,18 +21,7 @@ def direct_pins(direct_pins, postfix):
|
||||||
cols = ','.join(map(str, [col or 'NO_PIN' for col in row]))
|
cols = ','.join(map(str, [col or 'NO_PIN' for col in row]))
|
||||||
rows.append('{' + cols + '}')
|
rows.append('{' + cols + '}')
|
||||||
|
|
||||||
col_count = len(direct_pins[0])
|
|
||||||
row_count = len(direct_pins)
|
|
||||||
|
|
||||||
return f"""
|
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}
|
#ifndef DIRECT_PINS{postfix}
|
||||||
# define DIRECT_PINS{postfix} {{ {", ".join(rows)} }}
|
# define DIRECT_PINS{postfix} {{ {", ".join(rows)} }}
|
||||||
#endif // DIRECT_PINS{postfix}
|
#endif // DIRECT_PINS{postfix}
|
||||||
|
@ -42,14 +31,9 @@ def direct_pins(direct_pins, postfix):
|
||||||
def pin_array(define, pins, postfix):
|
def pin_array(define, pins, postfix):
|
||||||
"""Return the config.h lines that set a pin array.
|
"""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]))
|
pin_array = ', '.join(map(str, [pin or 'NO_PIN' for pin in pins]))
|
||||||
|
|
||||||
return f"""
|
return f"""
|
||||||
#ifndef {define}S{postfix}
|
|
||||||
# define {define}S{postfix} {pin_num}
|
|
||||||
#endif // {define}S{postfix}
|
|
||||||
|
|
||||||
#ifndef {define}_PINS{postfix}
|
#ifndef {define}_PINS{postfix}
|
||||||
# define {define}_PINS{postfix} {{ {pin_array} }}
|
# define {define}_PINS{postfix} {{ {pin_array} }}
|
||||||
#endif // {define}_PINS{postfix}
|
#endif // {define}_PINS{postfix}
|
||||||
|
@ -73,6 +57,24 @@ def matrix_pins(matrix_pins, postfix=''):
|
||||||
return '\n'.join(pins)
|
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):
|
def generate_config_items(kb_info_json, config_h_lines):
|
||||||
"""Iterate through the info_config map to generate basic config values.
|
"""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_config_items(kb_info_json, config_h_lines)
|
||||||
|
|
||||||
|
generate_matrix_size(kb_info_json, config_h_lines)
|
||||||
|
|
||||||
if 'matrix_pins' in kb_info_json:
|
if 'matrix_pins' in kb_info_json:
|
||||||
config_h_lines.append(matrix_pins(kb_info_json['matrix_pins']))
|
config_h_lines.append(matrix_pins(kb_info_json['matrix_pins']))
|
||||||
|
|
||||||
|
|
|
@ -40,17 +40,13 @@ def generate_layouts(cli):
|
||||||
# Build the layouts.h file.
|
# Build the layouts.h file.
|
||||||
layouts_h_lines = ['/* This file was generated by `qmk generate-layouts`. Do not edit or copy.', ' */', '', '#pragma once']
|
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 'matrix_size' not 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)
|
cli.log.error('%s: Invalid matrix config.', cli.config.generate_layouts.keyboard)
|
||||||
return False
|
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']:
|
for layout_name in kb_info_json['layouts']:
|
||||||
if kb_info_json['layouts'][layout_name]['c_macro']:
|
if kb_info_json['layouts'][layout_name]['c_macro']:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -29,7 +29,7 @@ def process_mapping_rule(kb_info_json, rules_key, info_dict):
|
||||||
if key_type in ['array', 'list']:
|
if key_type in ['array', 'list']:
|
||||||
return f'{rules_key} ?= {" ".join(rules_value)}'
|
return f'{rules_key} ?= {" ".join(rules_value)}'
|
||||||
elif key_type == 'bool':
|
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':
|
elif key_type == 'mapping':
|
||||||
return '\n'.join([f'{key} ?= {value}' for key, value in rules_value.items()])
|
return '\n'.join([f'{key} ?= {value}' for key, value in rules_value.items()])
|
||||||
|
|
||||||
|
|
|
@ -550,6 +550,11 @@ def _matrix_size(info_data):
|
||||||
info_data['matrix_size']['cols'] = len(info_data['matrix_pins']['cols'])
|
info_data['matrix_size']['cols'] = len(info_data['matrix_pins']['cols'])
|
||||||
info_data['matrix_size']['rows'] = len(info_data['matrix_pins']['rows'])
|
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
|
return info_data
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue