summaryrefslogtreecommitdiff
path: root/tmk_core
diff options
context:
space:
mode:
authorJames Young <xxiinophobia@yahoo.com>2020-02-29 12:00:00 -0800
committerFlorian Didron <fdidron@users.noreply.github.com>2020-06-12 17:00:27 +0900
commitf01c45ef54039366b666c28747fd57136d81c472 (patch)
treea09c6a4e1f7f1b447fc508f4ca542d2640443e71 /tmk_core
parentae8641748e4b2adb5b4f091027975e3884e325c9 (diff)
2020 February 29 Breaking Changes Update (#8064)
Diffstat (limited to 'tmk_core')
-rw-r--r--tmk_core/chibios.mk10
-rw-r--r--tmk_core/common.mk5
-rw-r--r--tmk_core/common/action.c28
-rw-r--r--tmk_core/common/action_code.h33
-rw-r--r--tmk_core/common/chibios/timer.c44
-rw-r--r--tmk_core/common/command.c6
-rw-r--r--tmk_core/common/timer.h5
-rw-r--r--tmk_core/protocol/chibios.mk1
-rw-r--r--tmk_core/protocol/chibios/usb_driver.c10
-rw-r--r--tmk_core/protocol/chibios/usb_main.c8
10 files changed, 64 insertions, 86 deletions
diff --git a/tmk_core/chibios.mk b/tmk_core/chibios.mk
index fcc5de183d..d447bc13ee 100644
--- a/tmk_core/chibios.mk
+++ b/tmk_core/chibios.mk
@@ -110,6 +110,8 @@ 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 $(STARTUPLD_CONTRIB)/$(MCU_LDSCRIPT).ld)","")
+ LDSCRIPT = $(STARTUPLD_CONTRIB)/$(MCU_LDSCRIPT).ld
else
LDSCRIPT = $(STARTUPLD)/$(MCU_LDSCRIPT).ld
endif
@@ -120,6 +122,7 @@ CHIBISRC = $(STARTUPSRC) \
$(OSALSRC) \
$(HALSRC) \
$(PLATFORMSRC) \
+ $(PLATFORMSRC_CONTRIB) \
$(BOARDSRC) \
$(STREAMSSRC) \
$(CHIBIOS)/os/various/syscalls.c
@@ -129,9 +132,9 @@ QUANTUM_LIB_SRC += $(STARTUPASM) $(PORTASM) $(OSALASM)
CHIBISRC := $(patsubst $(TOP_DIR)/%,%,$(CHIBISRC))
-EXTRAINCDIRS += $(CHIBIOS)/os/license \
+EXTRAINCDIRS += $(CHIBIOS)/os/license $(CHIBIOS)/os/oslib/include \
$(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
- $(HALINC) $(PLATFORMINC) $(BOARDINC) $(TESTINC) \
+ $(HALINC) $(PLATFORMINC) $(PLATFORMINC_CONTRIB) $(BOARDINC) $(TESTINC) \
$(STREAMSINC) $(CHIBIOS)/os/various $(COMMON_VPATH)
#
@@ -180,6 +183,9 @@ LDFLAGS += -Wl,--script=$(LDSCRIPT)$(LDSYMBOLS)
OPT_DEFS += -DPROTOCOL_CHIBIOS
+# Workaround to stop ChibiOS from complaining about new GCC -- it's been fixed for 7/8/9 already
+OPT_DEFS += -DPORT_IGNORE_GCC_VERSION_CHECK=1
+
MCUFLAGS = -mcpu=$(MCU)
# FPU options default (Cortex-M4 and Cortex-M7 single precision).
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index 278a6b6a14..bcd38240e6 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -167,11 +167,16 @@ ifeq ($(strip $(LTO_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.)
+ endif
EXTRAFLAGS += -flto
TMK_COMMON_DEFS += -DLINK_TIME_OPTIMIZATION_ENABLE
TMK_COMMON_DEFS += -DNO_ACTION_MACRO
TMK_COMMON_DEFS += -DNO_ACTION_FUNCTION
endif
+
# Bootloader address
ifdef STM32_BOOTLOADER_ADDRESS
TMK_COMMON_DEFS += -DSTM32_BOOTLOADER_ADDRESS=$(STM32_BOOTLOADER_ADDRESS)
diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c
index 001f0de13a..ab68681ded 100644
--- a/tmk_core/common/action.c
+++ b/tmk_core/common/action.c
@@ -562,34 +562,6 @@ void process_action(keyrecord_t *record, action_t action) {
action_macro_play(action_get_macro(record, action.func.id, action.func.opt));
break;
#endif
-#if defined(BACKLIGHT_ENABLE) | defined(LED_MATRIX_ENABLE)
- case ACT_BACKLIGHT:
- if (!event.pressed) {
- switch (action.backlight.opt) {
- case BACKLIGHT_INCREASE:
- backlight_increase();
- break;
- case BACKLIGHT_DECREASE:
- backlight_decrease();
- break;
- case BACKLIGHT_TOGGLE:
- backlight_toggle();
- break;
- case BACKLIGHT_STEP:
- backlight_step();
- break;
- case BACKLIGHT_ON:
- backlight_level(BACKLIGHT_LEVELS);
- break;
- case BACKLIGHT_OFF:
- backlight_level(0);
- break;
- }
- }
- break;
-#endif
- case ACT_COMMAND:
- break;
#ifdef SWAP_HANDS_ENABLE
case ACT_SWAP_HANDS:
switch (action.swap.code) {
diff --git a/tmk_core/common/action_code.h b/tmk_core/common/action_code.h
index 03fcb3382b..6c005b76d1 100644
--- a/tmk_core/common/action_code.h
+++ b/tmk_core/common/action_code.h
@@ -86,8 +86,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* 1100|opt | id(8) Macro play?
* 1100|1111| id(8) Macro record?
*
- * ACT_BACKLIGHT(1101):
- * 1101|opt |level(8) Backlight commands
+ * 1101|xxxx xxxx xxxx (reserved)
*
* ACT_COMMAND(1110):
* 1110|opt | id(8) Built-in Command exec
@@ -115,10 +114,9 @@ enum action_kind_id {
ACT_LAYER_TAP = 0b1010, /* Layer 0-15 */
ACT_LAYER_TAP_EXT = 0b1011, /* Layer 16-31 */
/* Extensions */
- ACT_MACRO = 0b1100,
- ACT_BACKLIGHT = 0b1101,
- ACT_COMMAND = 0b1110,
- ACT_FUNCTION = 0b1111
+ ACT_MACRO = 0b1100,
+ ACT_COMMAND = 0b1110,
+ ACT_FUNCTION = 0b1111
};
/** \brief Action Code Struct
@@ -169,11 +167,6 @@ typedef union {
uint8_t page : 2;
uint8_t kind : 4;
} usage;
- struct action_backlight {
- uint8_t level : 8;
- uint8_t opt : 4;
- uint8_t kind : 4;
- } backlight;
struct action_command {
uint8_t id : 8;
uint8_t opt : 4;
@@ -290,28 +283,10 @@ enum layer_param_tap_op {
#define ACTION_DEFAULT_LAYER_BIT_XOR(part, bits) ACTION_LAYER_BITOP(OP_BIT_XOR, (part), (bits), 0)
#define ACTION_DEFAULT_LAYER_BIT_SET(part, bits) ACTION_LAYER_BITOP(OP_BIT_SET, (part), (bits), 0)
-/** \brief Extensions
- */
-enum backlight_opt {
- BACKLIGHT_INCREASE = 0,
- BACKLIGHT_DECREASE = 1,
- BACKLIGHT_TOGGLE = 2,
- BACKLIGHT_STEP = 3,
- BACKLIGHT_ON = 4,
- BACKLIGHT_OFF = 5,
-};
-
/* Macro */
#define ACTION_MACRO(id) ACTION(ACT_MACRO, (id))
#define ACTION_MACRO_TAP(id) ACTION(ACT_MACRO, FUNC_TAP << 8 | (id))
#define ACTION_MACRO_OPT(id, opt) ACTION(ACT_MACRO, (opt) << 8 | (id))
-/* Backlight */
-#define ACTION_BACKLIGHT_INCREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_INCREASE << 8)
-#define ACTION_BACKLIGHT_DECREASE() ACTION(ACT_BACKLIGHT, BACKLIGHT_DECREASE << 8)
-#define ACTION_BACKLIGHT_TOGGLE() ACTION(ACT_BACKLIGHT, BACKLIGHT_TOGGLE << 8)
-#define ACTION_BACKLIGHT_STEP() ACTION(ACT_BACKLIGHT, BACKLIGHT_STEP << 8)
-#define ACTION_BACKLIGHT_ON() ACTION(ACT_BACKLIGHT, BACKLIGHT_ON << 8)
-#define ACTION_BACKLIGHT_OFF() ACTION(ACT_BACKLIGHT, BACKLIGHT_OFF << 8)
/* Command */
#define ACTION_COMMAND(id, opt) ACTION(ACT_COMMAND, (opt) << 8 | (id))
/* Function */
diff --git a/tmk_core/common/chibios/timer.c b/tmk_core/common/chibios/timer.c
index ed5cfe1b05..ac5a5af638 100644
--- a/tmk_core/common/chibios/timer.c
+++ b/tmk_core/common/chibios/timer.c
@@ -2,30 +2,44 @@
#include "timer.h"
-static systime_t last_systime = 0;
-static systime_t overflow = 0;
-static uint32_t current_time_ms = 0;
+static uint32_t reset_point = 0;
+#if CH_CFG_ST_RESOLUTION < 32
+static uint32_t last_systime = 0;
+static uint32_t overflow = 0;
+#endif
void timer_init(void) { timer_clear(); }
void timer_clear(void) {
- last_systime = chVTGetSystemTime();
- overflow = 0;
- current_time_ms = 0;
+ reset_point = (uint32_t)chVTGetSystemTime();
+#if CH_CFG_ST_RESOLUTION < 32
+ last_systime = reset_point;
+ overflow = 0;
+#endif
}
uint16_t timer_read(void) { return (uint16_t)timer_read32(); }
uint32_t timer_read32(void) {
- // Note: We assume that the timer update is called at least once betweeen every wrap around of the system time
- systime_t current_systime = chVTGetSystemTime();
- systime_t elapsed = current_systime - last_systime + overflow;
- uint32_t elapsed_ms = ST2MS(elapsed);
- current_time_ms += elapsed_ms;
- overflow = elapsed - MS2ST(elapsed_ms);
- last_systime = current_systime;
-
- return current_time_ms;
+ uint32_t systime = (uint32_t)chVTGetSystemTime();
+
+#if CH_CFG_ST_RESOLUTION < 32
+ // If/when we need to support 64-bit chips, this may need to be modified to match the native bit-ness of the MCU.
+ // At this point, the only SysTick resolution allowed other than 32 is 16 bit.
+ // In the 16-bit case, at:
+ // - CH_CFG_ST_FREQUENCY = 100000, overflow will occur every ~0.65 seconds
+ // - CH_CFG_ST_FREQUENCY = 10000, overflow will occur every ~6.5 seconds
+ // - CH_CFG_ST_FREQUENCY = 1000, overflow will occur every ~65 seconds
+ // With this implementation, as long as we ensure a timer read happens at least once during the overflow period, timing should be accurate.
+ if (systime < last_systime) {
+ overflow += ((uint32_t)1) << CH_CFG_ST_RESOLUTION;
+ }
+
+ last_systime = systime;
+ return (uint32_t)TIME_I2MS(systime - reset_point + overflow);
+#else
+ return (uint32_t)TIME_I2MS(systime - reset_point);
+#endif
}
uint16_t timer_elapsed(uint16_t last) { return TIMER_DIFF_16(timer_read(), last); }
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c
index 900de54103..77a205eac4 100644
--- a/tmk_core/common/command.c
+++ b/tmk_core/common/command.c
@@ -153,6 +153,9 @@ static void print_version(void) {
print("BUILD: (" __DATE__ ")\n");
#else
print("BUILD: " STR(QMK_VERSION) " (" __TIME__ " " __DATE__ ")\n");
+# ifdef PROTOCOL_CHIBIOS
+ print("CHIBIOS: " STR(CHIBIOS_VERSION) ", CONTRIB: " STR(CHIBIOS_CONTRIB_VERSION) "\n");
+# endif
#endif
/* build options */
@@ -182,6 +185,9 @@ static void print_version(void) {
#ifdef NKRO_ENABLE
" NKRO"
#endif
+#ifdef LINK_TIME_OPTIMIZATION_ENABLE
+ " LTO"
+#endif
" " STR(BOOTLOADER_SIZE) "\n");
diff --git a/tmk_core/common/timer.h b/tmk_core/common/timer.h
index 378cf7892c..bbaae109d0 100644
--- a/tmk_core/common/timer.h
+++ b/tmk_core/common/timer.h
@@ -45,9 +45,8 @@ uint16_t timer_elapsed(uint16_t last);
uint32_t timer_elapsed32(uint32_t last);
// Utility functions to check if a future time has expired & autmatically handle time wrapping if checked / reset frequently (half of max value)
-inline bool timer_expired(uint16_t current, uint16_t future) { return (uint16_t)(current - future) < 0x8000; }
-
-inline bool timer_expired32(uint32_t current, uint32_t future) { return (uint32_t)(current - future) < 0x80000000; }
+#define timer_expired(current, future) (((uint16_t)current - (uint16_t)future) < 0x8000)
+#define timer_expired32(current, future) (((uint32_t)current - (uint32_t)future) < 0x80000000)
#ifdef __cplusplus
}
diff --git a/tmk_core/protocol/chibios.mk b/tmk_core/protocol/chibios.mk
index 222fb4dad4..2070420f56 100644
--- a/tmk_core/protocol/chibios.mk
+++ b/tmk_core/protocol/chibios.mk
@@ -6,6 +6,7 @@ SRC += $(CHIBIOS_DIR)/usb_main.c
SRC += $(CHIBIOS_DIR)/main.c
SRC += usb_descriptor.c
SRC += $(CHIBIOS_DIR)/usb_driver.c
+SRC += $(LIBSRC)
VPATH += $(TMK_PATH)/$(PROTOCOL_DIR)
VPATH += $(TMK_PATH)/$(CHIBIOS_DIR)
diff --git a/tmk_core/protocol/chibios/usb_driver.c b/tmk_core/protocol/chibios/usb_driver.c
index 28a8c66635..22d3c91f5a 100644
--- a/tmk_core/protocol/chibios/usb_driver.c
+++ b/tmk_core/protocol/chibios/usb_driver.c
@@ -88,15 +88,15 @@ static msg_t _put(void *ip, uint8_t b) { return obqPutTimeout(&((QMKUSBDriver *)
static msg_t _get(void *ip) { return ibqGetTimeout(&((QMKUSBDriver *)ip)->ibqueue, TIME_INFINITE); }
-static msg_t _putt(void *ip, uint8_t b, systime_t timeout) { return obqPutTimeout(&((QMKUSBDriver *)ip)->obqueue, b, timeout); }
+static msg_t _putt(void *ip, uint8_t b, sysinterval_t timeout) { return obqPutTimeout(&((QMKUSBDriver *)ip)->obqueue, b, timeout); }
-static msg_t _gett(void *ip, systime_t timeout) { return ibqGetTimeout(&((QMKUSBDriver *)ip)->ibqueue, timeout); }
+static msg_t _gett(void *ip, sysinterval_t timeout) { return ibqGetTimeout(&((QMKUSBDriver *)ip)->ibqueue, timeout); }
-static size_t _writet(void *ip, const uint8_t *bp, size_t n, systime_t timeout) { return obqWriteTimeout(&((QMKUSBDriver *)ip)->obqueue, bp, n, timeout); }
+static size_t _writet(void *ip, const uint8_t *bp, size_t n, sysinterval_t timeout) { return obqWriteTimeout(&((QMKUSBDriver *)ip)->obqueue, bp, n, timeout); }
-static size_t _readt(void *ip, uint8_t *bp, size_t n, systime_t timeout) { return ibqReadTimeout(&((QMKUSBDriver *)ip)->ibqueue, bp, n, timeout); }
+static size_t _readt(void *ip, uint8_t *bp, size_t n, sysinterval_t timeout) { return ibqReadTimeout(&((QMKUSBDriver *)ip)->ibqueue, bp, n, timeout); }
-static const struct QMKUSBDriverVMT vmt = {_write, _read, _put, _get, _putt, _gett, _writet, _readt};
+static const struct QMKUSBDriverVMT vmt = {0, _write, _read, _put, _get, _putt, _gett, _writet, _readt};
/**
* @brief Notification of empty buffer released into the input buffers queue.
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index 6192baa4d2..3370964683 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -499,7 +499,7 @@ static bool usb_request_hook_cb(USBDriver *usbp) {
#endif /* NKRO_ENABLE */
/* arm the idle timer if boot protocol & idle */
osalSysLockFromISR();
- chVTSetI(&keyboard_idle_timer, 4 * MS2ST(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
+ chVTSetI(&keyboard_idle_timer, 4 * TIME_MS2I(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
osalSysUnlockFromISR();
}
}
@@ -516,7 +516,7 @@ static bool usb_request_hook_cb(USBDriver *usbp) {
if (keyboard_idle) {
#endif /* NKRO_ENABLE */
osalSysLockFromISR();
- chVTSetI(&keyboard_idle_timer, 4 * MS2ST(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
+ chVTSetI(&keyboard_idle_timer, 4 * TIME_MS2I(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
osalSysUnlockFromISR();
}
usbSetupTransfer(usbp, NULL, 0, NULL);
@@ -652,7 +652,7 @@ static void keyboard_idle_timer_cb(void *arg) {
usbStartTransmitI(usbp, KEYBOARD_IN_EPNUM, (uint8_t *)&keyboard_report_sent, KEYBOARD_EPSIZE);
}
/* rearm the timer */
- chVTSetI(&keyboard_idle_timer, 4 * MS2ST(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
+ chVTSetI(&keyboard_idle_timer, 4 * TIME_MS2I(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
}
/* do not rearm the timer if the condition above fails
@@ -751,7 +751,7 @@ void send_mouse(report_mouse_t *report) {
* every iteration - otherwise the system will remain locked,
* no interrupts served, so USB not going through as well.
* Note: for suspend, need USB_USE_WAIT == TRUE in halconf.h */
- if (osalThreadSuspendTimeoutS(&(&USB_DRIVER)->epc[MOUSE_IN_EPNUM]->in_state->thread, MS2ST(10)) == MSG_TIMEOUT) {
+ if (osalThreadSuspendTimeoutS(&(&USB_DRIVER)->epc[MOUSE_IN_EPNUM]->in_state->thread, TIME_MS2I(10)) == MSG_TIMEOUT) {
osalSysUnlock();
return;
}