diff options
author | Joel Challis <git@zvecr.com> | 2021-02-28 21:25:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-28 21:25:09 +0000 |
commit | f8266a228cacbc31b0455161e0a8bd073feaa9db (patch) | |
tree | 877017e74a4369e7b3b07f35f7777af8fee5d84a | |
parent | 59c7deab0931207016315636ae1ef74c2c54dd18 (diff) | |
download | qmk_firmware-f8266a228cacbc31b0455161e0a8bd073feaa9db.tar.gz qmk_firmware-f8266a228cacbc31b0455161e0a8bd073feaa9db.zip |
Migrate make_dfu_header to CLI (#12061)
* Migrate make_dfu_header to CLI
* lint fixes
* Update lib/python/qmk/cli/generate/dfu_header.py
Co-authored-by: Ryan <fauxpark@gmail.com>
* Rename object
Co-authored-by: Ryan <fauxpark@gmail.com>
-rw-r--r-- | data/mappings/info_config.json | 6 | ||||
-rw-r--r-- | data/schemas/keyboard.jsonschema | 22 | ||||
-rw-r--r-- | lib/python/qmk/cli/generate/__init__.py | 1 | ||||
-rw-r--r-- | lib/python/qmk/cli/generate/dfu_header.py | 59 | ||||
-rw-r--r-- | tmk_core/avr.mk | 2 | ||||
-rwxr-xr-x | tmk_core/make_dfu_header.sh | 14 |
6 files changed, 88 insertions, 16 deletions
diff --git a/data/mappings/info_config.json b/data/mappings/info_config.json index 885e6d025..b949b1332 100644 --- a/data/mappings/info_config.json +++ b/data/mappings/info_config.json | |||
@@ -38,5 +38,9 @@ | |||
38 | "RGBLIGHT_SPLIT": {"info_key": "rgblight.split", "value_type": "bool"}, | 38 | "RGBLIGHT_SPLIT": {"info_key": "rgblight.split", "value_type": "bool"}, |
39 | "PRODUCT": {"info_key": "keyboard_folder", "to_json": false}, | 39 | "PRODUCT": {"info_key": "keyboard_folder", "to_json": false}, |
40 | "PRODUCT_ID": {"info_key": "usb.pid", "value_type": "hex"}, | 40 | "PRODUCT_ID": {"info_key": "usb.pid", "value_type": "hex"}, |
41 | "VENDOR_ID": {"info_key": "usb.vid", "value_type": "hex"} | 41 | "VENDOR_ID": {"info_key": "usb.vid", "value_type": "hex"}, |
42 | "QMK_ESC_OUTPUT": {"info_key": "qmk_lufa_bootloader.esc_output"}, | ||
43 | "QMK_ESC_INPUT": {"info_key": "qmk_lufa_bootloader.esc_input"}, | ||
44 | "QMK_LED": {"info_key": "qmk_lufa_bootloader.led"}, | ||
45 | "QMK_SPEAKER": {"info_key": "qmk_lufa_bootloader.speaker"} | ||
42 | } | 46 | } |
diff --git a/data/schemas/keyboard.jsonschema b/data/schemas/keyboard.jsonschema index 749e8f100..ec03a8828 100644 --- a/data/schemas/keyboard.jsonschema +++ b/data/schemas/keyboard.jsonschema | |||
@@ -299,6 +299,28 @@ | |||
299 | "pattern": "^[0-9A-F]x[0-9A-F][0-9A-F][0-9A-F][0-9A-F]" | 299 | "pattern": "^[0-9A-F]x[0-9A-F][0-9A-F][0-9A-F][0-9A-F]" |
300 | } | 300 | } |
301 | } | 301 | } |
302 | }, | ||
303 | "qmk_lufa_bootloader": { | ||
304 | "type": "object", | ||
305 | "additionalProperties": false, | ||
306 | "properties": { | ||
307 | "esc_output": { | ||
308 | "type": "string", | ||
309 | "pattern": "^[A-K]\\d{1,2}$" | ||
310 | }, | ||
311 | "esc_input": { | ||
312 | "type": "string", | ||
313 | "pattern": "^[A-K]\\d{1,2}$" | ||
314 | }, | ||
315 | "led": { | ||
316 | "type": "string", | ||
317 | "pattern": "^[A-K]\\d{1,2}$" | ||
318 | }, | ||
319 | "speaker": { | ||
320 | "type": "string", | ||
321 | "pattern": "^[A-K]\\d{1,2}$" | ||
322 | } | ||
323 | } | ||
302 | } | 324 | } |
303 | } | 325 | } |
304 | } | 326 | } |
diff --git a/lib/python/qmk/cli/generate/__init__.py b/lib/python/qmk/cli/generate/__init__.py index bd75b044c..f064649ac 100644 --- a/lib/python/qmk/cli/generate/__init__.py +++ b/lib/python/qmk/cli/generate/__init__.py | |||
@@ -1,5 +1,6 @@ | |||
1 | from . import api | 1 | from . import api |
2 | from . import config_h | 2 | from . import config_h |
3 | from . import dfu_header | ||
3 | from . import docs | 4 | from . import docs |
4 | from . import info_json | 5 | from . import info_json |
5 | from . import layouts | 6 | from . import layouts |
diff --git a/lib/python/qmk/cli/generate/dfu_header.py b/lib/python/qmk/cli/generate/dfu_header.py new file mode 100644 index 000000000..6f958b3a3 --- /dev/null +++ b/lib/python/qmk/cli/generate/dfu_header.py | |||
@@ -0,0 +1,59 @@ | |||
1 | """Used by the make system to generate LUFA Keyboard.h from info.json | ||
2 | """ | ||
3 | from dotty_dict import dotty | ||
4 | from milc import cli | ||
5 | |||
6 | from qmk.decorators import automagic_keyboard | ||
7 | from qmk.info import info_json | ||
8 | from qmk.path import is_keyboard, normpath | ||
9 | |||
10 | |||
11 | @cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to') | ||
12 | @cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages") | ||
13 | @cli.argument('-kb', '--keyboard', help='Keyboard to generate LUFA Keyboard.h for.') | ||
14 | @cli.subcommand('Used by the make system to generate LUFA Keyboard.h from info.json', hidden=True) | ||
15 | @automagic_keyboard | ||
16 | def generate_dfu_header(cli): | ||
17 | """Generates the Keyboard.h file. | ||
18 | """ | ||
19 | # Determine our keyboard(s) | ||
20 | if not cli.config.generate_dfu_header.keyboard: | ||
21 | cli.log.error('Missing parameter: --keyboard') | ||
22 | cli.subcommands['info'].print_help() | ||
23 | return False | ||
24 | |||
25 | if not is_keyboard(cli.config.generate_dfu_header.keyboard): | ||
26 | cli.log.error('Invalid keyboard: "%s"', cli.config.generate_dfu_header.keyboard) | ||
27 | return False | ||
28 | |||
29 | # Build the Keyboard.h file. | ||
30 | kb_info_json = dotty(info_json(cli.config.generate_dfu_header.keyboard)) | ||
31 | |||
32 | keyboard_h_lines = ['/* This file was generated by `qmk generate-dfu-header`. Do not edit or copy.' ' */', '', '#pragma once'] | ||
33 | keyboard_h_lines.append(f'#define MANUFACTURER {kb_info_json["manufacturer"]}') | ||
34 | keyboard_h_lines.append(f'#define PRODUCT {cli.config.generate_dfu_header.keyboard} Bootloader') | ||
35 | |||
36 | # Optional | ||
37 | if 'qmk_lufa_bootloader.esc_output' in kb_info_json: | ||
38 | keyboard_h_lines.append(f'#define QMK_ESC_OUTPUT {kb_info_json["qmk_lufa_bootloader.esc_output"]}') | ||
39 | if 'qmk_lufa_bootloader.esc_input' in kb_info_json: | ||
40 | keyboard_h_lines.append(f'#define QMK_ESC_INPUT {kb_info_json["qmk_lufa_bootloader.esc_input"]}') | ||
41 | if 'qmk_lufa_bootloader.led' in kb_info_json: | ||
42 | keyboard_h_lines.append(f'#define QMK_LED {kb_info_json["qmk_lufa_bootloader.led"]}') | ||
43 | if 'qmk_lufa_bootloader.speaker' in kb_info_json: | ||
44 | keyboard_h_lines.append(f'#define QMK_SPEAKER {kb_info_json["qmk_lufa_bootloader.speaker"]}') | ||
45 | |||
46 | # Show the results | ||
47 | keyboard_h = '\n'.join(keyboard_h_lines) | ||
48 | |||
49 | if cli.args.output: | ||
50 | cli.args.output.parent.mkdir(parents=True, exist_ok=True) | ||
51 | if cli.args.output.exists(): | ||
52 | cli.args.output.replace(cli.args.output.parent / (cli.args.output.name + '.bak')) | ||
53 | cli.args.output.write_text(keyboard_h) | ||
54 | |||
55 | if not cli.args.quiet: | ||
56 | cli.log.info('Wrote Keyboard.h to %s.', cli.args.output) | ||
57 | |||
58 | else: | ||
59 | print(keyboard_h) | ||
diff --git a/tmk_core/avr.mk b/tmk_core/avr.mk index 336a83e9d..06c308e55 100644 --- a/tmk_core/avr.mk +++ b/tmk_core/avr.mk | |||
@@ -284,7 +284,7 @@ extcoff: $(BUILD_DIR)/$(TARGET).elf | |||
284 | 284 | ||
285 | bootloader: | 285 | bootloader: |
286 | make -C lib/lufa/Bootloaders/DFU/ clean | 286 | make -C lib/lufa/Bootloaders/DFU/ clean |
287 | $(TMK_DIR)/make_dfu_header.sh $(ALL_CONFIGS) | 287 | bin/qmk generate-dfu-header --quiet --keyboard $(KEYBOARD) --output lib/lufa/Bootloaders/DFU/Keyboard.h |
288 | $(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) $(CFLAGS) $(OPT_DEFS) tmk_core/common/avr/bootloader_size.c 2> /dev/null | sed -ne 's/\r//;/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0)) | 288 | $(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) $(CFLAGS) $(OPT_DEFS) tmk_core/common/avr/bootloader_size.c 2> /dev/null | sed -ne 's/\r//;/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0)) |
289 | $(eval PROGRAM_SIZE_KB=$(shell n=`expr $(MAX_SIZE) / 1024` && echo $$(($$n)) || echo 0)) | 289 | $(eval PROGRAM_SIZE_KB=$(shell n=`expr $(MAX_SIZE) / 1024` && echo $$(($$n)) || echo 0)) |
290 | $(eval BOOT_SECTION_SIZE_KB=$(shell n=`expr $(BOOTLOADER_SIZE) / 1024` && echo $$(($$n)) || echo 0)) | 290 | $(eval BOOT_SECTION_SIZE_KB=$(shell n=`expr $(BOOTLOADER_SIZE) / 1024` && echo $$(($$n)) || echo 0)) |
diff --git a/tmk_core/make_dfu_header.sh b/tmk_core/make_dfu_header.sh deleted file mode 100755 index 7e2283dd7..000000000 --- a/tmk_core/make_dfu_header.sh +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | #!/bin/sh | ||
2 | ALL_CONFIGS=$* | ||
3 | GREP="grep" | ||
4 | |||
5 | cat <<- EOF > lib/lufa/Bootloaders/DFU/Keyboard.h | ||
6 | #pragma once | ||
7 | |||
8 | $($GREP "MANUFACTURER[ \t]" $ALL_CONFIGS -h | tail -1) | ||
9 | $($GREP "PRODUCT[ \t]" $ALL_CONFIGS -h | tail -1 | tr -d '\r') Bootloader | ||
10 | $($GREP "QMK_ESC_OUTPUT[ \t]" $ALL_CONFIGS -h | tail -1) | ||
11 | $($GREP "QMK_ESC_INPUT[ \t]" $ALL_CONFIGS -h | tail -1) | ||
12 | $($GREP "QMK_LED[ \t]" $ALL_CONFIGS -h | tail -1) | ||
13 | $($GREP "QMK_SPEAKER[ \t]" $ALL_CONFIGS -h | tail -1) | ||
14 | EOF | ||