qmk new-keyboard: prompt for matrix type and dimensions

This commit is contained in:
fauxpark 2024-11-23 13:39:42 +11:00
parent 9e9b4acbde
commit edb15390d3
2 changed files with 41 additions and 9 deletions

View File

@ -2,11 +2,6 @@
"keyboard_name": "%KEYBOARD%",
"maintainer": "%USER_NAME%",
"manufacturer": "%REAL_NAME%",
"diode_direction": "COL2ROW",
"matrix_pins": {
"cols": ["C2"],
"rows": ["D1"]
},
"usb": {
"vid": "0xFEED",
"pid": "0x0000",

View File

@ -97,10 +97,21 @@ def augment_community_info(config, src, dest):
width = max(width, int(item["x"]) + 1)
height = max(height, int(item["y"]) + 1)
info["matrix_pins"] = {
"cols": ["C2"] * width,
"rows": ["D1"] * height,
}
matrix_type = prompt_matrix_type()
(rows, cols) = prompt_matrix_size(len(first_layout))
if matrix_type == 'direct':
info["matrix_pins"] = {
"direct": [
["C2"] * cols
] * rows
}
elif matrix_type in ['COL2ROW', 'ROW2COL']:
info["diode_direction"] = matrix_type
info["matrix_pins"] = {
"cols": ["C2"] * cols,
"rows": ["D1"] * rows,
}
# assume a 1:1 mapping on matrix to electrical
for item in first_layout:
@ -136,6 +147,32 @@ def prompt_heading_subheading(heading, subheading):
cli.log.info(subheading)
def prompt_matrix_type():
prompt_heading_subheading("Specify Matrix Type", "")
matrix_types = ['COL2ROW', 'ROW2COL', 'direct', 'custom']
return choice("Matrix type?", matrix_types)
def prompt_matrix_size(key_count):
prompt_heading_subheading("Specify Matrix Dimensions", "The number of rows and columns in the electrical matrix")
errmsg = 'Need at least one row or column!'
ret = True
while ret:
rows = int(_question("Rows:", reprompt=errmsg, validate=lambda x: int(x) > 0))
cols = int(_question("Cols:", reprompt=errmsg, validate=lambda x: int(x) > 0))
if rows * cols >= key_count:
ret = False
else:
cli.log.error(f"Number of rows ({rows}) * number of cols ({cols}) is not sufficient for the number of keys in the selected layout ({key_count})!")
return (rows, cols)
def prompt_keyboard():
prompt_heading_subheading("Name Your Keyboard Project", """For more information, see:
https://docs.qmk.fm/hardware_keyboard_guidelines#naming-your-keyboard-project""")