diff options
Diffstat (limited to 'lib/python/qmk/info.py')
-rw-r--r-- | lib/python/qmk/info.py | 184 |
1 files changed, 174 insertions, 10 deletions
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py index 858fbab33..b6f2ecf64 100644 --- a/lib/python/qmk/info.py +++ b/lib/python/qmk/info.py | |||
@@ -61,8 +61,8 @@ def info_json(keyboard): | |||
61 | 61 | ||
62 | # Merge in the data from info.json, config.h, and rules.mk | 62 | # Merge in the data from info.json, config.h, and rules.mk |
63 | info_data = merge_info_jsons(keyboard, info_data) | 63 | info_data = merge_info_jsons(keyboard, info_data) |
64 | info_data = _extract_config_h(info_data) | ||
65 | info_data = _extract_rules_mk(info_data) | 64 | info_data = _extract_rules_mk(info_data) |
65 | info_data = _extract_config_h(info_data) | ||
66 | 66 | ||
67 | # Ensure that we have matrix row and column counts | 67 | # Ensure that we have matrix row and column counts |
68 | info_data = _matrix_size(info_data) | 68 | info_data = _matrix_size(info_data) |
@@ -161,10 +161,9 @@ def _extract_pins(pins): | |||
161 | return [_pin_name(pin) for pin in pins.split(',')] | 161 | return [_pin_name(pin) for pin in pins.split(',')] |
162 | 162 | ||
163 | 163 | ||
164 | def _extract_direct_matrix(info_data, direct_pins): | 164 | def _extract_direct_matrix(direct_pins): |
165 | """ | 165 | """ |
166 | """ | 166 | """ |
167 | info_data['matrix_pins'] = {} | ||
168 | direct_pin_array = [] | 167 | direct_pin_array = [] |
169 | 168 | ||
170 | while direct_pins[-1] != '}': | 169 | while direct_pins[-1] != '}': |
@@ -188,12 +187,157 @@ def _extract_direct_matrix(info_data, direct_pins): | |||
188 | return direct_pin_array | 187 | return direct_pin_array |
189 | 188 | ||
190 | 189 | ||
190 | def _extract_audio(info_data, config_c): | ||
191 | """Populate data about the audio configuration | ||
192 | """ | ||
193 | audio_pins = [] | ||
194 | |||
195 | for pin in 'B5', 'B6', 'B7', 'C4', 'C5', 'C6': | ||
196 | if config_c.get(f'{pin}_AUDIO'): | ||
197 | audio_pins.append(pin) | ||
198 | |||
199 | if audio_pins: | ||
200 | info_data['audio'] = {'pins': audio_pins} | ||
201 | |||
202 | |||
203 | def _extract_split_main(info_data, config_c): | ||
204 | """Populate data about the split configuration | ||
205 | """ | ||
206 | # Figure out how the main half is determined | ||
207 | if config_c.get('SPLIT_HAND_PIN') is True: | ||
208 | if 'split' not in info_data: | ||
209 | info_data['split'] = {} | ||
210 | |||
211 | if 'main' in info_data['split']: | ||
212 | _log_warning(info_data, 'Split main hand is specified in both config.h (SPLIT_HAND_PIN) and info.json (split.main) (Value: %s), the config.h value wins.' % info_data['split']['main']) | ||
213 | |||
214 | info_data['split']['main'] = 'pin' | ||
215 | |||
216 | if config_c.get('SPLIT_HAND_MATRIX_GRID'): | ||
217 | if 'split' not in info_data: | ||
218 | info_data['split'] = {} | ||
219 | |||
220 | if 'main' in info_data['split']: | ||
221 | _log_warning(info_data, 'Split main hand is specified in both config.h (SPLIT_HAND_MATRIX_GRID) and info.json (split.main) (Value: %s), the config.h value wins.' % info_data['split']['main']) | ||
222 | |||
223 | info_data['split']['main'] = 'matrix_grid' | ||
224 | info_data['split']['matrix_grid'] = _extract_pins(config_c['SPLIT_HAND_MATRIX_GRID']) | ||
225 | |||
226 | if config_c.get('EE_HANDS') is True: | ||
227 | if 'split' not in info_data: | ||
228 | info_data['split'] = {} | ||
229 | |||
230 | if 'main' in info_data['split']: | ||
231 | _log_warning(info_data, 'Split main hand is specified in both config.h (EE_HANDS) and info.json (split.main) (Value: %s), the config.h value wins.' % info_data['split']['main']) | ||
232 | |||
233 | info_data['split']['main'] = 'eeprom' | ||
234 | |||
235 | if config_c.get('MASTER_RIGHT') is True: | ||
236 | if 'split' not in info_data: | ||
237 | info_data['split'] = {} | ||
238 | |||
239 | if 'main' in info_data['split']: | ||
240 | _log_warning(info_data, 'Split main hand is specified in both config.h (MASTER_RIGHT) and info.json (split.main) (Value: %s), the config.h value wins.' % info_data['split']['main']) | ||
241 | |||
242 | info_data['split']['main'] = 'right' | ||
243 | |||
244 | if config_c.get('MASTER_LEFT') is True: | ||
245 | if 'split' not in info_data: | ||
246 | info_data['split'] = {} | ||
247 | |||
248 | if 'main' in info_data['split']: | ||
249 | _log_warning(info_data, 'Split main hand is specified in both config.h (MASTER_LEFT) and info.json (split.main) (Value: %s), the config.h value wins.' % info_data['split']['main']) | ||
250 | |||
251 | info_data['split']['main'] = 'left' | ||
252 | |||
253 | |||
254 | def _extract_split_transport(info_data, config_c): | ||
255 | # Figure out the transport method | ||
256 | if config_c.get('USE_I2C') is True: | ||
257 | if 'split' not in info_data: | ||
258 | info_data['split'] = {} | ||
259 | |||
260 | if 'transport' not in info_data['split']: | ||
261 | info_data['split']['transport'] = {} | ||
262 | |||
263 | if 'protocol' in info_data['split']['transport']: | ||
264 | _log_warning(info_data, 'Split transport is specified in both config.h (USE_I2C) and info.json (split.transport.protocol) (Value: %s), the config.h value wins.' % info_data['split']['transport']) | ||
265 | |||
266 | info_data['split']['transport']['protocol'] = 'i2c' | ||
267 | |||
268 | elif 'protocol' not in info_data.get('split', {}).get('transport', {}): | ||
269 | if 'split' not in info_data: | ||
270 | info_data['split'] = {} | ||
271 | |||
272 | if 'transport' not in info_data['split']: | ||
273 | info_data['split']['transport'] = {} | ||
274 | |||
275 | info_data['split']['transport']['protocol'] = 'serial' | ||
276 | |||
277 | |||
278 | def _extract_split_right_pins(info_data, config_c): | ||
279 | # Figure out the right half matrix pins | ||
280 | row_pins = config_c.get('MATRIX_ROW_PINS_RIGHT', '').replace('{', '').replace('}', '').strip() | ||
281 | col_pins = config_c.get('MATRIX_COL_PINS_RIGHT', '').replace('{', '').replace('}', '').strip() | ||
282 | unused_pin_text = config_c.get('UNUSED_PINS_RIGHT') | ||
283 | unused_pins = unused_pin_text.replace('{', '').replace('}', '').strip() if isinstance(unused_pin_text, str) else None | ||
284 | direct_pins = config_c.get('DIRECT_PINS_RIGHT', '').replace(' ', '')[1:-1] | ||
285 | |||
286 | if row_pins and col_pins: | ||
287 | if info_data.get('split', {}).get('matrix_pins', {}).get('right') in info_data: | ||
288 | _log_warning(info_data, 'Right hand matrix data is specified in both info.json and config.h, the config.h values win.') | ||
289 | |||
290 | if 'split' not in info_data: | ||
291 | info_data['split'] = {} | ||
292 | |||
293 | if 'matrix_pins' not in info_data['split']: | ||
294 | info_data['split']['matrix_pins'] = {} | ||
295 | |||
296 | if 'right' not in info_data['split']['matrix_pins']: | ||
297 | info_data['split']['matrix_pins']['right'] = {} | ||
298 | |||
299 | info_data['split']['matrix_pins']['right'] = { | ||
300 | 'cols': _extract_pins(col_pins), | ||
301 | 'rows': _extract_pins(row_pins), | ||
302 | } | ||
303 | |||
304 | if direct_pins: | ||
305 | if info_data.get('split', {}).get('matrix_pins', {}).get('right', {}): | ||
306 | _log_warning(info_data, 'Right hand matrix data is specified in both info.json and config.h, the config.h values win.') | ||
307 | |||
308 | if 'split' not in info_data: | ||
309 | info_data['split'] = {} | ||
310 | |||
311 | if 'matrix_pins' not in info_data['split']: | ||
312 | info_data['split']['matrix_pins'] = {} | ||
313 | |||
314 | if 'right' not in info_data['split']['matrix_pins']: | ||
315 | info_data['split']['matrix_pins']['right'] = {} | ||
316 | |||
317 | info_data['split']['matrix_pins']['right']['direct'] = _extract_direct_matrix(direct_pins) | ||
318 | |||
319 | if unused_pins: | ||
320 | if 'split' not in info_data: | ||
321 | info_data['split'] = {} | ||
322 | |||
323 | if 'matrix_pins' not in info_data['split']: | ||
324 | info_data['split']['matrix_pins'] = {} | ||
325 | |||
326 | if 'right' not in info_data['split']['matrix_pins']: | ||
327 | info_data['split']['matrix_pins']['right'] = {} | ||
328 | |||
329 | info_data['split']['matrix_pins']['right']['unused'] = _extract_pins(unused_pins) | ||
330 | |||
331 | |||
191 | def _extract_matrix_info(info_data, config_c): | 332 | def _extract_matrix_info(info_data, config_c): |
192 | """Populate the matrix information. | 333 | """Populate the matrix information. |
193 | """ | 334 | """ |
194 | row_pins = config_c.get('MATRIX_ROW_PINS', '').replace('{', '').replace('}', '').strip() | 335 | row_pins = config_c.get('MATRIX_ROW_PINS', '').replace('{', '').replace('}', '').strip() |
195 | col_pins = config_c.get('MATRIX_COL_PINS', '').replace('{', '').replace('}', '').strip() | 336 | col_pins = config_c.get('MATRIX_COL_PINS', '').replace('{', '').replace('}', '').strip() |
337 | unused_pin_text = config_c.get('UNUSED_PINS') | ||
338 | unused_pins = unused_pin_text.replace('{', '').replace('}', '').strip() if isinstance(unused_pin_text, str) else None | ||
196 | direct_pins = config_c.get('DIRECT_PINS', '').replace(' ', '')[1:-1] | 339 | direct_pins = config_c.get('DIRECT_PINS', '').replace(' ', '')[1:-1] |
340 | info_snippet = {} | ||
197 | 341 | ||
198 | if 'MATRIX_ROWS' in config_c and 'MATRIX_COLS' in config_c: | 342 | if 'MATRIX_ROWS' in config_c and 'MATRIX_COLS' in config_c: |
199 | if 'matrix_size' in info_data: | 343 | if 'matrix_size' in info_data: |
@@ -205,19 +349,35 @@ def _extract_matrix_info(info_data, config_c): | |||
205 | } | 349 | } |
206 | 350 | ||
207 | if row_pins and col_pins: | 351 | if row_pins and col_pins: |
208 | if 'matrix_pins' in info_data: | 352 | if 'matrix_pins' in info_data and 'cols' in info_data['matrix_pins'] and 'rows' in info_data['matrix_pins']: |
209 | _log_warning(info_data, 'Matrix pins are specified in both info.json and config.h, the config.h values win.') | 353 | _log_warning(info_data, 'Matrix pins are specified in both info.json and config.h, the config.h values win.') |
210 | 354 | ||
211 | info_data['matrix_pins'] = { | 355 | info_snippet['cols'] = _extract_pins(col_pins) |
212 | 'cols': _extract_pins(col_pins), | 356 | info_snippet['rows'] = _extract_pins(row_pins) |
213 | 'rows': _extract_pins(row_pins), | ||
214 | } | ||
215 | 357 | ||
216 | if direct_pins: | 358 | if direct_pins: |
217 | if 'matrix_pins' in info_data: | 359 | if 'matrix_pins' in info_data and 'direct' in info_data['matrix_pins']: |
218 | _log_warning(info_data, 'Direct pins are specified in both info.json and config.h, the config.h values win.') | 360 | _log_warning(info_data, 'Direct pins are specified in both info.json and config.h, the config.h values win.') |
219 | 361 | ||
220 | info_data['matrix_pins']['direct'] = _extract_direct_matrix(info_data, direct_pins) | 362 | info_snippet['direct'] = _extract_direct_matrix(direct_pins) |
363 | |||
364 | if unused_pins: | ||
365 | if 'matrix_pins' not in info_data: | ||
366 | info_data['matrix_pins'] = {} | ||
367 | |||
368 | info_snippet['unused'] = _extract_pins(unused_pins) | ||
369 | |||
370 | if config_c.get('CUSTOM_MATRIX', 'no') != 'no': | ||
371 | if 'matrix_pins' in info_data and 'custom' in info_data['matrix_pins']: | ||
372 | _log_warning(info_data, 'Custom Matrix is specified in both info.json and config.h, the config.h values win.') | ||
373 | |||
374 | info_snippet['custom'] = True | ||
375 | |||
376 | if config_c['CUSTOM_MATRIX'] == 'lite': | ||
377 | info_snippet['custom_lite'] = True | ||
378 | |||
379 | if info_snippet: | ||
380 | info_data['matrix_pins'] = info_snippet | ||
221 | 381 | ||
222 | return info_data | 382 | return info_data |
223 | 383 | ||
@@ -275,6 +435,10 @@ def _extract_config_h(info_data): | |||
275 | 435 | ||
276 | # Pull data that easily can't be mapped in json | 436 | # Pull data that easily can't be mapped in json |
277 | _extract_matrix_info(info_data, config_c) | 437 | _extract_matrix_info(info_data, config_c) |
438 | _extract_audio(info_data, config_c) | ||
439 | _extract_split_main(info_data, config_c) | ||
440 | _extract_split_transport(info_data, config_c) | ||
441 | _extract_split_right_pins(info_data, config_c) | ||
278 | 442 | ||
279 | return info_data | 443 | return info_data |
280 | 444 | ||