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>
This commit is contained in:
Joel Challis 2021-02-14 01:44:22 +00:00 committed by GitHub
parent 72e515547a
commit 1f2fe2eab9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 224 additions and 283 deletions

View File

@ -1,5 +1,3 @@
PRINTF_PATH = $(LIB_PATH)/printf
COMMON_DIR = common COMMON_DIR = common
PLATFORM_COMMON_DIR = $(COMMON_DIR)/$(PLATFORM_KEY) 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_macro.c \
$(COMMON_DIR)/action_layer.c \ $(COMMON_DIR)/action_layer.c \
$(COMMON_DIR)/action_util.c \ $(COMMON_DIR)/action_util.c \
$(COMMON_DIR)/print.c \
$(COMMON_DIR)/debug.c \ $(COMMON_DIR)/debug.c \
$(COMMON_DIR)/sendchar_null.c \ $(COMMON_DIR)/sendchar_null.c \
$(COMMON_DIR)/eeconfig.c \ $(COMMON_DIR)/eeconfig.c \
@ -20,17 +17,11 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \
$(COMMON_DIR)/sync_timer.c \ $(COMMON_DIR)/sync_timer.c \
$(PLATFORM_COMMON_DIR)/bootloader.c \ $(PLATFORM_COMMON_DIR)/bootloader.c \
ifeq ($(PLATFORM),AVR) # Use platform provided print - fall back to lib/printf
TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/xprintf.S ifneq ("$(wildcard $(TMK_PATH)/$(PLATFORM_COMMON_DIR)/printf.mk)","")
else ifeq ($(PLATFORM),CHIBIOS) include $(TMK_PATH)/$(PLATFORM_COMMON_DIR)/printf.mk
TMK_COMMON_SRC += $(PRINTF_PATH)/printf.c else
TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_FLOAT include $(TMK_PATH)/$(COMMON_DIR)/lib_printf.mk
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 endif
# Option modules # Option modules

View File

@ -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 /* Very basic print functions, intended to be used with usb_debug_only.c
* http://www.pjrc.com/teensy/ * http://www.pjrc.com/teensy/
* Copyright (c) 2008 PJRC.COM, LLC * 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 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#pragma once
#include <stdint.h> #include "arm_atsam/printf.h"
#include "print.h"
#ifndef NO_PRINT // Create user & normal print defines
#define xprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__)
# if defined(__AVR__) #define print(s) xprintf(s)
#define println(s) xprintf(s "\r\n")
# define sendchar(c) xputc(c) #define uprint(s) print(s)
#define uprintln(s) println(s)
void print_set_sendchar(int8_t (*sendchar_func)(uint8_t)) { xdev_out(sendchar_func); } #define uprintf(fmt, ...) xprintf(fmt, ##__VA_ARGS__)
# 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

View File

@ -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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "printf.h"
#include "sendchar.h"
#ifdef CONSOLE_ENABLE #ifdef CONSOLE_ENABLE
# include "samd51j18a.h" # include "samd51j18a.h"
# include "arm_atsam_protocol.h" # include "arm_atsam_protocol.h"
# include "printf.h"
# include <string.h> # include <string.h>
# include <stdarg.h> # include <stdarg.h>
@ -66,3 +68,5 @@ void console_printf(char *fmt, ...) {
} }
#endif // CONSOLE_ENABLE #endif // CONSOLE_ENABLE
void print_set_sendchar(sendchar_func_t send) {}

View File

@ -0,0 +1 @@
TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/printf.c

View File

@ -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__)

View File

@ -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); }

View File

@ -0,0 +1,2 @@
TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/xprintf.S
TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/printf.c

View File

@ -1,24 +1,25 @@
#include <stdbool.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.
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" #include "debug.h"
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
debug_config_t debug_config = { debug_config_t debug_config = {
/* GCC Bug 10676 - Using unnamed fields in initializers .enable = false, //
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10676 */ .matrix = false, //
#if GCC_VERSION >= 40600 .keyboard = false, //
.enable = false, .mouse = false, //
.matrix = false, .reserved = 0 //
.keyboard = false,
.mouse = false,
.reserved = 0
#else
{
false, // .enable
false, // .matrix
false, // .keyboard
false, // .mouse
0 // .reserved
}
#endif
}; };

View File

@ -229,6 +229,7 @@ void keyboard_setup(void) {
#ifndef NO_JTAG_DISABLE #ifndef NO_JTAG_DISABLE
disable_jtag(); disable_jtag();
#endif #endif
print_set_sendchar(sendchar);
matrix_setup(); matrix_setup();
keyboard_pre_init_kb(); keyboard_pre_init_kb();
} }

View File

@ -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)

View File

