diff options
Diffstat (limited to 'tmk_core')
62 files changed, 539 insertions, 8194 deletions
diff --git a/tmk_core/avr.mk b/tmk_core/avr.mk index f5c1257712..04ae162246 100644 --- a/tmk_core/avr.mk +++ b/tmk_core/avr.mk @@ -156,17 +156,20 @@ dfu-split-right: $(BUILD_DIR)/$(TARGET).hex cpfirmware check-size define EXEC_AVRDUDE USB= ;\ if $(GREP) -q -s Microsoft /proc/version; then \ - echo 'ERROR: AVR flashing cannot be automated within the Windows Subsystem for Linux (WSL) currently. Instead, take the .hex file generated and flash it using AVRDUDE, AVRDUDESS, or XLoader.'; \ + echo 'ERROR: AVR flashing cannot be automated within the Windows Subsystem for Linux (WSL) currently. Instead, take the .hex file generated and flash it using QMK Toolbox, AVRDUDE, AVRDUDESS, or XLoader.'; \ else \ printf "Detecting USB port, reset your controller now."; \ - ls /dev/tty* > /tmp/1; \ + TMP1=`mktemp`; \ + TMP2=`mktemp`; \ + ls /dev/tty* > $$TMP1; \ while [ -z $$USB ]; do \ sleep 0.5; \ printf "."; \ - ls /dev/tty* > /tmp/2; \ - USB=`comm -13 /tmp/1 /tmp/2 | $(GREP) -o '/dev/tty.*'`; \ - mv /tmp/2 /tmp/1; \ + ls /dev/tty* > $$TMP2; \ + USB=`comm -13 $$TMP1 $$TMP2 | $(GREP) -o '/dev/tty.*'`; \ + mv $$TMP2 $$TMP1; \ done; \ + rm $$TMP1; \ echo ""; \ echo "Device $$USB has appeared; assuming it is the controller."; \ if $(GREP) -q -s 'MINGW\|MSYS' /proc/version; then \ diff --git a/tmk_core/chibios.mk b/tmk_core/chibios.mk index 6bacabbbf3..09aaddeef0 100644 --- a/tmk_core/chibios.mk +++ b/tmk_core/chibios.mk @@ -220,6 +220,18 @@ COMPILEFLAGS += -fno-common COMPILEFLAGS += -fshort-wchar COMPILEFLAGS += $(THUMBFLAGS) +# FPU options default (Cortex-M4 and Cortex-M7 single precision). +USE_FPU_OPT ?= -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant + +# FPU-related options +USE_FPU ?= no +ifneq ($(USE_FPU),no) + COMPILEFLAGS += $(USE_FPU_OPT) + OPT_DEFS += -DCORTEX_USE_FPU=TRUE +else + OPT_DEFS += -DCORTEX_USE_FPU=FALSE +endif + CFLAGS += $(COMPILEFLAGS) ASFLAGS += $(THUMBFLAGS) @@ -233,7 +245,6 @@ LDFLAGS += -mno-thumb-interwork -mthumb LDSYMBOLS =,--defsym=__process_stack_size__=$(USE_PROCESS_STACKSIZE) LDSYMBOLS :=$(LDSYMBOLS),--defsym=__main_stack_size__=$(USE_EXCEPTIONS_STACKSIZE) LDFLAGS += -Wl,--script=$(LDSCRIPT)$(LDSYMBOLS) -LDFLAGS += --specs=nano.specs OPT_DEFS += -DPROTOCOL_CHIBIOS @@ -242,22 +253,6 @@ OPT_DEFS += -DPORT_IGNORE_GCC_VERSION_CHECK=1 MCUFLAGS = -mcpu=$(MCU) -# FPU options default (Cortex-M4 and Cortex-M7 single precision). -ifeq ($(USE_FPU_OPT),) - USE_FPU_OPT = -mfloat-abi=$(USE_FPU) -mfpu=fpv4-sp-d16 -fsingle-precision-constant -endif - -# FPU-related options -ifeq ($(USE_FPU),) - USE_FPU = no -endif -ifneq ($(USE_FPU),no) - OPT += $(USE_FPU_OPT) - OPT_DEFS += -DCORTEX_USE_FPU=TRUE -else - OPT_DEFS += -DCORTEX_USE_FPU=FALSE -endif - DEBUG = gdb DFU_ARGS ?= diff --git a/tmk_core/common.mk b/tmk_core/common.mk index 3d0b83a01c..63de7c7ede 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -1,3 +1,5 @@ +PRINTF_PATH = $(LIB_PATH)/printf + COMMON_DIR = common PLATFORM_COMMON_DIR = $(COMMON_DIR)/$(PLATFORM_KEY) @@ -10,6 +12,7 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \ $(COMMON_DIR)/action_util.c \ $(COMMON_DIR)/print.c \ $(COMMON_DIR)/debug.c \ + $(COMMON_DIR)/sendchar_null.c \ $(COMMON_DIR)/util.c \ $(COMMON_DIR)/eeconfig.c \ $(COMMON_DIR)/report.c \ @@ -20,7 +23,12 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \ ifeq ($(PLATFORM),AVR) TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/xprintf.S else ifeq ($(PLATFORM),CHIBIOS) - TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/printf.c + TMK_COMMON_SRC += $(PRINTF_PATH)/printf.c + TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_FLOAT + TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_EXPONENTIAL + TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_LONG_LONG + TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_PTRDIFF_T + VPATH += $(PRINTF_PATH) else ifeq ($(PLATFORM),ARM_ATSAM) TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/printf.c endif diff --git a/tmk_core/common/action.c b/tmk_core/common/action.c index e5e9e27052..909b9c39c9 100644 --- a/tmk_core/common/action.c +++ b/tmk_core/common/action.c @@ -48,7 +48,7 @@ int retro_tapping_counter = 0; #endif #ifdef IGNORE_MOD_TAP_INTERRUPT_PER_KEY -__attribute__((weak)) bool get_ignore_mod_tap_interrupt(uint16_t keycode) { return false; } +__attribute__((weak)) bool get_ignore_mod_tap_interrupt(uint16_t keycode, keyrecord_t *record) { return false; } #endif #ifndef TAP_CODE_DELAY @@ -98,6 +98,11 @@ void action_exec(keyevent_t event) { if (has_oneshot_mods_timed_out()) { clear_oneshot_mods(); } +# ifdef SWAP_HANDS_ENABLE + if (has_oneshot_swaphands_timed_out()) { + clear_oneshot_swaphands(); + } +# endif # endif #endif @@ -165,6 +170,8 @@ void process_record_tap_hint(keyrecord_t *record) { # ifdef SWAP_HANDS_ENABLE case ACT_SWAP_HANDS: switch (action.swap.code) { + case OP_SH_ONESHOT: + break; case OP_SH_TAP_TOGGLE: default: swap_hands = !swap_hands; @@ -224,7 +231,11 @@ void process_action(keyrecord_t *record, action_t action) { #ifndef NO_ACTION_ONESHOT bool do_release_oneshot = false; // notice we only clear the one shot layer if the pressed key is not a modifier. - if (is_oneshot_layer_active() && event.pressed && !IS_MOD(action.key.code)) { + if (is_oneshot_layer_active() && event.pressed && !IS_MOD(action.key.code) +# ifdef SWAP_HANDS_ENABLE + && !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT) +# endif + ) { clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); do_release_oneshot = !is_oneshot_layer_active(); } @@ -324,7 +335,7 @@ void process_action(keyrecord_t *record, action_t action) { # if !defined(IGNORE_MOD_TAP_INTERRUPT) || defined(IGNORE_MOD_TAP_INTERRUPT_PER_KEY) if ( # ifdef IGNORE_MOD_TAP_INTERRUPT_PER_KEY - !get_ignore_mod_tap_interrupt(get_event_keycode(record->event, false)) && + !get_ignore_mod_tap_interrupt(get_event_keycode(record->event, false), record) && # endif record->tap.interrupted) { dprint("mods_tap: tap: cancel: add_mods\n"); @@ -593,6 +604,14 @@ void process_action(keyrecord_t *record, action_t action) { swap_hands = false; } break; + case OP_SH_ONESHOT: + if (event.pressed) { + set_oneshot_swaphands(); + } else { + release_oneshot_swaphands(); + } + break; + # ifndef NO_ACTION_TAPPING case OP_SH_TAP_TOGGLE: /* tap toggle */ @@ -681,6 +700,12 @@ void process_action(keyrecord_t *record, action_t action) { # endif #endif +#ifdef SWAP_HANDS_ENABLE + if (event.pressed && !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT)) { + use_oneshot_swaphands(); + } +#endif + #ifndef NO_ACTION_ONESHOT /* Because we switch layers after a oneshot event, we need to release the * key before we leave the layer or no key up event will be generated. diff --git a/tmk_core/common/action_code.h b/tmk_core/common/action_code.h index f80b7a782e..eea554ff21 100644 --- a/tmk_core/common/action_code.h +++ b/tmk_core/common/action_code.h @@ -294,11 +294,13 @@ enum swap_hands_param_tap_op { OP_SH_OFF_ON, OP_SH_OFF, OP_SH_ON, + OP_SH_ONESHOT, }; #define ACTION_SWAP_HANDS() ACTION_SWAP_HANDS_ON_OFF() #define ACTION_SWAP_HANDS_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TOGGLE) #define ACTION_SWAP_HANDS_TAP_TOGGLE() ACTION(ACT_SWAP_HANDS, OP_SH_TAP_TOGGLE) +#define ACTION_SWAP_HANDS_ONESHOT() ACTION(ACT_SWAP_HANDS, OP_SH_ONESHOT) #define ACTION_SWAP_HANDS_TAP_KEY(key) ACTION(ACT_SWAP_HANDS, key) #define ACTION_SWAP_HANDS_ON_OFF() ACTION(ACT_SWAP_HANDS, OP_SH_ON_OFF) #define ACTION_SWAP_HANDS_OFF_ON() ACTION(ACT_SWAP_HANDS, OP_SH_OFF_ON) diff --git a/tmk_core/common/action_layer.c b/tmk_core/common/action_layer.c index 81f86f0f34..af2d7d964b 100644 --- a/tmk_core/common/action_layer.c +++ b/tmk_core/common/action_layer.c @@ -257,7 +257,7 @@ uint8_t layer_switch_get_layer(keypos_t key) { layer_state_t layers = layer_state | default_layer_state; /* check top layer first */ - for (int8_t i = sizeof(layer_state_t) * 8 - 1; i >= 0; i--) { + for (int8_t i = MAX_LAYER - 1; i >= 0; i--) { if (layers & (1UL << i)) { action = action_for_key(i, key); if (action.code != ACTION_TRANSPARENT) { diff --git a/tmk_core/common/action_layer.h b/tmk_core/common/action_layer.h index c283d26232..16922c1ff9 100644 --- a/tmk_core/common/action_layer.h +++ b/tmk_core/common/action_layer.h @@ -23,12 +23,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #if defined(LAYER_STATE_8BIT) typedef uint8_t layer_state_t; +# define MAX_LAYER_BITS 3 +# ifndef MAX_LAYER +# define MAX_LAYER 8 +# endif # define get_highest_layer(state) biton(state) #elif defined(LAYER_STATE_16BIT) typedef uint16_t layer_state_t; +# define MAX_LAYER_BITS 4 +# ifndef MAX_LAYER +# define MAX_LAYER 16 +# endif # define get_highest_layer(state) biton16(state) #else typedef uint32_t layer_state_t; +# define MAX_LAYER_BITS 5 +# ifndef MAX_LAYER +# define MAX_LAYER 32 +# endif # define get_highest_layer(state) biton32(state) #endif @@ -96,8 +108,7 @@ layer_state_t layer_state_set_kb(layer_state_t state); /* pressed actions cache */ #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE) -/* The number of bits needed to represent the layer number: log2(32). */ -# define MAX_LAYER_BITS 5 + void update_source_layers_cache(keypos_t key, uint8_t layer); uint8_t read_source_layers_cache(keypos_t key); #endif diff --git a/tmk_core/common/action_tapping.c b/tmk_core/common/action_tapping.c index 34f08d8904..fe545c79a0 100644 --- a/tmk_core/common/action_tapping.c +++ b/tmk_core/common/action_tapping.c @@ -19,10 +19,10 @@ # define IS_TAPPING_RELEASED() (IS_TAPPING() && !tapping_key.event.pressed) # define IS_TAPPING_KEY(k) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k))) -__attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode) { return TAPPING_TERM; } +__attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { return TAPPING_TERM; } # ifdef TAPPING_TERM_PER_KEY -# define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_event_keycode(tapping_key.event, false))) +# define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < get_tapping_term(get_event_keycode(tapping_key.event, false), &tapping_key)) # else # define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM) # endif @@ -122,7 +122,7 @@ bool process_tapping(keyrecord_t *keyp) { # if defined(TAPPING_TERM_PER_KEY) || (TAPPING_TERM >= 500) || defined(PERMISSIVE_HOLD) || defined(PERMISSIVE_HOLD_PER_KEY) else if ( # ifdef TAPPING_TERM_PER_KEY - (get_tapping_term(get_event_keycode(tapping_key.event, false)) >= 500) && + (get_tapping_term(get_event_keycode(tapping_key.event, false), keyp) >= 500) && # endif # ifdef PERMISSIVE_HOLD_PER_KEY !get_permissive_hold(get_event_keycode(tapping_key.event, false), keyp) && diff --git a/tmk_core/common/action_tapping.h b/tmk_core/common/action_tapping.h index 5eaef1c5f0..7015ce7612 100644 --- a/tmk_core/common/action_tapping.h +++ b/tmk_core/common/action_tapping.h @@ -33,7 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #ifndef NO_ACTION_TAPPING uint16_t get_event_keycode(keyevent_t event, bool update_layer_cache); -uint16_t get_tapping_term(uint16_t keycode); +uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record); void action_tapping_process(keyrecord_t record); #endif diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c index 335aa36e62..371acfa610 100644 --- a/tmk_core/common/action_util.c +++ b/tmk_core/common/action_util.c @@ -83,9 +83,63 @@ static int8_t oneshot_layer_data = 0; inline uint8_t get_oneshot_layer(void) { return oneshot_layer_data >> 3; } inline uint8_t get_oneshot_layer_state(void) { return oneshot_layer_data & 0b111; } +# ifdef SWAP_HANDS_ENABLE +enum { + SHO_OFF, + SHO_ACTIVE, // Swap hands button was pressed, and we didn't send any swapped keys yet + SHO_PRESSED, // Swap hands button is currently pressed + SHO_USED, // Swap hands button is still pressed, and we already sent swapped keys +} swap_hands_oneshot = SHO_OFF; +# endif + # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) static uint16_t oneshot_layer_time = 0; inline bool has_oneshot_layer_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_layer_time) >= ONESHOT_TIMEOUT && !(get_oneshot_layer_state() & ONESHOT_TOGGLED); } +# ifdef SWAP_HANDS_ENABLE +static uint16_t oneshot_swaphands_time = 0; +inline bool has_oneshot_swaphands_timed_out() { return TIMER_DIFF_16(timer_read(), oneshot_swaphands_time) >= ONESHOT_TIMEOUT && !(swap_hands_oneshot >= SHO_PRESSED); } +# endif +# endif + +# ifdef SWAP_HANDS_ENABLE + +void set_oneshot_swaphands(void) { + swap_hands_oneshot = SHO_PRESSED; + swap_hands = true; +# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) + oneshot_swaphands_time = timer_read(); + if (oneshot_layer_time != 0) { + oneshot_layer_time = oneshot_swaphands_time; + } +# endif +} + +void release_oneshot_swaphands(void) { + if (swap_hands_oneshot == SHO_PRESSED) { + swap_hands_oneshot = SHO_ACTIVE; + } + if (swap_hands_oneshot == SHO_USED) { + clear_oneshot_swaphands(); + } +} + +void use_oneshot_swaphands(void) { + if (swap_hands_oneshot == SHO_PRESSED) { + swap_hands_oneshot = SHO_USED; + } + if (swap_hands_oneshot == SHO_ACTIVE) { + clear_oneshot_swaphands(); + } +} + +void clear_oneshot_swaphands(void) { + swap_hands_oneshot = SHO_OFF; + swap_hands = false; +# if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) + oneshot_swaphands_time = 0; +# endif +} + # endif /** \brief Set oneshot layer diff --git a/tmk_core/common/action_util.h b/tmk_core/common/action_util.h index 1ce03ed0e4..5dd8393da4 100644 --- a/tmk_core/common/action_util.h +++ b/tmk_core/common/action_util.h @@ -77,6 +77,7 @@ void reset_oneshot_layer(void); bool is_oneshot_layer_active(void); uint8_t get_oneshot_layer_state(void); bool has_oneshot_layer_timed_out(void); +bool has_oneshot_swaphands_timed_out(void); void oneshot_locked_mods_changed_user(uint8_t mods); void oneshot_locked_mods_changed_kb(uint8_t mods); @@ -88,6 +89,13 @@ void oneshot_layer_changed_kb(uint8_t layer); /* inspect */ uint8_t has_anymod(void); +#ifdef SWAP_HANDS_ENABLE +void set_oneshot_swaphands(void); +void release_oneshot_swaphands(void); +void use_oneshot_swaphands(void); +void clear_oneshot_swaphands(void); +#endif + #ifdef __cplusplus } #endif diff --git a/tmk_core/common/chibios/printf.c b/tmk_core/common/chibios/printf.c deleted file mode 100644 index a99752bb3d..0000000000 --- a/tmk_core/common/chibios/printf.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - * found at: http://www.sparetimelabs.com/tinyprintf/tinyprintf.php - * and: http://www.sparetimelabs.com/printfrevisited/printfrevisited.php - */ - -/* -File: printf.c - -Copyright (C) 2004 Kustaa Nyholm - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -*/ - -#include "printf.h" - -typedef void (*putcf)(void*, char); -static putcf stdout_putf; -static void* stdout_putp; - -// this adds cca 400 bytes -#define PRINTF_LONG_SUPPORT - -#ifdef PRINTF_LONG_SUPPORT - -static void uli2a(unsigned long int num, unsigned int base, int uc, char* bf) { - int n = 0; - unsigned int d = 1; - while (num / d >= base) d *= base; - while (d != 0) { - int dgt = num / d; - num %= d; - d /= base; - if (n || dgt > 0 || d == 0) { - *bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10); - ++n; - } - } - *bf = 0; -} - -static void li2a(long num, char* bf) { - if (num < 0) { - num = -num; - *bf++ = '-'; - } - uli2a(num, 10, 0, bf); -} - -#endif - -static void ui2a(unsigned int num, unsigned int base, int uc, char* bf) { - int n = 0; - unsigned int d = 1; - while (num / d >= base) d *= base; - while (d != 0) { - int dgt = num / d; - num %= d; - d /= base; - if (n || dgt > 0 || d == 0) { - *bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10); - ++n; - } - } - *bf = 0; -} - -static void i2a(int num |