aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile11
-rwxr-xr-xbin/qmk2
-rw-r--r--build_json.mk2
-rw-r--r--build_keyboard.mk9
-rw-r--r--common_features.mk26
-rw-r--r--docs/feature_rgb_matrix.md2
-rw-r--r--docs/keycodes.md3
-rw-r--r--docs/one_shot_keys.md3
-rw-r--r--docs/ws2812_driver.md3
-rw-r--r--drivers/chibios/ws2812_pwm.c11
-rw-r--r--drivers/oled/oled_driver.h4
-rw-r--r--keyboards/aeboards/ext65/rev2/config.h2
-rw-r--r--keyboards/aeboards/ext65/rev2/halconf.h2
-rw-r--r--keyboards/aeboards/ext65/rev2/mcuconf.h2
-rw-r--r--keyboards/cannonkeys/an_c/rules.mk2
-rw-r--r--keyboards/cannonkeys/chimera65/rules.mk2
-rw-r--r--keyboards/cannonkeys/instant60/rules.mk2
-rw-r--r--keyboards/cannonkeys/iron165/rules.mk2
-rw-r--r--keyboards/cannonkeys/satisfaction75/rules.mk2
-rw-r--r--keyboards/cannonkeys/savage65/rules.mk2
-rw-r--r--keyboards/cannonkeys/tmov2/rules.mk2
-rw-r--r--keyboards/cannonkeys/tsukuyomi/rules.mk2
-rw-r--r--keyboards/crkbd/rev1/common/config.h1
-rw-r--r--keyboards/crkbd/rev1/common/rules.mk1
-rw-r--r--keyboards/crkbd/rev1/rev1.c2
-rw-r--r--keyboards/daji/seis_cinco/rules.mk2
-rw-r--r--keyboards/handwired/ck4x4/rules.mk2
-rw-r--r--keyboards/handwired/onekey/rules.mk4
-rw-r--r--keyboards/projectkb/alice/config.h3
-rw-r--r--keyboards/projectkb/alice/halconf.h2
-rw-r--r--keyboards/projectkb/alice/mcuconf.h2
-rw-r--r--keyboards/projectkb/signature87/rules.mk2
-rw-r--r--keyboards/ramonimbao/wete/config.h2
-rw-r--r--keyboards/ramonimbao/wete/halconf.h2
-rw-r--r--keyboards/ramonimbao/wete/mcuconf.h2
-rw-r--r--keyboards/readme.md2
-rw-r--r--keyboards/westfoxtrot/prophet/config.h2
-rw-r--r--keyboards/westfoxtrot/prophet/halconf.h27
-rw-r--r--keyboards/westfoxtrot/prophet/mcuconf.h5
-rw-r--r--lib/python/qmk/commands.py1
-rw-r--r--lib/python/qmk/tests/test_cli_commands.py4
-rw-r--r--quantum/bootmagic/bootmagic.h24
-rw-r--r--quantum/bootmagic/bootmagic_full.c (renamed from tmk_core/common/bootmagic.c)112
-rw-r--r--quantum/bootmagic/bootmagic_full.h (renamed from tmk_core/common/bootmagic.h)21
-rw-r--r--quantum/bootmagic/bootmagic_lite.c (renamed from tmk_core/common/bootmagic_lite.c)17
-rw-r--r--quantum/bootmagic/bootmagic_lite.h25
-rw-r--r--quantum/bootmagic/magic.c54
-rw-r--r--quantum/bootmagic/magic.h18
-rw-r--r--quantum/keycode_config.h1
-rw-r--r--quantum/led_matrix.c8
-rw-r--r--quantum/led_matrix.h4
-rw-r--r--quantum/process_keycode/process_backlight.c29
-rw-r--r--quantum/quantum.c28
-rw-r--r--quantum/quantum.h55
-rw-r--r--quantum/quantum_keycodes.h14
-rw-r--r--quantum/rgb_matrix.c34
-rw-r--r--quantum/rgb_matrix_types.h9
-rw-r--r--quantum/split_common/split_util.c70
-rw-r--r--quantum/split_common/transport.c45
-rw-r--r--readme.md6
-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/arm_atsam/_wait.h22
-rw-r--r--tmk_core/common/avr/_wait.h29
-rw-r--r--tmk_core/common/avr/suspend.c4
-rw-r--r--tmk_core/common/chibios/_wait.h55
-rw-r--r--tmk_core/common/chibios/chibios_config.h3
-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/chibios/wait.c89
-rw-r--r--tmk_core/common/eeconfig.c2
-rw-r--r--tmk_core/common/eeconfig.h14
-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/test/_wait.h22
-rw-r--r--tmk_core/common/usb_util.c29
-rw-r--r--tmk_core/common/usb_util.h22
-rw-r--r--tmk_core/common/wait.h125
-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
87 files changed, 986 insertions, 490 deletions
diff --git a/Makefile b/Makefile
index 91ab9e4e8..de0a2d415 100644
--- a/Makefile
+++ b/Makefile
@@ -29,6 +29,13 @@ $(info QMK Firmware $(QMK_VERSION))
29endif 29endif
30endif 30endif
31 31
32# Determine which qmk cli to use
33ifeq (, $(shell which qmk))
34 QMK_BIN = bin/qmk
35else
36 QMK_BIN = qmk
37endif
38
32# avoid 'Entering|Leaving directory' messages 39# avoid 'Entering|Leaving directory' messages
33MAKEFLAGS += --no-print-directory 40MAKEFLAGS += --no-print-directory
34 41
@@ -501,8 +508,8 @@ endef
501%: 508%:
502 # Check if we have the CMP tool installed 509 # Check if we have the CMP tool installed
503 cmp $(ROOT_DIR)/Makefile $(ROOT_DIR)/Makefile >/dev/null 2>&1; if [ $$? -gt 0 ]; then printf "$(MSG_NO_CMP)"; exit 1; fi; 510 cmp $(ROOT_DIR)/Makefile $(ROOT_DIR)/Makefile >/dev/null 2>&1; if [ $$? -gt 0 ]; then printf "$(MSG_NO_CMP)"; exit 1; fi;
504 # Ensure that bin/qmk works. 511 # Ensure that $(QMK_BIN) works.
505 if ! bin/qmk hello 1> /dev/null 2>&1; then printf "$(MSG_PYTHON_MISSING)"; exit 1; fi 512 if ! $(QMK_BIN) hello 1> /dev/null 2>&1; then printf "$(MSG_PYTHON_MISSING)"; exit 1; fi
506 # Check if the submodules are dirty, and display a warning if they are 513 # Check if the submodules are dirty, and display a warning if they are
507ifndef SKIP_GIT 514ifndef SKIP_GIT
508 if [ ! -e lib/chibios ]; then git submodule sync lib/chibios && git submodule update --depth 50 --init lib/chibios; fi 515 if [ ! -e lib/chibios ]; then git submodule sync lib/chibios && git submodule update --depth 50 --init lib/chibios; fi
diff --git a/bin/qmk b/bin/qmk
index a3c1be328..28486026f 100755
--- a/bin/qmk
+++ b/bin/qmk
@@ -75,6 +75,8 @@ def main():
75 os.environ['ORIG_CWD'] = os.getcwd() 75 os.environ['ORIG_CWD'] = os.getcwd()
76 os.chdir(qmk_dir) 76 os.chdir(qmk_dir)
77 77
78 print('Warning: The bin/qmk script is being deprecated. Please install the QMK CLI: python3 -m pip install qmk', file=sys.stderr)
79
78 # Import the subcommands 80 # Import the subcommands
79 import qmk.cli # noqa 81 import qmk.cli # noqa
80 82
diff --git a/build_json.mk b/build_json.mk
index 6e2f9c4c8..8822be6a1 100644
--- a/build_json.mk
+++ b/build_json.mk
@@ -28,4 +28,4 @@ endif
28 28
29# Generate the keymap.c 29# Generate the keymap.c
30$(KEYBOARD_OUTPUT)/src/keymap.c: $(KEYMAP_JSON) 30$(KEYBOARD_OUTPUT)/src/keymap.c: $(KEYMAP_JSON)
31 bin/qmk json2c --quiet --output $(KEYMAP_C) $(KEYMAP_JSON) 31 $(QMK_BIN) json2c --quiet --output $(KEYMAP_C) $(KEYMAP_JSON)
diff --git a/build_keyboard.mk b/build_keyboard.mk
index 366d1f5d2..74046a094 100644
--- a/build_keyboard.mk
+++ b/build_keyboard.mk
@@ -12,6 +12,9 @@ endif
12 12
13include common.mk 13include common.mk
14 14
15# Set the qmk cli to use
16QMK_BIN ?= qmk
17
15# Set the filename for the final firmware binary 18# Set the filename for the final firmware binary
16KEYBOARD_FILESAFE := $(subst /,_,$(KEYBOARD)) 19KEYBOARD_FILESAFE := $(subst /,_,$(KEYBOARD))
17TARGET ?= $(KEYBOARD_FILESAFE)_$(KEYMAP) 20TARGET ?= $(KEYBOARD_FILESAFE)_$(KEYMAP)
@@ -97,7 +100,7 @@ MAIN_KEYMAP_PATH_4 := $(KEYBOARD_PATH_4)/keymaps/$(KEYMAP)
97MAIN_KEYMAP_PATH_5 := $(KEYBOARD_PATH_5)/keymaps/$(KEYMAP) 100MAIN_KEYMAP_PATH_5 := $(KEYBOARD_PATH_5)/keymaps/$(KEYMAP)
98 101
99# Pull in rules from info.json 102# Pull in rules from info.json
100INFO_RULES_MK = $(shell bin/qmk generate-rules-mk --quiet --escape --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/rules.mk) 103INFO_RULES_MK = $(shell $(QMK_BIN) generate-rules-mk --quiet --escape --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/rules.mk)
101include $(INFO_RULES_MK) 104include $(INFO_RULES_MK)
102 105
103# Check for keymap.json first, so we can regenerate keymap.c 106# Check for keymap.json first, so we can regenerate keymap.c
@@ -294,10 +297,10 @@ endif
294CONFIG_H += $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h 297CONFIG_H += $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h
295 298
296$(KEYBOARD_OUTPUT)/src/info_config.h: $(INFO_JSON_FILES) 299$(KEYBOARD_OUTPUT)/src/info_config.h: $(INFO_JSON_FILES)
297 bin/qmk generate-config-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/info_config.h 300 $(QMK_BIN) generate-config-h --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/info_config.h
298 301
299$(KEYBOARD_OUTPUT)/src/layouts.h: $(INFO_JSON_FILES) 302$(KEYBOARD_OUTPUT)/src/layouts.h: $(INFO_JSON_FILES)
300 bin/qmk generate-layouts --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/layouts.h 303 $(QMK_BIN) generate-layouts --quiet --keyboard $(KEYBOARD) --output $(KEYBOARD_OUTPUT)/src/layouts.h
301 304
302generated-files: $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h 305generated-files: $(KEYBOARD_OUTPUT)/src/info_config.h $(KEYBOARD_OUTPUT)/src/layouts.h
303 306
diff --git a/common_features.mk b/common_features.mk
index 8c9d0a90c..fdc481fd2 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -223,11 +223,10 @@ VALID_LED_MATRIX_TYPES := IS31FL3731 custom
223 223
224ifeq ($(strip $(LED_MATRIX_ENABLE)), yes) 224ifeq ($(strip $(LED_MATRIX_ENABLE)), yes)
225 ifeq ($(filter $(LED_MATRIX_DRIVER),$(VALID_LED_MATRIX_TYPES)),) 225 ifeq ($(filter $(LED_MATRIX_DRIVER),$(VALID_LED_MATRIX_TYPES)),)
226 $(error LED_MATRIX_DRIVER="$(LED_MATRIX_DRIVER)" is not a valid matrix type) 226 $(error "$(LED_MATRIX_DRIVER)" is not a valid matrix type)
227 else 227 else
228 BACKLIGHT_ENABLE = yes
229 BACKLIGHT_DRIVER = custom
230 OPT_DEFS += -DLED_MATRIX_ENABLE 228 OPT_DEFS += -DLED_MATRIX_ENABLE
229 SRC += $(QUANTUM_DIR)/process_keycode/process_backlight.c
231 SRC += $(QUANTUM_DIR)/led_matrix.c 230 SRC += $(QUANTUM_DIR)/led_matrix.c
232 SRC += $(QUANTUM_DIR)/led_matrix_drivers.c 231 SRC += $(QUANTUM_DIR)/led_matrix_drivers.c
233 endif 232 endif
@@ -422,10 +421,6 @@ ifeq ($(strip $(TERMINAL_ENABLE)), yes)
422 OPT_DEFS += -DUSER_PRINT 421 OPT_DEFS += -DUSER_PRINT
423endif 422endif
424 423
425ifeq ($(strip $(USB_HID_ENABLE)), yes)
426 include $(TMK_DIR)/protocol/usb_hid.mk
427endif
428
429ifeq ($(strip $(WPM_ENABLE)), yes) 424ifeq ($(strip $(WPM_ENABLE)), yes)
430 SRC += $(QUANTUM_DIR)/wpm.c 425 SRC += $(QUANTUM_DIR)/wpm.c
431 OPT_DEFS += -DWPM_ENABLE 426 OPT_DEFS += -DWPM_ENABLE
@@ -459,6 +454,23 @@ ifeq ($(strip $(DIP_SWITCH_ENABLE)), yes)
459 SRC += $(QUANTUM_DIR)/dip_switch.c 454 SRC += $(QUANTUM_DIR)/dip_switch.c
460endif 455endif
461 456
457VALID_MAGIC_TYPES := yes full lite
458BOOTMAGIC_ENABLE ?= no
459ifneq ($(strip $(BOOTMAGIC_ENABLE)), no)
460 ifeq ($(filter $(BOOTMAGIC_ENABLE),$(VALID_MAGIC_TYPES)),)
461 $(error BOOTMAGIC_ENABLE="$(BOOTMAGIC_ENABLE)" is not a valid type of magic)
462 endif
463 ifeq ($(strip $(BOOTMAGIC_ENABLE)), lite)
464 OPT_DEFS += -DBOOTMAGIC_LITE
465 QUANTUM_SRC += $(QUANTUM_DIR)/bootmagic/bootmagic_lite.c
466 else
467 OPT_DEFS += -DBOOTMAGIC_ENABLE
468 QUANTUM_SRC += $(QUANTUM_DIR)/bootmagic/bootmagic_full.c
469 endif
470endif
471COMMON_VPATH += $(QUANTUM_DIR)/bootmagic
472QUANTUM_SRC += $(QUANTUM_DIR)/bootmagic/magic.c
473
462VALID_CUSTOM_MATRIX_TYPES:= yes lite no 474VALID_CUSTOM_MATRIX_TYPES:= yes lite no
463 475
464CUSTOM_MATRIX ?= no 476CUSTOM_MATRIX ?= no
diff --git a/docs/feature_rgb_matrix.md b/docs/feature_rgb_matrix.md
index 6917de5ab..a83e1d2a2 100644
--- a/docs/feature_rgb_matrix.md
+++ b/docs/feature_rgb_matrix.md
@@ -441,6 +441,8 @@ These are defined in [`rgblight_list.h`](https://github.com/qmk/qmk_firmware/blo
441#define RGB_MATRIX_STARTUP_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS // Sets the default brightness value, if none has been set 441#define RGB_MATRIX_STARTUP_VAL RGB_MATRIX_MAXIMUM_BRIGHTNESS // Sets the default brightness value, if none has been set
442#define RGB_MATRIX_STARTUP_SPD 127 // Sets the default animation speed, if none has been set 442#define RGB_MATRIX_STARTUP_SPD 127 // Sets the default animation speed, if none has been set
443#define RGB_MATRIX_DISABLE_KEYCODES // disables control of rgb matrix by keycodes (must use code functions to control the feature) 443#define RGB_MATRIX_DISABLE_KEYCODES // disables control of rgb matrix by keycodes (must use code functions to control the feature)
444#define RGB_MATRIX_SPLIT { X, Y } // (Optional) For split keyboards, the number of LEDs connected on each half. X = left, Y = Right.
445 // If RGB_MATRIX_KEYPRESSES or RGB_MATRIX_KEYRELEASES is enabled, you also will want to enable SPLIT_TRANSPORT_MIRROR
444``` 446```
445 447
446## EEPROM storage :id=eeprom-storage 448## EEPROM storage :id=eeprom-storage
diff --git a/docs/keycodes.md b/docs/keycodes.md
index 9acf8b683..f3c519b13 100644
--- a/docs/keycodes.md
+++ b/docs/keycodes.md
@@ -516,6 +516,9 @@ See also: [One Shot Keys](one_shot_keys.md)
516|------------|----------------------------------| 516|------------|----------------------------------|
517|`OSM(mod)` |Hold `mod` for one keypress | 517|`OSM(mod)` |Hold `mod` for one keypress |
518|`OSL(layer)`|Switch to `layer` for one keypress| 518|`OSL(layer)`|Switch to `layer` for one keypress|
519|`OS_ON` |Turns One Shot keys on |
520|`OS_OFF` |Turns One Shot keys off |
521|`OS_TOGG` |Toggles One Shot keys status |
519 522
520## Space Cadet :id=space-cadet 523## Space Cadet :id=space-cadet
521 524
diff --git a/docs/one_shot_keys.md b/docs/one_shot_keys.md
index 9a082d7d6..9fc548629 100644
--- a/docs/one_shot_keys.md
+++ b/docs/one_shot_keys.md
@@ -17,6 +17,9 @@ You can control the behavior of one shot keys by defining these in `config.h`:
17 17
18* `OSM(mod)` - Momentarily hold down *mod*. You must use the `MOD_*` keycodes as shown in [Mod Tap](mod_tap.md), not the `KC_*` codes. 18* `OSM(mod)` - Momentarily hold down *mod*. You must use the `MOD_*` keycodes as shown in [Mod Tap](mod_tap.md), not the `KC_*` codes.
19* `OSL(layer)` - momentary switch to *layer*. 19* `OSL(layer)` - momentary switch to *layer*.
20* `OS_ON` - Turns on One Shot keys.
21* `OS_OFF` - Turns off One Shot keys. OSM act as regular mod keys, OSL act like `MO`.
22* `ON_TOGG` - Toggles the one shot key status.
20 23
21Sometimes, you want to activate a one-shot key as part of a macro or tap dance routine. 24Sometimes, you want to activate a one-shot key as part of a macro or tap dance routine.
22 25
diff --git a/docs/ws2812_driver.md b/docs/ws2812_driver.md
index cca6827ec..fa14f02fd 100644
--- a/docs/ws2812_driver.md
+++ b/docs/ws2812_driver.md
@@ -102,11 +102,14 @@ Configure the hardware via your config.h:
102#define WS2812_PWM_DRIVER PWMD2 // default: PWMD2 102#define WS2812_PWM_DRIVER PWMD2 // default: PWMD2
103#define WS2812_PWM_CHANNEL 2 // default: 2 103#define WS2812_PWM_CHANNEL 2 // default: 2
104#define WS2812_PWM_PAL_MODE 2 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 2 104#define WS2812_PWM_PAL_MODE 2 // Pin "alternate function", see the respective datasheet for the appropriate values for your MCU. default: 2
105//#define WS2812_PWM_COMPLEMENTARY_OUTPUT // Define for a complementary timer output (TIMx_CHyN); omit for a normal timer output (TIMx_CHy).
105#define WS2812_DMA_STREAM STM32_DMA1_STREAM2 // DMA Stream for TIMx_UP, see the respective reference manual for the appropriate values for your MCU. 106#define WS2812_DMA_STREAM STM32_DMA1_STREAM2 // DMA Stream for TIMx_UP, see the respective reference manual for the appropriate values for your MCU.
106#define WS2812_DMA_CHANNEL 2 // DMA Channel for TIMx_UP, see the respective reference manual for the appropriate values for your MCU. 107#define WS2812_DMA_CHANNEL 2 // DMA Channel for TIMx_UP, see the respective reference manual for the appropriate values for your MCU.
107#define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM2_UP // DMAMUX configuration for TIMx_UP -- only required if your MCU has a DMAMUX peripheral, see the respective reference manual for the appropriate values for your MCU. 108#define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM2_UP // DMAMUX configuration for TIMx_UP -- only required if your MCU has a DMAMUX peripheral, see the respective reference manual for the appropriate values for your MCU.
108``` 109```
109 110
111Note that using a complementary timer output (TIMx_CHyN) is possible only for advanced-control timers (TIM1, TIM8, TIM20 on STM32), and the `STM32_PWM_USE_ADVANCED` option in mcuconf.h must be set to `TRUE`. Complementary outputs of general-purpose timers are not supported due to ChibiOS limitations.
112
110You must also turn on the PWM feature in your halconf.h and mcuconf.h 113You must also turn on the PWM feature in your halconf.h and mcuconf.h
111 114
112#### Testing Notes 115#### Testing Notes
diff --git a/drivers/chibios/ws2812_pwm.c b/drivers/chibios/ws2812_pwm.c
index 140120d48..e6af55b6b 100644
--- a/drivers/chibios/ws2812_pwm.c
+++ b/drivers/chibios/ws2812_pwm.c
@@ -27,6 +27,15 @@
27# error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM?_UP" 27# error "please consult your MCU's datasheet and specify in your config.h: #define WS2812_DMAMUX_ID STM32_DMAMUX1_TIM?_UP"
28#endif 28#endif
29 29
30#ifndef WS2812_PWM_COMPLEMENTARY_OUTPUT
31# define WS2812_PWM_OUTPUT_MODE PWM_OUTPUT_ACTIVE_HIGH
32#else
33# if !STM32_PWM_USE_ADVANCED
34# error "WS2812_PWM_COMPLEMENTARY_OUTPUT requires STM32_PWM_USE_ADVANCED == TRUE"
35# endif
36# define WS2812_PWM_OUTPUT_MODE PWM_COMPLEMENTARY_OUTPUT_ACTIVE_HIGH
37#endif
38
30// Push Pull or Open Drain Configuration 39// Push Pull or Open Drain Configuration
31// Default Push Pull 40// Default Push Pull
32#ifndef WS2812_EXTERNAL_PULLUP 41#ifndef WS2812_EXTERNAL_PULLUP
@@ -247,7 +256,7 @@ void ws2812_init(void) {
247 .channels = 256 .channels =
248 { 257 {
249 [0 ... 3] = {.mode = PWM_OUTPUT_DISABLED, .callback = NULL}, // Channels default to disabled 258 [0 ... 3] = {.mode = PWM_OUTPUT_DISABLED, .callback = NULL}, // Channels default to disabled
250 [WS2812_PWM_CHANNEL - 1] = {.mode = PWM_OUTPUT_ACTIVE_HIGH, .callback = NULL}, // Turn on the channel we care about 259 [WS2812_PWM_CHANNEL - 1] = {.mode = WS2812_PWM_OUTPUT_MODE, .callback = NULL}, // Turn on the channel we care about
251 }, 260 },
252 .cr2 = 0, 261 .cr2 = 0,
253 .dier = TIM_DIER_UDE, // DMA on update event for next period 262 .dier = TIM_DIER_UDE, // DMA on update event for next period
diff --git a/drivers/oled/oled_driver.h b/drivers/oled/oled_driver.h
index 72ab21247..00896f01c 100644
--- a/drivers/oled/oled_driver.h
+++ b/drivers/oled/oled_driver.h
@@ -158,6 +158,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
158# define OLED_I2C_TIMEOUT 100 158# define OLED_I2C_TIMEOUT 100
159#endif 159#endif
160 160
161#if !defined(OLED_UPDATE_INTERVAL) && defined(SPLIT_KEYBOARD)
162# define OLED_UPDATE_INTERVAL 50
163#endif
164
161typedef struct __attribute__((__packed__)) { 165typedef struct __attribute__((__packed__)) {
162 uint8_t *current_element; 166 uint8_t *current_element;
163 uint16_t remaining_element_count; 167 uint16_t remaining_element_count;
diff --git a/keyboards/aeboards/ext65/rev2/config.h b/keyboards/aeboards/ext65/rev2/config.h
index 541f07ee9..dc1bfb71c 100644
--- a/keyboards/aeboards/ext65/rev2/config.h
+++ b/keyboards/aeboards/ext65/rev2/config.h
@@ -74,3 +74,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
74#define BACKLIGHT_LEVELS 6 74#define BACKLIGHT_LEVELS 6
75#define BACKLIGHT_BREATHING 75#define BACKLIGHT_BREATHING
76#define BREATHING_PERIOD 6 76#define BREATHING_PERIOD 6
77
78#define SLEEP_LED_GPT_DRIVER GPTD1
diff --git a/keyboards/aeboards/ext65/rev2/halconf.h b/keyboards/aeboards/ext65/rev2/halconf.h
index 6e2f53640..9fa1eca60 100644
--- a/keyboards/aeboards/ext65/rev2/halconf.h
+++ b/keyboards/aeboards/ext65/rev2/halconf.h
@@ -27,5 +27,7 @@
27 27
28#define HAL_USE_SPI TRUE 28#define HAL_USE_SPI TRUE
29 29
30#define HAL_USE_GPT TRUE
31
30#include_next <halconf.h> 32#include_next <halconf.h>
31 33
diff --git a/keyboards/aeboards/ext65/rev2/mcuconf.h b/keyboards/aeboards/ext65/rev2/mcuconf.h
index 26ce80615..43d53d4f2 100644
--- a/keyboards/aeboards/ext65/rev2/mcuconf.h
+++ b/keyboards/aeboards/ext65/rev2/mcuconf.h
@@ -32,3 +32,5 @@
32#undef STM32_SPI_USE_SPI2 32#undef STM32_SPI_USE_SPI2
33#define STM32_SPI_USE_SPI2 TRUE 33#define STM32_SPI_USE_SPI2 TRUE
34 34
35#undef STM32_GPT_USE_TIM1
36#define STM32_GPT_USE_TIM1 TRUE
diff --git a/keyboards/cannonkeys/an_c/rules.mk b/keyboards/cannonkeys/an_c/rules.mk
index 8ed2d0ead..7309744d1 100644
--- a/keyboards/cannonkeys/an_c/rules.mk
+++ b/keyboards/cannonkeys/an_c/rules.mk
@@ -11,7 +11,7 @@ MOUSEKEY_ENABLE = yes # Mouse keys
11EXTRAKEY_ENABLE = yes # Audio control and System control 11EXTRAKEY_ENABLE = yes # Audio control and System control
12CONSOLE_ENABLE = yes # Console for debug 12CONSOLE_ENABLE = yes # Console for debug
13COMMAND_ENABLE = yes # Commands for debug and configuration 13COMMAND_ENABLE = yes # Commands for debug and configuration
14SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 14SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
15NKRO_ENABLE = yes # USB Nkey Rollover 15NKRO_ENABLE = yes # USB Nkey Rollover
16CUSTOM_MATRIX = no # Custom matrix file 16CUSTOM_MATRIX = no # Custom matrix file
17BACKLIGHT_ENABLE = yes 17BACKLIGHT_ENABLE = yes
diff --git a/keyboards/cannonkeys/chimera65/rules.mk b/keyboards/cannonkeys/chimera65/rules.mk
index 4d940da78..a08f2fa49 100644
--- a/keyboards/cannonkeys/chimera65/rules.mk
+++ b/keyboards/cannonkeys/chimera65/rules.mk
@@ -11,7 +11,7 @@ MOUSEKEY_ENABLE = yes # Mouse keys
11EXTRAKEY_ENABLE = yes # Audio control and System control 11EXTRAKEY_ENABLE = yes # Audio control and System control
12CONSOLE_ENABLE = yes # Console for debug 12CONSOLE_ENABLE = yes # Console for debug
13COMMAND_ENABLE = yes # Commands for debug and configuration 13COMMAND_ENABLE = yes # Commands for debug and configuration
14SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 14SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
15NKRO_ENABLE = yes # USB Nkey Rollover 15NKRO_ENABLE = yes # USB Nkey Rollover
16CUSTOM_MATRIX = no # Custom matrix file 16CUSTOM_MATRIX = no # Custom matrix file
17BACKLIGHT_ENABLE = yes 17BACKLIGHT_ENABLE = yes
diff --git a/keyboards/cannonkeys/instant60/rules.mk b/keyboards/cannonkeys/instant60/rules.mk
index 0973ad954..e5ba2903b 100644
--- a/keyboards/cannonkeys/instant60/rules.mk
+++ b/keyboards/cannonkeys/instant60/rules.mk
@@ -10,7 +10,7 @@ MOUSEKEY_ENABLE = yes # Mouse keys
10EXTRAKEY_ENABLE = yes # Audio control and System control 10EXTRAKEY_ENABLE = yes # Audio control and System control
11CONSOLE_ENABLE = yes # Console for debug 11CONSOLE_ENABLE = yes # Console for debug
12COMMAND_ENABLE = yes # Commands for debug and configuration 12COMMAND_ENABLE = yes # Commands for debug and configuration
13SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 13SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
14NKRO_ENABLE = yes # USB Nkey Rollover 14NKRO_ENABLE = yes # USB Nkey Rollover
15CUSTOM_MATRIX = no # Custom matrix file 15CUSTOM_MATRIX = no # Custom matrix file
16BACKLIGHT_ENABLE = yes 16BACKLIGHT_ENABLE = yes
diff --git a/keyboards/cannonkeys/iron165/rules.mk b/keyboards/cannonkeys/iron165/rules.mk
index 3925458dd..9de75a614 100644
--- a/keyboards/cannonkeys/iron165/rules.mk
+++ b/keyboards/cannonkeys/iron165/rules.mk
@@ -9,7 +9,7 @@ MOUSEKEY_ENABLE = yes # Mouse keys
9EXTRAKEY_ENABLE = yes # Audio control and System control 9EXTRAKEY_ENABLE = yes # Audio control and System control
10CONSOLE_ENABLE = yes # Console for debug 10CONSOLE_ENABLE = yes # Console for debug
11COMMAND_ENABLE = yes # Commands for debug and configuration 11COMMAND_ENABLE = yes # Commands for debug and configuration
12SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 12SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
13NKRO_ENABLE = yes # USB Nkey Rollover 13NKRO_ENABLE = yes # USB Nkey Rollover
14CUSTOM_MATRIX = no # Custom matrix file 14CUSTOM_MATRIX = no # Custom matrix file
15BACKLIGHT_ENABLE = yes 15BACKLIGHT_ENABLE = yes
diff --git a/keyboards/cannonkeys/satisfaction75/rules.mk b/keyboards/cannonkeys/satisfaction75/rules.mk
index e3abea546..3861b4849 100644
--- a/keyboards/cannonkeys/satisfaction75/rules.mk
+++ b/keyboards/cannonkeys/satisfaction75/rules.mk
@@ -15,7 +15,7 @@ MOUSEKEY_ENABLE = yes # Mouse keys
15EXTRAKEY_ENABLE = yes # Audio control and System control 15EXTRAKEY_ENABLE = yes # Audio control and System control
16CONSOLE_ENABLE = yes # Console for debug 16CONSOLE_ENABLE = yes # Console for debug
17COMMAND_ENABLE = yes # Commands for debug and configuration 17COMMAND_ENABLE = yes # Commands for debug and configuration
18SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend 18SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
19NKRO_ENABLE = yes # USB Nkey Rollover 19NKRO_ENABLE = yes # USB Nkey Rollover
20CUSTOM_MATRIX = no # Custom matrix file 20CUSTOM_MATRIX = no # Custom matrix file
21ENCODER_ENABLE = yes 21ENCODER_ENABLE = yes
diff --git a/keyboards/cannonkeys/savage65/rules.mk b/keyboards/cannonkeys/savage65/rules.mk
index 8e1b984fd..2454573d2 100644
--- a/keyboards/cannonkeys/savage65/rules.mk
+++ b/keyboards/cannonkeys/savage65/rules.mk
@@ -11,7 +11,7 @@ MOUSEKEY_ENABLE = yes # Mouse keys
11EXTRAKEY_ENABLE = yes # Audio control and System control 11EXTRAKEY_ENABLE = yes # Audio control and System control
12CONSOLE_ENABLE = yes # Console for debug 12CONSOLE_ENABLE = yes # Console for debug
13COMMAND_ENABLE = yes # Commands for debug and configuration 13COMMAND_ENABLE = yes # Commands for debug and configuration
14SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 14SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
15NKRO_ENABLE = yes # USB Nkey Rollover 15NKRO_ENABLE = yes # USB Nkey Rollover
16CUSTOM_MATRIX = no # Custom matrix file 16CUSTOM_MATRIX = no # Custom matrix file
17BACKLIGHT_ENABLE = yes 17BACKLIGHT_ENABLE = yes
diff --git a/keyboards/cannonkeys/tmov2/rules.mk b/keyboards/cannonkeys/tmov2/rules.mk
index 9b29e8fd1..294c873ee 100644
--- a/keyboards/cannonkeys/tmov2/rules.mk
+++ b/keyboards/cannonkeys/tmov2/rules.mk
@@ -11,7 +11,7 @@ MOUSEKEY_ENABLE = yes # Mouse keys
11EXTRAKEY_ENABLE = yes # Audio control and System control 11EXTRAKEY_ENABLE = yes # Audio control and System control
12CONSOLE_ENABLE = yes # Console for debug 12CONSOLE_ENABLE = yes # Console for debug
13COMMAND_ENABLE = yes # Commands for debug and configuration 13COMMAND_ENABLE = yes # Commands for debug and configuration
14SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 14SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
15NKRO_ENABLE = yes # USB Nkey Rollover 15NKRO_ENABLE = yes # USB Nkey Rollover
16CUSTOM_MATRIX = no # Custom matrix file 16CUSTOM_MATRIX = no # Custom matrix file
17BACKLIGHT_ENABLE = yes 17BACKLIGHT_ENABLE = yes
diff --git a/keyboards/cannonkeys/tsukuyomi/rules.mk b/keyboards/cannonkeys/tsukuyomi/rules.mk
index ce881f198..4e7791a79 100644
--- a/keyboards/cannonkeys/tsukuyomi/rules.mk
+++ b/keyboards/cannonkeys/tsukuyomi/rules.mk
@@ -10,7 +10,7 @@ EXTRAKEY_ENABLE = yes # Audio control and System control
10CONSOLE_ENABLE = yes # Console for debug 10CONSOLE_ENABLE = yes # Console for debug
11COMMAND_ENABLE = yes # Commands for debug and configuration 11COMMAND_ENABLE = yes # Commands for debug and configuration
12# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE 12# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
13SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 13SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
14# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work 14# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
15NKRO_ENABLE = yes # USB Nkey Rollover 15NKRO_ENABLE = yes # USB Nkey Rollover
16BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality 16BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
diff --git a/keyboards/crkbd/rev1/common/config.h b/keyboards/crkbd/rev1/common/config.h
index a2c2cde0b..b468fe395 100644
--- a/keyboards/crkbd/rev1/common/config.h
+++ b/keyboards/crkbd/rev1/common/config.h
@@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
23 23
24#ifdef RGB_MATRIX_ENABLE 24#ifdef RGB_MATRIX_ENABLE
25# define RGB_MATRIX_SPLIT { 27, 27 } 25# define RGB_MATRIX_SPLIT { 27, 27 }
26# define SPLIT_TRANSPORT_MIRROR
26#endif 27#endif
27 28
28#define DIODE_DIRECTION COL2ROW 29#define DIODE_DIRECTION COL2ROW
diff --git a/keyboards/crkbd/rev1/common/rules.mk b/keyboards/crkbd/rev1/common/rules.mk
index 0b8106e3f..d38a61809 100644
--- a/keyboards/crkbd/rev1/common/rules.mk
+++ b/keyboards/crkbd/rev1/common/rules.mk
@@ -1,2 +1 @@
1SPLIT_KEYBOARD = yes SPLIT_KEYBOARD = yes
2SPLIT_TRANSPORT = mirror # for when Split Mirroring drops, it will maintain mirroring functionality
diff --git a/keyboards/crkbd/rev1/rev1.c b/keyboards/crkbd/rev1/rev1.c
index f2df8942a..347f98150 100644
--- a/keyboards/crkbd/rev1/rev1.c
+++ b/keyboards/crkbd/rev1/rev1.c
@@ -87,7 +87,7 @@ led_config_t g_led_config = { {
87 87
88void matrix_init_kb(void) { 88void matrix_init_kb(void) {
89 89
90#ifdef RGB_MATRIX_ENABLE 90#if defined(RGB_MATRIX_ENABLE) && !defined(RGB_MATRIX_SPLIT)
91 if (!isLeftHand) { 91 if (!isLeftHand) {
92 g_led_config = (led_config_t){ { 92 g_led_config = (led_config_t){ {
93 { 51, 50, 45, 44, 37, 36 }, 93 { 51, 50, 45, 44, 37, 36 },
diff --git a/keyboards/daji/seis_cinco/rules.mk b/keyboards/daji/seis_cinco/rules.mk
index fa34092cd..768e50069 100644
--- a/keyboards/daji/seis_cinco/rules.mk
+++ b/keyboards/daji/seis_cinco/rules.mk
@@ -11,7 +11,7 @@ EXTRAKEY_ENABLE = yes # Audio control and System control
11CONSOLE_ENABLE = no # Console for debug 11CONSOLE_ENABLE = no # Console for debug
12COMMAND_ENABLE = no # Commands for debug and configuration 12COMMAND_ENABLE = no # Commands for debug and configuration
13# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE 13# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
14SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 14SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
15# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work 15# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
16NKRO_ENABLE = yes # USB Nkey Rollover 16NKRO_ENABLE = yes # USB Nkey Rollover
17BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality 17BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
diff --git a/keyboards/handwired/ck4x4/rules.mk b/keyboards/handwired/ck4x4/rules.mk
index 0709f341b..e5785270b 100644
--- a/keyboards/handwired/ck4x4/rules.mk
+++ b/keyboards/handwired/ck4x4/rules.mk
@@ -10,7 +10,7 @@ MOUSEKEY_ENABLE = yes # Mouse keys
10EXTRAKEY_ENABLE = yes # Audio control and System control 10EXTRAKEY_ENABLE = yes # Audio control and System control
11CONSOLE_ENABLE = yes # Console for debug 11CONSOLE_ENABLE = yes # Console for debug
12COMMAND_ENABLE = yes # Commands for debug and configuration 12COMMAND_ENABLE = yes # Commands for debug and configuration
13SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 13SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
14NKRO_ENABLE = yes # USB Nkey Rollover 14NKRO_ENABLE = yes # USB Nkey Rollover
15CUSTOM_MATRIX = no # Custom matrix file 15CUSTOM_MATRIX = no # Custom matrix file
16 16
diff --git a/keyboards/handwired/onekey/rules.mk b/keyboards/handwired/onekey/rules.mk
index 259050d55..df2ec1ecf 100644
--- a/keyboards/handwired/onekey/rules.mk
+++ b/keyboards/handwired/onekey/rules.mk
@@ -7,9 +7,9 @@ EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
7CONSOLE_ENABLE = yes # Console for debug(+400) 7CONSOLE_ENABLE = yes # Console for debug(+400)
8COMMAND_ENABLE = no # Commands for debug and configuration 8COMMAND_ENABLE = no # Commands for debug and configuration
9# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE 9# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
10SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 10SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
11# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work 11# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
12NKRO_ENABLE = yes # USB Nkey Rollover 12NKRO_ENABLE = yes # USB Nkey Rollover
13BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default 13BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default
14RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow 14RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
15MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config) 15MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
diff --git a/keyboards/projectkb/alice/config.h b/keyboards/projectkb/alice/config.h
new file mode 100644
index 000000000..95fb682e1
--- /dev/null
+++ b/keyboards/projectkb/alice/config.h
@@ -0,0 +1,3 @@
1#pragma once
2
3#define SLEEP_LED_GPT_DRIVER GPTD1
diff --git a/keyboards/projectkb/alice/halconf.h b/keyboards/projectkb/alice/halconf.h
index b17808ffe..0016e53ba 100644
--- a/keyboards/projectkb/alice/halconf.h
+++ b/keyboards/projectkb/alice/halconf.h
@@ -27,5 +27,7 @@
27 27
28#define HAL_USE_SPI TRUE 28#define HAL_USE_SPI TRUE
29 29
30#define HAL_USE_GPT TRUE
31
30#include_next <halconf.h> 32#include_next <halconf.h>
31 33
diff --git a/keyboards/projectkb/alice/mcuconf.h b/keyboards/projectkb/alice/mcuconf.h
index 4bfc7f946..6e0f1a50d 100644
--- a/keyboards/projectkb/alice/mcuconf.h
+++ b/keyboards/projectkb/alice/mcuconf.h
@@ -32,3 +32,5 @@
32#undef STM32_SPI_USE_SPI2 32#undef STM32_SPI_USE_SPI2
33#define STM32_SPI_USE_SPI2 TRUE 33#define STM32_SPI_USE_SPI2 TRUE
34 34
35#undef STM32_GPT_USE_TIM1
36#define STM32_GPT_USE_TIM1 TRUE
diff --git a/keyboards/projectkb/signature87/rules.mk b/keyboards/projectkb/signature87/rules.mk
index fe0d976d1..caad4c83c 100644
--- a/keyboards/projectkb/signature87/rules.mk
+++ b/keyboards/projectkb/signature87/rules.mk
@@ -9,7 +9,7 @@ MOUSEKEY_ENABLE = yes # Mouse keys
9EXTRAKEY_ENABLE = yes # Audio control and System control 9EXTRAKEY_ENABLE = yes # Audio control and System control
10CONSOLE_ENABLE = yes # Console for debug 10CONSOLE_ENABLE = yes # Console for debug
11COMMAND_ENABLE = yes # Commands for debug and configuration 11COMMAND_ENABLE = yes # Commands for debug and configuration
12SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend 12SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
13NKRO_ENABLE = yes # USB Nkey Rollover 13NKRO_ENABLE = yes # USB Nkey Rollover
14BACKLIGHT_ENABLE = no 14BACKLIGHT_ENABLE = no
15 15
diff --git a/keyboards/ramonimbao/wete/config.h b/keyboards/ramonimbao/wete/config.h
index 5d68a7efd..3d8955009 100644
--- a/keyboards/ramonimbao/wete/config.h
+++ b/keyboards/ramonimbao/wete/config.h
@@ -46,6 +46,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
46#define RGBLED_NUM 24 46#define RGBLED_NUM 24
47#define RGBLIGHT_ANIMATIONS 47#define RGBLIGHT_ANIMATIONS
48 48
49#define SLEEP_LED_GPT_DRIVER GPTD1
50
49/* define if matrix has ghost */ 51/* define if matrix has ghost */
50//#define MATRIX_HAS_GHOST 52//#define MATRIX_HAS_GHOST
51 53
diff --git a/keyboards/ramonimbao/wete/halconf.h b/keyboards/ramonimbao/wete/halconf.h
index c43440a45..b3de873be 100644
--- a/keyboards/ramonimbao/wete/halconf.h
+++ b/keyboards/ramonimbao/wete/halconf.h
@@ -23,5 +23,7 @@
23 23
24#define HAL_USE_PWM TRUE 24#define HAL_USE_PWM TRUE
25 25
26#define HAL_USE_GPT TRUE
27
26#include_next <halconf.h> 28#include_next <halconf.h>
27 29
diff --git a/keyboards/ramonimbao/wete/mcuconf.h b/keyboards/ramonimbao/wete/mcuconf.h
index b7f2c481c..7a2e87776 100644
--- a/keyboards/ramonimbao/wete/mcuconf.h
+++ b/keyboards/ramonimbao/wete/mcuconf.h
@@ -35,3 +35,5 @@
35#undef STM32_SPI_USE_SPI2 35#undef STM32_SPI_USE_SPI2
36#define STM32_SPI_USE_SPI2 TRUE 36#define STM32_SPI_USE_SPI2 TRUE
37 37
38#undef STM32_GPT_USE_TIM1
39#define STM32_GPT_USE_TIM1 TRUE
diff --git a/keyboards/readme.md b/keyboards/readme.md
index 6b7b92e0c..a23d0845b 100644
--- a/keyboards/readme.md
+++ b/keyboards/readme.md
@@ -63,4 +63,4 @@ These keyboards are part of the QMK repository, but their manufacturers are not
63* [Vision Division](/keyboards/vision_division) &mdash; Full Size / Split Linear Keyboard by IBNobody. 63* [Vision Division](/keyboards/vision_division) &mdash; Full Size / Split Linear Keyboard by IBNobody.
64* [XD004](/keyboards/xd004) &mdash; 1x4 macro keyboard sold by KPrepublic. 64* [XD004](/keyboards/xd004) &mdash; 1x4 macro keyboard sold by KPrepublic.
65* [XD75](/keyboards/xd75) &mdash; 15x5 ortholinear keyboard by XIUDI. 65* [XD75](/keyboards/xd75) &mdash; 15x5 ortholinear keyboard by XIUDI.
66* [YMDK NP21](/keyboards/ymdk_np21) &mdash; ps2avrGB based number pad (numpad) sold by YMDK on Aliexpress. 66* [YMDK NP21](/keyboards/ymdk_np21) &mdash; ps2avrGB based number pad (numpad) sold by YMDK on Aliexpress.
diff --git a/keyboards/westfoxtrot/prophet/config.h b/keyboards/westfoxtrot/prophet/config.h
index 4f447e4ca..0f2ddc1dc 100644
--- a/keyboards/westfoxtrot/prophet/config.h
+++ b/keyboards/westfoxtrot/prophet/config.h
@@ -30,3 +30,5 @@
30#define LOCKING_SUPPORT_ENABLE 30#define LOCKING_SUPPORT_ENABLE
31/* Locking resynchronize hack */ 31/* Locking resynchronize hack */
32#define LOCKING_RESYNC_ENABLE 32#define LOCKING_RESYNC_ENABLE
33
34#define SLEEP_LED_GPT_DRIVER GPTD1
diff --git a/keyboards/westfoxtrot/prophet/halconf.h b/keyboards/westfoxtrot/prophet/halconf.h
new file mode 100644
index 000000000..cbfd1307f
--- /dev/null
+++ b/keyboards/westfoxtrot/prophet/halconf.h
@@ -0,0 +1,27 @@
1/* Copyright 2020 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 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17/*
18 * This file was auto-generated by:
19 * `qmk chibios-confmigrate -i keyboards/projectkb/alice/halconf.h -r platforms/chibios/common/configs/halconf.h`
20 */
21
22#pragma once
23
24#define HAL_USE_GPT TRUE
25
26#include_next <halconf.h>
27
diff --git a/keyboards/westfoxtrot/prophet/mcuconf.h b/keyboards/westfoxtrot/prophet/mcuconf.h
index 2665f9c9e..550141af6 100644
--- a/keyboards/westfoxtrot/prophet/mcuconf.h
+++ b/keyboards/westfoxtrot/prophet/mcuconf.h
@@ -23,6 +23,5 @@
23 23
24#include_next <mcuconf.h> 24#include_next <mcuconf.h>
25 25
26#undef STM32_PWM_USE_TIM3 26#undef STM32_GPT_USE_TIM1
27#define STM32_PWM_USE_TIM3 TRUE 27#define STM32_GPT_USE_TIM1 TRUE
28
diff --git a/lib/python/qmk/commands.py b/lib/python/qmk/commands.py
index 6a57c1ff5..ac9837695 100644
--- a/lib/python/qmk/commands.py
+++ b/lib/python/qmk/commands.py
@@ -180,6 +180,7 @@ def compile_configurator_json(user_keymap, bootloader=None, parallel=1, **env_va
180 f'VERBOSE={verbose}', 180 f'VERBOSE={verbose}',
181 f'COLOR={color}', 181 f'COLOR={color}',
182 'SILENT=false', 182 'SILENT=false',
183 'QMK_BIN=qmk',
183 ]) 184 ])
184 185
185 return make_command 186 return make_command
diff --git a/lib/python/qmk/tests/test_cli_commands.py b/lib/python/qmk/tests/test_cli_commands.py
index 82c42a20e..bfecebdd7 100644
--- a/lib/python/qmk/tests/test_cli_commands.py
+++ b/lib/python/qmk/tests/test_cli_commands.py
@@ -8,7 +8,7 @@ is_windows = 'windows' in platform.platform().lower()
8 8
9 9
10def check_subcommand(command, *args): 10def check_subcommand(command, *args):
11 cmd = ['bin/qmk', command, *args] 11 cmd = ['qmk', command, *args]
12 result = run(cmd, stdout=PIPE, stderr=STDOUT, universal_newlines=True) 12 result = run(cmd, stdout=PIPE, stderr=STDOUT, universal_newlines=True)
13 return result 13 return result
14 14
@@ -17,7 +17,7 @@ def check_subcommand_stdin(file_to_read, command, *args):
17 """Pipe content of a file to a command and return output. 17 """Pipe content of a file to a command and return output.
18 """ 18 """
19 with open(file_to_read, encoding='utf-8') as my_file: 19 with open(file_to_read, encoding='utf-8') as my_file:
20 cmd = ['bin/qmk', command, *args] 20 cmd = ['qmk', command, *args]
21 result = run(cmd, stdin=my_file, stdout=PIPE, stderr=STDOUT, universal_newlines=True) 21 result = run(cmd, stdin=my_file, stdout=PIPE, stderr=STDOUT, universal_newlines=True)
22 return result 22 return result
23 23
diff --git a/quantum/bootmagic/bootmagic.h b/quantum/bootmagic/bootmagic.h
new file mode 100644
index 000000000..959750178
--- /dev/null
+++ b/quantum/bootmagic/bootmagic.h
@@ -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#pragma once
17
18#if defined(BOOTMAGIC_ENABLE)
19# include "bootmagic_full.h"
20#elif defined(BOOTMAGIC_LITE)
21# include "bootmagic_lite.h"
22#endif
23
24void bootmagic(void);
diff --git a/tmk_core/common/bootmagic.c b/quantum/bootmagic/bootmagic_full.c
index c1b3adf94..a7a0dcfcb 100644
--- a/tmk_core/common/bootmagic.c
+++ b/quantum/bootmagic/bootmagic_full.c
@@ -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#include <stdint.h> 16#include <stdint.h>
2#include <stdbool.h> 17#include <stdbool.h>
3#include "wait.h" 18#include "wait.h"
@@ -10,18 +25,35 @@
10#include "eeconfig.h" 25#include "eeconfig.h"
11#include "bootmagic.h" 26#include "bootmagic.h"
12 27
13keymap_config_t keymap_config; 28/** \brief Scan Keycode
14
15/** \brief Bootmagic
16 * 29 *
17 * FIXME: needs doc 30 * FIXME: needs doc
18 */ 31 */
19void bootmagic(void) { 32static bool scan_keycode(uint8_t keycode) {
20 /* check signature */ 33 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
21 if (!eeconfig_is_enabled()) { 34 matrix_row_t matrix_row = matrix_get_row(r);
22 eeconfig_init(); 35 for (uint8_t c = 0; c < MATRIX_COLS; c++) {
36 if (matrix_row & ((matrix_row_t)1 << c)) {
37 if (keycode == keymap_key_to_keycode(0, (keypos_t){.row = r, .col = c})) {
38 return true;
39 }
40 }
41 }
23 } 42 }
43 return false;
44}
45
46/** \brief Bootmagic Scan Keycode
47 *
48 * FIXME: needs doc
49 */
50static bool bootmagic_scan_keycode(uint8_t keycode) {
51 if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false;
52
53 return scan_keycode(keycode);
54}
24 55
56void bootmagic(void) {
25 /* do scans in case of bounce */ 57 /* do scans in case of bounce */
26 print("bootmagic scan: ... "); 58 print("bootmagic scan: ... ");
27 uint8_t scan = 100; 59 uint8_t scan = 100;
@@ -46,8 +78,6 @@ void bootmagic(void) {
46 bootloader_jump(); 78 bootloader_jump();
47 } 79 }
48 80
49 /* debug enable */
50 debug_config.raw = eeconfig_read_debug();
51 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_ENABLE)) { 81 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_ENABLE)) {
52 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MATRIX)) { 82 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MATRIX)) {
53 debug_config.matrix = !debug_config.matrix; 83 debug_config.matrix = !debug_config.matrix;
@@ -61,8 +91,6 @@ void bootmagic(void) {
61 } 91 }
62 eeconfig_update_debug(debug_config.raw); 92 eeconfig_update_debug(debug_config.raw);
63 93
64 /* keymap config */
65 keymap_config.raw = eeconfig_read_keymap();
66 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) { 94 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) {
67 keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock; 95 keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
68 } 96 }
@@ -93,71 +121,27 @@ void bootmagic(void) {
93 uint8_t default_layer = 0; 121 uint8_t default_layer = 0;
94 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { 122 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) {
95 default_layer |= (1 << 0); 123 default_layer |= (1 << 0);
96 } 124 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) {
97 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) {
98 default_layer |= (1 << 1); 125 default_layer |= (1 << 1);
99 } 126 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) {
100 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) {
101 default_layer |= (1 << 2); 127 default_layer |= (1 << 2);
102 } 128 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) {
103 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) {
104 default_layer |= (1 << 3); 129 default_layer |= (1 << 3);
105 } 130 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) {
106 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) {
107 default_layer |= (1 << 4); 131 default_layer |= (1 << 4);
108 } 132 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) {
109 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) {
110 default_layer |= (1 << 5); 133 default_layer |= (1 << 5);
111 } 134 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) {
112 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) {
113 default_layer |= (1 << 6); 135 default_layer |= (1 << 6);
114 } 136 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) {
115 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) {
116 default_layer |= (1 << 7); 137 default_layer |= (1 << 7);
117 } 138 }
118 if (default_layer) { 139 eeconfig_update_default_layer(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 140
128 /* EE_HANDS handedness */ 141 /* EE_HANDS handedness */
129 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_LEFT)) { 142 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_LEFT)) {
130 eeconfig_update_handedness(true); 143 eeconfig_update_handedness(true);
131 } 144 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_RIGHT)) {
132 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_RIGHT)) {
133 eeconfig_update_handedness(false); 145 eeconfig_update_handedness(false);
134 } 146 }
135} 147}
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/quantum/bootmagic/bootmagic_full.h
index 8209d0194..28f914c1b 100644
--- a/tmk_core/common/bootmagic.h
+++ b/quantum/bootmagic/bootmagic_full.h
@@ -1,3 +1,19 @@
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
1#pragma once 17#pragma once
2 18
3/* FIXME: Add special doxygen comments for defines here. */ 19/* FIXME: Add special doxygen comments for defines here. */
@@ -96,7 +112,4 @@
96#endif 112#endif
97#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_7 113#ifndef BOOTMAGIC_KEY_DEFAULT_LAYER_7
98# define BOOTMAGIC_KEY_DEFAULT_LAYER_7 KC_7 114# define BOOTMAGIC_KEY_DEFAULT_LAYER_7 KC_7
99#endif 115#endif \ No newline at end of file
100
101void bootmagic(void);
102bool bootmagic_scan_keycode(uint8_t keycode);
diff --git a/tmk_core/common/bootmagic_lite.c b/quantum/bootmagic/bootmagic_lite.c
index cbf756a17..9cbdcb0bb 100644
--- a/tmk_core/common/bootmagic_lite.c
+++ b/quantum/bootmagic/bootmagic_lite.c
@@ -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#include "quantum.h" 16#include "quantum.h"
2 17
3/** \brief Reset eeprom 18/** \brief Reset eeprom
@@ -47,3 +62,5 @@ __attribute__((weak)) void bootmagic_lite(void) {
47 bootloader_jump(); 62 bootloader_jump();
48 } 63 }
49} 64}
65
66void bootmagic(void) { bootmagic_lite(); }
diff --git a/quantum/bootmagic/bootmagic_lite.h b/quantum/bootmagic/bootmagic_lite.h
new file mode 100644
index 000000000..17777e6b4
--- /dev/null
+++ b/quantum/bootmagic/bootmagic_lite.h
@@ -0,0 +1,25 @@
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#ifndef BOOTMAGIC_LITE_COLUMN
19# define BOOTMAGIC_LITE_COLUMN 0
20#endif
21#ifndef BOOTMAGIC_LITE_ROW
22# define BOOTMAGIC_LITE_ROW 0
23#endif
24
25void bootmagic_lite(void);
diff --git a/quantum/bootmagic/magic.c b/quantum/bootmagic/magic.c
new file mode 100644
index 000000000..f1cb11c39
--- /dev/null
+++ b/quantum/bootmagic/magic.c
@@ -0,0 +1,54 @@
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 <stdint.h>
17#include <stdbool.h>
18#include "wait.h"
19#include "matrix.h"
20#include "bootloader.h"
21#include "debug.h"
22#include "keymap.h"
23#include "host.h"
24#include "action_layer.h"
25#include "eeconfig.h"
26#include "bootmagic.h"
27
28keymap_config_t keymap_config;
29
30__attribute__((weak)) void bootmagic(void) {}
31
32/** \brief Magic
33 *
34 * FIXME: Needs doc
35 */
36void magic(void) {
37 /* check signature */
38 if (!eeconfig_is_enabled()) {
39 eeconfig_init();
40 }
41
42 /* init globals */
43 debug_config.raw = eeconfig_read_debug();
44 keymap_config.raw = eeconfig_read_keymap();
45
46 bootmagic();
47
48 /* read here just incase bootmagic process changed its value */
49 layer_state_t default_layer = (layer_state_t)eeconfig_read_default_layer();
50 default_layer_set(default_layer);
51
52 /* Also initialize layer state to trigger callback functions for layer_state */
53 layer_state_set_kb((layer_state_t)layer_state);
54}
diff --git a/quantum/bootmagic/magic.h b/quantum/bootmagic/magic.h
new file mode 100644
index 000000000..2c3969b85
--- /dev/null
+++ b/quantum/bootmagic/magic.h
@@ -0,0 +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 */
16#pragma once
17
18void magic(void);
diff --git a/quantum/keycode_config.h b/quantum/keycode_config.h
index f878168c5..d7e334fdc 100644
--- a/quantum/keycode_config.h
+++ b/quantum/keycode_config.h
@@ -37,6 +37,7 @@ typedef union {
37 bool nkro : 1; 37 bool nkro : 1;
38 bool swap_lctl_lgui : 1; 38 bool swap_lctl_lgui : 1;
39 bool swap_rctl_rgui : 1; 39 bool swap_rctl_rgui : 1;
40 bool oneshot_disable : 1;
40 }; 41 };
41} keymap_config_t; 42} keymap_config_t;
42 43
diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c
index 4f1f06c7a..39bccdd58 100644
--- a/quantum/led_matrix.c
+++ b/quantum/led_matrix.c
@@ -45,10 +45,6 @@ led_eeconfig_t led_matrix_eeconfig;
45# define LED_DISABLE_WHEN_USB_SUSPENDED false 45# define LED_DISABLE_WHEN_USB_SUSPENDED false
46#endif 46#endif
47 47
48#ifndef EECONFIG_LED_MATRIX
49# define EECONFIG_LED_MATRIX EECONFIG_RGBLIGHT
50#endif
51
52#if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > 255 48#if !defined(LED_MATRIX_MAXIMUM_BRIGHTNESS) || LED_MATRIX_MAXIMUM_BRIGHTNESS > 255
53# define LED_MATRIX_MAXIMUM_BRIGHTNESS 255 49# define LED_MATRIX_MAXIMUM_BRIGHTNESS 255
54#endif 50#endif
@@ -135,7 +131,7 @@ void led_matrix_set_suspend_state(bool state) { g_suspend_state = state; }
135void led_matrix_all_off(void) { led_matrix_set_index_value_all(0); } 131void led_matrix_all_off(void) { led_matrix_set_index_value_all(0); }
136 132
137// Uniform brightness 133// Uniform brightness
138void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(LED_MATRIX_MAXIMUM_BRIGHTNESS / BACKLIGHT_LEVELS * led_matrix_eeconfig.val); } 134void led_matrix_uniform_brightness(void) { led_matrix_set_index_value_all(led_matrix_eeconfig.val); }
139 135
140void led_matrix_custom(void) {} 136void led_matrix_custom(void) {}
141 137
@@ -344,5 +340,3 @@ void led_matrix_set_value(uint8_t val) {
344 led_matrix_set_value_noeeprom(val); 340 led_matrix_set_value_noeeprom(val);
345 eeconfig_update_led_matrix(led_matrix_eeconfig.raw); 341 eeconfig_update_led_matrix(led_matrix_eeconfig.raw);
346} 342}
347
348void backlight_set(uint8_t val) { led_matrix_set_value(val); }
diff --git a/quantum/led_matrix.h b/quantum/led_matrix.h
index 85bae43c1..0817d1357 100644
--- a/quantum/led_matrix.h
+++ b/quantum/led_matrix.h
@@ -21,10 +21,6 @@
21 21
22#include "led_matrix_types.h" 22#include "led_matrix_types.h"
23 23
24#ifndef BACKLIGHT_ENABLE
25# error You must define BACKLIGHT_ENABLE with LED_MATRIX_ENABLE
26#endif
27
28enum led_matrix_effects { 24enum led_matrix_effects {
29 LED_MATRIX_UNIFORM_BRIGHTNESS = 1, 25 LED_MATRIX_UNIFORM_BRIGHTNESS = 1,
30 // All new effects go above this line 26 // All new effects go above this line
diff --git a/quantum/process_keycode/process_backlight.c b/quantum/process_keycode/process_backlight.c
index 4d12f6813..8b70339a5 100644
--- a/quantum/process_keycode/process_backlight.c
+++ b/quantum/process_keycode/process_backlight.c
@@ -16,11 +16,35 @@
16 16
17#include "process_backlight.h" 17#include "process_backlight.h"
18 18
19#include "backlight.h" 19#ifdef LED_MATRIX_ENABLE
20# include "led_matrix.h"
21#else
22# include "backlight.h"
23#endif
20 24
21bool process_backlight(uint16_t keycode, keyrecord_t *record) { 25bool process_backlight(uint16_t keycode, keyrecord_t *record) {
22 if (record->event.pressed) { 26 if (record->event.pressed) {
23 switch (keycode) { 27 switch (keycode) {
28#ifdef LED_MATRIX_ENABLE
29 case BL_ON:
30 led_matrix_enable();
31 return false;
32 case BL_OFF:
33 led_matrix_disable();
34 return false;
35 case BL_DEC:
36 led_matrix_decrease_val();
37 return false;
38 case BL_INC:
39 led_matrix_increase_val();
40 return false;
41 case BL_TOGG:
42 led_matrix_toggle();
43 return false;
44 case BL_STEP:
45 led_matrix_step();
46 return false;
47#else
24 case BL_ON: 48 case BL_ON:
25 backlight_level(BACKLIGHT_LEVELS); 49 backlight_level(BACKLIGHT_LEVELS);
26 return false; 50 return false;
@@ -39,10 +63,11 @@ bool process_backlight(uint16_t keycode, keyrecord_t *record) {
39 case BL_STEP: 63 case BL_STEP:
40 backlight_step(); 64 backlight_step();
41 return false; 65 return false;
42#ifdef BACKLIGHT_BREATHING 66# ifdef BACKLIGHT_BREATHING
43 case BL_BRTG: 67 case BL_BRTG:
44 backlight_toggle_breathing(); 68 backlight_toggle_breathing();
45 return false; 69 return false;
70# endif
46#endif 71#endif
47 } 72 }
48 } 73 }
diff --git a/quantum/quantum.c b/quantum/quantum.c
index b40b40544..8ccdb774b 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -15,6 +15,7 @@
15 */ 15 */
16 16
17#include "quantum.h" 17#include "quantum.h"
18#include "magic.h"
18 19
19#ifdef BLUETOOTH_ENABLE 20#ifdef BLUETOOTH_ENABLE
20# include "outputselect.h" 21# include "outputselect.h"
@@ -233,7 +234,7 @@ bool process_record_quantum(keyrecord_t *record) {
233#ifdef AUDIO_ENABLE 234#ifdef AUDIO_ENABLE
234 process_audio(keycode, record) && 235 process_audio(keycode, record) &&
235#endif 236#endif
236#ifdef BACKLIGHT_ENABLE 237#if defined(BACKLIGHT_ENABLE) || defined(LED_MATRIX_ENABLE)
237 process_backlight(keycode, record) && 238 process_backlight(keycode, record) &&
238#endif 239#endif
239#ifdef STENO_ENABLE 240#ifdef STENO_ENABLE
@@ -318,6 +319,17 @@ bool process_record_quantum(keyrecord_t *record) {
318 set_output(OUTPUT_BLUETOOTH); 319 set_output(OUTPUT_BLUETOOTH);
319 return false; 320 return false;
320#endif 321#endif
322#ifndef NO_ACTION_ONESHOT
323 case ONESHOT_TOGGLE:
324 oneshot_toggle();
325 break;
326 case ONESHOT_ENABLE:
327 oneshot_enable();
328 break;
329 case ONESHOT_DISABLE:
330 oneshot_disable();
331 break;
332#endif
321 } 333 }
322 } 334 }
323 335
@@ -341,26 +353,20 @@ layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_
341void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { layer_state_set(update_tri_layer_state(layer_state, layer1, layer2, layer3)); } 353void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { layer_state_set(update_tri_layer_state(layer_state, layer1, layer2, layer3)); }
342 354
343void matrix_init_quantum() { 355void matrix_init_quantum() {
344#ifdef BOOTMAGIC_LITE 356 magic();
345 bootmagic_lite();
346#endif
347 if (!eeconfig_is_enabled()) {
348 eeconfig_init();
349 }
350#if defined(LED_NUM_LOCK_PIN) || defined(LED_CAPS_LOCK_PIN) || defined(LED_SCROLL_LOCK_PIN) || defined(LED_COMPOSE_PIN) || defined(LED_KANA_PIN) 357#if defined(LED_NUM_LOCK_PIN) || defined(LED_CAPS_LOCK_PIN) || defined(LED_SCROLL_LOCK_PIN) || defined(LED_COMPOSE_PIN) || defined(LED_KANA_PIN)
351 // TODO: remove calls to led_init_ports from keyboards and remove ifdef 358 // TODO: remove calls to led_init_ports from keyboards and remove ifdef
352 led_init_ports(); 359 led_init_ports();
353#endif 360#endif
354#ifdef BACKLIGHT_ENABLE 361#ifdef BACKLIGHT_ENABLE
355# ifdef LED_MATRIX_ENABLE
356 led_matrix_init();
357# else
358 backlight_init_ports(); 362 backlight_init_ports();
359# endif
360#endif 363#endif
361#ifdef AUDIO_ENABLE 364#ifdef AUDIO_ENABLE
362 audio_init(); 365 audio_init();
363#endif 366#endif
367#ifdef LED_MATRIX_ENABLE
368 led_matrix_init();
369#endif
364#ifdef RGB_MATRIX_ENABLE 370#ifdef RGB_MATRIX_ENABLE
365 rgb_matrix_init(); 371 rgb_matrix_init();
366#endif 372#endif
diff --git a/quantum/quantum.h b/quantum/quantum.h
index e24a4c43a..fe6bf310a 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -30,11 +30,11 @@
30#include "keymap.h" 30#include "keymap.h"
31 31
32#ifdef BACKLIGHT_ENABLE 32#ifdef BACKLIGHT_ENABLE
33# ifdef LED_MATRIX_ENABLE 33# include "backlight.h"
34# include "led_matrix.h" 34#endif
35# else 35
36# include "backlight.h" 36#ifdef LED_MATRIX_ENABLE
37# endif 37# include "led_matrix.h"
38#endif 38#endif
39 39
40#if defined(RGBLIGHT_ENABLE) 40#if defined(RGBLIGHT_ENABLE)
@@ -52,6 +52,7 @@
52#include "action_layer.h" 52#include "action_layer.h"
53#include "eeconfig.h" 53#include "eeconfig.h"
54#include "bootloader.h" 54#include "bootloader.h"
55#include "bootmagic.h"
55#include "timer.h" 56#include "timer.h"
56#include "sync_timer.h" 57#include "sync_timer.h"
57#include "config_common.h" 58#include "config_common.h"
@@ -97,7 +98,7 @@ extern layer_state_t layer_state;
97# include "process_music.h" 98# include "process_music.h"
98#endif 99#endif
99 100
100#ifdef BACKLIGHT_ENABLE 101#if defined(BACKLIGHT_ENABLE) || defined(LED_MATRIX_ENABLE)
101# include "process_backlight.h" 102# include "process_backlight.h"
102#endif 103#endif
103 104
@@ -199,39 +200,6 @@ extern layer_state_t layer_state;
199# include "usbpd.h" 200# include "usbpd.h"
200#endif 201#endif
201 202
202// Function substitutions to ease GPIO manipulation
203#if defined(__AVR__)
204
205/* The AVR series GPIOs have a one clock read delay for changes in the digital input signal.
206 * But here's more margin to make it two clocks. */
207# if !defined(GPIO_INPUT_PIN_DELAY)
208# define GPIO_INPUT_PIN_DELAY 2
209# endif
210# define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY)
211
212#elif defined(__ARMEL__) || defined(__ARMEB__)
213
214/* For GPIOs on ARM-based MCUs, the input pins are sampled by the clock of the bus
215 * to which the GPIO is connected.
216 * The connected buses differ depending on the various series of MCUs.
217 * And since the instruction execution clock of the CPU and the bus clock of GPIO are different,
218 * there is a delay of several clocks to read the change of the input signal.
219 *
220 * Define this delay with the GPIO_INPUT_PIN_DELAY macro.
221 * If the GPIO_INPUT_PIN_DELAY macro is not defined, the following default values will be used.
222 * (A fairly large value of 0.25 microseconds is set.)
223 */
224# if !defined(GPIO_INPUT_PIN_DELAY)
225# if defined(STM32_SYSCLK)
226# define GPIO_INPUT_PIN_DELAY (STM32_SYSCLK / 1000000L / 4)
227# elif defined(KINETIS_SYSCLK_FREQUENCY)
228# define GPIO_INPUT_PIN_DELAY (KINETIS_SYSCLK_FREQUENCY / 1000000L / 4)
229# endif
230# endif
231# define waitInputPinDelay() wait_cpuclock(GPIO_INPUT_PIN_DELAY)
232
233#endif
234
235// For tri-layer 203// For tri-layer
236void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3); 204void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3);
237layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3); 205layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3);
@@ -256,15 +224,6 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record);
256void post_process_record_kb(uint16_t keycode, keyrecord_t *record); 224void post_process_record_kb(uint16_t keycode, keyrecord_t *record);
257void post_process_record_user(uint16_t keycode, keyrecord_t *record); 225void post_process_record_user(uint16_t keycode, keyrecord_t *record);
258 226
259#ifndef BOOTMAGIC_LITE_COLUMN
260# define BOOTMAGIC_LITE_COLUMN 0
261#endif
262#ifndef BOOTMAGIC_LITE_ROW
263# define BOOTMAGIC_LITE_ROW 0
264#endif
265
266void bootmagic_lite(void);
267
268void reset_keyboard(void); 227void reset_keyboard(void);
269 228
270void startup_user(void); 229void startup_user(void);
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index 1863a7943..dab9ba3d7 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -569,6 +569,10 @@ enum quantum_keycodes {
569 569
570#endif 570#endif
571 571
572 ONESHOT_ENABLE,
573 ONESHOT_DISABLE,
574 ONESHOT_TOGGLE,
575
572 // always leave at the end 576 // always leave at the end
573 SAFE_RANGE 577 SAFE_RANGE
574}; 578};
@@ -676,16 +680,13 @@ enum quantum_keycodes {
676 680
677#define KC_DELT KC_DELETE // Del key (four letter code) 681#define KC_DELT KC_DELETE // Del key (four letter code)
678 682
679// Alias for function layers than expand past FN31
680#define FUNC(kc) (QK_FUNCTION | (kc))
681
682// Aliases 683// Aliases
683#define C(kc) LCTL(kc) 684#define C(kc) LCTL(kc)
684#define S(kc) LSFT(kc) 685#define S(kc) LSFT(kc)
685#define A(kc) LALT(kc) 686#define A(kc) LALT(kc)
686#define G(kc) LGUI(kc) 687#define G(kc) LGUI(kc)
687 688
688#define F(kc) FUNC(kc) 689#define F(kc) (QK_FUNCTION | (kc))
689#define M(kc) (QK_MACRO | (kc)) 690#define M(kc) (QK_MACRO | (kc))
690 691
691#define MACROTAP(kc) (QK_MACRO | (FUNC_TAP << 8) | (kc)) 692#define MACROTAP(kc) (QK_MACRO | (FUNC_TAP << 8) | (kc))
@@ -870,3 +871,8 @@ enum quantum_keycodes {
870#define DM_RSTP DYN_REC_STOP 871#define DM_RSTP DYN_REC_STOP
871#define DM_PLY1 DYN_MACRO_PLAY1 872#define DM_PLY1 DYN_MACRO_PLAY1
872#define DM_PLY2 DYN_MACRO_PLAY2 873#define DM_PLY2 DYN_MACRO_PLAY2
874
875// One Shot toggle
876#define OS_TOGG ONESHOT_TOGGLE
877#define OS_ON ONESHOT_ENABLE
878#define OS_OFF ONESHOT_DISABLE
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c
index ec17b4d72..8aae48603 100644
--- a/quantum/rgb_matrix.c
+++ b/quantum/rgb_matrix.c
@@ -131,7 +131,7 @@ last_hit_t g_last_hit_tracker;
131// internals 131// internals
132static uint8_t rgb_last_enable = UINT8_MAX; 132static uint8_t rgb_last_enable = UINT8_MAX;
133static uint8_t rgb_last_effect = UINT8_MAX; 133static uint8_t rgb_last_effect = UINT8_MAX;
134static effect_params_t rgb_effect_params = {0, 0xFF}; 134static effect_params_t rgb_effect_params = {0, LED_FLAG_ALL, false};
135static rgb_task_states rgb_task_state = SYNCING; 135static rgb_task_states rgb_task_state = SYNCING;
136#if RGB_DISABLE_TIMEOUT > 0 136#if RGB_DISABLE_TIMEOUT > 0
137static uint32_t rgb_anykey_timer; 137static uint32_t rgb_anykey_timer;
@@ -143,6 +143,11 @@ static uint32_t rgb_timer_buffer;
143static last_hit_t last_hit_buffer; 143static last_hit_t last_hit_buffer;
144#endif // RGB_MATRIX_KEYREACTIVE_ENABLED 144#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
145 145
146// split rgb matrix
147#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
148const uint8_t k_rgb_matrix_split[2] = RGB_MATRIX_SPLIT;
149#endif
150
146void eeconfig_read_rgb_matrix(void) { eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } 151void eeconfig_read_rgb_matrix(void) { eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); }
147 152
148void eeconfig_update_rgb_matrix(void) { eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); } 153void eeconfig_update_rgb_matrix(void) { eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config)); }
@@ -153,6 +158,7 @@ void eeconfig_update_rgb_matrix_default(void) {
153 rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE; 158 rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE;
154 rgb_matrix_config.hsv = (HSV){RGB_MATRIX_STARTUP_HUE, RGB_MATRIX_STARTUP_SAT, RGB_MATRIX_STARTUP_VAL}; 159 rgb_matrix_config.hsv = (HSV){RGB_MATRIX_STARTUP_HUE, RGB_MATRIX_STARTUP_SAT, RGB_MATRIX_STARTUP_VAL};
155 rgb_matrix_config.speed = RGB_MATRIX_STARTUP_SPD; 160 rgb_matrix_config.speed = RGB_MATRIX_STARTUP_SPD;
161 rgb_matrix_config.flags = LED_FLAG_ALL;
156 eeconfig_update_rgb_matrix(); 162 eeconfig_update_rgb_matrix();
157} 163}
158 164
@@ -164,6 +170,7 @@ void eeconfig_debug_rgb_matrix(void) {
164 dprintf("rgb_matrix_config.hsv.s = %d\n", rgb_matrix_config.hsv.s); 170 dprintf("rgb_matrix_config.hsv.s = %d\n", rgb_matrix_config.hsv.s);
165 dprintf("rgb_matrix_config.hsv.v = %d\n", rgb_matrix_config.hsv.v); 171 dprintf("rgb_matrix_config.hsv.v = %d\n", rgb_matrix_config.hsv.v);
166 dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed); 172 dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed);
173 dprintf("rgb_matrix_config.flags = %d\n", rgb_matrix_config.flags);
167} 174}
168 175
169__attribute__((weak)) uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; } 176__attribute__((weak)) uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; }
@@ -180,9 +187,22 @@ uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *l
180 187
181void rgb_matrix_update_pwm_buffers(void) { rgb_matrix_driver.flush(); } 188void rgb_matrix_update_pwm_buffers(void) { rgb_matrix_driver.flush(); }
182 189
183void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color(index, red, green, blue); } 190void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
191#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
192 if (!is_keyboard_left() && index >= k_rgb_matrix_split[0])
193 rgb_matrix_driver.set_color(index - k_rgb_matrix_split[0], red, green, blue);
194 else if (is_keyboard_left() && index < k_rgb_matrix_split[0])
195#endif
196 rgb_matrix_driver.set_color(index, red, green, blue);
197}
184 198
185void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color_all(red, green, blue); } 199void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
200#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
201 for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) rgb_matrix_set_color(i, red, green, blue);
202#else
203 rgb_matrix_driver.set_color_all(red, green, blue);
204#endif
205}
186 206
187void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) { 207void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) {
188#ifndef RGB_MATRIX_SPLIT 208#ifndef RGB_MATRIX_SPLIT
@@ -315,6 +335,10 @@ static void rgb_task_start(void) {
315static void rgb_task_render(uint8_t effect) { 335static void rgb_task_render(uint8_t effect) {
316 bool rendering = false; 336 bool rendering = false;
317 rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable); 337 rgb_effect_params.init = (effect != rgb_last_effect) || (rgb_matrix_config.enable != rgb_last_enable);
338 if (rgb_effect_params.flags != rgb_matrix_config.flags) {
339 rgb_effect_params.flags = rgb_matrix_config.flags;
340 rgb_matrix_set_color_all(0, 0, 0);
341 }
318 342
319 // each effect can opt to do calculations 343 // each effect can opt to do calculations
320 // and/or request PWM buffer updates. 344 // and/or request PWM buffer updates.
@@ -618,6 +642,6 @@ void rgb_matrix_decrease_speed_helper(bool write_to_eeprom) { rgb_matrix_set_spe
618void rgb_matrix_decrease_speed_noeeprom(void) { rgb_matrix_decrease_speed_helper(false); } 642void rgb_matrix_decrease_speed_noeeprom(void) { rgb_matrix_decrease_speed_helper(false); }
619void rgb_matrix_decrease_speed(void) { rgb_matrix_decrease_speed_helper(true); } 643void rgb_matrix_decrease_speed(void) { rgb_matrix_decrease_speed_helper(true); }
620 644
621led_flags_t rgb_matrix_get_flags(void) { return rgb_effect_params.flags; } 645led_flags_t rgb_matrix_get_flags(void) { return rgb_matrix_config.flags; }
622 646
623void rgb_matrix_set_flags(led_flags_t flags) { rgb_effect_params.flags = flags; } 647void rgb_matrix_set_flags(led_flags_t flags) { rgb_matrix_config.flags = flags; }
diff --git a/quantum/rgb_matrix_types.h b/quantum/rgb_matrix_types.h
index 7b8171fb2..1a37922af 100644
--- a/quantum/rgb_matrix_types.h
+++ b/quantum/rgb_matrix_types.h
@@ -85,10 +85,11 @@ typedef struct PACKED {
85typedef union { 85typedef union {
86 uint32_t raw; 86 uint32_t raw;
87 struct PACKED { 87 struct PACKED {
88 uint8_t enable : 2; 88 uint8_t enable : 2;
89 uint8_t mode : 6; 89 uint8_t mode : 6;
90 HSV hsv; 90 HSV hsv;
91 uint8_t speed; // EECONFIG needs to be increased to support this 91 uint8_t speed; // EECONFIG needs to be increased to support this
92 led_flags_t flags;
92 }; 93 };
93} rgb_config_t; 94} rgb_config_t;
94 95
diff --git a/quantum/split_common/split_util.c b/quantum/split_common/split_util.c
index 2ae44e6e1..9e75e19ce 100644
--- a/quantum/split_common/split_util.c
+++ b/quantum/split_common/split_util.c
@@ -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#include "split_util.h" 16#include "split_util.h"
2#include "matrix.h" 17#include "matrix.h"
3#include "keyboard.h" 18#include "keyboard.h"
@@ -6,14 +21,7 @@
6#include "transport.h" 21#include "transport.h"
7#include "quantum.h" 22#include "quantum.h"
8#include "wait.h" 23#include "wait.h"
9 24#include "usb_util.h"
10#ifdef PROTOCOL_LUFA
11# include <LUFA/Drivers/USB/USB.h>
12#endif
13
14#ifdef PROTOCOL_VUSB
15# include <usbdrv/usbdrv.h>
16#endif
17 25
18#ifdef EE_HANDS 26#ifdef EE_HANDS
19# include "eeconfig.h" 27# include "eeconfig.h"
@@ -31,56 +39,21 @@
31# define SPLIT_USB_TIMEOUT_POLL 10 39# define SPLIT_USB_TIMEOUT_POLL 10
32#endif 40#endif
33 41
34#ifdef PROTOCOL_CHIBIOS
35# define SPLIT_USB_DETECT // Force this on for now
36#endif
37
38volatile bool isLeftHand = true; 42volatile bool isLeftHand = true;
39 43
40#if defined(SPLIT_USB_DETECT) 44#if defined(SPLIT_USB_DETECT)
41# if defined(PROTOCOL_LUFA) 45static bool usbIsActive(void) {
42static inline bool usbHasActiveConnection(void) { return USB_Device_IsAddressSet(); }
43static inline void usbDisable(void) {
44 USB_Disable();
45 USB_DeviceState = DEVICE_STATE_Unattached;
46}
47# elif defined(PROTOCOL_CHIBIOS)
48static inline bool usbHasActiveConnection(void) { return usbGetDriverStateI(&USBD1) == USB_ACTIVE; }
49static inline void usbDisable(void) { usbStop(&USBD1); }
50# elif defined(PROTOCOL_VUSB)
51static inline bool usbHasActiveConnection(void) {
52 usbPoll();
53 return usbConfiguration;
54}
55static inline void usbDisable(void) { usbDeviceDisconnect(); }
56# else
57static inline bool usbHasActiveConnection(void) { return true; }
58static inline void usbDisable(void) {}
59# endif
60
61bool usbIsActive(void) {
62 for (uint8_t i = 0; i < (SPLIT_USB_TIMEOUT / SPLIT_USB_TIMEOUT_POLL); i++) { 46 for (uint8_t i = 0; i < (SPLIT_USB_TIMEOUT / SPLIT_USB_TIMEOUT_POLL); i++) {
63 // This will return true if a USB connection has been established 47 // This will return true if a USB connection has been established
64 if (usbHasActiveConnection()) { 48 if (usb_connected_state()) {
65 return true; 49 return true;
66 } 50 }
67 wait_ms(SPLIT_USB_TIMEOUT_POLL); 51 wait_ms(SPLIT_USB_TIMEOUT_POLL);
68 } 52 }
69
70 // Avoid NO_USB_STARTUP_CHECK - Disable USB as the previous checks seem to enable it somehow
71 usbDisable();
72
73 return false; 53 return false;
74} 54}
75#elif defined(PROTOCOL_LUFA) && defined(OTGPADE)
76static inline bool usbIsActive(void) {
77 USB_OTGPAD_On(); // enables VBUS pad
78 wait_us(5);
79
80 return USB_VBUS_GetStatus(); // checks state of VBUS
81}
82#else 55#else
83static inline bool usbIsActive(void) { return true; } 56static inline bool usbIsActive(void) { return usb_vbus_state(); }
84#endif 57#endif
85 58
86#ifdef SPLIT_HAND_MATRIX_GRID 59#ifdef SPLIT_HAND_MATRIX_GRID
@@ -126,6 +99,11 @@ __attribute__((weak)) bool is_keyboard_master(void) {
126 // only check once, as this is called often 99 // only check once, as this is called often
127 if (usbstate == UNKNOWN) { 100 if (usbstate == UNKNOWN) {
128 usbstate = usbIsActive() ? MASTER : SLAVE; 101 usbstate = usbIsActive() ? MASTER : SLAVE;
102
103 // Avoid NO_USB_STARTUP_CHECK - Disable USB as the previous checks seem to enable it somehow
104 if (usbstate == SLAVE) {
105 usb_disable();
106 }
129 } 107 }
130 108
131 return (usbstate == MASTER); 109 return (usbstate == MASTER);
diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c
index 61b61ea08..27a1c0d3a 100644
--- a/quantum/split_common/transport.c
+++ b/quantum/split_common/transport.c
@@ -22,6 +22,10 @@ static pin_t encoders_pad[] = ENCODERS_PAD_A;
22# define NUMBER_OF_ENCODERS (sizeof(encoders_pad) / sizeof(pin_t)) 22# define NUMBER_OF_ENCODERS (sizeof(encoders_pad) / sizeof(pin_t))
23#endif 23#endif
24 24
25#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
26# include "rgb_matrix.h"
27#endif
28
25#if defined(USE_I2C) 29#if defined(USE_I2C)
26 30
27# include "i2c_master.h" 31# include "i2c_master.h"
@@ -54,6 +58,10 @@ typedef struct _I2C_slave_buffer_t {
54# ifdef WPM_ENABLE 58# ifdef WPM_ENABLE
55 uint8_t current_wpm; 59 uint8_t current_wpm;
56# endif 60# endif
61# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
62 rgb_config_t rgb_matrix;
63 bool rgb_suspend_state;
64# endif
57} I2C_slave_buffer_t; 65} I2C_slave_buffer_t;
58 66
59static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg; 67static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_reg;
@@ -68,6 +76,8 @@ static I2C_slave_buffer_t *const i2c_buffer = (I2C_slave_buffer_t *)i2c_slave_re
68# define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync) 76# define I2C_RGB_START offsetof(I2C_slave_buffer_t, rgblight_sync)
69# define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state) 77# define I2C_ENCODER_START offsetof(I2C_slave_buffer_t, encoder_state)
70# define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm) 78# define I2C_WPM_START offsetof(I2C_slave_buffer_t, current_wpm)
79# define I2C_RGB_MATRIX_START offsetof(I2C_slave_buffer_t, rgb_matrix)
80# define I2C_RGB_SUSPEND_START offsetof(I2C_slave_buffer_t, rgb_suspend_state)
71 81
72# define TIMEOUT 100 82# define TIMEOUT 100
73 83
@@ -141,6 +151,11 @@ bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
141# endif 151# endif
142# endif 152# endif
143 153
154# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
155 i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_MATRIX_START, (void *)rgb_matrix_config, sizeof(i2c_buffer->rgb_matrix), TIMEOUT);
156 i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_RGB_SUSPEND_START, (void *)g_suspend_state, sizeof(i2c_buffer->rgb_suspend_state), TIMEOUT);
157# endif
158
144# ifndef DISABLE_SYNC_TIMER 159# ifndef DISABLE_SYNC_TIMER
145 i2c_buffer->sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; 160 i2c_buffer->sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET;
146 i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_SYNC_TIME_START, (void *)&i2c_buffer->sync_timer, sizeof(i2c_buffer->sync_timer), TIMEOUT); 161 i2c_writeReg(SLAVE_I2C_ADDRESS, I2C_SYNC_TIME_START, (void *)&i2c_buffer->sync_timer, sizeof(i2c_buffer->sync_timer), TIMEOUT);
@@ -186,6 +201,11 @@ void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
186 set_oneshot_mods(i2c_buffer->oneshot_mods); 201 set_oneshot_mods(i2c_buffer->oneshot_mods);
187# endif 202# endif
188# endif 203# endif
204
205# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
206 memcpy((void *)i2c_buffer->rgb_matrix, (void *)rgb_matrix_config, sizeof(i2c_buffer->rgb_matrix));
207 memcpy((void *)i2c_buffer->rgb_suspend_state, (void *)g_suspend_state, sizeof(i2c_buffer->rgb_suspend_state));
208# endif
189} 209}
190 210
191void transport_master_init(void) { i2c_init(); } 211void transport_master_init(void) { i2c_init(); }
@@ -226,6 +246,10 @@ typedef struct _Serial_m2s_buffer_t {
226# ifdef WPM_ENABLE 246# ifdef WPM_ENABLE
227 uint8_t current_wpm; 247 uint8_t current_wpm;
228# endif 248# endif
249# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
250 rgb_config_t rgb_matrix;
251 bool rgb_suspend_state;
252# endif
229} Serial_m2s_buffer_t; 253} Serial_m2s_buffer_t;
230 254
231# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT) 255# if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_SPLIT)
@@ -333,18 +357,24 @@ bool transport_master(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
333 357
334# ifdef WPM_ENABLE 358# ifdef WPM_ENABLE
335 // Write wpm to slave 359 // Write wpm to slave
336 serial_m2s_buffer.current_wpm = get_current_wpm(); 360 serial_m2s_buffer.current_wpm = get_current_wpm();
337# endif 361# endif
338 362
339# ifdef SPLIT_MODS_ENABLE 363# ifdef SPLIT_MODS_ENABLE
340 serial_m2s_buffer.real_mods = get_mods(); 364 serial_m2s_buffer.real_mods = get_mods();
341 serial_m2s_buffer.weak_mods = get_weak_mods(); 365 serial_m2s_buffer.weak_mods = get_weak_mods();
342# ifndef NO_ACTION_ONESHOT 366# ifndef NO_ACTION_ONESHOT
343 serial_m2s_buffer.oneshot_mods = get_oneshot_mods(); 367 serial_m2s_buffer.oneshot_mods = get_oneshot_mods();
344# endif 368# endif
345# endif 369# endif
370
371# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
372 serial_m2s_buffer.rgb_matrix = rgb_matrix_config;
373 serial_m2s_buffer.rgb_suspend_state = g_suspend_state;
374# endif
375
346# ifndef DISABLE_SYNC_TIMER 376# ifndef DISABLE_SYNC_TIMER
347 serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET; 377 serial_m2s_buffer.sync_timer = sync_timer_read32() + SYNC_TIMER_OFFSET;
348# endif 378# endif
349 return true; 379 return true;
350} 380}
@@ -381,6 +411,11 @@ void transport_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[])
381 set_oneshot_mods(serial_m2s_buffer.oneshot_mods); 411 set_oneshot_mods(serial_m2s_buffer.oneshot_mods);
382# endif 412# endif
383# endif 413# endif
414
415# if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_SPLIT)
416 rgb_matrix_config = serial_m2s_buffer.rgb_matrix;
417 g_suspend_state = serial_m2s_buffer.rgb_suspend_state;
418# endif
384} 419}
385 420
386#endif 421#endif
diff --git a/readme.md b/readme.md
index 6092f209b..bb85115af 100644
--- a/readme.md
+++ b/readme.md
@@ -9,6 +9,12 @@
9 9
10This is a keyboard firmware based on the [tmk\_keyboard firmware](https://github.com/tmk/tmk_keyboard) with some useful features for Atmel AVR and ARM controllers, and more specifically, the [OLKB product line](https://olkb.com), the [ErgoDox EZ](https://ergodox-ez.com) keyboard, and the [Clueboard product line](https://clueboard.co). 10This is a keyboard firmware based on the [tmk\_keyboard firmware](https://github.com/tmk/tmk_keyboard) with some useful features for Atmel AVR and ARM controllers, and more specifically, the [OLKB product line](https://olkb.com), the [ErgoDox EZ](https://ergodox-ez.com) keyboard, and the [Clueboard product line](https://clueboard.co).
11 11
12# THIS IS THE DEVELOP BRANCH
13
14Warning- This is the `develop` branch of QMK Firmware. You may encounter broken code here. Please see [Breaking Changes](https://docs.qmk.fm/#/breaking_changes) for more information.
15
16# Original readme continues
17
12## Documentation 18## Documentation
13 19
14* [See the official documentation on docs.qmk.fm](https://docs.qmk.fm) 20* [See the official documentation on docs.qmk.fm](https://docs.qmk.fm)
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/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/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/chibios_config.h b/tmk_core/common/chibios/chibios_config.h
index b4d96465d..9a66ac317 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,5 @@
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
31#endif 34#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/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
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/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
20void 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
20void usb_disable(void);
21bool usb_connected_state(void);
22bool 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 @@
6extern "C" { 21extern "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
115void 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
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}