aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-05-01 02:00:04 +0100
committerGitHub <noreply@github.com>2021-05-01 02:00:04 +0100
commitfc2b51194c58140b096b4c953c703b7f3f6f1fbc (patch)
treec0594513f50a37881ee31d794aba29a053717376
parent18dc12cd78448bffe4ad54aa15aa715ee959e64c (diff)
downloadqmk_firmware-fc2b51194c58140b096b4c953c703b7f3f6f1fbc.tar.gz
qmk_firmware-fc2b51194c58140b096b4c953c703b7f3f6f1fbc.zip
Allow <keyboard>.h to be optional when going data driven (#12706)
* Allow <keyboard>.h to be optional when going data driven * Remove stub files as no longer required * Rename function * Remove include of layouts.h for now * Take advantage of type=keyboard_folder * Take advantage of type=keyboard_folder - kb should still be mandatory
-rw-r--r--build_keyboard.mk6
-rw-r--r--keyboards/forever65/forever65.c16
-rw-r--r--keyboards/forever65/forever65.h18
-rw-r--r--lib/python/qmk/cli/generate/__init__.py1
-rwxr-xr-xlib/python/qmk/cli/generate/keyboard_h.py60
5 files changed, 66 insertions, 35 deletions
diff --git a/build_keyboard.mk b/build_keyboard.mk
index 366d1f5d2..ec6b026c5 100644
--- a/build_keyboard.mk
+++ b/build_keyboard.mk
@@ -205,6 +205,7 @@ endif
205# 205#
206# https://docs.qmk.fm/#/feature_layouts?id=tips-for-making-layouts-keyboard-agnostic 206# https://docs.qmk.fm/#/feature_layouts?id=tips-for-making-layouts-keyboard-agnostic
207# 207#
208QMK_KEYBOARD_H = $(KEYBOARD_OUTPUT)/src/default_keyboard.h
208ifneq ("$(wildcard $(KEYBOARD_PATH_1)/$(KEYBOARD_FOLDER_1).h)","") 209ifneq ("$(wildcard $(KEYBOARD_PATH_1)/$(KEYBOARD_FOLDER_1).h)","")
209 QMK_KEYBOARD_H = $(KEYBOARD_FOLDER_1).h 210 QMK_KEYBOARD_H = $(KEYBOARD_FOLDER_1).h
210endif 211endif
@@ -296,10 +297,13 @@ CONFIG_H += $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.
296$(KEYBOARD_OUTPUT)/src/info_config.h: $(INFO_JSON_FILES) 297$(KEYBOARD_OUTPUT)/src/info_config.h: $(INFO_JSON_FILES)
297 bin/qmk generate-config-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/info_config.h 298 bin/qmk generate-config-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/info_config.h
298 299
300$(KEYBOARD_OUTPUT)/src/default_keyboard.h: $(INFO_JSON_FILES)
301 bin/qmk generate-keyboard-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/default_keyboard.h
302
299$(KEYBOARD_OUTPUT)/src/layouts.h: $(INFO_JSON_FILES) 303$(KEYBOARD_OUTPUT)/src/layouts.h: $(INFO_JSON_FILES)
300 bin/qmk generate-layouts --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/layouts.h 304 bin/qmk generate-layouts --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/layouts.h
301 305
302generated-files: $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h 306generated-files: $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/default_keyboard.h $(KEYBOARD_OUTPUT)/src/layouts.h
303 307
304.INTERMEDIATE : generated-files 308.INTERMEDIATE : generated-files
305 309
diff --git a/keyboards/forever65/forever65.c b/keyboards/forever65/forever65.c
deleted file mode 100644
index 940f3300f..000000000
--- a/keyboards/forever65/forever65.c
+++ /dev/null
@@ -1,16 +0,0 @@
1/* Copyright 2021 zvecr<git@zvecr.com>
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#include "forever65.h"
diff --git a/keyboards/forever65/forever65.h b/keyboards/forever65/forever65.h
deleted file mode 100644
index 0edfd0b45..000000000
--- a/keyboards/forever65/forever65.h
+++ /dev/null
@@ -1,18 +0,0 @@
1/* Copyright 2021 zvecr<git@zvecr.com>
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#pragma once
17
18#include "quantum.h" \ No newline at end of file
diff --git a/lib/python/qmk/cli/generate/__init__.py b/lib/python/qmk/cli/generate/__init__.py
index f064649ac..0efca0022 100644
--- a/lib/python/qmk/cli/generate/__init__.py
+++ b/lib/python/qmk/cli/generate/__init__.py
@@ -3,6 +3,7 @@ from . import config_h
3from . import dfu_header 3from . import dfu_header
4from . import docs 4from . import docs
5from . import info_json 5from . import info_json
6from . import keyboard_h
6from . import layouts 7from . import layouts
7from . import rgb_breathe_table 8from . import rgb_breathe_table
8from . import rules_mk 9from . import rules_mk
diff --git a/lib/python/qmk/cli/generate/keyboard_h.py b/lib/python/qmk/cli/generate/keyboard_h.py
new file mode 100755
index 000000000..5a2b3656e
--- /dev/null
+++ b/lib/python/qmk/cli/generate/keyboard_h.py
@@ -0,0 +1,60 @@
1"""Used by the make system to generate keyboard.h from info.json.
2"""
3from milc import cli
4
5from qmk.decorators import automagic_keyboard, automagic_keymap
6from qmk.info import info_json
7from qmk.keyboard import keyboard_completer, keyboard_folder
8from qmk.path import is_keyboard, normpath
9
10
11def would_populate_layout_h(keyboard):
12 """Detect if a given keyboard is doing data driven layouts
13 """
14 # Build the info.json file
15 kb_info_json = info_json(keyboard)
16
17 for layout_name in kb_info_json['layouts']:
18 if kb_info_json['layouts'][layout_name]['c_macro']:
19 continue
20
21 if 'matrix' not in kb_info_json['layouts'][layout_name]['layout'][0]:
22 cli.log.debug('%s/%s: No matrix data!', keyboard, layout_name)
23 continue
24
25 return True
26
27 return False
28
29
30@cli.argument('-o', '--output', arg_only=True, type=normpath, help='File to write to')
31@cli.argument('-q', '--quiet', arg_only=True, action='store_true', help="Quiet mode, only output error messages")
32@cli.argument('-kb', '--keyboard', type=keyboard_folder, completer=keyboard_completer, required=True, help='Keyboard to generate keyboard.h for.')
33@cli.subcommand('Used by the make system to generate keyboard.h from info.json', hidden=True)
34@automagic_keyboard
35@automagic_keymap
36def generate_keyboard_h(cli):
37 """Generates the keyboard.h file.
38 """
39 has_layout_h = would_populate_layout_h(cli.config.generate_keyboard_h.keyboard)
40
41 # Build the layouts.h file.
42 keyboard_h_lines = ['/* This file was generated by `qmk generate-keyboard-h`. Do not edit or copy.' ' */', '', '#pragma once', '#include "quantum.h"']
43
44 if not has_layout_h:
45 keyboard_h_lines.append('#pragma error("<keyboard>.h is only optional for data driven keyboards - kb.h == bad times")')
46
47 # Show the results
48 keyboard_h = '\n'.join(keyboard_h_lines) + '\n'
49
50 if cli.args.output:
51 cli.args.output.parent.mkdir(parents=True, exist_ok=True)
52 if cli.args.output.exists():
53 cli.args.output.replace(cli.args.output.parent / (cli.args.output.name + '.bak'))
54 cli.args.output.write_text(keyboard_h)
55
56 if not cli.args.quiet:
57 cli.log.info('Wrote keyboard_h to %s.', cli.args.output)
58
59 else:
60 print(keyboard_h)