From a19ae3d78466588caa9caf7c38d1617932255733 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 1 Nov 2023 00:55:48 +0000 Subject: [PATCH] Add dd mapping for hardware based split handedness (#22369) --- data/mappings/info_config.hjson | 2 ++ data/schemas/keyboard.jsonschema | 21 +++++++++++++++++---- docs/reference_info_json.md | 6 ++++++ lib/python/qmk/cli/generate/config_h.py | 13 +++++++++++++ lib/python/qmk/cli/generate/keyboard_c.py | 13 +++++++------ lib/python/qmk/info.py | 9 +++++++++ 6 files changed, 54 insertions(+), 10 deletions(-) diff --git a/data/mappings/info_config.hjson b/data/mappings/info_config.hjson index 9b65c73084..2ad0135950 100644 --- a/data/mappings/info_config.hjson +++ b/data/mappings/info_config.hjson @@ -154,6 +154,8 @@ // Split Keyboard "SOFT_SERIAL_PIN": {"info_key": "split.soft_serial_pin"}, "SOFT_SERIAL_SPEED": {"info_key": "split.soft_serial_speed"}, + "SPLIT_HAND_MATRIX_GRID": {"info_key": "split.handedness.matrix_grid", "value_type": "array", "to_c": false}, + "SPLIT_HAND_PIN": {"info_key": "split.handedness.pin"}, "SPLIT_USB_DETECT": {"info_key": "split.usb_detect.enabled", "value_type": "bool"}, "SPLIT_USB_TIMEOUT": {"info_key": "split.usb_detect.timeout", "value_type": "int"}, "SPLIT_USB_TIMEOUT_POLL": {"info_key": "split.usb_detect.polling_interval", "value_type": "int"}, diff --git a/data/schemas/keyboard.jsonschema b/data/schemas/keyboard.jsonschema index 20216a7f86..188e0a5b3c 100644 --- a/data/schemas/keyboard.jsonschema +++ b/data/schemas/keyboard.jsonschema @@ -640,10 +640,6 @@ } } }, - "matrix_grid": { - "type": "array", - "items": {"$ref": "qmk.definitions.v1#/mcu_pin"} - }, "matrix_pins": { "type": "object", "additionalProperties": false, @@ -681,6 +677,18 @@ } } }, + "handedness": { + "type": "object", + "additionalProperties": false, + "properties": { + "pin": {"$ref": "qmk.definitions.v1#/mcu_pin"}, + "matrix_grid": { + "$ref": "qmk.definitions.v1#/mcu_pin_array", + "minItems": 2, + "maxItems": 2 + } + } + }, "soft_serial_pin": {"$ref": "qmk.definitions.v1#/mcu_pin"}, "soft_serial_speed": { "type": "integer", @@ -736,6 +744,11 @@ "type": "string", "enum": ["eeprom", "left", "matrix_grid", "pin", "right"], "$comment": "Deprecated: use config.h options for now" + }, + "matrix_grid": { + "type": "array", + "items": {"$ref": "qmk.definitions.v1#/mcu_pin"}, + "$comment": "Deprecated: use split.handedness.matrix_grid instead" } } }, diff --git a/docs/reference_info_json.md b/docs/reference_info_json.md index 1d9429b54d..d9336fa2bb 100644 --- a/docs/reference_info_json.md +++ b/docs/reference_info_json.md @@ -647,6 +647,12 @@ Configures the [Split Keyboard](feature_split_keyboard.md) feature. * `right` * `rotary` * See [Encoder](#encoder) config. + * `handedness` + * `pin` + * The GPIO pin connected to determine handedness. + * `matrix_grid` + * The GPIO pins of the matrix position which determines the handedness. + * Example: `["A1", "B5"]` * `matrix_pins` * `right` * See [Matrix](#matrix) config. diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py index 924834caef..2c624e3e9a 100755 --- a/lib/python/qmk/cli/generate/config_h.py +++ b/lib/python/qmk/cli/generate/config_h.py @@ -74,7 +74,14 @@ def generate_matrix_size(kb_info_json, config_h_lines): def generate_matrix_masked(kb_info_json, config_h_lines): """"Enable matrix mask if required""" + mask_required = False + if 'matrix_grid' in kb_info_json.get('dip_switch', {}): + mask_required = True + if 'matrix_grid' in kb_info_json.get('split', {}).get('handedness', {}): + mask_required = True + + if mask_required: config_h_lines.append(generate_define('MATRIX_MASKED')) @@ -141,6 +148,12 @@ def generate_encoder_config(encoder_json, config_h_lines, postfix=''): def generate_split_config(kb_info_json, config_h_lines): """Generate the config.h lines for split boards.""" + if 'handedness' in kb_info_json['split']: + # TODO: change SPLIT_HAND_MATRIX_GRID to require brackets + handedness = kb_info_json['split']['handedness'] + if 'matrix_grid' in handedness: + config_h_lines.append(generate_define('SPLIT_HAND_MATRIX_GRID', ', '.join(handedness['matrix_grid']))) + if 'protocol' in kb_info_json['split'].get('transport', {}): if kb_info_json['split']['transport']['protocol'] == 'i2c': config_h_lines.append(generate_define('USE_I2C')) diff --git a/lib/python/qmk/cli/generate/keyboard_c.py b/lib/python/qmk/cli/generate/keyboard_c.py index 325624c9cc..f8a2372cf3 100755 --- a/lib/python/qmk/cli/generate/keyboard_c.py +++ b/lib/python/qmk/cli/generate/keyboard_c.py @@ -63,13 +63,14 @@ def _gen_matrix_mask(info_data): 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)] + # Default mask to everything disabled + mask = [['0'] * 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' + # Mirror layout macros squashed on top of each other + for layout_data in info_data['layouts'].values(): + for key_data in layout_data['layout']: + row, col = key_data['matrix'] + mask[row][col] = '1' lines = [] lines.append('#ifdef MATRIX_MASKED') diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index b56ec0fbff..fe829a724a 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py @@ -352,6 +352,14 @@ def _extract_secure_unlock(info_data, config_c): info_data['secure']['unlock_sequence'] = unlock_array +def _extract_split_handedness(info_data, config_c): + # Migrate + split = info_data.get('split', {}) + if 'matrix_grid' in split: + split['handedness'] = split.get('handedness', {}) + split['handedness']['matrix_grid'] = split.pop('matrix_grid') + + def _extract_split_transport(info_data, config_c): # Figure out the transport method if config_c.get('USE_I2C') is True: @@ -543,6 +551,7 @@ def _extract_config_h(info_data, config_c): _extract_matrix_info(info_data, config_c) _extract_audio(info_data, config_c) _extract_secure_unlock(info_data, config_c) + _extract_split_handedness(info_data, config_c) _extract_split_transport(info_data, config_c) _extract_split_right_pins(info_data, config_c) _extract_encoders(info_data, config_c)