aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/cli/generate/config_h.py
diff options
context:
space:
mode:
authorZach White <skullydazed@gmail.com>2021-08-16 15:33:30 -0700
committerGitHub <noreply@github.com>2021-08-16 23:33:30 +0100
commit8d9bfdc25437bb401985ba93b47edae2126e7fac (patch)
tree2439e7adde0bafd6af9a403c92c1a89384c3f6ea /lib/python/qmk/cli/generate/config_h.py
parentfac717c11cfa27780f2f9098383673784174141a (diff)
downloadqmk_firmware-8d9bfdc25437bb401985ba93b47edae2126e7fac.tar.gz
qmk_firmware-8d9bfdc25437bb401985ba93b47edae2126e7fac.zip
Add a lot more data to info.json (#13366)
* add some split data to info.json * add tags * add half of config_options.md to info.json * add support for designating master split * sort out split transport and primary * fix bad data in UNUSED_PINS * fixup custom transport * wip * allow for setting split right half keyboard matrix * add SPLIT_USB_DETECT * minor cleanup * fix an erroneous message * rework split.usb_detect * adding missing rgblight vars to info.json * add mouse_key to info.json * add all remaining options from docs/config_options.md * fix audio voices * qmk info: Change text output to use dotted notation * tweak layout output * resolve alias names * break out some functions to make flake8 happy * add a field for bootloader instructions * qmk generate-info-json: add a write-to-file argument Adds an argument that instructs qmk generate-info-json to write the output to a file instead of just to the terminal. * -arg_only, +action Because it was never my intention that one would have to specify a value for the argument that enables writing the file. * Bring qmk generate-info-json inline with other generate commands * pytest fixup * fix esca/getawayvan * fix data driven errors for bpiphany converters * features.force_nkro -> usb.force_nkro * split.primary->split.main * fix esca/getawayvan_f042 * fix the bpiphany converters for real * fix bpiphany/tiger_lily * Apply suggestions from code review Co-authored-by: Nick Brassel <nick@tzarc.org> * fix generate-api errors * fix matrix pin extraction for split boards * fix ploopyco/trackball_nano/rev1_001 Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Nick Brassel <nick@tzarc.org>
Diffstat (limited to 'lib/python/qmk/cli/generate/config_h.py')
-rwxr-xr-xlib/python/qmk/cli/generate/config_h.py140
1 files changed, 94 insertions, 46 deletions
diff --git a/lib/python/qmk/cli/generate/config_h.py b/lib/python/qmk/cli/generate/config_h.py
index 54cd5b96a..c0c148f1c 100755
--- a/lib/python/qmk/cli/generate/config_h.py
+++ b/lib/python/qmk/cli/generate/config_h.py
@@ -12,7 +12,7 @@ from qmk.keyboard import keyboard_completer, keyboard_folder
12from qmk.path import is_keyboard, normpath 12from qmk.path import is_keyboard, normpath
13 13
14 14
15def direct_pins(direct_pins): 15def direct_pins(direct_pins, postfix):
16 """Return the config.h lines that set the direct pins. 16 """Return the config.h lines that set the direct pins.
17 """ 17 """
18 rows = [] 18 rows = []
@@ -24,81 +24,60 @@ def direct_pins(direct_pins):
24 col_count = len(direct_pins[0]) 24 col_count = len(direct_pins[0])
25 row_count = len(direct_pins) 25 row_count = len(direct_pins)
26 26
27 return """ 27 return f"""
28#ifndef MATRIX_COLS 28#ifndef MATRIX_COLS{postfix}
29# define MATRIX_COLS %s 29# define MATRIX_COLS{postfix} {col_count}
30#endif // MATRIX_COLS 30#endif // MATRIX_COLS{postfix}
31 31
32#ifndef MATRIX_ROWS 32#ifndef MATRIX_ROWS{postfix}
33# define MATRIX_ROWS %s 33# define MATRIX_ROWS{postfix} {row_count}
34#endif // MATRIX_ROWS 34#endif // MATRIX_ROWS{postfix}
35 35
36#ifndef DIRECT_PINS 36#ifndef DIRECT_PINS{postfix}
37# define DIRECT_PINS {%s} 37# define DIRECT_PINS{postfix} {{ {", ".join(rows)} }}
38#endif // DIRECT_PINS 38#endif // DIRECT_PINS{postfix}
39""" % (col_count, row_count, ','.join(rows)) 39"""
40 40
41 41
42def pin_array(define, pins): 42def pin_array(define, pins, postfix):
43 """Return the config.h lines that set a pin array. 43 """Return the config.h lines that set a pin array.
44 """ 44 """
45 pin_num = len(pins) 45 pin_num = len(pins)
46 pin_array = ', '.join(map(str, [pin or 'NO_PIN' for pin in pins])) 46 pin_array = ', '.join(map(str, [pin or 'NO_PIN' for pin in pins]))
47 47
48 return f""" 48 return f"""
49#ifndef {define}S 49#ifndef {define}S{postfix}
50# define {define}S {pin_num} 50# define {define}S{postfix} {pin_num}
51#endif // {define}S 51#endif // {define}S{postfix}
52 52
53#ifndef {define}_PINS 53#ifndef {define}_PINS{postfix}
54# define {define}_PINS {{ {pin_array} }} 54# define {define}_PINS{postfix} {{ {pin_array} }}
55#endif // {define}_PINS 55#endif // {define}_PINS{postfix}
56""" 56"""
57 57
58 58
59def matrix_pins(matrix_pins): 59def matrix_pins(matrix_pins, postfix=''):
60 """Add the matrix config to the config.h. 60 """Add the matrix config to the config.h.
61 """ 61 """
62 pins = [] 62 pins = []
63 63
64 if 'direct' in matrix_pins: 64 if 'direct' in matrix_pins:
65 pins.append(direct_pins(matrix_pins['direct'])) 65 pins.append(direct_pins(matrix_pins['direct'], postfix))
66 66
67 if 'cols' in matrix_pins: 67 if 'cols' in matrix_pins:
68 pins.append(pin_array('MATRIX_COL', matrix_pins['cols'])) 68 pins.append(pin_array('MATRIX_COL', matrix_pins['cols'], postfix))
69 69
70 if 'rows' in matrix_pins: 70 if 'rows' in matrix_pins:
71 pins.append(pin_array('MATRIX_ROW', matrix_pins['rows'])) 71 pins.append(pin_array('MATRIX_ROW', matrix_pins['rows'], postfix))
72 72
73 return '\n'.join(pins) 73 return '\n'.join(pins)
74 74
75 75
76@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') 76def generate_config_items(kb_info_json, config_h_lines):
77@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") 77 """Iterate through the info_config map to generate basic config values.
78@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Keyboard to generate config.h for.')
79@cli.subcommand('Used by the make system to generate info_config.h from info.json', hidden=True)
80@automagic_keyboard
81@automagic_keymap
82def generate_config_h(cli):
83 """Generates the info_config.h file.
84 """ 78 """
85 # Determine our keyboard(s)
86 if not cli.config.generate_config_h.keyboard:
87 cli.log.error('Missing parameter: --keyboard')
88 cli.subcommands['info'].print_help()
89 return False
90
91 if not is_keyboard(cli.config.generate_config_h.keyboard):
92 cli.log.error('Invalid keyboard: "%s"', cli.config.generate_config_h.keyboard)
93 return False
94
95 # Build the info_config.h file.
96 kb_info_json = dotty(info_json(cli.config.generate_config_h.keyboard))
97 info_config_map = json_load(Path('data/mappings/info_config.json')) 79 info_config_map = json_load(Path('data/mappings/info_config.json'))
98 80
99 config_h_lines = ['/* This file was generated by `qmk generate-config-h`. Do not edit or copy.' ' */', '', '#pragma once']
100
101 # Iterate through the info_config map to generate basic things
102 for config_key, info_dict in info_config_map.items(): 81 for config_key, info_dict in info_config_map.items():
103 info_key = info_dict['info_key'] 82 info_key = info_dict['info_key']
104 key_type = info_dict.get('value_type', 'str') 83 key_type = info_dict.get('value_type', 'str')
@@ -135,9 +114,78 @@ def generate_config_h(cli):
135 config_h_lines.append(f'# define {config_key} {config_value}') 114 config_h_lines.append(f'# define {config_key} {config_value}')
136 config_h_lines.append(f'#endif // {config_key}') 115 config_h_lines.append(f'#endif // {config_key}')
137 116
117
118def generate_split_config(kb_info_json, config_h_lines):
119 """Generate the config.h lines for split boards."""
120 if 'primary' in kb_info_json['split']:
121 if kb_info_json['split']['primary'] in ('left', 'right'):
122 config_h_lines.append('')
123 config_h_lines.append('#ifndef MASTER_LEFT')
124 config_h_lines.append('# ifndef MASTER_RIGHT')
125 if kb_info_json['split']['primary'] == 'left':
126 config_h_lines.append('# define MASTER_LEFT')
127 elif kb_info_json['split']['primary'] == 'right':
128 config_h_lines.append('# define MASTER_RIGHT')
129 config_h_lines.append('# endif // MASTER_RIGHT')
130 config_h_lines.append('#endif // MASTER_LEFT')
131 elif kb_info_json['split']['primary'] == 'pin':
132 config_h_lines.append('')
133 config_h_lines.append('#ifndef SPLIT_HAND_PIN')
134 config_h_lines.append('# define SPLIT_HAND_PIN')
135 config_h_lines.append('#endif // SPLIT_HAND_PIN')
136 elif kb_info_json['split']['primary'] == 'matrix_grid':
137 config_h_lines.append('')
138 config_h_lines.append('#ifndef SPLIT_HAND_MATRIX_GRID')
139 config_h_lines.append('# define SPLIT_HAND_MATRIX_GRID {%s}' % (','.join(kb_info_json["split"]["matrix_grid"],)))
140 config_h_lines.append('#endif // SPLIT_HAND_MATRIX_GRID')
141 elif kb_info_json['split']['primary'] == 'eeprom':
142 config_h_lines.append('')
143 config_h_lines.append('#ifndef EE_HANDS')
144 config_h_lines.append('# define EE_HANDS')
145 config_h_lines.append('#endif // EE_HANDS')
146
147 if 'protocol' in kb_info_json['split'].get('transport', {}):
148 if kb_info_json['split']['transport']['protocol'] == 'i2c':
149 config_h_lines.append('')
150 config_h_lines.append('#ifndef USE_I2C')
151 config_h_lines.append('# define USE_I2C')
152 config_h_lines.append('#endif // USE_I2C')
153
154 if 'right' in kb_info_json['split'].get('matrix_pins', {}):
155 config_h_lines.append(matrix_pins(kb_info_json['split']['matrix_pins']['right'], '_RIGHT'))
156
157
158@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
159@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
160@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, help='Keyboard to generate config.h for.')
161@cli.subcommand('Used by the make system to generate info_config.h from info.json', hidden=True)
162@automagic_keyboard
163@automagic_keymap
164def generate_config_h(cli):
165 """Generates the info_config.h file.
166 """
167 # Determine our keyboard(s)
168 if not cli.config.generate_config_h.keyboard:
169 cli.log.error('Missing parameter: --keyboard')
170 cli.subcommands['info'].print_help()
171 return False
172
173 if not is_keyboard(cli.config.generate_config_h.keyboard):
174 cli.log.error('Invalid keyboard: "%s"', cli.config.generate_config_h.keyboard)
175 return False
176
177 # Build the info_config.h file.
178 kb_info_json = dotty(info_json(cli.config.generate_config_h.keyboard))
179 config_h_lines = ['/* This file was generated by `qmk generate-config-h`. Do not edit or copy.' ' */', '', '#pragma once']
180
181 generate_config_items(kb_info_json, config_h_lines)
182
138 if 'matrix_pins' in kb_info_json: 183 if 'matrix_pins' in kb_info_json:
139 config_h_lines.append(matrix_pins(kb_info_json['matrix_pins'])) 184 config_h_lines.append(matrix_pins(kb_info_json['matrix_pins']))
140 185
186 if 'split' in kb_info_json:
187 generate_split_config(kb_info_json, config_h_lines)
188
141 # Show the results 189 # Show the results
142 config_h = '\n'.join(config_h_lines) 190 config_h = '\n'.join(config_h_lines)
143 191