[Core] Update mpaland/printf to eyalroz/printf fork (#16163)

mpaland printf implementation was abandoned in ~2019 and the fork by
eyalroz is now regarded to be the goto replacement of it. So this commit
incoporates the changes needed to use this fork in QMK.

Note that pointer ptrdiff_t is always supported since commit
51c90f93a97fdaef895783ecbe24569be0db7cb8
master
Stefan Kerkmann 2022-07-07 09:27:50 +02:00 committed by GitHub
parent 8f086faf8a
commit d9bb189e25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 61 additions and 39 deletions

View File

@ -38,11 +38,11 @@ CREATE_MAP := no
VPATH += \ VPATH += \
$(LIB_PATH)/googletest \ $(LIB_PATH)/googletest \
$(LIB_PATH)/googlemock \ $(LIB_PATH)/googlemock \
$(LIB_PATH)/printf $(COMMON_VPATH) \
$(TEST_PATH)
all: elf all: elf
VPATH += $(TEST_PATH) $(COMMON_VPATH)
PLATFORM:=TEST PLATFORM:=TEST
PLATFORM_KEY:=test PLATFORM_KEY:=test
BOOTLOADER_TYPE:=none BOOTLOADER_TYPE:=none
@ -64,6 +64,7 @@ include $(QUANTUM_PATH)/debounce/tests/rules.mk
include $(QUANTUM_PATH)/encoder/tests/rules.mk include $(QUANTUM_PATH)/encoder/tests/rules.mk
include $(QUANTUM_PATH)/sequencer/tests/rules.mk include $(QUANTUM_PATH)/sequencer/tests/rules.mk
include $(QUANTUM_PATH)/wear_leveling/tests/rules.mk include $(QUANTUM_PATH)/wear_leveling/tests/rules.mk
include $(QUANTUM_PATH)/logging/print.mk
include $(PLATFORM_PATH)/test/rules.mk include $(PLATFORM_PATH)/test/rules.mk
ifneq ($(filter $(FULL_TESTS),$(TEST)),) ifneq ($(filter $(FULL_TESTS),$(TEST)),)
include $(BUILDDEFS_PATH)/build_full_test.mk include $(BUILDDEFS_PATH)/build_full_test.mk
@ -71,7 +72,6 @@ endif
$(TEST)_SRC += \ $(TEST)_SRC += \
tests/test_common/main.c \ tests/test_common/main.c \
$(LIB_PATH)/printf/printf.c \
$(QUANTUM_PATH)/logging/print.c $(QUANTUM_PATH)/logging/print.c
$(TEST_OBJ)/$(TEST)_SRC := $($(TEST)_SRC) $(TEST_OBJ)/$(TEST)_SRC := $($(TEST)_SRC)

@ -1 +1 @@
Subproject commit d3b984684bb8a8bdc48cc7a1abecb93ce59bbe3e Subproject commit c2e3b4e10d281e7f0f694d3ecbd9f320977288cc

View File

@ -24,6 +24,7 @@ COMPILEFLAGS += -fno-strict-aliasing
COMPILEFLAGS += -mfloat-abi=hard COMPILEFLAGS += -mfloat-abi=hard
COMPILEFLAGS += -mfpu=fpv4-sp-d16 COMPILEFLAGS += -mfpu=fpv4-sp-d16
COMPILEFLAGS += -mthumb COMPILEFLAGS += -mthumb
COMPILEFLAGS += -fno-builtin-printf
#ALLOW_WARNINGS = yes #ALLOW_WARNINGS = yes

View File

@ -24,6 +24,7 @@ COMPILEFLAGS += -fdata-sections
COMPILEFLAGS += -fpack-struct COMPILEFLAGS += -fpack-struct
COMPILEFLAGS += -fshort-enums COMPILEFLAGS += -fshort-enums
COMPILEFLAGS += -mcall-prologues COMPILEFLAGS += -mcall-prologues
COMPILEFLAGS += -fno-builtin-printf
# Linker relaxation is only possible if # Linker relaxation is only possible if
# link time optimizations are not enabled. # link time optimizations are not enabled.

View File

@ -349,7 +349,8 @@ SHARED_CFLAGS = -fomit-frame-pointer \
-ffunction-sections \ -ffunction-sections \
-fdata-sections \ -fdata-sections \
-fno-common \ -fno-common \
-fshort-wchar -fshort-wchar \
-fno-builtin-printf
LDSCRIPT_PATH := $(shell dirname "$(LDSCRIPT)") LDSCRIPT_PATH := $(shell dirname "$(LDSCRIPT)")

View File

@ -28,6 +28,6 @@ void print_set_sendchar(sendchar_func_t send) {
func = send; func = send;
} }
void _putchar(char character) { void putchar_(char character) {
func(character); func(character);
} }

