aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/protocol/chibios
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2020-04-13 09:39:38 +1000
committerGitHub <noreply@github.com>2020-04-13 09:39:38 +1000
commit05e9ff6554a1be119a585d691067ca2379c1d80d (patch)
treecd483e68d7e05950600fd4b96a2698d963b5b250 /tmk_core/protocol/chibios
parent17bda000f39dd40317160576d0a948d7abb2612f (diff)
downloadqmk_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/protocol/chibios')
-rw-r--r--tmk_core/protocol/chibios/init_hooks.h5
-rw-r--r--tmk_core/protocol/chibios/main.c38
2 files changed, 43 insertions, 0 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
123void __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
134void 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 */
106int main(void) { 144int main(void) {