summaryrefslogtreecommitdiff
path: root/tmk_core/common
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common')
-rw-r--r--tmk_core/common/action_util.c10
-rw-r--r--tmk_core/common/avr/xprintf.h6
-rw-r--r--tmk_core/common/bootmagic.c4
-rw-r--r--tmk_core/common/command.c6
-rw-r--r--tmk_core/common/host.c5
-rw-r--r--tmk_core/common/host.h4
-rw-r--r--tmk_core/common/keyboard.c4
-rw-r--r--tmk_core/common/magic.c4
-rw-r--r--tmk_core/common/mbed/xprintf.cpp2
-rw-r--r--tmk_core/common/mbed/xprintf.h2
-rw-r--r--tmk_core/common/print.h168
11 files changed, 168 insertions, 47 deletions
diff --git a/tmk_core/common/action_util.c b/tmk_core/common/action_util.c
index 61ff202bef..cb4b252648 100644
--- a/tmk_core/common/action_util.c
+++ b/tmk_core/common/action_util.c
@@ -20,6 +20,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "action_util.h"
#include "action_layer.h"
#include "timer.h"
+#include "keycode_config.h"
+
+extern keymap_config_t keymap_config;
+
static inline void add_key_byte(uint8_t code);
static inline void del_key_byte(uint8_t code);
@@ -139,7 +143,7 @@ void send_keyboard_report(void) {
void add_key(uint8_t key)
{
#ifdef NKRO_ENABLE
- if (keyboard_protocol && keyboard_nkro) {
+ if (keyboard_protocol && keymap_config.nkro) {
add_key_bit(key);
return;
}
@@ -150,7 +154,7 @@ void add_key(uint8_t key)
void del_key(uint8_t key)
{
#ifdef NKRO_ENABLE
- if (keyboard_protocol && keyboard_nkro) {
+ if (keyboard_protocol && keymap_config.nkro) {
del_key_bit(key);
return;
}
@@ -231,7 +235,7 @@ uint8_t has_anymod(void)
uint8_t get_first_key(void)
{
#ifdef NKRO_ENABLE
- if (keyboard_protocol && keyboard_nkro) {
+ if (keyboard_protocol && keymap_config.nkro) {
uint8_t i = 0;
for (; i < KEYBOARD_REPORT_BITS && !keyboard_report->nkro.bits[i]; i++)
;
diff --git a/tmk_core/common/avr/xprintf.h b/tmk_core/common/avr/xprintf.h
index e53c0dd8e0..08d9f93a0c 100644
--- a/tmk_core/common/avr/xprintf.h
+++ b/tmk_core/common/avr/xprintf.h
@@ -56,8 +56,8 @@ void xitoa(long value, char radix, char width);
#define xfprintf(func, format, ...) __xfprintf(func, PSTR(format), ##__VA_ARGS__)
void __xprintf(const char *format_p, ...); /* Send formatted string to the registered device */
-void __xsprintf(char*, const char *format_p, ...); /* Put formatted string to the memory */
-void __xfprintf(void(*func)(uint8_t), const char *format_p, ...); /* Send formatted string to the specified device */
+// void __xsprintf(char*, const char *format_p, ...); /* Put formatted string to the memory */
+// void __xfprintf(void(*func)(uint8_t), const char *format_p, ...); /* Send formatted string to the specified device */
/* Format string is placed in the ROM. The format flags is similar to printf().
@@ -88,7 +88,7 @@ void __xfprintf(void(*func)(uint8_t), const char *format_p, ...); /* Send format
/*-----------------------------------------------------------------------------*/
char xatoi(char **str, long *ret);
-/* Get value of the numeral string.
+/* Get value of the numeral string.
str
Pointer to pointer to source string
diff --git a/tmk_core/common/bootmagic.c b/tmk_core/common/bootmagic.c
index 6730a2a4aa..2c6bcbae56 100644
--- a/tmk_core/common/bootmagic.c
+++ b/tmk_core/common/bootmagic.c
@@ -83,10 +83,6 @@ void bootmagic(void)
}
eeconfig_update_keymap(keymap_config.raw);
-#ifdef NKRO_ENABLE
- keyboard_nkro = keymap_config.nkro;
-#endif
-
/* default layer */
uint8_t default_layer = 0;
if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { default_layer |= (1<<0); }
diff --git a/tmk_core/common/command.c b/tmk_core/common/command.c
index 476fc6fe3c..54d6117fd1 100644
--- a/tmk_core/common/command.c
+++ b/tmk_core/common/command.c
@@ -238,7 +238,7 @@ static void print_status(void)
print_val_hex8(keyboard_protocol);
print_val_hex8(keyboard_idle);
#ifdef NKRO_ENABLE
- print_val_hex8(keyboard_nkro);
+ print_val_hex8(keymap_config.nkro);
#endif
print_val_hex32(timer_read32());
@@ -435,8 +435,8 @@ static bool command_common(uint8_t code)
// NKRO toggle
case MAGIC_KC(MAGIC_KEY_NKRO):
clear_keyboard(); // clear to prevent stuck keys
- keyboard_nkro = !keyboard_nkro;
- if (keyboard_nkro) {
+ keymap_config.nkro = !keymap_config.nkro;
+ if (keymap_config.nkro) {
print("NKRO: on\n");
} else {
print("NKRO: off\n");
diff --git a/tmk_core/common/host.c b/tmk_core/common/host.c
index 11a05c2ddd..e12b622165 100644
--- a/tmk_core/common/host.c
+++ b/tmk_core/common/host.c
@@ -22,11 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "util.h"
#include "debug.h"
-
-#ifdef NKRO_ENABLE
-bool keyboard_nkro = true;
-#endif
-
static host_driver_t *driver;
static uint16_t last_system_report = 0;
static uint16_t last_consumer_report = 0;
diff --git a/tmk_core/common/host.h b/tmk_core/common/host.h
index 9814b10d2d..aeabba7107 100644
--- a/tmk_core/common/host.h
+++ b/tmk_core/common/host.h
@@ -28,10 +28,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern "C" {
#endif
-#ifdef NKRO_ENABLE
-extern bool keyboard_nkro;
-#endif
-
extern uint8_t keyboard_idle;
extern uint8_t keyboard_protocol;
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index c46a701b3b..371d93f3e5 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -57,6 +57,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "visualizer/visualizer.h"
#endif
+
+
#ifdef MATRIX_HAS_GHOST
static bool has_ghost_in_row(uint8_t row)
{
@@ -106,7 +108,7 @@ void keyboard_init(void) {
rgblight_init();
#endif
#if defined(NKRO_ENABLE) && defined(FORCE_NKRO)
- keyboard_nkro = true;
+ keymap_config.nkro = 1;
#endif
}
diff --git a/tmk_core/common/magic.c b/tmk_core/common/magic.c
index 194e4cc026..49617a3d10 100644
--- a/tmk_core/common/magic.c
+++ b/tmk_core/common/magic.c
@@ -27,10 +27,6 @@ void magic(void)
/* keymap config */
keymap_config.raw = eeconfig_read_keymap();
-#ifdef NKRO_ENABLE
- keyboard_nkro = keymap_config.nkro;
-#endif
-
uint8_t default_layer = 0;
default_layer = eeconfig_read_default_layer();
default_layer_set((uint32_t)default_layer);
diff --git a/tmk_core/common/mbed/xprintf.cpp b/tmk_core/common/mbed/xprintf.cpp
index 3647ece751..b1aac2c99d 100644
--- a/tmk_core/common/mbed/xprintf.cpp
+++ b/tmk_core/common/mbed/xprintf.cpp
@@ -7,7 +7,7 @@
#define STRING_STACK_LIMIT 120
//TODO
-int xprintf(const char* format, ...) { return 0; }
+int __xprintf(const char* format, ...) { return 0; }
#if 0
/* mbed Serial */
diff --git a/tmk_core/common/mbed/xprintf.h b/tmk_core/common/mbed/xprintf.h
index 26bc529e5b..1e7a48c06d 100644
--- a/tmk_core/common/mbed/xprintf.h
+++ b/tmk_core/common/mbed/xprintf.h
@@ -7,7 +7,7 @@
extern "C" {
#endif
-int xprintf(const char *format, ...);
+int __xprintf(const char *format, ...);
#ifdef __cplusplus
}
diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h
index a1352527fc..8836c0fc7c 100644
--- a/tmk_core/common/print.h
+++ b/tmk_core/common/print.h
@@ -36,40 +36,140 @@
#ifndef NO_PRINT
+#if defined(__AVR__) /* __AVR__ */
-#if defined(__AVR__)
+# include "avr/xprintf.h"
-#include "avr/xprintf.h"
-#define print(s) xputs(PSTR(s))
-#define println(s) xputs(PSTR(s "\r\n"))
+# ifdef USER_PRINT /* USER_PRINT */
-#ifdef __cplusplus
+// Remove normal print defines
+# define print(s)
+# define println(s)
+# undef xprintf
+# define xprintf(fmt, ...)
+
+// Create user print defines
+# define uprint(s) xputs(PSTR(s))
+# define uprintln(s) xputs(PSTR(s "\r\n"))
+# define uprintf(fmt, ...) __xprintf(PSTR(fmt), ##__VA_ARGS__)
+
+# else /* NORMAL PRINT */
+
+// Create user & normal print defines
+# define print(s) xputs(PSTR(s))
+# define println(s) xputs(PSTR(s "\r\n"))
+# define uprint(s) print(s)
+# define uprintln(s) println(s)
+# define uprintf(fmt, ...) xprintf(fmt, ...)
+
+# endif /* USER_PRINT / NORMAL PRINT */
+
+# ifdef __cplusplus
extern "C"
-#endif
+# endif
+
/* function pointer of sendchar to be used by print utility */
void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t));
-#elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */
+#elif defined(PROTOCOL_CHIBIOS) /* PROTOCOL_CHIBIOS */
+
+# include "chibios/printf.h"
+
+# ifdef USER_PRINT /* USER_PRINT */
+
+// Remove normal print defines
+# define print(s)
+# define println(s)
+# define xprintf(fmt, ...)
+
+// Create user print defines
+# define uprint(s) printf(s)
+# define uprintln(s) printf(s "\r\n")
+# define uprintf printf
+
+# else /* NORMAL PRINT */
+
+// Create user & normal print defines
+# define print(s) printf(s)
+# define println(s) printf(s "\r\n")
+# define xprintf printf
+# define uprint(s) printf(s)
+# define uprintln(s) printf(s "\r\n")
+# define uprintf printf
-#include "chibios/printf.h"
+# endif /* USER_PRINT / NORMAL PRINT */
-#define print(s) printf(s)
-#define println(s) printf(s "\r\n")
-#define xprintf printf
+#elif defined(__arm__) /* __arm__ */
-#elif defined(__arm__) /* __AVR__ */
+# include "mbed/xprintf.h"
-#include "mbed/xprintf.h"
+# ifdef USER_PRINT /* USER_PRINT */
-#define print(s) xprintf(s)
-#define println(s) xprintf(s "\r\n")
+// Remove normal print defines
+# define print(s)
+# define println(s)
+# define xprintf(fmt, ...)
+
+// Create user print defines
+# define uprintf(fmt, ...) __xprintf(fmt, ...)
+# define uprint(s) xprintf(s)
+# define uprintln(s) xprintf(s "\r\n")
+
+# else /* NORMAL PRINT */
+
+// Create user & normal print defines
+# define xprintf(fmt, ...) __xprintf(fmt, ...)
+# define print(s) xprintf(s)
+# define println(s) xprintf(s "\r\n")
+# define uprint(s) print(s)
+# define uprintln(s) println(s)
+# define uprintf(fmt, ...) xprintf(fmt, ...)
+
+# endif /* USER_PRINT / NORMAL PRINT */
/* TODO: to select output destinations: UART/USBSerial */
-#define print_set_sendchar(func)
+# define print_set_sendchar(func)
+
+#endif /* __AVR__ / PROTOCOL_CHIBIOS / __arm__ */
+
+// User print disables the normal print messages in the body of QMK/TMK code and
+// is meant as a lightweight alternative to NOPRINT. Use it when you only want to do
+// a spot of debugging but lack flash resources for allowing all of the codebase to
+// print (and store their wasteful strings).
+//
+// !!! DO NOT USE USER PRINT CALLS IN THE BODY OF QMK/TMK !!!
+//
+#ifdef USER_PRINT
-#endif /* __AVR__ */
+// Disable normal print
+#define print_dec(data)
+#define print_decs(data)
+#define print_hex4(data)
+#define print_hex8(data)
+#define print_hex16(data)
+#define print_hex32(data)
+#define print_bin4(data)
+#define print_bin8(data)
+#define print_bin16(data)
+#define print_bin32(data)
+#define print_bin_reverse8(data)
+#define print_bin_reverse16(data)
+#define print_bin_reverse32(data)
+#define print_val_dec(v)
+#define print_val_decs(v)
+#define print_val_hex8(v)
+#define print_val_hex16(v)
+#define print_val_hex32(v)
+#define print_val_bin8(v)
+#define print_val_bin16(v)
+#define print_val_bin32(v)
+#define print_val_bin_reverse8(v)
+#define print_val_bin_reverse16(v)
+#define print_val_bin_reverse32(v)
+#else /* NORMAL_PRINT */
+//Enable normal print
/* decimal */
#define print_dec(i) xprintf("%u", i)
#define print_decs(i) xprintf("%d", i)
@@ -99,6 +199,39 @@ void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t));
#define print_val_bin_reverse16(v) xprintf(#v ": %016b\n", bitrev16(v))
#define print_val_bin_reverse32(v) xprintf(#v ": %032lb\n", bitrev32(v))
+#endif /* USER_PRINT / NORMAL_PRINT */
+
+// User Print
+
+/* decimal */
+#define uprint_dec(i) uprintf("%u", i)
+#define uprint_decs(i) uprintf("%d", i)
+/* hex */
+#define uprint_hex4(i) uprintf("%X", i)
+#define uprint_hex8(i) uprintf("%02X", i)
+#define uprint_hex16(i) uprintf("%04X", i)
+#define uprint_hex32(i) uprintf("%08lX", i)
+/* binary */
+#define uprint_bin4(i) uprintf("%04b", i)
+#define uprint_bin8(i) uprintf("%08b", i)
+#define uprint_bin16(i) uprintf("%016b", i)
+#define uprint_bin32(i) uprintf("%032lb", i)
+#define uprint_bin_reverse8(i) uprintf("%08b", bitrev(i))
+#define uprint_bin_reverse16(i) uprintf("%016b", bitrev16(i))
+#define uprint_bin_reverse32(i) uprintf("%032lb", bitrev32(i))
+/* print value utility */
+#define uprint_val_dec(v) uprintf(#v ": %u\n", v)
+#define uprint_val_decs(v) uprintf(#v ": %d\n", v)
+#define uprint_val_hex8(v) uprintf(#v ": %X\n", v)
+#define uprint_val_hex16(v) uprintf(#v ": %02X\n", v)
+#define uprint_val_hex32(v) uprintf(#v ": %04lX\n", v)
+#define uprint_val_bin8(v) uprintf(#v ": %08b\n", v)
+#define uprint_val_bin16(v) uprintf(#v ": %016b\n", v)
+#define uprint_val_bin32(v) uprintf(#v ": %032lb\n", v)
+#define uprint_val_bin_reverse8(v) uprintf(#v ": %08b\n", bitrev(v))
+#define uprint_val_bin_reverse16(v) uprintf(#v ": %016b\n", bitrev16(v))
+#define uprint_val_bin_reverse32(v) uprintf(#v ": %032lb\n", bitrev32(v))
+
#else /* NO_PRINT */
#define xprintf(fmt, ...)
@@ -143,5 +276,4 @@ void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t));
#define pbin_reverse(data) print_bin_reverse8(data)
#define pbin_reverse16(data) print_bin_reverse16(data)
-
#endif