aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZach White <skullydazed@gmail.com>2020-12-30 11:21:18 -0800
committerZach White <skullydazed@drpepper.org>2021-01-07 21:21:12 -0800
commit56ef80216ae4c67e2a70857c61d1e62eec1ab380 (patch)
tree2c52f7c3f81e87eb9656d6e09843fcf72ad364ad /lib
parent2a67ff690ee5b0789b10448eef9fa0724a6c8d60 (diff)
downloadqmk_firmware-56ef80216ae4c67e2a70857c61d1e62eec1ab380.tar.gz
qmk_firmware-56ef80216ae4c67e2a70857c61d1e62eec1ab380.zip
make flake8 happy
Diffstat (limited to 'lib')
-rwxr-xr-xlib/python/qmk/cli/generate/rules_mk.py5
-rw-r--r--lib/python/qmk/info.py84
2 files changed, 50 insertions, 39 deletions
diff --git a/lib/python/qmk/cli/generate/rules_mk.py b/lib/python/qmk/cli/generate/rules_mk.py
index 570ef5a0d..2a7e91856 100755
--- a/lib/python/qmk/cli/generate/rules_mk.py
+++ b/lib/python/qmk/cli/generate/rules_mk.py
@@ -8,9 +8,10 @@ from qmk.path import is_keyboard, normpath
8 8
9info_to_rules = { 9info_to_rules = {
10 'bootloader': 'BOOTLOADER', 10 'bootloader': 'BOOTLOADER',
11 'processor': 'MCU' 11 'processor': 'MCU',
12} 12}
13 13
14
14@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') 15@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
15@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") 16@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
16@cli.argument('-kb', '--keyboard', help='Keyboard to generate config.h for.') 17@cli.argument('-kb', '--keyboard', help='Keyboard to generate config.h for.')
@@ -42,7 +43,7 @@ def generate_rules_mk(cli):
42 if 'features' in kb_info_json: 43 if 'features' in kb_info_json:
43 for feature, enabled in kb_info_json['features'].items(): 44 for feature, enabled in kb_info_json['features'].items():
44 if feature == 'bootmagic_lite' and enabled: 45 if feature == 'bootmagic_lite' and enabled:
45 rules_mk_lines.append(f'BOOTMAGIC_ENABLE := lite') 46 rules_mk_lines.append('BOOTMAGIC_ENABLE := lite')
46 else: 47 else:
47 feature = feature.upper() 48 feature = feature.upper()
48 enabled = 'yes' if enabled else 'no' 49 enabled = 'yes' if enabled else 'no'
diff --git a/lib/python/qmk/info.py b/lib/python/qmk/info.py
index 39af88f79..efd339115 100644
--- a/lib/python/qmk/info.py
+++ b/lib/python/qmk/info.py
@@ -234,14 +234,14 @@ def _extract_features(info_data, rules):
234 # Special handling for bootmagic which also supports a "lite" mode. 234 # Special handling for bootmagic which also supports a "lite" mode.
235 if rules.get('BOOTMAGIC_ENABLE') == 'lite': 235 if rules.get('BOOTMAGIC_ENABLE') == 'lite':
236 rules['BOOTMAGIC_LITE_ENABLE'] = 'on' 236 rules['BOOTMAGIC_LITE_ENABLE'] = 'on'
237 del(rules['BOOTMAGIC_ENABLE']) 237 del rules['BOOTMAGIC_ENABLE']
238 if rules.get('BOOTMAGIC_ENABLE') == 'full': 238 if rules.get('BOOTMAGIC_ENABLE') == 'full':
239 rules['BOOTMAGIC_ENABLE'] = 'on' 239 rules['BOOTMAGIC_ENABLE'] = 'on'
240 240
241 # Skip non-boolean features we haven't implemented special handling for 241 # Skip non-boolean features we haven't implemented special handling for
242 for feature in 'HAPTIC_ENABLE', 'QWIIC_ENABLE': 242 for feature in 'HAPTIC_ENABLE', 'QWIIC_ENABLE':
243 if rules.get(feature): 243 if rules.get(feature):
244 del(rules[feature]) 244 del rules[feature]
245 245
246 # Process the rest of the rules as booleans 246 # Process the rest of the rules as booleans
247 for key, value in rules.items(): 247 for key, value in rules.items():
@@ -337,6 +337,45 @@ def _extract_rgblight(info_data, config_c):
337 return info_data 337 return info_data
338 338
339 339
340def _extract_pins(pins):
341 """Returns a list of pins from a comma separated string of pins.
342 """
343 pins = [pin.strip() for pin in pins.split(',') if pin]
344
345 for pin in pins:
346 if pin[0] not in 'ABCDEFGHIJK' or not pin[1].isdigit():
347 raise ValueError(f'Invalid pin: {pin}')
348
349 return pins
350
351
352def _extract_direct_matrix(info_data, direct_pins):
353 """
354 """
355 info_data['matrix_pins'] = {}
356 direct_pin_array = []
357
358 while direct_pins[-1] != '}':
359 direct_pins = direct_pins[:-1]
360
361 for row in direct_pins.split('},{'):
362 if row.startswith('{'):
363 row = row[1:]
364
365 if row.endswith('}'):
366 row = row[:-1]
367
368 direct_pin_array.append([])
369
370 for pin in row.split(','):
371 if pin == 'NO_PIN':
372 pin = None
373
374 direct_pin_array[-1].append(pin)
375
376 return direct_pin_array
377
378
340def _extract_matrix_info(info_data, config_c): 379def _extract_matrix_info(info_data, config_c):
341 """Populate the matrix information. 380 """Populate the matrix information.
342 """ 381 """
@@ -349,53 +388,24 @@ def _extract_matrix_info(info_data, config_c):
349 _log_warning(info_data, 'Matrix size is specified in both info.json and config.h, the config.h values win.') 388 _log_warning(info_data, 'Matrix size is specified in both info.json and config.h, the config.h values win.')
350 389
351 info_data['matrix_size'] = { 390 info_data['matrix_size'] = {
352 'rows': compute(config_c.get('MATRIX_ROWS', '0')),
353 'cols': compute(config_c.get('MATRIX_COLS', '0')), 391 'cols': compute(config_c.get('MATRIX_COLS', '0')),
392 'rows': compute(config_c.get('MATRIX_ROWS', '0')),
354 } 393 }
355 394
356 if row_pins and col_pins: 395 if row_pins and col_pins:
357 if 'matrix_pins' in info_data: 396 if 'matrix_pins' in info_data:
358 _log_warning(info_data, 'Matrix pins are specified in both info.json and config.h, the config.h values win.') 397 _log_warning(info_data, 'Matrix pins are specified in both info.json and config.h, the config.h values win.')
359 398
360 info_data['matrix_pins'] = {} 399 info_data['matrix_pins'] = {
361 400 'cols': _extract_pins(col_pins),
362 # FIXME(skullydazed/anyone): Should really check every pin, not just the first 401 'rows': _extract_pins(row_pins),
363 if row_pins: 402 }
364 row_pins = [pin.strip() for pin in row_pins.split(',') if pin]
365 if row_pins[0][0] in 'ABCDEFGHIJK' and row_pins[0][1].isdigit():
366 info_data['matrix_pins']['rows'] = row_pins
367
368 if col_pins:
369 col_pins = [pin.strip() for pin in col_pins.split(',') if pin]
370 if col_pins[0][0] in 'ABCDEFGHIJK' and col_pins[0][1].isdigit():
371 info_data['matrix_pins']['cols'] = col_pins
372 403
373 if direct_pins: 404 if direct_pins:
374 if 'matrix_pins' in info_data: 405 if 'matrix_pins' in info_data:
375 _log_warning(info_data, 'Direct pins are specified in both info.json and config.h, the config.h values win.') 406 _log_warning(info_data, 'Direct pins are specified in both info.json and config.h, the config.h values win.')
376 407
377 info_data['matrix_pins'] = {} 408 info_data['matrix_pins']['direct'] = _extract_direct_matrix(info_data, direct_pins)
378 direct_pin_array = []
379
380 while direct_pins[-1] != '}':
381 direct_pins = direct_pins[:-1]
382
383 for row in direct_pins.split('},{'):
384 if row.startswith('{'):
385 row = row[1:]
386
387 if row.endswith('}'):
388 row = row[:-1]
389
390 direct_pin_array.append([])
391
392 for pin in row.split(','):
393 if pin == 'NO_PIN':
394 pin = None
395
396 direct_pin_array[-1].append(pin)
397
398 info_data['matrix_pins']['direct'] = direct_pin_array
399 409
400 return info_data 410 return info_data
401 411