summaryrefslogtreecommitdiffstats
path: root/tmk_core/common
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/action.c31
-rw-r--r--tmk_core/common/action_code.h2
-rw-r--r--tmk_core/common/action_layer.c2
-rw-r--r--tmk_core/common/action_layer.h15
-rw-r--r--tmk_core/common/action_tapping.c6
-rw-r--r--tmk_core/common/action_tapping.h2
-rw-r--r--tmk_core/common/action_util.c54
-rw-r--r--tmk_core/common/action_util.h8
-rw-r--r--tmk_core/common/chibios/printf.c233
-rw-r--r--tmk_core/common/chibios/printf.h110
-rw-r--r--tmk_core/common/command.c23
-rw-r--r--tmk_core/common/keyboard.c16
-rw-r--r--tmk_core/common/print.h5
-rw-r--r--tmk_core/common/report.h2
-rw-r--r--tmk_core/common/sendchar_null.c2
15 files changed, 135 insertions, 376 deletions
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, char* bf) {
- if (num < 0) {
- num = -num;
- *bf++ = '-';
- }
- ui2a(num, 10, 0, bf);
-}
-
-static int a2d(char ch) {
- if (ch >= '0' && ch <= '9')
- return ch - '0';
- else if (ch >= 'a' && ch <= 'f')
- return ch - 'a' + 10;
- else if (ch >= 'A' && ch <= 'F')
- return ch - 'A' + 10;
- else
- return -1;
-}
-
-static char a2i(char ch, const char** src, int base, int* nump) {
- const char* p = *src;
- int num = 0;
- int digit;
- while ((digit = a2d(ch)) >= 0) {
- if (digit > base) break;
- num = num * base + digit;
- ch = *p++;
- }
- *src = p;
- *nump = num;
- return ch;
-}
-
-static void putchw(void* putp, putcf putf, int n, char z, char* bf) {
- char fc = z ? '0' : ' ';
- char ch;
- char* p = bf;
- while (*p++ && n > 0) n--;
- while (n-- > 0) putf(putp, fc);
- while ((ch = *bf++)) putf(putp, ch);
-}
-
-void tfp_format(void* putp, putcf putf, const char* fmt, va_list va) {
- // This used to handle max of 12, but binary support jumps this to at least 32
- char bf[36];
-
- char ch;
-
- while ((ch = *(fmt++))) {
- if (ch != '%')
- putf(putp, ch);
- else {
- char lz = 0;
-#ifdef PRINTF_LONG_SUPPORT
- char lng = 0;
-#endif
- int w = 0;
- ch = *(fmt++);
- if (ch == '0') {
- ch = *(fmt++);
- lz = 1;
- }
- if (ch >= '0' && ch <= '9') {
- ch = a2i(ch, &fmt, 10, &w);
- }
-#ifdef PRINTF_LONG_SUPPORT
- if (ch == 'l') {
- ch = *(fmt++);
- lng = 1;
- }
-#endif
- switch (ch) {
- case 0:
- goto abort;
- case 'u': {
-#ifdef PRINTF_LONG_SUPPORT
- if (lng)
- uli2a(va_arg(va, unsigned long int), 10, 0, bf);
- else
-#endif
- ui2a(va_arg(va, unsigned int), 10, 0, bf);
- putchw(putp, putf, w, lz, bf);
- break;
- }
- case 'd': {
-#ifdef PRINTF_LONG_SUPPORT
- if (lng)
- li2a(va_arg(va, unsigned long int), bf);
- else
-#endif
- i2a(va_arg(va, int), bf);
- putchw(putp, putf, w, lz, bf);
- break;
- }
- case 'x':
- case 'X':
-#ifdef PRINTF_LONG_SUPPORT
- if (lng)
- uli2a(va_arg(va, unsigned long int), 16, (ch == 'X'), bf);
- else
-#endif
- ui2a(va_arg(va, unsigned int), 16, (ch == 'X'), bf);
- putchw(putp, putf, w, lz, bf);
- break;
- case 'c':
- putf(putp, (char)(va_arg(va, int)));
- break;
- case 's':
- putchw(putp, putf, w, 0, va_arg(va, char*));
- break;
- case 'b':
-#ifdef PRINTF_LONG_SUPPORT
- if (lng)
- uli2a(va_arg(va, unsigned long int), 2, 0, bf);
- else
-#endif
- ui2a(va_arg(va, unsigned int), 2, 0, bf);
- putchw(putp, putf, w, lz, bf);
- break;
- case '%':
- putf(putp, ch);
- default:
- break;
- }
- }
- }
-abort:;
-}
-
-void init_printf(void* putp, void (*putf)(void*, char)) {
- stdout_putf = putf;
- stdout_putp = putp;
-}
-
-int tfp_printf(const char* fmt, ...) {
- va_list va;
- va_start(va, fmt);
- tfp_format(stdout_putp, stdout_putf, fmt, va);
- va_end(va);
-
- return 1;
-}
-
-static void putcp(void* p, char c) { *(*((char**)p))++ = c; }
-
-int tfp_sprintf(char* s, const char* fmt, ...) {
- va_list va;
- va_start(va, fmt);
- tfp_format(&s, putcp, fmt, va);
- putcp(&s, 0);
- va_end(va);
-
- return 1;
-}
diff --git a/tmk_core/common/chibios/printf.h b/tmk_core/common/chibios/printf.h
deleted file mode 100644
index 775459e1e8..0000000000
--- a/tmk_core/common/chibios/printf.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * found at: http://www.sparetimelabs.com/tinyprintf/tinyprintf.php
- * and: http://www.sparetimelabs.com/printfrevisited/printfrevisited.php
- */
-
-/*
-File: printf.h
-
-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
-
-This library is realy just two files: 'printf.h' and 'printf.c'.
-
-They provide a simple and small (+200 loc) printf functionality to
-be used in embedded systems.
-
-I've found them so usefull in debugging that I do not bother with a
-debugger at all.
-
-They are distributed in source form, so to use them, just compile them
-into your project.
-
-Two printf variants are provided: printf and sprintf.
-
-The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'.
-
-Zero padding and field width are also supported.
-
-If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the
-long specifier is also
-supported. Note that this will pull in some long math routines (pun intended!)
-and thus make your executable noticably longer.
-
-The memory foot print of course depends on the target cpu, compiler and
-compiler options, but a rough guestimate (based on a H8S target) is about
-1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space.
-Not too bad. Your milage may vary. By hacking the source code you can
-get rid of some hunred bytes, I'm sure, but personally I feel the balance of
-functionality and flexibility versus code size is close to optimal for
-many embedded systems.
-
-To use the printf you need to supply your own character output function,
-something like :
-
- void putc ( void* p, char c)
- {
- while (!SERIAL_PORT_EMPTY) ;
- SERIAL_PORT_TX_REGISTER = c;
- }
-
-Before you can call printf you need to initialize it to use your
-character output function with something like:
-
- init_printf(NULL,putc);
-
-Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc',
-the NULL (or any pointer) you pass into the 'init_printf' will eventually be
-passed to your 'putc' routine. This allows you to pass some storage space (or
-anything realy) to the character output function, if necessary.
-This is not often needed but it was implemented like that because it made
-implementing the sprintf function so neat (look at the source code).
-
-The code is re-entrant, except for the 'init_printf' function, so it
-is safe to call it from interupts too, although this may result in mixed output.
-If you rely on re-entrancy, take care that your 'putc' function is re-entrant!
-
-The printf and sprintf functions are actually macros that translate to
-'tfp_printf' and 'tfp_sprintf'. This makes it possible
-to use them along with 'stdio.h' printf's in a single source file.
-You just need to undef the names before you include the 'stdio.h'.
-Note that these are not function like macros, so if you have variables
-or struct members with these names, things will explode in your face.
-Without variadic macros this is the best we can do to wrap these
-fucnction. If it is a problem just give up the macros and use the
-functions directly or rename them.
-
-For further details see source code.
-
-regs Kusti, 23.10.2004
-*/
-
-#ifndef __TFP_PRINTF__
-#define __TFP_PRINTF__
-
-#include <stdarg.h>
-
-void init_printf(void* putp, void (*putf)(void*, char));
-
-int tfp_printf(const char* fmt, ...);
-int tfp_sprintf(char* s, const char* fmt, ...);
-
-void tfp_format(void* putp, void (*putf)(void*, char), const char* fmt, va_list va);
-
-#define printf tfp_printf
-#define sprintf tfp_sprintf
-
-#endif
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c
index 77a205eac4..3cfcba3058 100644
--- a/tmk_core/common/command.c
+++ b/tmk_core/common/command.c
@@ -39,14 +39,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "backlight.h"
#endif
-#ifdef MOUSEKEY_ENABLE
+#if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED)
# include "mousekey.h"
#endif
-#ifdef PROTOCOL_VUSB
-# include "usbdrv.h"
-#endif
-
#ifdef AUDIO_ENABLE
# include "audio.h"
#endif /* AUDIO_ENABLE */
@@ -57,7 +53,7 @@ static void print_version(void);
static void print_status(void);
static bool command_console(uint8_t code);
static void command_console_help(void);
-#ifdef MOUSEKEY_ENABLE
+#if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED)
static bool mousekey_console(uint8_t code);
static void mousekey_console_help(void);
#endif
@@ -78,7 +74,7 @@ bool command_proc(uint8_t code) {
else
return (command_console_extra(code) || command_console(code));
break;
-#ifdef MOUSEKEY_ENABLE
+#if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED)
case MOUSEKEY:
mousekey_console(code);
break;
@@ -359,15 +355,8 @@ static bool command_common(uint8_t code) {
// jump to bootloader
case MAGIC_KC(MAGIC_KEY_BOOTLOADER):
case MAGIC_KC(MAGIC_KEY_BOOTLOADER_ALT):
- clear_keyboard(); // clear to prevent stuck keys
print("\n\nJumping to bootloader... ");
-#ifdef AUDIO_ENABLE
- stop_all_notes();
- shutdown_user();
-#else
- wait_ms(1000);
-#endif
- bootloader_jump(); // not return
+ reset_keyboard();
break;
// debug toggle
@@ -538,7 +527,7 @@ static bool command_console(uint8_t code) {
case KC_ESC:
command_state = ONESHOT;
return false;
-#ifdef MOUSEKEY_ENABLE
+#if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED)
case KC_M:
mousekey_console_help();
print("M> ");
@@ -553,7 +542,7 @@ static bool command_console(uint8_t code) {
return true;
}
-#ifdef MOUSEKEY_ENABLE
+#if defined(MOUSEKEY_ENABLE) && !defined(MK_3_SPEED)
/***********************************************************
* Mousekey console
***********************************************************/
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 200b1e8722..714c3d048f 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -89,6 +89,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef VIA_ENABLE
# include "via.h"
#endif
+#ifdef DIP_SWITCH_ENABLE
+# include "dip_switch.h"
+#endif
// Only enable this if console is enabled to print to
#if defined(DEBUG_MATRIX_SCAN_RATE) && defined(CONSOLE_ENABLE)
@@ -216,6 +219,13 @@ void keyboard_setup(void) {
*/
__attribute__((weak)) bool is_keyboard_master(void) { return true; }
+/** \brief should_process_keypress
+ *
+ * Override this function if you have a condition where keypresses processing should change:
+ * - splits where the slave side needs to process for rgb/oled functionality
+ */
+__attribute__((weak)) bool should_process_keypress(void) { return is_keyboard_master(); }
+
/** \brief keyboard_init
*
* FIXME: needs doc
@@ -268,6 +278,10 @@ void keyboard_init(void) {
keymap_config.nkro = 1;
eeconfig_update_keymap(keymap_config.raw);
#endif
+#ifdef DIP_SWITCH_ENABLE
+ dip_switch_init();
+#endif
+
keyboard_post_init_kb(); /* Always keep this last */
}
@@ -298,7 +312,7 @@ void keyboard_task(void) {
matrix_scan();
#endif
- if (is_keyboard_master()) {
+ if (should_process_keypress()) {
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
matrix_row = matrix_get_row(r);
matrix_change = matrix_row ^ matrix_prev[r];
diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h
index 04ca558109..1c77236212 100644
--- a/tmk_core/common/print.h
+++ b/tmk_core/common/print.h
@@ -72,9 +72,7 @@ extern "C"
# elif defined(PROTOCOL_CHIBIOS) /* PROTOCOL_CHIBIOS */
-# ifndef TERMINAL_ENABLE
-# include "chibios/printf.h"
-# endif
+# include "printf.h" // lib/printf/printf.h
# ifdef USER_PRINT /* USER_PRINT */
@@ -89,7 +87,6 @@ extern "C"
# define uprintf printf
# else /* NORMAL PRINT */
-
// Create user & normal print defines
# define print(s) printf(s)
# define println(s) printf(s "\r\n")
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h
index 61ef6ea66c..c2b1b7c710 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/common/report.h
@@ -69,6 +69,8 @@ enum consumer_usages {
AL_CALCULATOR = 0x192,
AL_LOCAL_BROWSER = 0x194,
AL_LOCK = 0x19E,
+ AL_CONTROL_PANEL = 0x19F,
+ AL_ASSISTANT = 0x1CB,
// 15.16 Generic GUI Application Controls
AC_MINIMIZE = 0x206,
AC_SEARCH = 0x221,
diff --git a/tmk_core/common/sendchar_null.c b/tmk_core/common/sendchar_null.c
index f6cab1b9d1..fb67f70866 100644
--- a/tmk_core/common/sendchar_null.c
+++ b/tmk_core/common/sendchar_null.c
@@ -16,4 +16,4 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sendchar.h"
-int8_t sendchar(uint8_t c) { return 0; }
+__attribute__((weak)) int8_t sendchar(uint8_t c) { return 0; }