diff options
author | Joel Challis <git@zvecr.com> | 2023-10-29 01:09:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-29 01:09:02 +0100 |
commit | 98530cad3ba8733d8a100e0bc5f3cf47339c4b3e (patch) | |
tree | c6c7306052b2707daddcbfd5c53e298e093f9b09 /lib/python | |
parent | 64ea1179b10794d6b97a968c21752417e8ac70c5 (diff) |
Implement data driven dip switches (#22017)
* Add data driven dip switches
* Autogen weak matrix_mask
Diffstat (limited to 'lib/python')
-rwxr-xr-x | lib/python/qmk/cli/generate/config_h.py | 8 | ||||
-rwxr-xr-x | lib/python/qmk/cli/generate/keyboard_c.py | 26 |
2 files changed, 34 insertions, 0 deletions
diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py index 828785ea48..b261d6f851 100755 --- a/lib/python/qmk/cli/generate/config_h.py +++ b/lib/python/qmk/cli/generate/config_h.py @@ -72,6 +72,12 @@ def generate_matrix_size(kb_info_json, config_h_lines): config_h_lines.append(generate_define('MATRIX_ROWS', kb_info_json['matrix_size']['rows'])) +def generate_matrix_masked(kb_info_json, config_h_lines): + """"Enable matrix mask if required""" + if 'matrix_grid' in kb_info_json.get('dip_switch', {}): + config_h_lines.append(generate_define('MATRIX_MASKED')) + + def generate_config_items(kb_info_json, config_h_lines): """Iterate through the info_config map to generate basic config values. """ @@ -196,6 +202,8 @@ def generate_config_h(cli): generate_matrix_size(kb_info_json, config_h_lines) + generate_matrix_masked(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/keyboard_c.py b/lib/python/qmk/cli/generate/keyboard_c.py index 9004b41abb..325624c9cc 100755 --- a/lib/python/qmk/cli/generate/keyboard_c.py +++ b/lib/python/qmk/cli/generate/keyboard_c.py @@ -57,6 +57,31 @@ def _gen_led_config(info_data): return lines +def _gen_matrix_mask(info_data): + """Convert info.json content to matrix_mask + """ + cols = info_data['matrix_size']['cols'] + rows = info_data['matrix_size']['rows'] + + # Default mask to everything enabled + mask = [['1'] * cols for i in range(rows)] + + # Automatically mask out dip_switch.matrix_grid locations + matrix_grid = info_data.get('dip_switch', {}).get('matrix_grid', []) + for row, col in matrix_grid: + mask[row][col] = '0' + + lines = [] + lines.append('#ifdef MATRIX_MASKED') + lines.append('__attribute__((weak)) const matrix_row_t matrix_mask[] = {') + for i in range(rows): + lines.append(f' 0b{"".join(reversed(mask[i]))},') + lines.append('};') + lines.append('#endif') + + return lines + + @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") @cli.argument('-kb', '--keyboard', arg_only=True, type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate keyboard.c for.') @@ -70,6 +95,7 @@ def generate_keyboard_c(cli): keyboard_h_lines = [GPL2_HEADER_C_LIKE, GENERATED_HEADER_C_LIKE, '#include QMK_KEYBOARD_H', ''] keyboard_h_lines.extend(_gen_led_config(kb_info_json)) + keyboard_h_lines.extend(_gen_matrix_mask(kb_info_json)) # Show the results dump_lines(cli.args.output, keyboard_h_lines, cli.args.quiet) |