Browse Source

Fix `USER_PRINT` stripping out `uprintf` (#25919)

Joel Challis 3 months ago
parent
commit
1a56fbece2
2 changed files with 29 additions and 19 deletions
  1. 6 0
      platforms/avr/_print.h
  2. 23 19
      quantum/logging/print.h

+ 6 - 0
platforms/avr/_print.h

@@ -24,3 +24,9 @@
 #pragma once
 
 #include "avr/xprintf.h"
+
+// TODO: Remove xprintf due to conflicts/assumptions on direct library usage
+#undef xprintf
+
+// Export main print function
+#define print_printf(fmt, ...) __xprintf(PSTR(fmt), ##__VA_ARGS__)

+ 23 - 19
quantum/logging/print.h

@@ -30,8 +30,26 @@
 #include "sendchar.h"
 #include "progmem.h"
 
+/**
+ * @brief Configure the destination for routing all log data to.
+ */
 void print_set_sendchar(sendchar_func_t func);
 
+/**
+ * @def print_printf(fmt, ...)
+ * @brief Low-level logging entrypoint - should not be called directly
+ */
+#ifndef NO_PRINT
+#    if __has_include_next("_print.h")
+#        include_next "_print.h" // Include the platforms print.h - must export print_printf
+#    else
+#        include "printf.h" // Fall back to lib/printf/printf.h
+#        define print_printf printf
+#    endif
+#else
+#    define print_printf(fmt, ...) // Remove ALL print defines
+#endif
+
 /**
  * @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
@@ -48,26 +66,10 @@ void print_set_sendchar(sendchar_func_t func);
         _Pragma("GCC diagnostic pop");                             \
     } while (0)
 
-#ifndef NO_PRINT
-#    if __has_include_next("_print.h")
-#        include_next "_print.h" /* Include the platforms print.h */
-#    else
-#        include "printf.h" // // Fall back to lib/printf/printf.h
-#        define xprintf printf
-#    endif
-#else
-// Remove print defines
-#    undef xprintf
-#    define xprintf(fmt, ...)
-#endif
-
-// Resolve before USER_PRINT can remove
-#define uprintf xprintf
-
 #ifdef USER_PRINT
-// Remove normal print defines
-#    undef xprintf
-#    define xprintf(fmt, ...)
+#    define xprintf(fmt, ...) // Remove normal print defines
+#else
+#    define xprintf print_printf
 #endif
 
 #define print(s) xprintf(s)
@@ -108,6 +110,8 @@ void print_set_sendchar(sendchar_func_t func);
 //
 // !!! DO NOT USE USER PRINT CALLS IN THE BODY OF QMK/TMK !!!
 
+#define uprintf print_printf
+
 #define uprint(s) uprintf(s)
 #define uprintln(s) uprintf(s "\r\n")