summaryrefslogtreecommitdiffstats
path: root/tmk_core
diff options
context:
space:
mode:
authorstein3 <stein3@gmail.com>2020-10-06 07:15:41 -0700
committerstein3 <stein3@gmail.com>2020-10-06 07:15:41 -0700
commit2e402741a89c5eec8cf30c966ce6f36d6ec9249b (patch)
tree3592e8c5e6bd19943ae55db7fc02a5f755afbb51 /tmk_core
parent3e5e4f74272c610bb9fa737f674f8e65ed6100ca (diff)
parent2013f6313430b977e557e482d30daa279a46e75d (diff)
Merge branch 'master' into meteor
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/avr.mk7
-rw-r--r--tmk_core/chibios.mk120
-rw-r--r--tmk_core/common.mk33
-rw-r--r--tmk_core/common/action.h2
-rw-r--r--tmk_core/common/action_layer.h13
-rw-r--r--tmk_core/common/bootmagic.c2
-rw-r--r--tmk_core/common/chibios/bootloader.c74
-rw-r--r--tmk_core/common/chibios/suspend.c16
-rw-r--r--tmk_core/common/command.c2
-rw-r--r--tmk_core/common/keyboard.c7
-rw-r--r--tmk_core/common/magic.c3
-rw-r--r--tmk_core/common/mousekey.c91
-rw-r--r--tmk_core/common/progmem.h1
-rw-r--r--tmk_core/common/report.h20
-rw-r--r--tmk_core/protocol/chibios/main.c1
-rw-r--r--tmk_core/protocol/chibios/usb_main.c85
-rw-r--r--tmk_core/protocol/iwrap.mk32
-rw-r--r--tmk_core/protocol/iwrap/iWRAP4.txt376
-rw-r--r--tmk_core/protocol/iwrap/iWRAP5.txt356
-rw-r--r--tmk_core/protocol/iwrap/iwrap.c420
-rw-r--r--tmk_core/protocol/iwrap/iwrap.h47
-rw-r--r--tmk_core/protocol/iwrap/main.c412
-rw-r--r--tmk_core/protocol/iwrap/mux_exit.rb7
-rw-r--r--tmk_core/protocol/iwrap/suart.S156
-rw-r--r--tmk_core/protocol/iwrap/suart.h8
-rw-r--r--tmk_core/protocol/iwrap/wd.h161
-rw-r--r--tmk_core/protocol/lufa.mk25
-rw-r--r--tmk_core/protocol/lufa/adafruit_ble.cpp4
-rw-r--r--tmk_core/protocol/lufa/adafruit_ble.h27
-rw-r--r--tmk_core/protocol/lufa/bluetooth.c38
-rw-r--r--tmk_core/protocol/lufa/bluetooth.h48
-rw-r--r--tmk_core/protocol/lufa/lufa.c314
-rw-r--r--tmk_core/protocol/lufa/lufa.h4
-rw-r--r--tmk_core/protocol/lufa/outputselect.c14
-rw-r--r--tmk_core/protocol/lufa/outputselect.h6
-rw-r--r--tmk_core/protocol/serial.h5
-rw-r--r--tmk_core/protocol/usb_descriptor.c121
-rw-r--r--tmk_core/protocol/usb_descriptor.h20
-rw-r--r--tmk_core/protocol/vusb.mk7
-rw-r--r--tmk_core/protocol/vusb/main.c37
-rw-r--r--tmk_core/protocol/vusb/sendchar_usart.c19
-rw-r--r--tmk_core/protocol/vusb/usbconfig.h20
-rw-r--r--tmk_core/protocol/vusb/vusb.c144
-rw-r--r--tmk_core/readme.md5
-rw-r--r--tmk_core/rules.mk8
45 files changed, 823 insertions, 2495 deletions
diff --git a/tmk_core/avr.mk b/tmk_core/avr.mk
index 04ae162246..336a83e9d3 100644
--- a/tmk_core/avr.mk
+++ b/tmk_core/avr.mk
@@ -120,15 +120,16 @@ define EXEC_DFU
if $(DFU_PROGRAMMER) --version 2>&1 | $(GREP) -q 0.7 ; then\
$(DFU_PROGRAMMER) $(MCU) erase --force; \
if [ "$(1)" ]; then \
- $(DFU_PROGRAMMER) $(MCU) flash --eeprom $(QUANTUM_PATH)/split_common/$(1);\
+ $(DFU_PROGRAMMER) $(MCU) flash --force --eeprom $(QUANTUM_PATH)/split_common/$(1);\
fi; \
+ $(DFU_PROGRAMMER) $(MCU) flash --force $(BUILD_DIR)/$(TARGET).hex;\
else \
$(DFU_PROGRAMMER) $(MCU) erase; \
if [ "$(1)" ]; then \
$(DFU_PROGRAMMER) $(MCU) flash-eeprom $(QUANTUM_PATH)/split_common/$(1);\
fi; \
+ $(DFU_PROGRAMMER) $(MCU) flash $(BUILD_DIR)/$(TARGET).hex;\
fi; \
- $(DFU_PROGRAMMER) $(MCU) flash $(BUILD_DIR)/$(TARGET).hex;\
$(DFU_PROGRAMMER) $(MCU) reset
endef
@@ -141,7 +142,7 @@ dfu-start:
dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
if $(DFU_PROGRAMMER) --version 2>&1 | $(GREP) -q 0.7 ; then\
- $(DFU_PROGRAMMER) $(MCU) flash --eeprom $(BUILD_DIR)/$(TARGET).eep;\
+ $(DFU_PROGRAMMER) $(MCU) flash --force --eeprom $(BUILD_DIR)/$(TARGET).eep;\
else\
$(DFU_PROGRAMMER) $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep;\
fi
diff --git a/tmk_core/chibios.mk b/tmk_core/chibios.mk
index 09aaddeef0..2bd53f0dc8 100644
--- a/tmk_core/chibios.mk
+++ b/tmk_core/chibios.mk
@@ -50,11 +50,42 @@ PLATFORM_MK = $(CHIBIOS_CONTRIB)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/$(PLAT
endif
include $(PLATFORM_MK)
+BOARD_MK :=
+
+ifneq ("$(wildcard $(KEYBOARD_PATH_5)/boards/$(BOARD)/board.mk)","")
+ BOARD_PATH = $(KEYBOARD_PATH_5)
+ BOARD_MK += $(KEYBOARD_PATH_5)/boards/$(BOARD)/board.mk
+else ifneq ("$(wildcard $(KEYBOARD_PATH_4)/boards/$(BOARD)/board.mk)","")
+ BOARD_PATH = $(KEYBOARD_PATH_4)
+ BOARD_MK += $(KEYBOARD_PATH_4)/boards/$(BOARD)/board.mk
+else ifneq ("$(wildcard $(KEYBOARD_PATH_3)/boards/$(BOARD)/board.mk)","")
+ BOARD_PATH = $(KEYBOARD_PATH_3)
+ BOARD_MK += $(KEYBOARD_PATH_3)/boards/$(BOARD)/board.mk
+else ifneq ("$(wildcard $(KEYBOARD_PATH_2)/boards/$(BOARD)/board.mk)","")
+ BOARD_PATH = $(KEYBOARD_PATH_2)
+ BOARD_MK += $(KEYBOARD_PATH_2)/boards/$(BOARD)/board.mk
+else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/boards/$(BOARD)/board.mk)","")
+ BOARD_PATH = $(KEYBOARD_PATH_1)
+ BOARD_MK += $(KEYBOARD_PATH_1)/boards/$(BOARD)/board.mk
+else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/$(BOARD)/board/board.mk)","")
+ BOARD_PATH = $(TOP_DIR)/platforms/chibios/$(BOARD)
+ BOARD_MK += $(TOP_DIR)/platforms/chibios/$(BOARD)/board/board.mk
+ KEYBOARD_PATHS += $(BOARD_PATH)/configs
+endif
+
+ifeq ("$(wildcard $(BOARD_MK))","")
+ BOARD_MK = $(CHIBIOS)/os/hal/boards/$(BOARD)/board.mk
+ ifeq ("$(wildcard $(BOARD_MK))","")
+ BOARD_MK = $(CHIBIOS_CONTRIB)/os/hal/boards/$(BOARD)/board.mk
+ endif
+endif
+
# Bootloader address
ifdef STM32_BOOTLOADER_ADDRESS
OPT_DEFS += -DSTM32_BOOTLOADER_ADDRESS=$(STM32_BOOTLOADER_ADDRESS)
endif
+# Work out if we need to set up the include for the bootloader definitions
ifneq ("$(wildcard $(KEYBOARD_PATH_5)/bootloader_defs.h)","")
OPT_DEFS += -include $(KEYBOARD_PATH_5)/bootloader_defs.h
else ifneq ("$(wildcard $(KEYBOARD_PATH_5)/boards/$(BOARD)/bootloader_defs.h)","")
@@ -75,38 +106,52 @@ else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/bootloader_defs.h)","")
OPT_DEFS += -include $(KEYBOARD_PATH_1)/bootloader_defs.h
else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/boards/$(BOARD)/bootloader_defs.h)","")
OPT_DEFS += -include $(KEYBOARD_PATH_1)/boards/$(BOARD)/bootloader_defs.h
-else ifneq ("$(wildcard $(TOP_DIR)/drivers/boards/$(BOARD)/bootloader_defs.h)","")
- OPT_DEFS += -include $(TOP_DIR)/drivers/boards/$(BOARD)/bootloader_defs.h
+else ifneq ("$(wildcard $(BOARD_PATH)/configs/bootloader_defs.h)","")
+ OPT_DEFS += -include $(BOARD_PATH)/configs/bootloader_defs.h
endif
-BOARD_MK :=
+# Work out the config file directories
+ifneq ("$(wildcard $(KEYBOARD_PATH_5)/chconf.h)","")
+ CHCONFDIR = $(KEYBOARD_PATH_5)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_4)/chconf.h)","")
+ CHCONFDIR = $(KEYBOARD_PATH_4)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_3)/chconf.h)","")
+ CHCONFDIR = $(KEYBOARD_PATH_3)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_2)/chconf.h)","")
+ CHCONFDIR = $(KEYBOARD_PATH_2)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/chconf.h)","")
+ CHCONFDIR = $(KEYBOARD_PATH_1)
+else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/$(BOARD)/configs/chconf.h)","")
+ CHCONFDIR = $(TOP_DIR)/platforms/chibios/$(BOARD)/configs
+endif
-ifneq ("$(wildcard $(KEYBOARD_PATH_5)/boards/$(BOARD)/board.mk)","")
- BOARD_PATH = $(KEYBOARD_PATH_5)
- BOARD_MK += $(KEYBOARD_PATH_5)/boards/$(BOARD)/board.mk
-else ifneq ("$(wildcard $(KEYBOARD_PATH_4)/boards/$(BOARD)/board.mk)","")
- BOARD_PATH = $(KEYBOARD_PATH_4)
- BOARD_MK += $(KEYBOARD_PATH_4)/boards/$(BOARD)/board.mk
-else ifneq ("$(wildcard $(KEYBOARD_PATH_3)/boards/$(BOARD)/board.mk)","")
- BOARD_PATH = $(KEYBOARD_PATH_3)
- BOARD_MK += $(KEYBOARD_PATH_3)/boards/$(BOARD)/board.mk
-else ifneq ("$(wildcard $(KEYBOARD_PATH_2)/boards/$(BOARD)/board.mk)","")
- BOARD_PATH = $(KEYBOARD_PATH_2)
- BOARD_MK += $(KEYBOARD_PATH_2)/boards/$(BOARD)/board.mk
-else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/boards/$(BOARD)/board.mk)","")
- BOARD_PATH = $(KEYBOARD_PATH_1)
- BOARD_MK += $(KEYBOARD_PATH_1)/boards/$(BOARD)/board.mk
-else ifneq ("$(wildcard $(TOP_DIR)/drivers/boards/$(BOARD)/board.mk)","")
- BOARD_PATH = $(TOP_DIR)/drivers
- BOARD_MK += $(TOP_DIR)/drivers/boards/$(BOARD)/board.mk
+ifneq ("$(wildcard $(KEYBOARD_PATH_5)/halconf.h)","")
+ HALCONFDIR = $(KEYBOARD_PATH_5)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_4)/halconf.h)","")
+ HALCONFDIR = $(KEYBOARD_PATH_4)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_3)/halconf.h)","")
+ HALCONFDIR = $(KEYBOARD_PATH_3)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_2)/halconf.h)","")
+ HALCONFDIR = $(KEYBOARD_PATH_2)
+else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/halconf.h)","")
+ HALCONFDIR = $(KEYBOARD_PATH_1)
+else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/$(BOARD)/configs/halconf.h)","")
+ HALCONFDIR = $(TOP_DIR)/platforms/chibios/$(BOARD)/configs
endif
-ifeq ("$(wildcard $(BOARD_MK))","")
- BOARD_MK = $(CHIBIOS)/os/hal/boards/$(BOARD)/board.mk
- ifeq ("$(wildcard $(BOARD_MK))","")
- BOARD_MK = $(CHIBIOS_CONTRIB)/os/hal/boards/$(BOARD)/board.mk
- endif
+# HAL-OSAL files (optional).
+include $(CHIBIOS)/os/hal/hal.mk
+
+ifeq ("$(PLATFORM_NAME)","")
+ PLATFORM_NAME = platform
+endif
+
+PLATFORM_MK = $(CHIBIOS)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/$(PLATFORM_NAME).mk
+ifeq ("$(wildcard $(PLATFORM_MK))","")
+PLATFORM_MK = $(CHIBIOS_CONTRIB)/os/hal/ports/$(MCU_FAMILY)/$(MCU_SERIES)/$(PLATFORM_NAME).mk
endif
+include $(PLATFORM_MK)
+
include $(BOARD_MK)
-include $(CHIBIOS)/os/hal/osal/rt/osal.mk # ChibiOS <= 19.x
@@ -138,8 +183,8 @@ else ifneq ("$(wildcard $(KEYBOARD_PATH_2)/ld/$(MCU_LDSCRIPT).ld)","")
LDSCRIPT = $(KEYBOARD_PATH_2)/ld/$(MCU_LDSCRIPT).ld
else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/ld/$(MCU_LDSCRIPT).ld)","")
LDSCRIPT = $(KEYBOARD_PATH_1)/ld/$(MCU_LDSCRIPT).ld
-else ifneq ("$(wildcard $(TOP_DIR)/drivers/boards/ld/$(MCU_LDSCRIPT).ld)","")
- LDSCRIPT = $(TOP_DIR)/drivers/boards/ld/$(MCU_LDSCRIPT).ld
+else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/ld/$(MCU_LDSCRIPT).ld)","")
+ LDSCRIPT = $(TOP_DIR)/platforms/chibios/ld/$(MCU_LDSCRIPT).ld
else ifneq ("$(wildcard $(STARTUPLD_CONTRIB)/$(MCU_LDSCRIPT).ld)","")
LDSCRIPT = $(STARTUPLD_CONTRIB)/$(MCU_LDSCRIPT).ld
USE_CHIBIOS_CONTRIB = yes
@@ -163,6 +208,7 @@ QUANTUM_LIB_SRC += $(STARTUPASM) $(PORTASM) $(OSALASM)
CHIBISRC := $(patsubst $(TOP_DIR)/%,%,$(CHIBISRC))
EXTRAINCDIRS += $(CHIBIOS)/os/license $(CHIBIOS)/os/oslib/include \
+ $(TOP_DIR)/platforms/chibios/$(BOARD)/configs \
$(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
$(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
$(STREAMSINC) $(CHIBIOS)/os/various $(COMMON_VPATH)
@@ -182,6 +228,8 @@ else ifneq ("$(wildcard $(KEYBOARD_PATH_2)/halconf_community.h)","")
USE_CHIBIOS_CONTRIB = yes
else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/halconf_community.h)","")
USE_CHIBIOS_CONTRIB = yes
+else ifneq ("$(wildcard $(TOP_DIR)/platforms/chibios/$(BOARD)/configs/halconf_community.h)","")
+ USE_CHIBIOS_CONTRIB = yes
endif
ifeq ($(strip $(USE_CHIBIOS_CONTRIB)),yes)
@@ -194,6 +242,15 @@ endif
# Project, sources and paths
##############################################################################
+##############################################################################
+# Injected configs
+#
+ifneq ("$(wildcard $(BOARD_PATH)/configs/config.h)","")
+ CONFIG_H += $(BOARD_PATH)/configs/config.h
+endif
+ifneq ("$(wildcard $(BOARD_PATH)/configs/post_config.h)","")
+ POST_CONFIG_H += $(BOARD_PATH)/configs/post_config.h
+endif
##############################################################################
# Compiler settings
@@ -261,12 +318,14 @@ ifneq ("$(SERIAL)","")
endif
ST_LINK_ARGS ?=
+ST_FLASH_ARGS ?=
# List any extra directories to look for libraries here.
EXTRALIBDIRS = $(RULESPATH)/ld
DFU_UTIL ?= dfu-util
ST_LINK_CLI ?= st-link_cli
+ST_FLASH ?= st-flash
define EXEC_DFU_UTIL
until $(DFU_UTIL) -l | grep -q "Found DFU"; do\
@@ -300,6 +359,9 @@ dfu-util-split-right: dfu-util
st-link-cli: $(BUILD_DIR)/$(TARGET).hex sizeafter
$(ST_LINK_CLI) $(ST_LINK_ARGS) -q -c SWD -p $(BUILD_DIR)/$(TARGET).hex -Rst
+st-flash: $(BUILD_DIR)/$(TARGET).hex sizeafter
+ $(ST_FLASH) $(ST_FLASH_ARGS) --reset --format ihex write $(BUILD_DIR)/$(TARGET).hex
+
# Autodetect teensy loader
ifndef TEENSY_LOADER_CLI
@@ -324,7 +386,7 @@ bin: $(BUILD_DIR)/$(TARGET).bin sizeafter
flash: $(BUILD_DIR)/$(TARGET).bin cpfirmware sizeafter
ifneq ($(strip $(PROGRAM_CMD)),)
$(PROGRAM_CMD)
-else ifeq ($(strip $(BOOTLOADER)),dfu)
+else ifeq ($(strip $(BOOTLOADER)),kiibohd)
$(call EXEC_DFU_UTIL)
else ifeq ($(strip $(MCU_FAMILY)),KINETIS)
$(call EXEC_TEENSY)
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index 63de7c7ede..fdf2aa0972 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -99,8 +99,16 @@ ifeq ($(strip $(COMMAND_ENABLE)), yes)
endif
ifeq ($(strip $(NKRO_ENABLE)), yes)
- TMK_COMMON_DEFS += -DNKRO_ENABLE
- SHARED_EP_ENABLE = yes
+ ifeq ($(PROTOCOL), VUSB)
+ $(info NKRO is not currently supported on V-USB, and has been disabled.)
+ else ifeq ($(strip $(BLUETOOTH_ENABLE)), yes)
+ $(info NKRO is not currently supported with Bluetooth, and has been disabled.)
+ else ifneq ($(BLUETOOTH),)
+ $(info NKRO is not currently supported with Bluetooth, and has been disabled.)
+ else
+ TMK_COMMON_DEFS += -DNKRO_ENABLE
+ SHARED_EP_ENABLE = yes
+ endif
endif
ifeq ($(strip $(USB_6KRO_ENABLE)), yes)
@@ -113,10 +121,6 @@ ifeq ($(strip $(SLEEP_LED_ENABLE)), yes)
TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN
endif
-ifeq ($(strip $(NO_UART)), yes)
- TMK_COMMON_DEFS += -DNO_UART
-endif
-
ifeq ($(strip $(NO_SUSPEND_POWER_DOWN)), yes)
TMK_COMMON_DEFS += -DNO_SUSPEND_POWER_DOWN
endif
@@ -132,12 +136,6 @@ ifeq ($(strip $(BLUETOOTH)), AdafruitBLE)
TMK_COMMON_DEFS += -DNO_USB_STARTUP_CHECK
endif
-ifeq ($(strip $(BLUETOOTH)), AdafruitEZKey)
- TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE
- TMK_COMMON_DEFS += -DMODULE_ADAFRUIT_EZKEY
- TMK_COMMON_DEFS += -DNO_USB_STARTUP_CHECK
-endif
-
ifeq ($(strip $(BLUETOOTH)), RN42)
TMK_COMMON_DEFS += -DBLUETOOTH_ENABLE
TMK_COMMON_DEFS += -DMODULE_RN42
@@ -160,16 +158,15 @@ ifeq ($(strip $(SHARED_EP_ENABLE)), yes)
endif
ifeq ($(strip $(LTO_ENABLE)), yes)
- LINK_TIME_OPTIMIZATION_ENABLE = yes
-endif
-
-ifeq ($(strip $(LINK_TIME_OPTIMIZATION_ENABLE)), yes)
ifeq ($(PLATFORM),CHIBIOS)
$(info Enabling LTO on ChibiOS-targeting boards is known to have a high likelihood of failure.)
- $(info If unsure, set LINK_TIME_OPTIMIZATION_ENABLE = no.)
+ $(info If unsure, set LTO_ENABLE = no.)
endif
EXTRAFLAGS += -flto
- TMK_COMMON_DEFS += -DLINK_TIME_OPTIMIZATION_ENABLE
+ TMK_COMMON_DEFS += -DLTO_ENABLE
+ TMK_COMMON_DEFS += -DLINK_TIME_OPTIMIZATON_ENABLE
+else ifdef LINK_TIME_OPTIMIZATION_ENABLE
+ $(error The LINK_TIME_OPTIMIZATION_ENABLE flag has been renamed to LTO_ENABLE.)
endif
# Search Path
diff --git a/tmk_core/common/action.h b/tmk_core/common/action.h
index c82c9c81be..345c030c94 100644
--- a/tmk_core/common/action.h
+++ b/tmk_core/common/action.h
@@ -29,7 +29,7 @@ extern "C" {
#endif
/* Disable macro and function features when LTO is enabled, since they break */
-#ifdef LINK_TIME_OPTIMIZATION_ENABLE
+#ifdef LTO_ENABLE
# ifndef NO_ACTION_MACRO
# define NO_ACTION_MACRO
# endif
diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h
index 16922c1ff9..f9f6861120 100644
--- a/tmk_core/common/action_layer.h
+++ b/tmk_core/common/action_layer.h
@@ -82,9 +82,11 @@ void layer_on(uint8_t layer);
void layer_off(uint8_t layer);
void layer_invert(uint8_t layer);
/* bitwise operation */
-void layer_or(layer_state_t state);
-void layer_and(layer_state_t state);
-void layer_xor(layer_state_t state);
+void layer_or(layer_state_t state);
+void layer_and(layer_state_t state);
+void layer_xor(layer_state_t state);
+layer_state_t layer_state_set_user(layer_state_t state);
+layer_state_t layer_state_set_kb(layer_state_t state);
#else
# define layer_state 0
@@ -101,11 +103,10 @@ void layer_xor(layer_state_t state);
# define layer_or(state) (void)state
# define layer_and(state) (void)state
# define layer_xor(state) (void)state
+# define layer_state_set_kb(state) (void)state
+# define layer_state_set_user(state) (void)state
#endif
-layer_state_t layer_state_set_user(layer_state_t state);
-layer_state_t layer_state_set_kb(layer_state_t state);
-
/* pressed actions cache */
#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
diff --git a/tmk_core/common/bootmagic.c b/tmk_core/common/bootmagic.c
index bb2aa0db8c..c1b3adf94d 100644
--- a/tmk_core/common/bootmagic.c
+++ b/tmk_core/common/bootmagic.c
@@ -122,6 +122,8 @@ void bootmagic(void) {
default_layer = eeconfig_read_default_layer();
default_layer_set((layer_state_t)default_layer);
}
+ /* Also initialize layer state to trigger callback functions for layer_state */
+ layer_state_set_kb((layer_state_t)layer_state);
/* EE_HANDS handedness */
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_LEFT)) {
diff --git a/tmk_core/common/chibios/bootloader.c b/tmk_core/common/chibios/bootloader.c
index 4cf5dae7e6..7b2cf5c435 100644
--- a/tmk_core/common/chibios/bootloader.c
+++ b/tmk_core/common/chibios/bootloader.c
@@ -2,29 +2,67 @@
#include "ch.h"
#include "hal.h"
-
-#ifdef STM32_BOOTLOADER_ADDRESS
-/* STM32 */
+#include "wait.h"
/* This code should be checked whether it runs correctly on platforms */
-# define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
+#define SYMVAL(sym) (uint32_t)(((uint8_t *)&(sym)) - ((uint8_t *)0))
+#define BOOTLOADER_MAGIC 0xDEADBEEF
+#define MAGIC_ADDR (unsigned long *)(SYMVAL(__ram0_end__) - 4)
+
+#ifndef STM32_BOOTLOADER_DUAL_BANK
+# define STM32_BOOTLOADER_DUAL_BANK FALSE
+#endif
+
+#if STM32_BOOTLOADER_DUAL_BANK
+
+// Need pin definitions
+# include "config_common.h"
+
+# ifndef STM32_BOOTLOADER_DUAL_BANK_GPIO
+# error "No STM32_BOOTLOADER_DUAL_BANK_GPIO defined, don't know which pin to toggle"
+# endif
+
+# ifndef STM32_BOOTLOADER_DUAL_BANK_POLARITY
+# define STM32_BOOTLOADER_DUAL_BANK_POLARITY 0
+# endif
+
+# ifndef STM32_BOOTLOADER_DUAL_BANK_DELAY
+# define STM32_BOOTLOADER_DUAL_BANK_DELAY 100000
+# endif
+
+extern uint32_t __ram0_end__;
+
+void bootloader_jump(void) {
+ // For STM32 MCUs with dual-bank flash, and we're incapable of jumping to the bootloader. The first valid flash
+ // bank is executed unconditionally after a reset, so it doesn't enter DFU unless BOOT0 is high. Instead, we do
+ // it with hardware...in this case, we pull a GPIO high/low depending on the configuration, connects 3.3V to
+ // BOOT0's RC charging circuit, lets it charge the capacitor, and issue a system reset. See the QMK discord
+ // #hardware channel pins for an example circuit.
+ palSetPadMode(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_MODE_OUTPUT_PUSHPULL);
+# if STM32_BOOTLOADER_DUAL_BANK_POLARITY
+ palSetPad(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO));
+# else
+ palClearPad(PAL_PORT(STM32_BOOTLOADER_DUAL_BANK_GPIO), PAL_PAD(STM32_BOOTLOADER_DUAL_BANK_GPIO));
+# endif
+
+ // Wait for a while for the capacitor to charge
+ wait_ms(100);
+
+ // Issue a system reset to get the ROM bootloader to execute, with BOOT0 high
+ NVIC_SystemReset();
+}
+
+void enter_bootloader_mode_if_requested(void) {} // not needed at all, but if anybody attempts to invoke it....
+
+#elif defined(STM32_BOOTLOADER_ADDRESS) // STM32_BOOTLOADER_DUAL_BANK
+
extern uint32_t __ram0_end__;
-# define BOOTLOADER_MAGIC 0xDEADBEEF
-# define MAGIC_ADDR (unsigned long *)(SYMVAL(__ram0_end__) - 4)
-/** \brief Jump to the bootloader
- *
- * FIXME: needs doc
- */
void bootloader_jump(void) {
*MAGIC_ADDR = BOOTLOADER_MAGIC; // set magic flag => reset handler will jump into boot loader
NVIC_SystemReset();
}
-/** \brief Enter bootloader mode if requested
- *
- * FIXME: needs doc
- */
void enter_bootloader_mode_if_requested(void) {
unsigned long *check = MAGIC_ADDR;
if (*check == BOOTLOADER_MAGIC) {
@@ -41,10 +79,10 @@ void enter_bootloader_mode_if_requested(void) {
}
}
-#elif defined(KL2x) || defined(K20x) /* STM32_BOOTLOADER_ADDRESS */
+#elif defined(KL2x) || defined(K20x) // STM32_BOOTLOADER_DUAL_BANK // STM32_BOOTLOADER_ADDRESS
/* Kinetis */
-# if defined(KIIBOHD_BOOTLOADER)
+# if defined(BOOTLOADER_KIIBOHD)
/* Kiibohd Bootloader (MCHCK and Infinity KB) */
# define SCB_AIRCR_VECTKEY_WRITEMAGIC 0x05FA0000
const uint8_t sys_reset_to_loader_magic[] = "\xff\x00\x7fRESET TO LOADER\x7f\x00\xff";
@@ -54,14 +92,14 @@ void bootloader_jump(void) {
SCB->AIRCR = SCB_AIRCR_VECTKEY_WRITEMAGIC | SCB_AIRCR_SYSRESETREQ_Msk;
}
-# else /* defined(KIIBOHD_BOOTLOADER) */
+# else /* defined(BOOTLOADER_KIIBOHD) */
/* Default for Kinetis - expecting an ARM Teensy */
# include "wait.h"
void bootloader_jump(void) {
wait_ms(100);
__BKPT(0);
}
-# endif /* defined(KIIBOHD_BOOTLOADER) */
+# endif /* defined(BOOTLOADER_KIIBOHD) */
#else /* neither STM32 nor KINETIS */
__attribute__((weak)) void bootloader_jump(void) {}
diff --git a/tmk_core/common/chibios/suspend.c b/tmk_core/common/chibios/suspend.c
index 8c071e7a08..64dfc05abc 100644
--- a/tmk_core/common/chibios/suspend.c
+++ b/tmk_core/common/chibios/suspend.c
@@ -9,6 +9,7 @@
#include "mousekey.h"
#include "host.h"
#include "suspend.h"
+#include "led.h"
#include "wait.h"
#ifdef BACKLIGHT_ENABLE
@@ -47,6 +48,20 @@ __attribute__((weak)) void suspend_power_down_kb(void) { suspend_power_down_user
* FIXME: needs doc
*/
void suspend_power_down(void) {
+#ifdef BACKLIGHT_ENABLE
+ backlight_set(0);
+#endif
+
+ // Turn off LED indicators
+ uint8_t leds_off = 0;
+#if defined(BACKLIGHT_CAPS_LOCK) && defined(BACKLIGHT_ENABLE)
+ if (is_backlight_enabled()) {
+ // Don't try to turn off Caps Lock indicator as it is backlight and backlight is already off
+ leds_off |= (1 << USB_LED_CAPS_LOCK);
+ }
+#endif
+ led_set(leds_off);
+
// TODO: figure out what to power down and how
// shouldn't power down TPM/FTM if we want a breathing LED
// also shouldn't power down USB
@@ -119,6 +134,7 @@ void suspend_wakeup_init(void) {
#ifdef BACKLIGHT_ENABLE
backlight_init();
#endif /* BACKLIGHT_ENABLE */
+ led_set(host_keyboard_leds());
#if defined(RGBLIGHT_SLEEP) && defined(RGBLIGHT_ENABLE)
is_suspended = false;
if (rgblight_enabled) {
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c
index ef6a39c0fe..feeb2202e2 100644
--- a/tmk_core/common/command.c
+++ b/tmk_core/common/command.c
@@ -180,7 +180,7 @@ static void print_version(void) {
#ifdef NKRO_ENABLE
" NKRO"
#endif
-#ifdef LINK_TIME_OPTIMIZATION_ENABLE
+#ifdef LTO_ENABLE
" LTO"
#endif
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 714c3d048f..a45af56dfd 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -74,6 +74,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef MIDI_ENABLE
# include "process_midi.h"
#endif
+#ifdef JOYSTICK_ENABLE
+# include "process_joystick.h"
+#endif
#ifdef HD44780_ENABLE
# include "hd44780.h"
#endif
@@ -420,6 +423,10 @@ MATRIX_LOOP_END:
}
#endif
+#ifdef JOYSTICK_ENABLE
+ joystick_task();
+#endif
+
// update LED
if (led_status != host_keyboard_leds()) {
led_status = host_keyboard_leds();
diff --git a/tmk_core/common/magic.c b/tmk_core/common/magic.c
index d8ab525735..e14994164e 100644
--- a/tmk_core/common/magic.c
+++ b/tmk_core/common/magic.c
@@ -33,4 +33,7 @@ void magic(void) {
uint8_t default_layer = 0;
default_layer = eeconfig_read_default_layer();
default_layer_set((layer_state_t)default_layer);
+
+ /* Also initialize layer state to trigger callback functions for layer_state */
+ layer_state_set_kb((layer_state_t)layer_state);
}
diff --git a/tmk_core/common/mousekey.c b/tmk_core/common/mousekey.c
index 42bf231f4c..ef18bcf1a8 100644
--- a/tmk_core/common/mousekey.c
+++ b/tmk_core/common/mousekey.c
@@ -33,9 +33,9 @@ inline int8_t times_inv_sqrt2(int8_t x) {
static report_mouse_t mouse_report = {0};
static void mousekey_debug(void);
-static uint8_t mousekey_accel = 0;
-static uint8_t mousekey_repeat = 0;
-static uint16_t last_timer = 0;
+static uint8_t mousekey_accel = 0;
+static uint8_t mousekey_repeat = 0;
+static uint8_t mousekey_wheel_repeat = 0;
#ifndef MK_3_SPEED
@@ -94,12 +94,12 @@ static uint8_t wheel_unit(void) {
unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed) / 2;
} else if (mousekey_accel & (1 << 2)) {
unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed);
- } else if (mousekey_repeat == 0) {
+ } else if (mousekey_wheel_repeat == 0) {
unit = MOUSEKEY_WHEEL_DELTA;
- } else if (mousekey_repeat >= mk_wheel_time_to_max) {
+ } else if (mousekey_wheel_repeat >= mk_wheel_time_to_max) {
unit = MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed;
} else {
- unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_repeat) / mk_wheel_time_to_max;
+ unit = (MOUSEKEY_WHEEL_DELTA * mk_wheel_max_speed * mousekey_wheel_repeat) / mk_wheel_time_to_max;
}
return (unit > MOUSEKEY_WHEEL_MAX ? MOUSEKEY_WHEEL_MAX : (unit == 0 ? 1 : unit));
}
@@ -147,14 +147,17 @@ static uint8_t wheel_unit(void) {
void mousekey_task(void) {
// report cursor and scroll movement independently
report_mouse_t const tmpmr = mouse_report;
- if ((mouse_report.x || mouse_report.y) && timer_elapsed(last_timer_c) > (mousekey_repeat ? mk_interval : mk_delay * 10)) {
+
+ mouse_report.x = 0;
+ mouse_report.y = 0;
+ mouse_report.v = 0;
+ mouse_report.h = 0;
+
+ if ((tmpmr.x || tmpmr.y) && timer_elapsed(last_timer_c) > (mousekey_repeat ? mk_interval : mk_delay * 10)) {
if (mousekey_repeat != UINT8_MAX) mousekey_repeat++;
- mouse_report.v = 0;
- mouse_report.h = 0;
- if (mouse_report.x > 0) mouse_report.x = move_unit();
- if (mouse_report.x < 0) mouse_report.x = move_unit() * -1;
- if (mouse_report.y > 0) mouse_report.y = move_unit();
- if (mouse_report.y < 0) mouse_report.y = move_unit() * -1;
+ if (tmpmr.x != 0) mouse_report.x = move_unit() * ((tmpmr.x > 0) ? 1 : -1);
+ if (tmpmr.y != 0) mouse_report.y = move_unit() * ((tmpmr.y > 0) ? 1 : -1);
+
/* diagonal move [1/sqrt(2)] */
if (mouse_report.x && mouse_report.y) {
mouse_report.x = times_inv_sqrt2(mouse_report.x);
@@ -166,18 +169,12 @@ void mousekey_task(void) {
mouse_report.y = 1;
}
}