diff options
author | Joel Challis <git@zvecr.com> | 2021-02-14 01:44:22 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-14 01:44:22 +0000 |
commit | 1f2fe2eab99548f4bde2a79b03e3303cc9b73214 (patch) | |
tree | 22c7b61acf16ce3e25b5c35ce56cc2bb6ebec290 /tmk_core/common | |
parent | 72e515547aedbfd0b91296a51a81861236be8fe5 (diff) |
Refactor platform logic within print.h (#11863)
* Remove GCC check from debug
* Remove platform logic from common.mk
* Refactor platform logic within print.h
* restore debug.c format
* headers
* Rename function pointer type
* review comments
* Update tmk_core/common/printf.c
Co-authored-by: Nick Brassel <nick@tzarc.org>
* Format
Co-authored-by: Nick Brassel <nick@tzarc.org>
Diffstat (limited to 'tmk_core/common')
-rw-r--r-- | tmk_core/common/arm_atsam/_print.h (renamed from tmk_core/common/print.c) | 33 | ||||
-rw-r--r-- | tmk_core/common/arm_atsam/printf.c | 6 | ||||
-rw-r--r-- | tmk_core/common/arm_atsam/printf.mk | 1 | ||||
-rw-r--r-- | tmk_core/common/avr/_print.h | 33 | ||||
-rw-r--r-- | tmk_core/common/avr/printf.c | 20 | ||||
-rw-r--r-- | tmk_core/common/avr/printf.mk | 2 | ||||
-rw-r--r-- | tmk_core/common/debug.c | 41 | ||||
-rw-r--r-- | tmk_core/common/keyboard.c | 1 | ||||
-rw-r--r-- | tmk_core/common/lib_printf.mk | 9 | ||||
-rw-r--r-- | tmk_core/common/print.h | 291 | ||||
-rw-r--r-- | tmk_core/common/printf.c | 27 | ||||
-rw-r--r-- | tmk_core/common/progmem.h | 1 | ||||
-rw-r--r-- | tmk_core/common/sendchar.h | 2 |
13 files changed, 215 insertions, 252 deletions
diff --git a/tmk_core/common/print.c b/tmk_core/common/arm_atsam/_print.h index 07aef0b0eb..a774f5d8d2 100644 --- a/tmk_core/common/print.c +++ b/tmk_core/common/arm_atsam/_print.h @@ -1,4 +1,4 @@ -/* Copyright 2012,2013 Jun Wako <wakojun@gmail.com> */ +/* Copyright 2012 Jun Wako <wakojun@gmail.com> */ /* 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 <stdint.h> -#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 cd7cdb52e6..2cb59706a8 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 <http://www.gnu.org/licenses/>. */ +#include "printf.h" +#include "sendchar.h" + #ifdef CONSOLE_ENABLE # include "samd51j18a.h" # include "arm_atsam_protocol.h" -# include "printf.h" # include <string.h> # include <stdarg.h> @@ -66,3 +68,5 @@ void console_printf(char *fmt, ...) { } #endif // CONSOLE_ENABLE + +void print_set_sendchar(sendchar_func_t send) {}
\ No newline at end of file diff --git a/tmk_core/common/arm_atsam/printf.mk b/tmk_core/common/arm_atsam/printf.mk new file mode 100644 index 0000000000..f70e02731f --- /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/_print.h b/tmk_core/common/avr/_print.h new file mode 100644 index 0000000000..f9b79bdf85 --- /dev/null +++ b/tmk_core/common/avr/_print.h @@ -0,0 +1,33 @@ +/* Copyright 2012 Jun Wako <wakojun@gmail.com> */ +/* 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 0000000000..9ad7a38693 --- /dev/null +++ b/tmk_core/common/avr/printf.c @@ -0,0 +1,20 @@ +/* +Copyright 2011 Jun Wako <wakojun@gmail.com> + +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 <http://www.gnu.org/licenses/>. +*/ +#include "xprintf.h" +#include "sendchar.h" + +void print_set_sendchar(sendchar_func_t func) { xdev_out(func); } diff --git a/tmk_core/common/avr/printf.mk b/tmk_core/common/avr/printf.mk new file mode 100644 index 0000000000..060ad88c57 --- /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 diff --git a/tmk_core/common/debug.c b/tmk_core/common/debug.c index bea96dfc14..ea62deaa8c 100644 --- a/tmk_core/common/debug.c +++ b/tmk_core/common/debug.c @@ -1,24 +1,25 @@ -#include <stdbool.h> -#include "debug.h" +/* +Copyright 2011 Jun Wako <wakojun@gmail.com> + +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 <http://www.gnu.org/licenses/>. +*/ +#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 + .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 a6bde9df85..299bda2c12 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 0000000000..10d2d8468d --- /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 35fcad0f40..48f91e6342 100644 --- a/tmk_core/common/print.h +++ b/tmk_core/common/print.h @@ -27,104 +27,76 @@ #include <stdint.h> #include <stdbool.h> #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(sendchar_func_t func); #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 0000000000..e8440e55ee --- /dev/null +++ b/tmk_core/common/printf.c @@ -0,0 +1,27 @@ +/* +Copyright 2011 Jun Wako <wakojun@gmail.com> + +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 <http://www.gnu.org/licenses/>. +*/ +#include <stddef.h> +#include "sendchar.h" + +// bind lib/printf to console interface - sendchar + +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); } diff --git a/tmk_core/common/progmem.h b/tmk_core/common/progmem.h index c8863d3ad2..4e4771e523 100644 --- a/tmk_core/common/progmem.h +++ b/tmk_core/common/progmem.h @@ -4,6 +4,7 @@ # include <avr/pgmspace.h> #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 b150dd464e..edcddaa6bb 100644 --- a/tmk_core/common/sendchar.h +++ b/tmk_core/common/sendchar.h @@ -23,6 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. extern "C" { #endif +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); |