View File

@ -32,6 +32,22 @@
void print_set_sendchar(sendchar_func_t func); void print_set_sendchar(sendchar_func_t func);
/**
* @brief This macro suppress format warnings for the function that is passed
* in. The main use-case is that `b` format specifier for printing binary
* numbers is not in the official C standard. Inclusion is planned for the
* upcoming C2X C standard, but until then GCC will always output a warning for
* a unknown format specifier.
*/
#define IGNORE_FORMAT_WARNING(func) \
do { \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Wformat\""); \
_Pragma("GCC diagnostic ignored \"-Wformat-extra-args\""); \
func; \
_Pragma("GCC diagnostic pop"); \
} while (0)
#ifndef NO_PRINT #ifndef NO_PRINT
# if __has_include_next("_print.h") # if __has_include_next("_print.h")
# include_next "_print.h" /* Include the platforms print.h */ # include_next "_print.h" /* Include the platforms print.h */
@ -78,25 +94,25 @@ void print_set_sendchar(sendchar_func_t func);
#define print_hex16(i) xprintf("%04X", i) #define print_hex16(i) xprintf("%04X", i)
#define print_hex32(i) xprintf("%08lX", i) #define print_hex32(i) xprintf("%08lX", i)
/* binary */ /* binary */
#define print_bin4(i) xprintf("%04b", i) #define print_bin4(i) IGNORE_FORMAT_WARNING(xprintf("%04b", i))
#define print_bin8(i) xprintf("%08b", i) #define print_bin8(i) IGNORE_FORMAT_WARNING(xprintf("%08b", i))
#define print_bin16(i) xprintf("%016b", i) #define print_bin16(i) IGNORE_FORMAT_WARNING(xprintf("%016b", i))
#define print_bin32(i) xprintf("%032lb", i) #define print_bin32(i) IGNORE_FORMAT_WARNING(xprintf("%032lb", i))
#define print_bin_reverse8(i) xprintf("%08b", bitrev(i)) #define print_bin_reverse8(i) IGNORE_FORMAT_WARNING(xprintf("%08b", bitrev(i)))
#define print_bin_reverse16(i) xprintf("%016b", bitrev16(i)) #define print_bin_reverse16(i) IGNORE_FORMAT_WARNING(xprintf("%016b", bitrev16(i)))
#define print_bin_reverse32(i) xprintf("%032lb", bitrev32(i)) #define print_bin_reverse32(i) IGNORE_FORMAT_WARNINGxprintf("%032lb", bitrev32(i)))
/* print value utility */ /* print value utility */
#define print_val_dec(v) xprintf(#v ": %u\n", v) #define print_val_dec(v) xprintf(#v ": %u\n", v)
#define print_val_decs(v) xprintf(#v ": %d\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_hex8(v) xprintf(#v ": %X\n", v)
#define print_val_hex16(v) xprintf(#v ": %02X\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_hex32(v) xprintf(#v ": %04lX\n", v)
#define print_val_bin8(v) xprintf(#v ": %08b\n", v) #define print_val_bin8(v) IGNORE_FORMAT_WARNING(xprintf(#v ": %08b\n", v))
#define print_val_bin16(v) xprintf(#v ": %016b\n", v) #define print_val_bin16(v) IGNORE_FORMAT_WARNING(xprintf(#v ": %016b\n", v))
#define print_val_bin32(v) xprintf(#v ": %032lb\n", v) #define print_val_bin32(v) IGNORE_FORMAT_WARNING(xprintf(#v ": %032lb\n", v))
#define print_val_bin_reverse8(v) xprintf(#v ": %08b\n", bitrev(v)) #define print_val_bin_reverse8(v) IGNORE_FORMAT_WARNING(xprintf(#v ": %08b\n", bitrev(v)))
#define print_val_bin_reverse16(v) xprintf(#v ": %016b\n", bitrev16(v)) #define print_val_bin_reverse16(v) IGNORE_FORMAT_WARNING(xprintf(#v ": %016b\n", bitrev16(v)))
#define print_val_bin_reverse32(v) xprintf(#v ": %032lb\n", bitrev32(v)) #define print_val_bin_reverse32(v) IGNORE_FORMAT_WARNING(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
@ -114,22 +130,22 @@ void print_set_sendchar(sendchar_func_t func);
#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) IGNORE_FORMAT_WARNING(uprintf("%04b", i))
#define uprint_bin8(i) uprintf("%08b", i) #define uprint_bin8(i) IGNORE_FORMAT_WARNING(uprintf("%08b", i))
#define uprint_bin16(i) uprintf("%016b", i) #define uprint_bin16(i) IGNORE_FORMAT_WARNING(uprintf("%016b", i))
#define uprint_bin32(i) uprintf("%032lb", i) #define uprint_bin32(i) IGNORE_FORMAT_WARNING(uprintf("%032lb", i))
#define uprint_bin_reverse8(i) uprintf("%08b", bitrev(i)) #define uprint_bin_reverse8(i) IGNORE_FORMAT_WARNING(uprintf("%08b", bitrev(i)))
#define uprint_bin_reverse16(i) uprintf("%016b", bitrev16(i)) #define uprint_bin_reverse16(i) IGNORE_FORMAT_WARNING(uprintf("%016b", bitrev16(i)))
#define uprint_bin_reverse32(i) uprintf("%032lb", bitrev32(i)) #define uprint_bin_reverse32(i) IGNORE_FORMAT_WARNING(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) IGNORE_FORMAT_WARNING(uprintf(#v ": %08b\n", v))
#define uprint_val_bin16(v) uprintf(#v ": %016b\n", v) #define uprint_val_bin16(v) IGNORE_FORMAT_WARNING(uprintf(#v ": %016b\n", v))
#define uprint_val_bin32(v) uprintf(#v ": %032lb\n", v) #define uprint_val_bin32(v) IGNORE_FORMAT_WARNING(uprintf(#v ": %032lb\n", v))
#define uprint_val_bin_reverse8(v) uprintf(#v ": %08b\n", bitrev(v)) #define uprint_val_bin_reverse8(v) IGNORE_FORMAT_WARNING(uprintf(#v ": %08b\n", bitrev(v)))
#define uprint_val_bin_reverse16(v) uprintf(#v ": %016b\n", bitrev16(v)) #define uprint_val_bin_reverse16(v) IGNORE_FORMAT_WARNING(uprintf(#v ": %016b\n", bitrev16(v)))
#define uprint_val_bin_reverse32(v) uprintf(#v ": %032lb\n", bitrev32(v)) #define uprint_val_bin_reverse32(v) IGNORE_FORMAT_WARNING(uprintf(#v ": %032lb\n", bitrev32(v)))

