Skip to content

Commit

Permalink
Add dd mapping for hardware based split handedness (qmk#22369)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr authored and zgagnon committed Dec 15, 2023
1 parent 83cf826 commit ac973e3
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
2 changes: 2 additions & 0 deletions data/mappings/info_config.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
21 changes: 17 additions & 4 deletions data/schemas/keyboard.jsonschema
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,6 @@
}
}
},
"matrix_grid": {
"type": "array",
"items": {"$ref": "qmk.definitions.v1#/mcu_pin"}
},
"matrix_pins": {
"type": "object",
"additionalProperties": false,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
},
Expand Down
6 changes: 6 additions & 0 deletions docs/reference_info_json.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions lib/python/qmk/cli/generate/config_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))


Expand Down Expand Up @@ -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'))
Expand Down
15 changes: 8 additions & 7 deletions lib/python/qmk/cli/generate/keyboard_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

# 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'
# Default mask to everything disabled
mask = [['0'] * cols for i in range(rows)]

# 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')
Expand Down
9 changes: 9 additions & 0 deletions lib/python/qmk/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ac973e3

Please sign in to comment.