@ -27,104 +27,76 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include "util.h" #include "util.h"
#include "sendchar.h"
#include "progmem.h"
#if defined(PROTOCOL_CHIBIOS) || defined(PROTOCOL_ARM_ATSAM) void print_set_sendchar(sendchar_func_t func);
# define PSTR(x) x
#endif
#ifndef NO_PRINT #ifndef NO_PRINT
# if __has_include_next("_print.h")
# if defined(__AVR__) /* __AVR__ */ # include_next "_print.h" /* Include the platforms print.h */
# else
# include "avr/xprintf.h" // Fall back to lib/printf
# 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 */
# include "printf.h" // lib/printf/printf.h # 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 // Create user & normal print defines
# define print(s) printf(s) # define print(s) printf(s)
# define println(s) printf(s "\r\n") # define println(s) printf(s "\r\n")
# define xprintf printf # define xprintf printf
# define uprint(s) printf(s) # define uprint(s) printf(s)
# define uprintln(s) printf(s "\r\n") # define uprintln(s) printf(s "\r\n")
# define uprintf printf # define uprintf printf
# endif /* USER_PRINT / NORMAL PRINT */
# elif defined(PROTOCOL_ARM_ATSAM) /* PROTOCOL_ARM_ATSAM */
# include "arm_atsam/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 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 */
# endif /* __AVR__ / PROTOCOL_CHIBIOS / PROTOCOL_ARM_ATSAM */ # 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)
#endif /* NO_PRINT */
#ifdef USER_PRINT
// Remove normal print defines
# undef print
# undef println
# undef xprintf
# define print(s)
# define println(s)
# define xprintf(fmt, ...)
#endif
#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 // 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 // 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). // print (and store their wasteful strings).
// //
// !!! DO NOT USE USER PRINT CALLS IN THE BODY OF QMK/TMK !!! // !!! 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)
/* 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))
# endif /* USER_PRINT / NORMAL_PRINT */
// User Print
/* decimal */ /* decimal */
# define uprint_dec(i) uprintf("%u", i) #define uprint_dec(i) uprintf("%u", i)
# define uprint_decs(i) uprintf("%d", i) #define uprint_decs(i) uprintf("%d", i)
/* hex */ /* hex */
# define uprint_hex4(i) uprintf("%X", i) #define uprint_hex4(i) uprintf("%X", i)
# define uprint_hex8(i) uprintf("%02X", i) #define uprint_hex8(i) uprintf("%02X", i)
# define uprint_hex16(i) uprintf("%04X", i) #define uprint_hex16(i) uprintf("%04X", i)
# define uprint_hex32(i) uprintf("%08lX", i) #define uprint_hex32(i) uprintf("%08lX", i)
/* binary */ /* binary */
# define uprint_bin4(i) uprintf("%04b", i) #define uprint_bin4(i) uprintf("%04b", i)
# define uprint_bin8(i) uprintf("%08b", i) #define uprint_bin8(i) uprintf("%08b", i)
# define uprint_bin16(i) uprintf("%016b", i) #define uprint_bin16(i) uprintf("%016b", i)
# define uprint_bin32(i) uprintf("%032lb", i) #define uprint_bin32(i) uprintf("%032lb", i)
# define uprint_bin_reverse8(i) uprintf("%08b", bitrev(i)) #define uprint_bin_reverse8(i) uprintf("%08b", bitrev(i))
# define uprint_bin_reverse16(i) uprintf("%016b", bitrev16(i)) #define uprint_bin_reverse16(i) uprintf("%016b", bitrev16(i))
# define uprint_bin_reverse32(i) uprintf("%032lb", bitrev32(i)) #define uprint_bin_reverse32(i) uprintf("%032lb", bitrev32(i))
/* print value utility */ /* print value utility */
# define uprint_val_dec(v) uprintf(# v ": %u\n", v) #define uprint_val_dec(v) uprintf(#v ": %u\n", v)
# define uprint_val_decs(v) uprintf(# v ": %d\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_hex8(v) uprintf(#v ": %X\n", v)
# define uprint_val_hex16(v) uprintf(# v ": %02X\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_hex32(v) uprintf(#v ": %04lX\n", v)
# define uprint_val_bin8(v) uprintf(# v ": %08b\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_bin16(v) uprintf(#v ": %016b\n", v)
# define uprint_val_bin32(v) uprintf(# v ": %032lb\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_reverse8(v) uprintf(#v ": %08b\n", bitrev(v))
# define uprint_val_bin_reverse16(v) uprintf(# v ": %016b\n", bitrev16(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)) #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 */

27
tmk_core/common/printf.c Normal file
View File

@ -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); }

View File

@ -4,6 +4,7 @@
# include <avr/pgmspace.h> # include <avr/pgmspace.h>
#else #else
# define PROGMEM # define PROGMEM
# define PSTR(x) x
# define PGM_P const char* # define PGM_P const char*
# define memcpy_P(dest, src, n) memcpy(dest, src, n) # define memcpy_P(dest, src, n) memcpy(dest, src, n)
# define pgm_read_byte(address_short) *((uint8_t*)(address_short)) # define pgm_read_byte(address_short) *((uint8_t*)(address_short))

View File

@ -23,6 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern "C" { extern "C" {
#endif #endif
typedef int8_t (*sendchar_func_t)(uint8_t c);
/* transmit a character. return 0 on success, -1 on error. */ /* transmit a character. return 0 on success, -1 on error. */
int8_t sendchar(uint8_t c); int8_t sendchar(uint8_t c);

View File

@ -953,15 +953,8 @@ void console_task(void) {
} while (size > 0); } while (size > 0);
} }
#else /* CONSOLE_ENABLE */
int8_t sendchar(uint8_t c) {
(void)c;
return 0;
}
#endif /* CONSOLE_ENABLE */ #endif /* CONSOLE_ENABLE */
void _putchar(char character) { sendchar(character); }
#ifdef RAW_ENABLE #ifdef RAW_ENABLE
void raw_hid_send(uint8_t *data, uint8_t length) { void raw_hid_send(uint8_t *data, uint8_t length) {
// TODO: implement variable size packet // TODO: implement variable size packet

View File

@ -1025,7 +1025,6 @@ static void setup_usb(void) {
// for Console_Task // for Console_Task
USB_Device_EnableSOFEvents(); USB_Device_EnableSOFEvents();
print_set_sendchar(sendchar);
} }
/** \brief Main /** \brief Main

View File

@ -74,12 +74,7 @@ static void usb_remote_wakeup(void) {
* *
* FIXME: Needs doc * FIXME: Needs doc
*/ */
static void setup_usb(void) { static void setup_usb(void) { initForUsbConnectivity(); }
initForUsbConnectivity();
// for Console_Task
print_set_sendchar(sendchar);
}
/** \brief Main /** \brief Main
* *