View File

@ -1,9 +1,12 @@
PRINTF_PATH = $(LIB_PATH)/printf PRINTF_PATH = $(LIB_PATH)/printf/src
VPATH += $(PRINTF_PATH) VPATH += $(PRINTF_PATH) $(PRINTF_PATH)/printf
SRC += $(PRINTF_PATH)/printf.c SRC += printf.c
QUANTUM_SRC +=$(QUANTUM_DIR)/logging/print.c QUANTUM_SRC +=$(QUANTUM_DIR)/logging/print.c
OPT_DEFS += -DPRINTF_DISABLE_SUPPORT_FLOAT
OPT_DEFS += -DPRINTF_DISABLE_SUPPORT_EXPONENTIAL OPT_DEFS += -DPRINTF_SUPPORT_DECIMAL_SPECIFIERS=0
OPT_DEFS += -DPRINTF_DISABLE_SUPPORT_LONG_LONG OPT_DEFS += -DPRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS=0
OPT_DEFS += -DPRINTF_DISABLE_SUPPORT_PTRDIFF_T OPT_DEFS += -DPRINTF_SUPPORT_LONG_LONG=0
OPT_DEFS += -DPRINTF_SUPPORT_WRITEBACK_SPECIFIER=0
OPT_DEFS += -DSUPPORT_MSVC_STYLE_INTEGER_SPECIFIERS=0
OPT_DEFS += -DPRINTF_ALIAS_STANDARD_FUNCTION_NAMES=1