diff options
| author | Nick Brassel <nick@tzarc.org> | 2020-04-13 09:39:38 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-13 09:39:38 +1000 |
| commit | 05e9ff6554a1be119a585d691067ca2379c1d80d (patch) | |
| tree | cd483e68d7e05950600fd4b96a2698d963b5b250 /tmk_core | |
| parent | 17bda000f39dd40317160576d0a948d7abb2612f (diff) | |
| download | qmk_firmware-05e9ff6554a1be119a585d691067ca2379c1d80d.tar.gz qmk_firmware-05e9ff6554a1be119a585d691067ca2379c1d80d.zip | |
Add support for hardware and board initialisation overrides. (#8330)
* Add support for hardware and board initialisation overrides.
* qmk cformat.
* Add some documentation.
* Docs clarity.
* Make early_hardware_init_pre a no-op for now, until migrations occur.
* Doco update
* Make distinction between keyboard and ChibiOS board in docs
* Doc anchors.
* Update tmk_core/protocol/chibios/main.c
Co-Authored-By: Joel Challis <git@zvecr.com>
* Rework bootloader entry to be off by default, allow opting-in.
Co-authored-by: Joel Challis <git@zvecr.com>
Diffstat (limited to 'tmk_core')
| -rw-r--r-- | tmk_core/protocol/chibios/init_hooks.h | 5 | ||||
| -rw-r--r-- | tmk_core/protocol/chibios/main.c | 38 | ||||
| -rw-r--r-- | tmk_core/rules.mk | 16 |
3 files changed, 54 insertions, 5 deletions
diff --git a/tmk_core/protocol/chibios/init_hooks.h b/tmk_core/protocol/chibios/init_hooks.h new file mode 100644 index 000000000..fffced913 --- /dev/null +++ b/tmk_core/protocol/chibios/init_hooks.h | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | // Override the initialisation functions inside the ChibiOS board.c files | ||
| 4 | #define __early_init __chibios_override___early_init | ||
| 5 | #define boardInit __chibios_override_boardInit | ||
diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c index 6479fd09d..61665eb6f 100644 --- a/tmk_core/protocol/chibios/main.c +++ b/tmk_core/protocol/chibios/main.c | |||
| @@ -33,6 +33,11 @@ | |||
| 33 | #include "debug.h" | 33 | #include "debug.h" |
| 34 | #include "printf.h" | 34 | #include "printf.h" |
| 35 | 35 | ||
| 36 | #ifndef EARLY_INIT_PERFORM_BOOTLOADER_JUMP | ||
| 37 | // Change this to be TRUE once we've migrated keyboards to the new init system | ||
| 38 | # define EARLY_INIT_PERFORM_BOOTLOADER_JUMP FALSE | ||
| 39 | #endif | ||
| 40 | |||
| 36 | #ifdef SLEEP_LED_ENABLE | 41 | #ifdef SLEEP_LED_ENABLE |
| 37 | # include "sleep_led.h" | 42 | # include "sleep_led.h" |
| 38 | #endif | 43 | #endif |
| @@ -101,6 +106,39 @@ void midi_ep_task(void); | |||
| 101 | // } | 106 | // } |
| 102 | // } | 107 | // } |
| 103 | 108 | ||
| 109 | /* Early initialisation | ||
| 110 | */ | ||
| 111 | __attribute__((weak)) void early_hardware_init_pre(void) { | ||
| 112 | #if EARLY_INIT_PERFORM_BOOTLOADER_JUMP | ||
| 113 | void enter_bootloader_mode_if_requested(void); | ||
| 114 | enter_bootloader_mode_if_requested(); | ||
| 115 | #endif // EARLY_INIT_PERFORM_BOOTLOADER_JUMP | ||
| 116 | } | ||
| 117 | |||
| 118 | __attribute__((weak)) void early_hardware_init_post(void) {} | ||
| 119 | |||
| 120 | __attribute__((weak)) void board_init(void) {} | ||
| 121 | |||
| 122 | // This overrides what's normally in ChibiOS board definitions | ||
| 123 | void __early_init(void) { | ||
| 124 | early_hardware_init_pre(); | ||
| 125 | |||
| 126 | // This is the renamed equivalent of __early_init in the board.c file | ||
| 127 | void __chibios_override___early_init(void); | ||
| 128 | __chibios_override___early_init(); | ||
| 129 | |||
| 130 | early_hardware_init_post(); | ||
| 131 | } | ||
| 132 | |||
| 133 | // This overrides what's normally in ChibiOS board definitions | ||
| 134 | void boardInit(void) { | ||
| 135 | // This is the renamed equivalent of boardInit in the board.c file | ||
| 136 | void __chibios_override_boardInit(void); | ||
| 137 | __chibios_override_boardInit(); | ||
| 138 | |||
| 139 | board_init(); | ||
| 140 | } | ||
| 141 | |||
| 104 | /* Main thread | 142 | /* Main thread |
| 105 | */ | 143 | */ |
| 106 | int main(void) { | 144 | int main(void) { |
diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk index c1474a5c2..a66718cd2 100644 --- a/tmk_core/rules.mk +++ b/tmk_core/rules.mk | |||
| @@ -223,6 +223,12 @@ $(foreach LOBJ, $(NO_LTO_OBJ), $(eval $(call NO_LTO,$(LOBJ)))) | |||
| 223 | 223 | ||
| 224 | MOVE_DEP = mv -f $(patsubst %.o,%.td,$@) $(patsubst %.o,%.d,$@) | 224 | MOVE_DEP = mv -f $(patsubst %.o,%.td,$@) $(patsubst %.o,%.d,$@) |
| 225 | 225 | ||
| 226 | # For a ChibiOS build, ensure that the board files have the hook overrides injected | ||
| 227 | define BOARDSRC_INJECT_HOOKS | ||
| 228 | $(KEYBOARD_OUTPUT)/$(patsubst %.c,%.o,$(patsubst ./%,%,$1)): INIT_HOOK_CFLAGS += -include $(TOP_DIR)/tmk_core/protocol/chibios/init_hooks.h | ||
| 229 | endef | ||
| 230 | $(foreach LOBJ, $(BOARDSRC), $(eval $(call BOARDSRC_INJECT_HOOKS,$(LOBJ)))) | ||
| 231 | |||
| 226 | # Add QMK specific flags | 232 | # Add QMK specific flags |
| 227 | DFU_SUFFIX ?= dfu-suffix | 233 | DFU_SUFFIX ?= dfu-suffix |
| 228 | DFU_SUFFIX_ARGS ?= | 234 | DFU_SUFFIX_ARGS ?= |
| @@ -306,27 +312,27 @@ ifdef $1_CONFIG | |||
| 306 | $1_CONFIG_FLAGS += $$(patsubst %,-include %,$$($1_CONFIG)) | 312 | $1_CONFIG_FLAGS += $$(patsubst %,-include %,$$($1_CONFIG)) |
| 307 | endif | 313 | endif |
| 308 | $1_CFLAGS = $$(ALL_CFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) $$(NOLTO_CFLAGS) | 314 | $1_CFLAGS = $$(ALL_CFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) $$(NOLTO_CFLAGS) |
| 309 | $1_CXXFLAGS= $$(ALL_CXXFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) $$(NOLTO_CFLAGS) | 315 | $1_CXXFLAGS = $$(ALL_CXXFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) $$(NOLTO_CFLAGS) |
| 310 | $1_ASFLAGS= $$(ALL_ASFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) | 316 | $1_ASFLAGS = $$(ALL_ASFLAGS) $$($1_DEFS) $$($1_INCFLAGS) $$($1_CONFIG_FLAGS) |
| 311 | 317 | ||
| 312 | # Compile: create object files from C source files. | 318 | # Compile: create object files from C source files. |
| 313 | $1/%.o : %.c $1/%.d $1/cflags.txt $1/compiler.txt | $(BEGIN) | 319 | $1/%.o : %.c $1/%.d $1/cflags.txt $1/compiler.txt | $(BEGIN) |
| 314 | @mkdir -p $$(@D) | 320 | @mkdir -p $$(@D) |
| 315 | @$$(SILENT) || printf "$$(MSG_COMPILING) $$<" | $$(AWK_CMD) | 321 | @$$(SILENT) || printf "$$(MSG_COMPILING) $$<" | $$(AWK_CMD) |
| 316 | $$(eval CMD := $$(CC) -c $$($1_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) | 322 | $$(eval CMD := $$(CC) -c $$($1_CFLAGS) $$(INIT_HOOK_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) |
| 317 | @$$(BUILD_CMD) | 323 | @$$(BUILD_CMD) |
| 318 | 324 | ||
| 319 | # Compile: create object files from C++ source files. | 325 | # Compile: create object files from C++ source files. |
| 320 | $1/%.o : %.cpp $1/%.d $1/cxxflags.txt $1/compiler.txt | $(BEGIN) | 326 | $1/%.o : %.cpp $1/%.d $1/cxxflags.txt $1/compiler.txt | $(BEGIN) |
| 321 | @mkdir -p $$(@D) | 327 | @mkdir -p $$(@D) |
| 322 | @$$(SILENT) || printf "$$(MSG_COMPILING_CXX) $$<" | $$(AWK_CMD) | 328 | @$$(SILENT) || printf "$$(MSG_COMPILING_CXX) $$<" | $$(AWK_CMD) |
| 323 | $$(eval CMD=$$(CC) -c $$($1_CXXFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) | 329 | $$(eval CMD=$$(CC) -c $$($1_CXXFLAGS) $$(INIT_HOOK_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) |
| 324 | @$$(BUILD_CMD) | 330 | @$$(BUILD_CMD) |
| 325 | 331 | ||
| 326 | $1/%.o : %.cc $1/%.d $1/cxxflags.txt $1/compiler.txt | $(BEGIN) | 332 | $1/%.o : %.cc $1/%.d $1/cxxflags.txt $1/compiler.txt | $(BEGIN) |
| 327 | @mkdir -p $$(@D) | 333 | @mkdir -p $$(@D) |
| 328 | @$$(SILENT) || printf "$$(MSG_COMPILING_CXX) $$<" | $$(AWK_CMD) | 334 | @$$(SILENT) || printf "$$(MSG_COMPILING_CXX) $$<" | $$(AWK_CMD) |
| 329 | $$(eval CMD=$$(CC) -c $$($1_CXXFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) | 335 | $$(eval CMD=$$(CC) -c $$($1_CXXFLAGS) $$(INIT_HOOK_CFLAGS) $$(GENDEPFLAGS) $$< -o $$@ && $$(MOVE_DEP)) |
| 330 | @$$(BUILD_CMD) | 336 | @$$(BUILD_CMD) |
| 331 | 337 | ||
| 332 | # Assemble: create object files from assembler source files. | 338 | # Assemble: create object files from assembler source files. |
