diff options
Diffstat (limited to 'tmk_core')
31 files changed, 490 insertions, 566 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 |
25 | endif | 26 | endif |
26 | 27 | ||
27 | # Option modules | ||
28 | BOOTMAGIC_ENABLE ?= no | ||
29 | VALID_MAGIC_TYPES := yes full lite | ||
30 | ifneq ($(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 | ||
44 | else | ||
45 | TMK_COMMON_DEFS += -DMAGIC_ENABLE | ||
46 | TMK_COMMON_SRC += $(COMMON_DIR)/magic.c | ||
47 | endif | ||
48 | |||
49 | SHARED_EP_ENABLE = no | 28 | SHARED_EP_ENABLE = no |
50 | MOUSE_SHARED_EP ?= yes | 29 | MOUSE_SHARED_EP ?= yes |
51 | ifeq ($(strip $(KEYBOARD_SHARED_EP)), yes) | 30 | ifeq ($(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 | */ |
149 | void set_oneshot_layer(uint8_t layer, uint8_t state) { | 149 | void 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) { | |||
172 | void clear_oneshot_layer_state(oneshot_fullfillment_t state) { | 176 | void 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 | */ |
184 | bool is_oneshot_layer_active(void) { return get_oneshot_layer_state(); } | 188 | bool is_oneshot_layer_active(void) { return get_oneshot_layer_state(); } |
189 | |||
190 | /** \brief set oneshot | ||
191 | * | ||
192 | * FIXME: needs doc | ||
193 | */ | ||
194 | void 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 | */ | ||
206 | void oneshot_toggle(void) { oneshot_set(!keymap_config.oneshot_disable); } | ||
207 | |||
208 | /** \brief enable oneshot | ||
209 | * | ||
210 | * FIXME: needs doc | ||
211 | */ | ||
212 | void oneshot_enable(void) { oneshot_set(true); } | ||
213 | |||
214 | /** \brief disable oneshot | ||
215 | * | ||
216 | * FIXME: needs doc | ||
217 | */ | ||
218 | void oneshot_disable(void) { oneshot_set(false); } | ||
219 | |||
220 | bool 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 | */ |
323 | void set_oneshot_mods(uint8_t mods) { | 360 | void 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); | |||
85 | void oneshot_layer_changed_user(uint8_t layer); | 85 | void oneshot_layer_changed_user(uint8_t layer); |
86 | void oneshot_layer_changed_kb(uint8_t layer); | 86 | void oneshot_layer_changed_kb(uint8_t layer); |
87 | 87 | ||
88 | void oneshot_toggle(void); | ||
89 | void oneshot_enable(void); | ||
90 | void oneshot_disable(void); | ||
91 | bool is_oneshot_enabled(void); | ||
92 | |||
88 | /* inspect */ | 93 | /* inspect */ |
89 | uint8_t has_anymod(void); | 94 | uint8_t has_anymod(void); |
90 | 95 | ||
diff --git a/tmk_core/common/arm_atsam/_wait.h b/tmk_core/common/arm_atsam/_wait.h new file mode 100644 index 000000000..41b686b56 --- /dev/null +++ b/tmk_core/common/arm_atsam/_wait.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 "clks.h" | ||
19 | |||
20 | #define wait_ms(ms) CLK_delay_ms(ms) | ||
21 | #define wait_us(us) CLK_delay_us(us) | ||
22 | #define waitInputPinDelay() | ||
diff --git a/tmk_core/common/avr/_wait.h b/tmk_core/common/avr/_wait.h new file mode 100644 index 000000000..56eb316fa --- /dev/null +++ b/tmk_core/common/avr/_wait.h | |||
@@ -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 | #pragma once | ||
17 | |||
18 | #include <util/delay.h> | ||
19 | |||
20 | #define wait_ms(ms) _delay_ms(ms) | ||
21 | #define wait_us(us) _delay_us(us) | ||
22 | |||
23 | /* The AVR series GPIOs have a one clock read delay for changes in the digital input signal. | ||
24 | * But here's more margin to make it two clocks. */ | ||
25 | #ifndef GPIO_INPUT_PIN_DELAY | ||
26 | # define GPIO_INPUT_PIN_DELAY 2 | ||
27 | #endif | ||
28 | |||
29 | #define waitInputPinDelay() __builtin_avr_delay_cycles(GPIO_INPUT_PIN_DELAY) | ||
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 | |||
13 | keymap_config_t keymap_config; | ||
14 | |||
15 | /** \brief Bootmagic | ||
16 | * | ||
17 | * FIXME: needs doc | ||
18 | */ | ||
19 | void 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 | */ | ||
141 | static 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 | */ | ||
159 | bool 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 | |||
101 | void bootmagic(void); | ||
102 | bool 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/_wait.h b/tmk_core/common/chibios/_wait.h new file mode 100644 index 000000000..5bface53e --- /dev/null +++ b/tmk_core/common/chibios/_wait.h | |||
@@ -0,0 +1,55 @@ | |||
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 <ch.h> | ||
19 | |||
20 | /* chThdSleepX of zero maps to infinite - so we map to a tiny delay to still yield */ | ||
21 | #define wait_ms(ms) \ | ||
22 | do { \ | ||
23 | if (ms != 0) { \ | ||
24 | chThdSleepMilliseconds(ms); \ | ||
25 | } else { \ | ||
26 | chThdSleepMicroseconds(1); \ | ||
27 | } \ | ||
28 | } while (0) | ||
29 | #define wait_us(us) \ | ||
30 | do { \ | ||
31 | if (us != 0) { \ | ||
32 | chThdSleepMicroseconds(us); \ | ||
33 | } else { \ | ||
34 | chThdSleepMicroseconds(1); \ | ||
35 | } \ | ||
36 | } while (0) | ||
37 | |||
38 | /* For GPIOs on ARM-based MCUs, the input pins are sampled by the clock of the bus | ||
39 | * to which the GPIO is connected. | ||
40 | * The connected buses differ depending on the various series of MCUs. | ||
41 | * And since the instruction execution clock of the CPU and the bus clock of GPIO are different, | ||
42 | * there is a delay of several clocks to read the change of the input signal. | ||
43 | * | ||
44 | * Define this delay with the GPIO_INPUT_PIN_DELAY macro. | ||
45 | * If the GPIO_INPUT_PIN_DELAY macro is not defined, the following default values will be used. | ||
46 | * (A fairly large value of 0.25 microseconds is set.) | ||
47 | */ | ||
48 | |||
49 | #include "wait.c" | ||
50 | |||
51 | #ifndef GPIO_INPUT_PIN_DELAY | ||
52 | # define GPIO_INPUT_PIN_DELAY (STM32_SYSCLK / 1000000L / 4) | ||
53 | #endif | ||
54 | |||
55 | #define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY) | ||
diff --git a/tmk_core/common/chibios/bootloader.c b/tmk_core/common/chibios/bootloader.c index 6cabcc4b8..4a175a628 100644 --- a/tmk_core/common/chibios/bootloader.c +++ b/tmk_core/common/chibios/bootloader.c | |||
@@ -79,7 +79,7 @@ void enter_bootloader_mode_if_requested(void) { | |||
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | #elif defined(KL2x) || defined(K20x) // STM32_BOOTLOADER_DUAL_BANK // STM32_BOOTLOADER_ADDRESS | 82 | #elif defined(KL2x) || defined(K20x) || defined(MK66F18) // STM32_BOOTLOADER_DUAL_BANK // STM32_BOOTLOADER_ADDRESS |
83 | /* Kinetis */ | 83 | /* Kinetis */ |
84 | 84 | ||
85 | # if defined(BOOTLOADER_KIIBOHD) | 85 | # if defined(BOOTLOADER_KIIBOHD) |
diff --git a/tmk_core/common/chibios/chibios_config.h b/tmk_core/common/chibios/chibios_config.h index b4d96465d..1d8ace495 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 |
@@ -28,4 +30,9 @@ | |||
28 | # define USE_I2CV1 | 30 | # define USE_I2CV1 |
29 | # define USE_I2CV1_CONTRIB // for some reason a bunch of ChibiOS-Contrib boards only have clock_speed | 31 | # define USE_I2CV1_CONTRIB // for some reason a bunch of ChibiOS-Contrib boards only have clock_speed |
30 | # define USE_GPIOV1 | 32 | # define USE_GPIOV1 |
33 | # define STM32_SYSCLK KINETIS_SYSCLK_FREQUENCY | ||
34 | #endif | ||
35 | |||
36 | #if defined(MK66F18) | ||
37 | # define STM32_SYSCLK KINETIS_SYSCLK_FREQUENCY | ||
31 | #endif | 38 | #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 | */ |
34 | static 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}; | 26 | static 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 */ | 28 | void sleep_led_timer_callback(void) { |
37 | OSAL_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 */ | ||
78 | OSAL_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 */ |
90 | void sleep_led_init(void) { | 90 | void 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 */ | ||
165 | void 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 */ | 164 | static 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 */ | 169 | static 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 */ | 172 | void sleep_led_init(void) { gptStart(&SLEEP_LED_GPT_DRIVER, &gptcfg); } |
184 | } | ||
185 | 173 | ||
186 | void sleep_led_enable(void) { | 174 | void 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 | ||
192 | void sleep_led_disable(void) { | 176 | void sleep_led_disable(void) { gptStopTimer(&SLEEP_LED_GPT_DRIVER); } |
193 | /* Disable the timer */ | ||
194 | STM32_TIM14->CR1 = 0; | ||
195 | } | ||
196 | 177 | ||
197 | void sleep_led_toggle(void) { | 178 | void 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/chibios/wait.c b/tmk_core/common/chibios/wait.c new file mode 100644 index 000000000..c6270fd95 --- /dev/null +++ b/tmk_core/common/chibios/wait.c | |||
@@ -0,0 +1,89 @@ | |||
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 | |||
17 | #ifndef __OPTIMIZE__ | ||
18 | # pragma message "Compiler optimizations disabled; wait_cpuclock() won't work as designed" | ||
19 | #endif | ||
20 | |||
21 | #define CLOCK_DELAY_NOP8 "nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t" | ||
22 | |||
23 | __attribute__((always_inline)) static inline void wait_cpuclock(unsigned int n) { /* n: 1..135 */ | ||
24 | /* The argument n must be a constant expression. | ||
25 | * That way, compiler optimization will remove unnecessary code. */ | ||
26 | if (n < 1) { | ||
27 | return; | ||
28 | } | ||
29 | if (n > 8) { | ||
30 | unsigned int n8 = n / 8; | ||
31 | n = n - n8 * 8; | ||
32 | switch (n8) { | ||
33 | case 16: | ||
34 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
35 | case 15: | ||
36 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
37 | case 14: | ||
38 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
39 | case 13: | ||
40 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
41 | case 12: | ||
42 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
43 | case 11: | ||
44 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
45 | case 10: | ||
46 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
47 | case 9: | ||
48 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
49 | case 8: | ||
50 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
51 | case 7: | ||
52 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
53 | case 6: | ||
54 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
55 | case 5: | ||
56 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
57 | case 4: | ||
58 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
59 | case 3: | ||
60 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
61 | case 2: | ||
62 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
63 | case 1: | ||
64 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
65 | case 0: | ||
66 | break; | ||
67 | } | ||
68 | } | ||
69 | switch (n) { | ||
70 | case 8: | ||
71 | asm volatile("nop" ::: "memory"); | ||
72 | case 7: | ||
73 | asm volatile("nop" ::: "memory"); | ||
74 | case 6: | ||
75 | asm volatile("nop" ::: "memory"); | ||
76 | case 5: | ||
77 | asm volatile("nop" ::: "memory"); | ||
78 | case 4: | ||
79 | asm volatile("nop" ::: "memory"); | ||
80 | case 3: | ||
81 | asm volatile("nop" ::: "memory"); | ||
82 | case 2: | ||
83 | asm volatile("nop" ::: "memory"); | ||
84 | case 1: | ||
85 | asm volatile("nop" ::: "memory"); | ||
86 | case 0: | ||
87 | break; | ||
88 | } | ||
89 | } \ No newline at end of file | ||
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..9e18fd4e1 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 | ||
@@ -43,12 +43,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
43 | #define EECONFIG_VELOCIKEY (uint8_t *)23 | 43 | #define EECONFIG_VELOCIKEY (uint8_t *)23 |
44 | 44 | ||
45 | #define EECONFIG_HAPTIC (uint32_t *)24 | 45 | #define EECONFIG_HAPTIC (uint32_t *)24 |
46 | |||
47 | // Mutually exclusive | ||
48 | #define EECONFIG_LED_MATRIX (uint32_t *)28 | ||
46 | #define EECONFIG_RGB_MATRIX (uint32_t *)28 | 49 | #define EECONFIG_RGB_MATRIX (uint32_t *)28 |
47 | #define EECONFIG_RGB_MATRIX_SPEED (uint8_t *)32 | 50 | // Speed & Flags |
51 | #define EECONFIG_LED_MATRIX_EXTENDED (uint16_t *)32 | ||
52 | #define EECONFIG_RGB_MATRIX_EXTENDED (uint16_t *)32 | ||
53 | |||
48 | // TODO: Combine these into a single word and single block of EEPROM | 54 | // TODO: Combine these into a single word and single block of EEPROM |
49 | #define EECONFIG_KEYMAP_UPPER_BYTE (uint8_t *)33 | 55 | #define EECONFIG_KEYMAP_UPPER_BYTE (uint8_t *)34 |
50 | // Size of EEPROM being used, other code can refer to this for available EEPROM | 56 | // Size of EEPROM being used, other code can refer to this for available EEPROM |
51 | #define EECONFIG_SIZE 34 | 57 | #define EECONFIG_SIZE 35 |
52 | /* debug bit */ | 58 | /* debug bit */ |
53 | #define EECONFIG_DEBUG_ENABLE (1 << 0) | 59 | #define EECONFIG_DEBUG_ENABLE (1 << 0) |
54 | #define EECONFIG_DEBUG_MATRIX (1 << 1) | 60 | #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 | |||
15 | keymap_config_t keymap_config; | ||
16 | |||
17 | /** \brief Magic | ||
18 | * | ||
19 | * FIXME: Needs doc | ||
20 | */ | ||
21 | void 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 | |||
3 | void magic(void); | ||
diff --git a/tmk_core/common/test/_wait.h b/tmk_core/common/test/_wait.h new file mode 100644 index 000000000..4e22f593b --- /dev/null +++ b/tmk_core/common/test/_wait.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 <inttypes.h> | ||
19 | |||
20 | void wait_ms(uint32_t ms); | ||
21 | #define wait_us(us) wait_ms(us / 1000) | ||
22 | #define waitInputPinDelay() | ||
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 | |||
20 | void usb_disable(void); | ||
21 | bool usb_connected_state(void); | ||
22 | bool usb_vbus_state(void); | ||
diff --git a/tmk_core/common/wait.h b/tmk_core/common/wait.h index 28224fe3a..cf7180fb0 100644 --- a/tmk_core/common/wait.h +++ b/tmk_core/common/wait.h | |||
@@ -1,3 +1,18 @@ | |||
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 | */ | ||
1 | #pragma once | 16 | #pragma once |
2 | 17 | ||
3 | #include <inttypes.h> | 18 | #include <inttypes.h> |
@@ -6,114 +21,8 @@ | |||
6 | extern "C" { | 21 | extern "C" { |
7 | #endif | 22 | #endif |
8 | 23 | ||
9 | #if defined(__ARMEL__) || defined(__ARMEB__) | 24 | #if __has_include_next("_wait.h") |
10 | # ifndef __OPTIMIZE__ | 25 | # include_next "_wait.h" /* Include the platforms _wait.h */ |
11 | # pragma message "Compiler optimizations disabled; wait_cpuclock() won't work as designed" | ||
12 | # endif | ||
13 | |||
14 | # define wait_cpuclock(x) wait_cpuclock_allnop(x) | ||
15 | |||
16 | # define CLOCK_DELAY_NOP8 "nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t nop\n\t" | ||
17 | |||
18 | __attribute__((always_inline)) static inline void wait_cpuclock_allnop(unsigned int n) { /* n: 1..135 */ | ||
19 | /* The argument n must be a constant expression. | ||
20 | * That way, compiler optimization will remove unnecessary code. */ | ||
21 | if (n < 1) { | ||
22 | return; | ||
23 | } | ||
24 | if (n > 8) { | ||
25 | unsigned int n8 = n / 8; | ||
26 | n = n - n8 * 8; | ||
27 | switch (n8) { | ||
28 | case 16: | ||
29 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
30 | case 15: | ||
31 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
32 | case 14: | ||
33 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
34 | case 13: | ||
35 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
36 | case 12: | ||
37 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
38 | case 11: | ||
39 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
40 | case 10: | ||
41 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
42 | case 9: | ||
43 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
44 | case 8: | ||
45 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
46 | case 7: | ||
47 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
48 | case 6: | ||
49 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
50 | case 5: | ||
51 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
52 | case 4: | ||
53 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
54 | case 3: | ||
55 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
56 | case 2: | ||
57 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
58 | case 1: | ||
59 | asm volatile(CLOCK_DELAY_NOP8::: "memory"); | ||
60 | case 0: | ||
61 | break; | ||
62 | } | ||
63 | } | ||
64 | switch (n) { | ||
65 | case 8: | ||
66 | asm volatile("nop" ::: "memory"); | ||
67 | case 7: | ||
68 | asm volatile("nop" ::: "memory"); | ||
69 | case 6: | ||
70 | asm volatile("nop" ::: "memory"); | ||
71 | case 5: | ||
72 | asm volatile("nop" ::: "memory"); | ||
73 | case 4: | ||
74 | asm volatile("nop" ::: "memory"); | ||
75 | case 3: | ||
76 | asm volatile("nop" ::: "memory"); | ||
77 | case 2: | ||
78 | asm volatile("nop" ::: "memory"); | ||
79 | case 1: | ||
80 | asm volatile("nop" ::: "memory"); | ||
81 | case 0: | ||
82 | break; | ||
83 | } | ||
84 | } | ||
85 | #endif | ||
86 | |||
87 | #if defined(__AVR__) | ||
88 | # include <util/delay.h> | ||
89 | # define wait_ms(ms) _delay_ms(ms) | ||
90 | # define wait_us(us) _delay_us(us) | ||
91 | # define wait_cpuclock(x) __builtin_avr_delay_cycles(x) | ||
92 | #elif defined PROTOCOL_CHIBIOS | ||
93 | # include <ch.h> | ||
94 | # define wait_ms(ms) \ | ||
95 | do { \ | ||
96 | if (ms != 0) { \ | ||
97 | chThdSleepMilliseconds(ms); \ | ||
98 | } else { \ | ||
99 | chThdSleepMicroseconds(1); \ | ||
100 | } \ | ||
101 | } while (0) | ||
102 | # define wait_us(us) \ | ||
103 | do { \ | ||
104 | if (us != 0) { \ | ||
105 | chThdSleepMicroseconds(us); \ | ||
106 | } else { \ | ||
107 | chThdSleepMicroseconds(1); \ | ||
108 | } \ | ||
109 | } while (0) | ||
110 | #elif defined PROTOCOL_ARM_ATSAM | ||
111 | # include "clks.h" | ||
112 | # define wait_ms(ms) CLK_delay_ms(ms) | ||
113 | # define wait_us(us) CLK_delay_us(us) | ||
114 | #else // Unit tests | ||
115 | void wait_ms(uint32_t ms); | ||
116 | # define wait_us(us) wait_ms(us / 1000) | ||
117 | #endif | 26 | #endif |
118 | 27 | ||
119 | #ifdef __cplusplus | 28 | #ifdef __cplusplus |
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 |
55 | endif | 55 | endif |
56 | 56 | ||
57 | ifeq ($(strip $(USB_HID_ENABLE)), yes) | ||
58 | include $(TMK_DIR)/protocol/usb_hid.mk | ||
59 | endif | ||
60 | |||
57 | # Search Path | 61 | # Search Path |
58 | VPATH += $(TMK_DIR)/protocol | 62 | VPATH += $(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 | |||
6 | SRC += $(CHIBIOS_DIR)/main.c | 6 | SRC += $(CHIBIOS_DIR)/main.c |
7 | SRC += usb_descriptor.c | 7 | SRC += usb_descriptor.c |
8 | SRC += $(CHIBIOS_DIR)/usb_driver.c | 8 | SRC += $(CHIBIOS_DIR)/usb_driver.c |
9 | SRC += $(CHIBIOS_DIR)/usb_util.c | ||
9 | SRC += $(LIBSRC) | 10 | SRC += $(LIBSRC) |
10 | 11 | ||
11 | VPATH += $(TMK_PATH)/$(PROTOCOL_DIR) | 12 | VPATH += $(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 | |||
19 | void usb_disable(void) { usbStop(&USBD1); } | ||
20 | |||
21 | bool 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) | |||
44 | endif | 44 | endif |
45 | 45 | ||
46 | SRC += $(LUFA_SRC) | 46 | SRC += $(LUFA_SRC) |
47 | SRC += $(LUFA_DIR)/usb_util.c | ||
47 | 48 | ||
48 | # Search Path | 49 | # Search Path |
49 | VPATH += $(TMK_PATH)/$(LUFA_DIR) | 50 | VPATH += $(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 | |||
20 | void usb_disable(void) { | ||
21 | USB_Disable(); | ||
22 | USB_DeviceState = DEVICE_STATE_Unattached; | ||
23 | } | ||
24 | |||
25 | bool usb_connected_state(void) { return USB_Device_IsAddressSet(); } | ||
26 | |||
27 | #if defined(OTGPADE) | ||
28 | bool 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 | ||
6 | SRC += $(VUSB_DIR)/main.c \ | 6 | SRC += $(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 | |||
19 | void usb_disable(void) { usbDeviceDisconnect(); } | ||
20 | |||
21 | bool usb_connected_state(void) { | ||
22 | usbPoll(); | ||
23 | return usbConfiguration; | ||
24 | } | ||