From 1c6c14d90493101cf122554ef79e92aaeb280eb4 Mon Sep 17 00:00:00 2001 From: zvecr Date: Thu, 11 Feb 2021 22:46:57 +0000 Subject: [PATCH 1/9] Remove GCC check from debug --- tmk_core/common/debug.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tmk_core/common/debug.c b/tmk_core/common/debug.c index bea96dfc14a1..db966b695db1 100644 --- a/tmk_core/common/debug.c +++ b/tmk_core/common/debug.c @@ -1,24 +1,25 @@ -#include -#include "debug.h" +/* +Copyright 2011 Jun Wako + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. -#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) +This program 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ +#include "debug.h" debug_config_t debug_config = { -/* GCC Bug 10676 - Using unnamed fields in initializers - * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10676 */ -#if GCC_VERSION >= 40600 .enable = false, .matrix = false, .keyboard = false, .mouse = false, .reserved = 0 -#else - { - false, // .enable - false, // .matrix - false, // .keyboard - false, // .mouse - 0 // .reserved - } -#endif }; From dbfd3391213abc13f58601194015e0b05d0d73a5 Mon Sep 17 00:00:00 2001 From: zvecr Date: Thu, 11 Feb 2021 22:49:48 +0000 Subject: [PATCH 2/9] Remove platform logic from common.mk --- tmk_core/common.mk | 8 +++----- tmk_core/common/arm_atsam/printf.mk | 1 + tmk_core/common/avr/printf.mk | 2 ++ 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 tmk_core/common/arm_atsam/printf.mk create mode 100644 tmk_core/common/avr/printf.mk diff --git a/tmk_core/common.mk b/tmk_core/common.mk index 3cf3edde35d9..bff935270471 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -20,17 +20,15 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \ $(COMMON_DIR)/sync_timer.c \ $(PLATFORM_COMMON_DIR)/bootloader.c \ -ifeq ($(PLATFORM),AVR) - TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/xprintf.S -else ifeq ($(PLATFORM),CHIBIOS) +ifneq ("$(wildcard $(TMK_PATH)/$(PLATFORM_COMMON_DIR)/printf.mk)","") + include $(TMK_PATH)/$(PLATFORM_COMMON_DIR)/printf.mk +else 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 # Option modules diff --git a/tmk_core/common/arm_atsam/printf.mk b/tmk_core/common/arm_atsam/printf.mk new file mode 100644 index 000000000000..f70e02731fb1 --- /dev/null +++ b/tmk_core/common/arm_atsam/printf.mk @@ -0,0 +1 @@ +TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/printf.c diff --git a/tmk_core/common/avr/printf.mk b/tmk_core/common/avr/printf.mk new file mode 100644 index 000000000000..060ad88c57c9 --- /dev/null +++ b/tmk_core/common/avr/printf.mk @@ -0,0 +1,2 @@ +TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/xprintf.S +TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/printf.c From 61750032c5a9494ce56a7794f0e0ae3be52f120b Mon Sep 17 00:00:00 2001 From: zvecr Date: Thu, 11 Feb 2021 23:02:02 +0000 Subject: [PATCH 3/9] Refactor platform logic within print.h --- tmk_core/common.mk | 11 +- .../common/{print.c => arm_atsam/_print.h} | 33 +- tmk_core/common/arm_atsam/printf.c | 6 +- tmk_core/common/avr/_print.h | 33 ++ tmk_core/common/avr/printf.c | 4 + tmk_core/common/debug.c | 8 +- tmk_core/common/keyboard.c | 1 + tmk_core/common/lib_printf.mk | 9 + tmk_core/common/print.h | 291 +++++------------- tmk_core/common/printf.c | 12 + tmk_core/common/progmem.h | 1 + tmk_core/common/sendchar.h | 2 + tmk_core/protocol/chibios/usb_main.c | 7 - tmk_core/protocol/lufa/lufa.c | 1 - tmk_core/protocol/vusb/main.c | 1 - 15 files changed, 163 insertions(+), 257 deletions(-) rename tmk_core/common/{print.c => arm_atsam/_print.h} (71%) create mode 100644 tmk_core/common/avr/_print.h create mode 100644 tmk_core/common/avr/printf.c create mode 100644 tmk_core/common/lib_printf.mk create mode 100644 tmk_core/common/printf.c diff --git a/tmk_core/common.mk b/tmk_core/common.mk index bff935270471..238b3c69fd56 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -1,5 +1,3 @@ -PRINTF_PATH = $(LIB_PATH)/printf - COMMON_DIR = common PLATFORM_COMMON_DIR = $(COMMON_DIR)/$(PLATFORM_KEY) @@ -10,7 +8,6 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \ $(COMMON_DIR)/action_macro.c \ $(COMMON_DIR)/action_layer.c \ $(COMMON_DIR)/action_util.c \ - $(COMMON_DIR)/print.c \ $(COMMON_DIR)/debug.c \ $(COMMON_DIR)/sendchar_null.c \ $(COMMON_DIR)/eeconfig.c \ @@ -20,15 +17,11 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \ $(COMMON_DIR)/sync_timer.c \ $(PLATFORM_COMMON_DIR)/bootloader.c \ +# Use platform provided print - fall back to lib/printf ifneq ("$(wildcard $(TMK_PATH)/$(PLATFORM_COMMON_DIR)/printf.mk)","") include $(TMK_PATH)/$(PLATFORM_COMMON_DIR)/printf.mk else - 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) + include $(TMK_PATH)/$(COMMON_DIR)/lib_printf.mk endif # Option modules diff --git a/tmk_core/common/print.c b/tmk_core/common/arm_atsam/_print.h similarity index 71% rename from tmk_core/common/print.c rename to tmk_core/common/arm_atsam/_print.h index 07aef0b0eb27..a774f5d8d2c5 100644 --- a/tmk_core/common/print.c +++ b/tmk_core/common/arm_atsam/_print.h @@ -1,4 +1,4 @@ -/* Copyright 2012,2013 Jun Wako */ +/* Copyright 2012 Jun Wako */ /* Very basic print functions, intended to be used with usb_debug_only.c * http://www.pjrc.com/teensy/ * Copyright (c) 2008 PJRC.COM, LLC @@ -21,27 +21,14 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#pragma once -#include -#include "print.h" +#include "arm_atsam/printf.h" -#ifndef NO_PRINT - -# if defined(__AVR__) - -# define sendchar(c) xputc(c) - -void print_set_sendchar(int8_t (*sendchar_func)(uint8_t)) { xdev_out(sendchar_func); } - -# elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */ - -// don't need anything extra - -# elif defined(__arm__) /* __AVR__ */ - -// TODO -// void print_set_sendchar(int8_t (*sendchar_func)(uint8_t)) { } - -# endif /* __AVR__ */ - -#endif +// Create user & normal print defines +#define xprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) +#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, ##__VA_ARGS__) diff --git a/tmk_core/common/arm_atsam/printf.c b/tmk_core/common/arm_atsam/printf.c index cd7cdb52e682..be6b692cbfb7 100644 --- a/tmk_core/common/arm_atsam/printf.c +++ b/tmk_core/common/arm_atsam/printf.c @@ -15,11 +15,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include "printf.h" +#include "sendchar.h" + #ifdef CONSOLE_ENABLE # include "samd51j18a.h" # include "arm_atsam_protocol.h" -# include "printf.h" # include # include @@ -66,3 +68,5 @@ void console_printf(char *fmt, ...) { } #endif // CONSOLE_ENABLE + +void print_set_sendchar(SendcharFunc send) {} \ No newline at end of file diff --git a/tmk_core/common/avr/_print.h b/tmk_core/common/avr/_print.h new file mode 100644 index 000000000000..f9b79bdf85ef --- /dev/null +++ b/tmk_core/common/avr/_print.h @@ -0,0 +1,33 @@ +/* Copyright 2012 Jun Wako */ +/* Very basic print functions, intended to be used with usb_debug_only.c + * http://www.pjrc.com/teensy/ + * Copyright (c) 2008 PJRC.COM, LLC + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#pragma once + +#include "avr/xprintf.h" + +// 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, ##__VA_ARGS__) \ No newline at end of file diff --git a/tmk_core/common/avr/printf.c b/tmk_core/common/avr/printf.c new file mode 100644 index 000000000000..056fd23b1f30 --- /dev/null +++ b/tmk_core/common/avr/printf.c @@ -0,0 +1,4 @@ +#include "xprintf.h" +#include "sendchar.h" + +void print_set_sendchar(SendcharFunc func) { xdev_out(func); } \ No newline at end of file diff --git a/tmk_core/common/debug.c b/tmk_core/common/debug.c index db966b695db1..27757dab6fe3 100644 --- a/tmk_core/common/debug.c +++ b/tmk_core/common/debug.c @@ -16,10 +16,4 @@ along with this program. If not, see . */ #include "debug.h" -debug_config_t debug_config = { - .enable = false, - .matrix = false, - .keyboard = false, - .mouse = false, - .reserved = 0 -}; +debug_config_t debug_config = {.enable = false, .matrix = false, .keyboard = false, .mouse = false, .reserved = 0}; diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index a6bde9df8503..299bda2c127d 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c @@ -229,6 +229,7 @@ void keyboard_setup(void) { #ifndef NO_JTAG_DISABLE disable_jtag(); #endif + print_set_sendchar(sendchar); matrix_setup(); keyboard_pre_init_kb(); } diff --git a/tmk_core/common/lib_printf.mk b/tmk_core/common/lib_printf.mk new file mode 100644 index 000000000000..10d2d8468d95 --- /dev/null +++ b/tmk_core/common/lib_printf.mk @@ -0,0 +1,9 @@ +PRINTF_PATH = $(LIB_PATH)/printf + +TMK_COMMON_SRC += $(PRINTF_PATH)/printf.c +TMK_COMMON_SRC += $(COMMON_DIR)/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) diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h index 35fcad0f4043..394d702a3638 100644 --- a/tmk_core/common/print.h +++ b/tmk_core/common/print.h @@ -27,104 +27,76 @@ #include #include #include "util.h" +#include "sendchar.h" +#include "progmem.h" -#if defined(PROTOCOL_CHIBIOS) || defined(PROTOCOL_ARM_ATSAM) -# define PSTR(x) x -#endif +void print_set_sendchar(SendcharFunc send); #ifndef NO_PRINT - -# if defined(__AVR__) /* __AVR__ */ - -# include "avr/xprintf.h" - -# ifdef USER_PRINT /* USER_PRINT */ - -// 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, ##__VA_ARGS__) - -# endif /* USER_PRINT / NORMAL PRINT */ - -# ifdef __cplusplus -extern "C" -# 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) /* PROTOCOL_CHIBIOS */ - +# if __has_include_next("_print.h") +# include_next "_print.h" /* Include the platforms print.h */ +# else +// Fall back to lib/printf # include "printf.h" // lib/printf/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 - -# endif /* USER_PRINT / NORMAL PRINT */ - -# elif defined(PROTOCOL_ARM_ATSAM) /* PROTOCOL_ARM_ATSAM */ +# 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 "arm_atsam/printf.h" +# endif /* __AVR__ / PROTOCOL_CHIBIOS / PROTOCOL_ARM_ATSAM */ +#else /* NO_PRINT */ +# undef xprintf +// Remove print defines +# define print(s) +# define println(s) +# define xprintf(fmt, ...) +# define uprintf(fmt, ...) +# define uprint(s) +# define uprintln(s) -# ifdef USER_PRINT /* USER_PRINT */ +#endif /* NO_PRINT */ +#ifdef USER_PRINT // Remove normal print defines -# define print(s) -# define println(s) -# define xprintf(fmt, ...) - -// Create user print defines -# define uprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) -# 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, ##__VA_ARGS__) -# 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, ##__VA_ARGS__) - -# endif /* USER_PRINT / NORMAL PRINT */ +# undef print +# undef println +# undef xprintf +# define print(s) +# define println(s) +# define xprintf(fmt, ...) +#endif -# endif /* __AVR__ / PROTOCOL_CHIBIOS / PROTOCOL_ARM_ATSAM */ +#define print_dec(i) xprintf("%u", i) +#define print_decs(i) xprintf("%d", i) +/* hex */ +#define print_hex4(i) xprintf("%X", i) +#define print_hex8(i) xprintf("%02X", i) +#define print_hex16(i) xprintf("%04X", i) +#define print_hex32(i) xprintf("%08lX", i) +/* binary */ +#define print_bin4(i) xprintf("%04b", i) +#define print_bin8(i) xprintf("%08b", i) +#define print_bin16(i) xprintf("%016b", i) +#define print_bin32(i) xprintf("%032lb", i) +#define print_bin_reverse8(i) xprintf("%08b", bitrev(i)) +#define print_bin_reverse16(i) xprintf("%016b", bitrev16(i)) +#define print_bin_reverse32(i) xprintf("%032lb", bitrev32(i)) +/* print value utility */ +#define print_val_dec(v) xprintf(#v ": %u\n", v) +#define print_val_decs(v) xprintf(#v ": %d\n", v) +#define print_val_hex8(v) xprintf(#v ": %X\n", v) +#define print_val_hex16(v) xprintf(#v ": %02X\n", v) +#define print_val_hex32(v) xprintf(#v ": %04lX\n", v) +#define print_val_bin8(v) xprintf(#v ": %08b\n", v) +#define print_val_bin16(v) xprintf(#v ": %016b\n", v) +#define print_val_bin32(v) xprintf(#v ": %032lb\n", v) +#define print_val_bin_reverse8(v) xprintf(#v ": %08b\n", bitrev(v)) +#define print_val_bin_reverse16(v) xprintf(#v ": %016b\n", bitrev16(v)) +#define print_val_bin_reverse32(v) xprintf(#v ": %032lb\n", bitrev32(v)) // 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 @@ -132,129 +104,32 @@ extern "C" // print (and store their wasteful strings). // // !!! DO NOT USE USER PRINT CALLS IN THE BODY OF QMK/TMK !!! -// -# ifdef USER_PRINT - -// 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) +#define uprint_dec(i) uprintf("%u", i) +#define uprint_decs(i) uprintf("%d", i) /* hex */ -# define print_hex4(i) xprintf("%X", i) -# define print_hex8(i) xprintf("%02X", i) -# define print_hex16(i) xprintf("%04X", i) -# define print_hex32(i) xprintf("%08lX", i) +#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 print_bin4(i) xprintf("%04b", i) -# define print_bin8(i) xprintf("%08b", i) -# define print_bin16(i) xprintf("%016b", i) -# define print_bin32(i) xprintf("%032lb", i) -# define print_bin_reverse8(i) xprintf("%08b", bitrev(i)) -# define print_bin_reverse16(i) xprintf("%016b", bitrev16(i)) -# define print_bin_reverse32(i) xprintf("%032lb", bitrev32(i)) +#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 print_val_dec(v) xprintf(# v ": %u\n", v) -# define print_val_decs(v) xprintf(# v ": %d\n", v) -# define print_val_hex8(v) xprintf(# v ": %X\n", v) -# define print_val_hex16(v) xprintf(# v ": %02X\n", v) -# define print_val_hex32(v) xprintf(# v ": %04lX\n", v) -# define print_val_bin8(v) xprintf(# v ": %08b\n", v) -# define print_val_bin16(v) xprintf(# v ": %016b\n", v) -# define print_val_bin32(v) xprintf(# v ": %032lb\n", v) -# define print_val_bin_reverse8(v) xprintf(# v ": %08b\n", bitrev(v)) -# 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, ...) -# define print(s) -# define println(s) -# define print_set_sendchar(func) -# 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) - -#endif /* NO_PRINT */ +#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)) diff --git a/tmk_core/common/printf.c b/tmk_core/common/printf.c new file mode 100644 index 000000000000..07a38a7fff70 --- /dev/null +++ b/tmk_core/common/printf.c @@ -0,0 +1,12 @@ +#include +#include "sendchar.h" + +// bind lib/printf to console interface - sendchar + +static SendcharFunc func = NULL; + +void print_set_sendchar(SendcharFunc send) { func = send; } + +void _putchar(char character) { + if (func) func(character); +} diff --git a/tmk_core/common/progmem.h b/tmk_core/common/progmem.h index c8863d3ad2bc..4e4771e52383 100644 --- a/tmk_core/common/progmem.h +++ b/tmk_core/common/progmem.h @@ -4,6 +4,7 @@ # include #else # define PROGMEM +# define PSTR(x) x # define PGM_P const char* # define memcpy_P(dest, src, n) memcpy(dest, src, n) # define pgm_read_byte(address_short) *((uint8_t*)(address_short)) diff --git a/tmk_core/common/sendchar.h b/tmk_core/common/sendchar.h index b150dd464efd..3c100e70972c 100644 --- a/tmk_core/common/sendchar.h +++ b/tmk_core/common/sendchar.h @@ -23,6 +23,8 @@ along with this program. If not, see . extern "C" { #endif +typedef int8_t (*SendcharFunc)(uint8_t c); + /* transmit a character. return 0 on success, -1 on error. */ int8_t sendchar(uint8_t c); diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index 13b1e34d2825..4c088e2b5bf7 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c @@ -953,15 +953,8 @@ void console_task(void) { } while (size > 0); } -#else /* CONSOLE_ENABLE */ -int8_t sendchar(uint8_t c) { - (void)c; - return 0; -} #endif /* CONSOLE_ENABLE */ -void _putchar(char character) { sendchar(character); } - #ifdef RAW_ENABLE void raw_hid_send(uint8_t *data, uint8_t length) { // TODO: implement variable size packet diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 74e48222d0cf..bd9daaac9031 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -1025,7 +1025,6 @@ static void setup_usb(void) { // for Console_Task USB_Device_EnableSOFEvents(); - print_set_sendchar(sendchar); } /** \brief Main diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c index 2e8bb2fbbc71..35116c8b2c53 100644 --- a/tmk_core/protocol/vusb/main.c +++ b/tmk_core/protocol/vusb/main.c @@ -78,7 +78,6 @@ static void setup_usb(void) { initForUsbConnectivity(); // for Console_Task - print_set_sendchar(sendchar); } /** \brief Main From d6d2071ab5f377d6a58bff10d26610dea43e190d Mon Sep 17 00:00:00 2001 From: zvecr Date: Fri, 12 Feb 2021 23:07:58 +0000 Subject: [PATCH 4/9] restore debug.c format --- tmk_core/common/debug.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tmk_core/common/debug.c b/tmk_core/common/debug.c index 27757dab6fe3..ea62deaa8ccc 100644 --- a/tmk_core/common/debug.c +++ b/tmk_core/common/debug.c @@ -16,4 +16,10 @@ along with this program. If not, see . */ #include "debug.h" -debug_config_t debug_config = {.enable = false, .matrix = false, .keyboard = false, .mouse = false, .reserved = 0}; +debug_config_t debug_config = { + .enable = false, // + .matrix = false, // + .keyboard = false, // + .mouse = false, // + .reserved = 0 // +}; From 2caa9422257d70a42b28cb0c79de963c97a15bcc Mon Sep 17 00:00:00 2001 From: zvecr Date: Fri, 12 Feb 2021 23:11:18 +0000 Subject: [PATCH 5/9] headers --- tmk_core/common/avr/printf.c | 18 +++++++++++++++++- tmk_core/common/printf.c | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/tmk_core/common/avr/printf.c b/tmk_core/common/avr/printf.c index 056fd23b1f30..9e2301116cab 100644 --- a/tmk_core/common/avr/printf.c +++ b/tmk_core/common/avr/printf.c @@ -1,4 +1,20 @@ +/* +Copyright 2011 Jun Wako + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ #include "xprintf.h" #include "sendchar.h" -void print_set_sendchar(SendcharFunc func) { xdev_out(func); } \ No newline at end of file +void print_set_sendchar(SendcharFunc func) { xdev_out(func); } diff --git a/tmk_core/common/printf.c b/tmk_core/common/printf.c index 07a38a7fff70..6778ff487847 100644 --- a/tmk_core/common/printf.c +++ b/tmk_core/common/printf.c @@ -1,3 +1,19 @@ +/* +Copyright 2011 Jun Wako + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ #include #include "sendchar.h" From 1cdd9eaad884a1eccdd639cfd7058c5f05298918 Mon Sep 17 00:00:00 2001 From: zvecr Date: Sat, 13 Feb 2021 10:29:09 +0000 Subject: [PATCH 6/9] Rename function pointer type --- tmk_core/common/arm_atsam/printf.c | 2 +- tmk_core/common/avr/printf.c | 2 +- tmk_core/common/print.h | 2 +- tmk_core/common/printf.c | 4 ++-- tmk_core/common/sendchar.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tmk_core/common/arm_atsam/printf.c b/tmk_core/common/arm_atsam/printf.c index be6b692cbfb7..2cb59706a850 100644 --- a/tmk_core/common/arm_atsam/printf.c +++ b/tmk_core/common/arm_atsam/printf.c @@ -69,4 +69,4 @@ void console_printf(char *fmt, ...) { #endif // CONSOLE_ENABLE -void print_set_sendchar(SendcharFunc send) {} \ No newline at end of file +void print_set_sendchar(sendchar_func_t send) {} \ No newline at end of file diff --git a/tmk_core/common/avr/printf.c b/tmk_core/common/avr/printf.c index 9e2301116cab..9ad7a38693c5 100644 --- a/tmk_core/common/avr/printf.c +++ b/tmk_core/common/avr/printf.c @@ -17,4 +17,4 @@ along with this program. If not, see . #include "xprintf.h" #include "sendchar.h" -void print_set_sendchar(SendcharFunc func) { xdev_out(func); } +void print_set_sendchar(sendchar_func_t func) { xdev_out(func); } diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h index 394d702a3638..48f91e63429b 100644 --- a/tmk_core/common/print.h +++ b/tmk_core/common/print.h @@ -30,7 +30,7 @@ #include "sendchar.h" #include "progmem.h" -void print_set_sendchar(SendcharFunc send); +void print_set_sendchar(sendchar_func_t func); #ifndef NO_PRINT # if __has_include_next("_print.h") diff --git a/tmk_core/common/printf.c b/tmk_core/common/printf.c index 6778ff487847..b33e8ee7632d 100644 --- a/tmk_core/common/printf.c +++ b/tmk_core/common/printf.c @@ -19,9 +19,9 @@ along with this program. If not, see . // bind lib/printf to console interface - sendchar -static SendcharFunc func = NULL; +static sendchar_func_t func = NULL; -void print_set_sendchar(SendcharFunc send) { func = send; } +void print_set_sendchar(sendchar_func_t send) { func = send; } void _putchar(char character) { if (func) func(character); diff --git a/tmk_core/common/sendchar.h b/tmk_core/common/sendchar.h index 3c100e70972c..edcddaa6bb97 100644 --- a/tmk_core/common/sendchar.h +++ b/tmk_core/common/sendchar.h @@ -23,7 +23,7 @@ along with this program. If not, see . extern "C" { #endif -typedef int8_t (*SendcharFunc)(uint8_t c); +typedef int8_t (*sendchar_func_t)(uint8_t c); /* transmit a character. return 0 on success, -1 on error. */ int8_t sendchar(uint8_t c); From a8a2d34001ab42fdc52378d5425a5281c71d5885 Mon Sep 17 00:00:00 2001 From: zvecr Date: Sat, 13 Feb 2021 14:04:23 +0000 Subject: [PATCH 7/9] review comments --- tmk_core/protocol/vusb/main.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c index 35116c8b2c53..3f93ef6d24f2 100644 --- a/tmk_core/protocol/vusb/main.c +++ b/tmk_core/protocol/vusb/main.c @@ -74,11 +74,7 @@ static void usb_remote_wakeup(void) { * * FIXME: Needs doc */ -static void setup_usb(void) { - initForUsbConnectivity(); - - // for Console_Task -} +static void setup_usb(void) { initForUsbConnectivity(); } /** \brief Main * From 43b5eaf821d849222f80a707963edfaecd6a77b9 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 14 Feb 2021 00:51:48 +0000 Subject: [PATCH 8/9] Update tmk_core/common/printf.c Co-authored-by: Nick Brassel --- tmk_core/common/printf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tmk_core/common/printf.c b/tmk_core/common/printf.c index b33e8ee7632d..ce4faffdf051 100644 --- a/tmk_core/common/printf.c +++ b/tmk_core/common/printf.c @@ -19,10 +19,11 @@ along with this program. If not, see . // bind lib/printf to console interface - sendchar -static sendchar_func_t func = NULL; +static int8_t null_sendchar_func(uint8_t c) { return 0; } +static sendchar_func_t func = null_sendchar_func; void print_set_sendchar(sendchar_func_t send) { func = send; } void _putchar(char character) { - if (func) func(character); + func(character); } From 9576fadc22f10084157defd267fea9aa4dec3e3f Mon Sep 17 00:00:00 2001 From: zvecr Date: Sun, 14 Feb 2021 00:53:36 +0000 Subject: [PATCH 9/9] Format --- tmk_core/common/printf.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tmk_core/common/printf.c b/tmk_core/common/printf.c index ce4faffdf051..e8440e55ee5d 100644 --- a/tmk_core/common/printf.c +++ b/tmk_core/common/printf.c @@ -19,11 +19,9 @@ along with this program. If not, see . // bind lib/printf to console interface - sendchar -static int8_t null_sendchar_func(uint8_t c) { return 0; } +static int8_t null_sendchar_func(uint8_t c) { return 0; } static sendchar_func_t func = null_sendchar_func; void print_set_sendchar(sendchar_func_t send) { func = send; } -void _putchar(char character) { - func(character); -} +void _putchar(char character) { func(character); }