aboutsummaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/common.mk23
-rw-r--r--tmk_core/common/action_util.c58
-rw-r--r--tmk_core/common/action_util.h5
-rw-r--r--tmk_core/common/avr/suspend.c4
-rw-r--r--tmk_core/common/bootmagic.c163
-rw-r--r--tmk_core/common/bootmagic.h102
-rw-r--r--tmk_core/common/bootmagic_lite.c49
-rw-r--r--tmk_core/common/chibios/chibios_config.h2
-rw-r--r--tmk_core/common/chibios/sleep_led.c88
-rw-r--r--tmk_core/common/chibios/suspend.c8
-rw-r--r--tmk_core/common/eeconfig.c2
-rw-r--r--tmk_core/common/eeconfig.h9
-rw-r--r--tmk_core/common/keyboard.c10
-rw-r--r--tmk_core/common/magic.c39
-rw-r--r--tmk_core/common/magic.h3
-rw-r--r--tmk_core/common/usb_util.c29
-rw-r--r--tmk_core/common/usb_util.h22
-rw-r--r--tmk_core/protocol.mk4
-rw-r--r--tmk_core/protocol/chibios.mk1
-rw-r--r--tmk_core/protocol/chibios/usb_util.c21
-rw-r--r--tmk_core/protocol/lufa.mk1
-rw-r--r--tmk_core/protocol/lufa/usb_util.c34
-rw-r--r--tmk_core/protocol/vusb.mk1
-rw-r--r--tmk_core/protocol/vusb/usb_util.c24
24 files changed, 245 insertions, 457 deletions
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index 238b3c69f..2f8f81126 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -12,6 +12,7 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \
12 $(COMMON_DIR)/sendchar_null.c \ 12 $(COMMON_DIR)/sendchar_null.c \
13 $(COMMON_DIR)/eeconfig.c \ 13 $(COMMON_DIR)/eeconfig.c \
14 $(COMMON_DIR)/report.c \ 14 $(COMMON_DIR)/report.c \
15 $(COMMON_DIR)/usb_util.c \
15 $(PLATFORM_COMMON_DIR)/suspend.c \ 16 $(PLATFORM_COMMON_DIR)/suspend.c \
16 $(PLATFORM_COMMON_DIR)/timer.c \ 17 $(PLATFORM_COMMON_DIR)/timer.c \
17 $(COMMON_DIR)/sync_timer.c \ 18 $(COMMON_DIR)/sync_timer.c \
@@ -24,28 +25,6 @@ else
24 include $(TMK_PATH)/$(COMMON_DIR)/lib_printf.mk 25 include $(TMK_PATH)/$(COMMON_DIR)/lib_printf.mk
25endif 26endif
26 27
27# Option modules
28BOOTMAGIC_ENABLE ?= no
29VALID_MAGIC_TYPES := yes full lite
30ifneq ($(strip $(BOOTMAGIC_ENABLE)), no)
31 ifeq ($(filter $(BOOTMAGIC_ENABLE),$(VALID_MAGIC_TYPES)),)
32 $(error BOOTMAGIC_ENABLE="$(BOOTMAGIC_ENABLE)" is not a valid type of magic)
33 endif
34 ifeq ($(strip $(BOOTMAGIC_ENABLE)), lite)
35 TMK_COMMON_DEFS += -DBOOTMAGIC_LITE
36 TMK_COMMON_SRC += $(COMMON_DIR)/bootmagic_lite.c
37
38 TMK_COMMON_DEFS += -DMAGIC_ENABLE
39 TMK_COMMON_SRC += $(COMMON_DIR)/magic.c
40 else
41 TMK_COMMON_DEFS += -DBOOTMAGIC_ENABLE
42 TMK_COMMON_SRC += $(COMMON_DIR)/bootmagic.c
43 endif
44else
45 TMK_COMMON_DEFS += -DMAGIC_ENABLE
46 TMK_COMMON_SRC += $(COMMON_DIR)/magic.c
47endif
48
49SHARED_EP_ENABLE = no 28SHARED_EP_ENABLE = no
50MOUSE_SHARED_EP ?= yes 29MOUSE_SHARED_EP ?= yes
51ifeq ($(strip $(KEYBOARD_SHARED_EP)), yes) 30ifeq ($(strip $(KEYBOARD_SHARED_EP)), yes)
diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c
index 000503b08..a57c8bf66 100644
--- a/tmk_core/common/action_util.c
+++ b/tmk_core/common/action_util.c
@@ -147,12 +147,16 @@ void clear_oneshot_swaphands(void) {
147 * FIXME: needs doc 147 * FIXME: needs doc
148 */ 148 */
149void set_oneshot_layer(uint8_t layer, uint8_t state) { 149void set_oneshot_layer(uint8_t layer, uint8_t state) {
150 oneshot_layer_data = layer << 3 | state; 150 if (!keymap_config.oneshot_disable) {
151 layer_on(layer); 151 oneshot_layer_data = layer << 3 | state;
152 layer_on(layer);
152# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) 153# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
153 oneshot_layer_time = timer_read(); 154 oneshot_layer_time = timer_read();
154# endif 155# endif
155 oneshot_layer_changed_kb(get_oneshot_layer()); 156 oneshot_layer_changed_kb(get_oneshot_layer());
157 } else {
158 layer_on(layer);
159 }
156} 160}
157/** \brief Reset oneshot layer 161/** \brief Reset oneshot layer
158 * 162 *
@@ -172,7 +176,7 @@ void reset_oneshot_layer(void) {
172void clear_oneshot_layer_state(oneshot_fullfillment_t state) { 176void clear_oneshot_layer_state(oneshot_fullfillment_t state) {
173 uint8_t start_state = oneshot_layer_data; 177 uint8_t start_state = oneshot_layer_data;
174 oneshot_layer_data &= ~state; 178 oneshot_layer_data &= ~state;
175 if (!get_oneshot_layer_state() && start_state != oneshot_layer_data) { 179 if ((!get_oneshot_layer_state() && start_state != oneshot_layer_data) || keymap_config.oneshot_disable) {
176 layer_off(get_oneshot_layer()); 180 layer_off(get_oneshot_layer());
177 reset_oneshot_layer(); 181 reset_oneshot_layer();
178 } 182 }
@@ -182,6 +186,39 @@ void clear_oneshot_layer_state(oneshot_fullfillment_t state) {
182 * FIXME: needs doc 186 * FIXME: needs doc
183 */ 187 */
184bool is_oneshot_layer_active(void) { return get_oneshot_layer_state(); } 188bool is_oneshot_layer_active(void) { return get_oneshot_layer_state(); }
189
190/** \brief set oneshot
191 *
192 * FIXME: needs doc
193 */
194void oneshot_set(bool active) {
195 if (keymap_config.oneshot_disable != active) {
196 keymap_config.oneshot_disable = active;
197 eeconfig_update_keymap(keymap_config.raw);
198 dprintf("Oneshot: active: %d\n", active);
199 }
200}
201
202/** \brief toggle oneshot
203 *
204 * FIXME: needs doc
205 */
206void oneshot_toggle(void) { oneshot_set(!keymap_config.oneshot_disable); }
207
208/** \brief enable oneshot
209 *
210 * FIXME: needs doc
211 */
212void oneshot_enable(void) { oneshot_set(true); }
213
214/** \brief disable oneshot
215 *
216 * FIXME: needs doc
217 */
218void oneshot_disable(void) { oneshot_set(false); }
219
220bool is_oneshot_enabled(void) { return keymap_config.oneshot_disable; }
221
185#endif 222#endif
186 223
187/** \brief Send keyboard report 224/** \brief Send keyboard report
@@ -321,14 +358,17 @@ void del_oneshot_mods(uint8_t mods) {
321 * FIXME: needs doc 358 * FIXME: needs doc
322 */ 359 */
323void set_oneshot_mods(uint8_t mods) { 360void set_oneshot_mods(uint8_t mods) {
324 if (oneshot_mods != mods) { 361 if (!keymap_config.oneshot_disable) {
362 if (oneshot_mods != mods) {
325# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) 363# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
326 oneshot_time = timer_read(); 364 oneshot_time = timer_read();
327# endif 365# endif
328 oneshot_mods = mods; 366 oneshot_mods = mods;
329 oneshot_mods_changed_kb(mods); 367 oneshot_mods_changed_kb(mods);
368 }
330 } 369 }
331} 370}
371
332/** \brief clear oneshot mods 372/** \brief clear oneshot mods
333 * 373 *
334 * FIXME: needs doc 374 * FIXME: needs doc
diff --git a/tmk_core/common/action_util.h b/tmk_core/common/action_util.h
index ff29f79b0..f2b3897ae 100644
--- a/tmk_core/common/action_util.h
+++ b/tmk_core/common/action_util.h
@@ -85,6 +85,11 @@ void oneshot_mods_changed_kb(uint8_t mods);
85void oneshot_layer_changed_user(uint8_t layer); 85void oneshot_layer_changed_user(uint8_t layer);
86void oneshot_layer_changed_kb(uint8_t layer); 86void oneshot_layer_changed_kb(uint8_t layer);
87 87
88void oneshot_toggle(void);
89void oneshot_enable(void);
90void oneshot_disable(void);
91bool is_oneshot_enabled(void);
92
88/* inspect */ 93/* inspect */
89uint8_t has_anymod(void); 94uint8_t has_anymod(void);
90 95
diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c
index 47a82a2ee..d52c8ac41 100644
--- a/tmk_core/common/avr/suspend.c
+++ b/tmk_core/common/avr/suspend.c
@@ -28,6 +28,10 @@
28# include "rgblight.h" 28# include "rgblight.h"
29#endif 29#endif
30 30
31#ifdef RGB_MATRIX_ENABLE
32# include "rgb_matrix.h"
33#endif
34
31/** \brief Suspend idle 35/** \brief Suspend idle
32 * 36 *
33 * FIXME: needs doc 37 * FIXME: needs doc
diff --git a/tmk_core/common/bootmagic.c b/tmk_core/common/bootmagic.c
deleted file mode 100644
index c1b3adf94..000000000
--- a/tmk_core/common/bootmagic.c
+++ /dev/null
@@ -1,163 +0,0 @@
1#include <stdint.h>
2#include <stdbool.h>
3#include "wait.h"
4#include "matrix.h"
5#include "bootloader.h"
6#include "debug.h"
7#include "keymap.h"
8#include "host.h"
9#include "action_layer.h"
10#include "eeconfig.h"
11#include "bootmagic.h"
12
13keymap_config_t keymap_config;
14
15/** \brief Bootmagic
16 *
17 * FIXME: needs doc
18 */
19void bootmagic(void) {
20 /* check signature */
21 if (!eeconfig_is_enabled()) {
22 eeconfig_init();
23 }
24
25 /* do scans in case of bounce */
26 print("bootmagic scan: ... ");
27 uint8_t scan = 100;
28 while (scan--) {
29 matrix_scan();
30 wait_ms(10);
31 }
32 print("done.\n");
33
34 /* bootmagic skip */
35 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SKIP)) {
36 return;
37 }
38
39 /* eeconfig clear */
40 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) {
41 eeconfig_init();
42 }
43
44 /* bootloader */
45 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_BOOTLOADER)) {
46 bootloader_jump();
47 }
48
49 /* debug enable */
50 debug_config.raw = eeconfig_read_debug();
51 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_ENABLE)) {
52 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MATRIX)) {
53 debug_config.matrix = !debug_config.matrix;
54 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_KEYBOARD)) {
55 debug_config.keyboard = !debug_config.keyboard;
56 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MOUSE)) {
57 debug_config.mouse = !debug_config.mouse;
58 } else {
59 debug_config.enable = !debug_config.enable;
60 }
61 }
62 eeconfig_update_debug(debug_config.raw);
63
64 /* keymap config */
65 keymap_config.raw = eeconfig_read_keymap();
66 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) {
67 keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
68 }
69 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) {
70 keymap_config.capslock_to_control = !keymap_config.capslock_to_control;
71 }
72 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) {
73 keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
74 }
75 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) {
76 keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui;
77 }
78 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_NO_GUI)) {
79 keymap_config.no_gui = !keymap_config.no_gui;
80 }
81 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) {
82 keymap_config.swap_grave_esc = !keymap_config.swap_grave_esc;
83 }
84 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) {
85 keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace;
86 }
87 if (bootmagic_scan_keycode(BOOTMAGIC_HOST_NKRO)) {
88 keymap_config.nkro = !keymap_config.nkro;
89 }
90 eeconfig_update_keymap(keymap_config.raw);
91
92 /* default layer */
93 uint8_t default_layer = 0;
94 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) {
95 default_layer |= (1 << 0);
96 }
97 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) {
98 default_layer |= (1 << 1);
99 }
100 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) {
101 default_layer |= (1 << 2);
102 }
103 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) {
104 default_layer |= (1 << 3);
105 }
106 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) {
107 default_layer |= (1 << 4);
108 }
109 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) {
110 default_layer |= (1 << 5);
111 }
112 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) {
113 default_layer |= (1 << 6);
114 }
115 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) {
116 default_layer |= (1 << 7);
117 }
118 if (default_layer) {
119 eeconfig_update_default_layer(default_layer);
120 default_layer_set((layer_state_t)default_layer);
121 } else {
122 default_layer = eeconfig_read_default_layer();
123 default_layer_set((layer_state_t)default_layer);
124 }
125 /* Also initialize layer state to trigger callback functions for layer_state */
126 layer_state_set_kb((layer_state_t)layer_state);
127
128 /* EE_HANDS handedness */
129 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_LEFT)) {
130 eeconfig_update_handedness(true);
131 }
132 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_RIGHT)) {
133 eeconfig_update_handedness(false);
134 }
135}
136
137/** \brief Scan Keycode
138 *
139 * FIXME: needs doc
140 */
141static bool scan_keycode(uint8_t keycode) {
142 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
143 matrix_row_t matrix_row = matrix_get_row(r);
144 for (uint8_t c = 0; c < MATRIX_COLS; c++) {
145 if (matrix_row & ((matrix_row_t)1 << c)) {
146 if (keycode == keymap_key_to_keycode(0, (keypos_t){.row = r, .col = c})) {
147 return true;
148 }
149 }
150 }
151 }
152 return false;
153}
154
155/** \brief Bootmagic Scan Keycode
156 *
157 * FIXME: needs doc
158 */
159bool bootmagic_scan_keycode(uint8_t keycode) {
160 if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false;
161
162 return scan_keycode(keycode);
163}
diff --git a/tmk_core/common/bootmagic.h b/tmk_core/common/bootmagic.h
deleted file mode 100644
index 8209d0194..000000000
--- a/tmk_core/common/bootmagic.h
+++ /dev/null
@@ -1,102 +0,0 @@
1#pragma once
2
3/* FIXME: Add special doxygen comments for defines here. */
4
5/* bootmagic salt key */
6#ifndef BOOTMAGIC_KEY_SALT
7# define BOOTMAGIC_KEY_SALT KC_SPACE
8#endif
9
10/* skip bootmagic and eeconfig */
11#ifndef BOOTMAGIC_KEY_SKIP
12# define BOOTMAGIC_KEY_SKIP KC_ESC
13#endif
14
15/* eeprom clear */
16#ifndef BOOTMAGIC_KEY_EEPROM_CLEAR
17# define BOOTMAGIC_KEY_EEPROM_CLEAR KC_BSPACE
18#endif
19
20/* kick up bootloader */
21#ifndef BOOTMAGIC_KEY_BOOTLOADER
22# define BOOTMAGIC_KEY_BOOTLOADER KC_B
23#endif
24
25/* debug enable */
26#ifndef BOOTMAGIC_KEY_DEBUG_ENABLE
27# define BOOTMAGIC_KEY_DEBUG_ENABLE KC_D
28#endif
29#ifndef BOOTMAGIC_KEY_DEBUG_MATRIX
30# define BOOTMAGIC_KEY_DEBUG_MATRIX KC_X
31#endif
32#ifndef BOOTMAGIC_KEY_DEBUG_KEYBOARD
33# define BOOTMAGIC_KEY_DEBUG_KEYBOARD KC_K
34#endif
35#ifndef BOOTMAGIC_KEY_DEBUG_MOUSE
36# define BOOTMAGIC_KEY_DEBUG_MOUSE KC_M
37#endif
38#ifndef BOOTMAGIC_KEY_EE_HANDS_LEFT
39# define BOOTMAGIC_KEY_EE_HANDS_LEFT KC_L
40#endif
41#ifndef BOOTMAGIC_KEY_EE_HANDS_RIGHT
42# define BOOTMAGIC_KEY_EE_HANDS_RIGHT KC_R
43#endif
44
45/*
46 * keymap config
47 */
48#ifndef BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK
49# define BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK KC_LCTRL
50#endif
51#ifndef BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL
52# define BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL KC_CAPSLOCK
53#endif
54#ifndef BOOTMAGIC_KEY_SWAP_LALT_LGUI
55# define BOOTMAGIC_KEY_SWAP_LALT_LGUI KC_LALT
56#endif
57#ifndef BOOTMAGIC_KEY_SWAP_RALT_RGUI
58# define BOOTMAGIC_KEY_SWAP_RALT_RGUI KC_RALT
59#endif
60#ifndef BOOTMAGIC_KEY_NO_GUI
61# define BOOTMAGIC_KEY_NO_GUI KC_LGUI
62#endif
63#ifndef BOOTMAGIC_KEY_SWAP_GRAVE_ESC
64# define BOOTMAGIC_KEY_SWAP_GRAVE_ESC KC_GRAVE
65#endif
66#ifndef BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE
67# define BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE KC_BSLASH
68#endif
69#ifndef BOOTMAGIC_HOST_NKRO
70# define BOOTMAGIC_HOST_NKRO KC_N
71#endif
72
73/*
74 * change default layer
75 */
76#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_0
77# define BOOTMAGIC_KEY_DEFAULT_LAYER_0 KC_0
78#endif
79#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_1
80# define BOOTMAGIC_KEY_DEFAULT_LAYER_1 KC_1
81#endif
82#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_2
83# define BOOTMAGIC_KEY_DEFAULT_LAYER_2 KC_2
84#endif
85#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_3
86# define BOOTMAGIC_KEY_DEFAULT_LAYER_3 KC_3
87#endif
88#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_4
89# define BOOTMAGIC_KEY_DEFAULT_LAYER_4 KC_4
90#endif
91#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_5
92# define BOOTMAGIC_KEY_DEFAULT_LAYER_5 KC_5
93#endif
94#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_6
95# define BOOTMAGIC_KEY_DEFAULT_LAYER_6 KC_6
96#endif
97#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_7
98# define BOOTMAGIC_KEY_DEFAULT_LAYER_7 KC_7
99#endif
100
101void bootmagic(void);
102bool bootmagic_scan_keycode(uint8_t keycode);
diff --git a/tmk_core/common/bootmagic_lite.c b/tmk_core/common/bootmagic_lite.c
deleted file mode 100644
index cbf756a17..000000000
--- a/tmk_core/common/bootmagic_lite.c
+++ /dev/null
@@ -1,49 +0,0 @@
1#include "quantum.h"
2
3/** \brief Reset eeprom
4 *
5 * ...just incase someone wants to only change the eeprom behaviour
6 */
7__attribute__((weak)) void bootmagic_lite_reset_eeprom(void) {
8#if defined(VIA_ENABLE)
9 via_eeprom_reset();
10#else
11 eeconfig_disable();
12#endif
13}
14
15/** \brief The lite version of TMK's bootmagic based on Wilba.
16 *
17 * 100% less potential for accidentally making the keyboard do stupid things.
18 */
19__attribute__((weak)) void bootmagic_lite(void) {
20 // We need multiple scans because debouncing can't be turned off.
21 matrix_scan();
22#if defined(DEBOUNCE) && DEBOUNCE > 0
23 wait_ms(DEBOUNCE * 2);
24#else
25 wait_ms(30);
26#endif
27 matrix_scan();
28
29 // If the configured key (commonly Esc) is held down on power up,
30 // reset the EEPROM valid state and jump to bootloader.
31 // This isn't very generalized, but we need something that doesn't
32 // rely on user's keymaps in firmware or EEPROM.
33 uint8_t row = BOOTMAGIC_LITE_ROW;
34 uint8_t col = BOOTMAGIC_LITE_COLUMN;
35
36#if defined(SPLIT_KEYBOARD) && defined(BOOTMAGIC_LITE_ROW_RIGHT) && defined(BOOTMAGIC_LITE_COLUMN_RIGHT)
37 if (!is_keyboard_left()) {
38 row = BOOTMAGIC_LITE_ROW_RIGHT;
39 col = BOOTMAGIC_LITE_COLUMN_RIGHT;
40 }
41#endif
42
43 if (matrix_get_row(row) & (1 << col)) {
44 bootmagic_lite_reset_eeprom();
45
46 // Jump to bootloader.
47 bootloader_jump();
48 }
49}
diff --git a/tmk_core/common/chibios/chibios_config.h b/tmk_core/common/chibios/chibios_config.h
index b4d96465d..bebf026de 100644
--- a/tmk_core/common/chibios/chibios_config.h
+++ b/tmk_core/common/chibios/chibios_config.h
@@ -15,6 +15,8 @@
15 */ 15 */
16#pragma once 16#pragma once
17 17
18#define SPLIT_USB_DETECT // Force this on for now
19
18#if defined(STM32F1XX) 20#if defined(STM32F1XX)
19# define USE_GPIOV1 21# define USE_GPIOV1
20#endif 22#endif
diff --git a/tmk_core/common/chibios/sleep_led.c b/tmk_core/common/chibios/sleep_led.c
index 5595eec0e..477056a45 100644
--- a/tmk_core/common/chibios/sleep_led.c
+++ b/tmk_core/common/chibios/sleep_led.c
@@ -9,21 +9,13 @@
9 * Use LP timer on Kinetises, TIM14 on STM32F0. 9 * Use LP timer on Kinetises, TIM14 on STM32F0.
10 */ 10 */
11 11
12#if defined(KL2x) || defined(K20x) 12#ifndef SLEEP_LED_GPT_DRIVER
13 13# if defined(STM32F0XX)
14/* Use Low Power Timer (LPTMR) */ 14# define SLEEP_LED_GPT_DRIVER GPTD14
15# define TIMER_INTERRUPT_VECTOR KINETIS_LPTMR0_IRQ_VECTOR 15# endif
16# define RESET_COUNTER LPTMR0->CSR |= LPTMRx_CSR_TCF
17
18#elif defined(STM32F0XX)
19
20/* Use TIM14 manually */
21# define TIMER_INTERRUPT_VECTOR STM32_TIM14_HANDLER
22# define RESET_COUNTER STM32_TIM14->SR &= ~STM32_TIM_SR_UIF
23
24#endif 16#endif
25 17
26#if defined(KL2x) || defined(K20x) || defined(STM32F0XX) /* common parts for timers/interrupts */ 18#if defined(KL2x) || defined(K20x) || defined(SLEEP_LED_GPT_DRIVER) /* common parts for timers/interrupts */
27 19
28/* Breathing Sleep LED brighness(PWM On period) table 20/* Breathing Sleep LED brighness(PWM On period) table
29 * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle 21 * (64[steps] * 4[duration]) / 64[PWM periods/s] = 4 second breath cycle
@@ -33,10 +25,7 @@
33 */ 25 */
34static const uint8_t breathing_table[64] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10, 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252, 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23, 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 26static const uint8_t breathing_table[64] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 6, 10, 15, 23, 32, 44, 58, 74, 93, 113, 135, 157, 179, 199, 218, 233, 245, 252, 255, 252, 245, 233, 218, 199, 179, 157, 135, 113, 93, 74, 58, 44, 32, 23, 15, 10, 6, 4, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
35 27
36/* interrupt handler */ 28void sleep_led_timer_callback(void) {
37OSAL_IRQ_HANDLER(TIMER_INTERRUPT_VECTOR) {
38 OSAL_IRQ_PROLOGUE();
39
40 /* Software PWM 29 /* Software PWM
41 * timer:1111 1111 1111 1111 30 * timer:1111 1111 1111 1111
42 * \_____/\/ \_______/____ count(0-255) 31 * \_____/\/ \_______/____ count(0-255)
@@ -64,17 +53,16 @@ OSAL_IRQ_HANDLER(TIMER_INTERRUPT_VECTOR) {
64 if (timer.pwm.count == breathing_table[timer.pwm.index]) { 53 if (timer.pwm.count == breathing_table[timer.pwm.index]) {
65 led_set(0); 54 led_set(0);
66 } 55 }
67
68 /* Reset the counter */
69 RESET_COUNTER;
70
71 OSAL_IRQ_EPILOGUE();
72} 56}
73 57
74#endif /* common parts for known platforms */ 58#endif /* common parts for known platforms */
75 59
76#if defined(KL2x) || defined(K20x) /* platform selection: familiar Kinetis chips */ 60#if defined(KL2x) || defined(K20x) /* platform selection: familiar Kinetis chips */
77 61
62/* Use Low Power Timer (LPTMR) */
63# define TIMER_INTERRUPT_VECTOR KINETIS_LPTMR0_IRQ_VECTOR
64# define RESET_COUNTER LPTMR0->CSR |= LPTMRx_CSR_TCF
65
78/* LPTMR clock options */ 66/* LPTMR clock options */
79# define LPTMR_CLOCK_MCGIRCLK 0 /* 4MHz clock */ 67# define LPTMR_CLOCK_MCGIRCLK 0 /* 4MHz clock */
80# define LPTMR_CLOCK_LPO 1 /* 1kHz clock */ 68# define LPTMR_CLOCK_LPO 1 /* 1kHz clock */
@@ -86,6 +74,18 @@ OSAL_IRQ_HANDLER(TIMER_INTERRUPT_VECTOR) {
86# define SIM_SCGC5_LPTMR SIM_SCGC5_LPTIMER 74# define SIM_SCGC5_LPTMR SIM_SCGC5_LPTIMER
87# endif 75# endif
88 76
77/* interrupt handler */
78OSAL_IRQ_HANDLER(TIMER_INTERRUPT_VECTOR) {
79 OSAL_IRQ_PROLOGUE();
80
81 sleep_led_timer_callback();
82
83 /* Reset the counter */
84 RESET_COUNTER;
85
86 OSAL_IRQ_EPILOGUE();
87}
88
89/* Initialise the timer */ 89/* Initialise the timer */
90void sleep_led_init(void) { 90void sleep_led_init(void) {
91 /* Make sure the clock to the LPTMR is enabled */ 91 /* Make sure the clock to the LPTMR is enabled */
@@ -159,45 +159,23 @@ void sleep_led_toggle(void) {
159 LPTMR0->CSR ^= LPTMRx_CSR_TEN; 159 LPTMR0->CSR ^= LPTMRx_CSR_TEN;
160} 160}
161 161
162#elif defined(STM32F0XX) /* platform selection: STM32F0XX */ 162#elif defined(SLEEP_LED_GPT_DRIVER)
163
164/* Initialise the timer */
165void sleep_led_init(void) {
166 /* enable clock */
167 rccEnableTIM14(FALSE); /* low power enable = FALSE */
168 rccResetTIM14();
169
170 /* prescale */
171 /* Assuming 48MHz internal clock */
172 /* getting cca 65484 irqs/sec */
173 STM32_TIM14->PSC = 733;
174 163
175 /* auto-reload */ 164static void gptTimerCallback(GPTDriver *gptp) {
176 /* 0 => interrupt every time */ 165 (void)gptp;
177 STM32_TIM14->ARR = 3; 166 sleep_led_timer_callback();
167}
178 168
179 /* enable counter update event interrupt */ 169static const GPTConfig gptcfg = {1000000, gptTimerCallback, 0, 0};
180 STM32_TIM14->DIER |= STM32_TIM_DIER_UIE;
181 170
182 /* register interrupt vector */ 171/* Initialise the timer */
183 nvicEnableVector(STM32_TIM14_NUMBER, 2); /* vector, priority */ 172void sleep_led_init(void) { gptStart(&SLEEP_LED_GPT_DRIVER, &gptcfg); }
184}
185 173
186void sleep_led_enable(void) { 174void sleep_led_enable(void) { gptStartContinuous(&SLEEP_LED_GPT_DRIVER, gptcfg.frequency / 0xFFFF); }
187 /* Enable the timer */
188 STM32_TIM14->CR1 = STM32_TIM_CR1_CEN | STM32_TIM_CR1_URS;
189 /* URS => update event only on overflow; setting UG bit disabled */
190}
191 175
192void sleep_led_disable(void) { 176void sleep_led_disable(void) { gptStopTimer(&SLEEP_LED_GPT_DRIVER); }
193 /* Disable the timer */
194 STM32_TIM14->CR1 = 0;
195}
196 177
197void sleep_led_toggle(void) { 178void sleep_led_toggle(void) { (SLEEP_LED_GPT_DRIVER.state == GPT_READY) ? sleep_led_enable() : sleep_led_disable(); }
198 /* Toggle the timer */
199 STM32_TIM14->CR1 ^= STM32_TIM_CR1_CEN;
200}
201 179
202#else /* platform selection: not on familiar chips */ 180#else /* platform selection: not on familiar chips */
203 181
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c
index 49e20641f..17f024cab 100644
--- a/tmk_core/common/chibios/suspend.c
+++ b/tmk_core/common/chibios/suspend.c
@@ -24,6 +24,10 @@
24# include "rgblight.h" 24# include "rgblight.h"
25#endif 25#endif
26 26
27#ifdef RGB_MATRIX_ENABLE
28# include "rgb_matrix.h"
29#endif
30
27/** \brief suspend idle 31/** \brief suspend idle
28 * 32 *
29 * FIXME: needs doc 33 * FIXME: needs doc
@@ -53,6 +57,10 @@ void suspend_power_down(void) {
53 backlight_set(0); 57 backlight_set(0);
54#endif 58#endif
55 59
60#ifdef RGB_MATRIX_ENABLE
61 rgb_matrix_task();
62#endif
63
56 // Turn off LED indicators 64 // Turn off LED indicators
57 uint8_t leds_off = 0; 65 uint8_t leds_off = 0;
58#if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE) 66#if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE)
diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c
index 5e3ebe6ee..92a509217 100644
--- a/tmk_core/common/eeconfig.c
+++ b/tmk_core/common/eeconfig.c
@@ -57,7 +57,7 @@ void eeconfig_init_quantum(void) {
57 eeprom_update_dword(EECONFIG_HAPTIC, 0); 57 eeprom_update_dword(EECONFIG_HAPTIC, 0);
58 eeprom_update_byte(EECONFIG_VELOCIKEY, 0); 58 eeprom_update_byte(EECONFIG_VELOCIKEY, 0);
59 eeprom_update_dword(EECONFIG_RGB_MATRIX, 0); 59 eeprom_update_dword(EECONFIG_RGB_MATRIX, 0);
60 eeprom_update_byte(EECONFIG_RGB_MATRIX_SPEED, 0); 60 eeprom_update_word(EECONFIG_RGB_MATRIX_EXTENDED, 0);
61 61
62 // TODO: Remove once ARM has a way to configure EECONFIG_HANDEDNESS 62 // TODO: Remove once ARM has a way to configure EECONFIG_HANDEDNESS
63 // within the emulated eeprom via dfu-util or another tool 63 // within the emulated eeprom via dfu-util or another tool
diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h
index 86b9e6f99..39bc51d5d 100644
--- a/tmk_core/common/eeconfig.h
+++ b/tmk_core/common/eeconfig.h
@@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21#include <stdbool.h> 21#include <stdbool.h>
22 22
23#ifndef EECONFIG_MAGIC_NUMBER 23#ifndef EECONFIG_MAGIC_NUMBER
24# define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEEB // When changing, decrement this value to avoid future re-init issues 24# define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEEA // When changing, decrement this value to avoid future re-init issues
25#endif 25#endif
26#define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF 26#define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF
27 27
@@ -44,11 +44,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
44 44
45#define EECONFIG_HAPTIC (uint32_t *)24 45#define EECONFIG_HAPTIC (uint32_t *)24
46#define EECONFIG_RGB_MATRIX (uint32_t *)28 46#define EECONFIG_RGB_MATRIX (uint32_t *)28
47#define EECONFIG_RGB_MATRIX_SPEED (uint8_t *)32 47// Speed & Flags
48#define EECONFIG_RGB_MATRIX_EXTENDED (uint16_t *)32
48// TODO: Combine these into a single word and single block of EEPROM 49// TODO: Combine these into a single word and single block of EEPROM
49#define EECONFIG_KEYMAP_UPPER_BYTE (uint8_t *)33 50#define EECONFIG_KEYMAP_UPPER_BYTE (uint8_t *)34
50// Size of EEPROM being used, other code can refer to this for available EEPROM 51// Size of EEPROM being used, other code can refer to this for available EEPROM
51#define EECONFIG_SIZE 34 52#define EECONFIG_SIZE 35
52/* debug bit */ 53/* debug bit */
53#define EECONFIG_DEBUG_ENABLE (1 << 0) 54#define EECONFIG_DEBUG_ENABLE (1 << 0)
54#define EECONFIG_DEBUG_MATRIX (1 << 1) 55#define EECONFIG_DEBUG_MATRIX (1 << 1)
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index ce3255c06..65d9e00c7 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -34,11 +34,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
34#ifdef BACKLIGHT_ENABLE 34#ifdef BACKLIGHT_ENABLE
35# include "backlight.h" 35# include "backlight.h"
36#endif 36#endif
37#ifdef BOOTMAGIC_ENABLE
38# include "bootmagic.h"
39#else
40# include "magic.h"
41#endif
42#ifdef MOUSEKEY_ENABLE 37#ifdef MOUSEKEY_ENABLE
43# include "mousekey.h" 38# include "mousekey.h"
44#endif 39#endif
@@ -296,11 +291,6 @@ void keyboard_init(void) {
296#ifdef ADB_MOUSE_ENABLE 291#ifdef ADB_MOUSE_ENABLE
297 adb_mouse_init(); 292 adb_mouse_init();
298#endif 293#endif
299#ifdef BOOTMAGIC_ENABLE
300 bootmagic();
301#else
302 magic();
303#endif
304#ifdef BACKLIGHT_ENABLE 294#ifdef BACKLIGHT_ENABLE
305 backlight_init(); 295 backlight_init();
306#endif 296#endif
diff --git a/tmk_core/common/magic.c b/tmk_core/common/magic.c
deleted file mode 100644
index e14994164..000000000
--- a/tmk_core/common/magic.c
+++ /dev/null
@@ -1,39 +0,0 @@
1#include <stdint.h>
2#include <stdbool.h>
3#if defined(__AVR__)
4# include <util/delay.h>
5#endif
6#include "matrix.h"
7#include "bootloader.h"
8#include "debug.h"
9#include "keymap.h"
10#include "host.h"
11#include "action_layer.h"
12#include "eeconfig.h"
13#include "magic.h"
14
15keymap_config_t keymap_config;
16
17/** \brief Magic
18 *
19 * FIXME: Needs doc
20 */
21void magic(void) {
22 /* check signature */
23 if (!eeconfig_is_enabled()) {
24 eeconfig_init();
25 }
26
27 /* debug enable */
28 debug_config.raw = eeconfig_read_debug();
29
30 /* keymap config */
31 keymap_config.raw = eeconfig_read_keymap();
32
33 uint8_t default_layer = 0;
34 default_layer = eeconfig_read_default_layer();
35 default_layer_set((layer_state_t)default_layer);
36
37 /* Also initialize layer state to trigger callback functions for layer_state */
38 layer_state_set_kb((layer_state_t)layer_state);
39}
diff --git a/tmk_core/common/magic.h b/tmk_core/common/magic.h
deleted file mode 100644
index a6552c04d..000000000
--- a/tmk_core/common/magic.h
+++ /dev/null
@@ -1,3 +0,0 @@
1#pragma once
2
3void magic(void);
diff --git a/tmk_core/common/usb_util.c b/tmk_core/common/usb_util.c
new file mode 100644
index 000000000..e4c50fcb1
--- /dev/null
+++ b/tmk_core/common/usb_util.c
@@ -0,0 +1,29 @@
1/* Copyright 2021 QMK
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 3 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 "usb_util.h"
17#include "wait.h"
18
19__attribute__((weak)) void usb_disable(void) {}
20__attribute__((weak)) bool usb_connected_state(void) { return true; }
21__attribute__((weak)) bool usb_vbus_state(void) {
22#ifdef USB_VBUS_PIN
23 setPinInput(USB_VBUS_PIN);
24 wait_us(5);
25 return readPin(USB_VBUS_PIN);
26#else
27 return true;
28#endif
29}
diff --git a/tmk_core/common/usb_util.h b/tmk_core/common/usb_util.h
new file mode 100644
index 000000000..4ebedb1e7
--- /dev/null
+++ b/tmk_core/common/usb_util.h
@@ -0,0 +1,22 @@
1/* Copyright 2021 QMK
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 3 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 <stdbool.h>
19
20void usb_disable(void);
21bool usb_connected_state(void);
22bool usb_vbus_state(void);
diff --git a/tmk_core/protocol.mk b/tmk_core/protocol.mk
index 0c41642b9..cc87e8347 100644
--- a/tmk_core/protocol.mk
+++ b/tmk_core/protocol.mk
@@ -54,5 +54,9 @@ ifeq ($(strip $(XT_ENABLE)), yes)
54 OPT_DEFS += -DXT_ENABLE 54 OPT_DEFS += -DXT_ENABLE
55endif 55endif
56 56
57ifeq ($(strip $(USB_HID_ENABLE)), yes)
58 include $(TMK_DIR)/protocol/usb_hid.mk
59endif
60
57# Search Path 61# Search Path
58VPATH += $(TMK_DIR)/protocol 62VPATH += $(TMK_DIR)/protocol
diff --git a/tmk_core/protocol/chibios.mk b/tmk_core/protocol/chibios.mk
index 80554abb3..d01697835 100644
--- a/tmk_core/protocol/chibios.mk
+++ b/tmk_core/protocol/chibios.mk
@@ -6,6 +6,7 @@ SRC += $(CHIBIOS_DIR)/usb_main.c
6SRC += $(CHIBIOS_DIR)/main.c 6SRC += $(CHIBIOS_DIR)/main.c
7SRC += usb_descriptor.c 7SRC += usb_descriptor.c
8SRC += $(CHIBIOS_DIR)/usb_driver.c 8SRC += $(CHIBIOS_DIR)/usb_driver.c
9SRC += $(CHIBIOS_DIR)/usb_util.c
9SRC += $(LIBSRC) 10SRC += $(LIBSRC)
10 11
11VPATH += $(TMK_PATH)/$(PROTOCOL_DIR) 12VPATH += $(TMK_PATH)/$(PROTOCOL_DIR)
diff --git a/tmk_core/protocol/chibios/usb_util.c b/tmk_core/protocol/chibios/usb_util.c
new file mode 100644
index 000000000..5945e8a8d
--- /dev/null
+++ b/tmk_core/protocol/chibios/usb_util.c
@@ -0,0 +1,21 @@
1/* Copyright 2021 QMK
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 3 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 <hal.h>
17#include "usb_util.h"
18
19void usb_disable(void) { usbStop(&USBD1); }
20
21bool usb_connected_state(void) { return usbGetDriverStateI(&USBD1) == USB_ACTIVE; }
diff --git a/tmk_core/protocol/lufa.mk b/tmk_core/protocol/lufa.mk
index 1cc1fa04e..9d9fb728b 100644
--- a/tmk_core/protocol/lufa.mk
+++ b/tmk_core/protocol/lufa.mk
@@ -44,6 +44,7 @@ ifeq ($(strip $(VIRTSER_ENABLE)), yes)
44endif 44endif
45 45
46SRC += $(LUFA_SRC) 46SRC += $(LUFA_SRC)
47SRC += $(LUFA_DIR)/usb_util.c
47 48
48# Search Path 49# Search Path
49VPATH += $(TMK_PATH)/$(LUFA_DIR) 50VPATH += $(TMK_PATH)/$(LUFA_DIR)
diff --git a/tmk_core/protocol/lufa/usb_util.c b/tmk_core/protocol/lufa/usb_util.c
new file mode 100644
index 000000000..9e943a21b
--- /dev/null
+++ b/tmk_core/protocol/lufa/usb_util.c
@@ -0,0 +1,34 @@
1/* Copyright 2021 QMK
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 3 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 <LUFA/Drivers/USB/USB.h>
17#include "usb_util.h"
18#include "wait.h"
19
20void usb_disable(void) {
21 USB_Disable();
22 USB_DeviceState = DEVICE_STATE_Unattached;
23}
24
25bool usb_connected_state(void) { return USB_Device_IsAddressSet(); }
26
27#if defined(OTGPADE)
28bool usb_vbus_state(void) {
29 USB_OTGPAD_On(); // enables VBUS pad
30 wait_us(5);
31
32 return USB_VBUS_GetStatus(); // checks state of VBUS
33}
34#endif
diff --git a/tmk_core/protocol/vusb.mk b/tmk_core/protocol/vusb.mk
index 1de600308..e4d013b38 100644
--- a/tmk_core/protocol/vusb.mk
+++ b/tmk_core/protocol/vusb.mk
@@ -5,6 +5,7 @@ VUSB_PATH = $(LIB_PATH)/vusb
5 5
6SRC += $(VUSB_DIR)/main.c \ 6SRC += $(VUSB_DIR)/main.c \
7 $(VUSB_DIR)/vusb.c \ 7 $(VUSB_DIR)/vusb.c \
8 $(VUSB_DIR)/usb_util.c \
8 $(VUSB_PATH)/usbdrv/usbdrv.c \ 9 $(VUSB_PATH)/usbdrv/usbdrv.c \
9 $(VUSB_PATH)/usbdrv/usbdrvasm.S \ 10 $(VUSB_PATH)/usbdrv/usbdrvasm.S \
10 $(VUSB_PATH)/usbdrv/oddebug.c 11 $(VUSB_PATH)/usbdrv/oddebug.c
diff --git a/tmk_core/protocol/vusb/usb_util.c b/tmk_core/protocol/vusb/usb_util.c
new file mode 100644
index 000000000..602854dbe
--- /dev/null
+++ b/tmk_core/protocol/vusb/usb_util.c
@@ -0,0 +1,24 @@
1/* Copyright 2021 QMK
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 3 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 <usbdrv/usbdrv.h>
17#include "usb_util.h"
18
19void usb_disable(void) { usbDeviceDisconnect(); }
20
21bool usb_connected_state(void) {
22 usbPoll();
23 return usbConfiguration;
24}