summaryrefslogtreecommitdiff
path: root/quantum/logging
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-08-03 18:49:33 +0100
committerGitHub <noreply@github.com>2021-08-03 18:49:33 +0100
commit34de7ca224d613e1ae19a45860e27c15d40254dd (patch)
tree3176aa05dd5175ae1a7a56b5b881fc89c1aa18ef /quantum/logging
parent3f419dc872d3ab61d129c644e114f62fd738e9d6 (diff)
Move print/debug files to quantum (#12069)
* move print/debug files to quantum * Update comments
Diffstat (limited to 'quantum/logging')
-rw-r--r--quantum/logging/debug.c25
-rw-r--r--quantum/logging/debug.h169
-rw-r--r--quantum/logging/nodebug.h26
-rw-r--r--quantum/logging/print.c27
-rw-r--r--quantum/logging/print.h135
-rw-r--r--quantum/logging/print.mk9
-rw-r--r--quantum/logging/sendchar.c20
-rw-r--r--quantum/logging/sendchar.h33
8 files changed, 444 insertions, 0 deletions
diff --git a/quantum/logging/debug.c b/quantum/logging/debug.c
new file mode 100644
index 0000000000..ea62deaa8c
--- /dev/null
+++ b/quantum/logging/debug.c
@@ -0,0 +1,25 @@
+/*
+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"
+
+debug_config_t debug_config = {
+ .enable = false, //
+ .matrix = false, //
+ .keyboard = false, //
+ .mouse = false, //
+ .reserved = 0 //
+};
diff --git a/quantum/logging/debug.h b/quantum/logging/debug.h
new file mode 100644
index 0000000000..8415310356
--- /dev/null
+++ b/quantum/logging/debug.h
@@ -0,0 +1,169 @@
+/*
+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/>.
+*/
+
+#pragma once
+
+#include <stdbool.h>
+#include "print.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Debug output control
+ */
+typedef union {
+ struct {
+ bool enable : 1;
+ bool matrix : 1;
+ bool keyboard : 1;
+ bool mouse : 1;
+ uint8_t reserved : 4;
+ };
+ uint8_t raw;
+} debug_config_t;
+
+extern debug_config_t debug_config;
+
+#ifdef __cplusplus
+}
+#endif
+
+/* for backward compatibility */
+#define debug_enable (debug_config.enable)
+#define debug_matrix (debug_config.matrix)
+#define debug_keyboard (debug_config.keyboard)
+#define debug_mouse (debug_config.mouse)
+
+/*
+ * Debug print utils
+ */
+#ifndef NO_DEBUG
+
+# define dprint(s) \
+ do { \
+ if (debug_enable) print(s); \
+ } while (0)
+# define dprintln(s) \
+ do { \
+ if (debug_enable) println(s); \
+ } while (0)
+# define dprintf(fmt, ...) \
+ do { \
+ if (debug_enable) xprintf(fmt, ##__VA_ARGS__); \
+ } while (0)
+# define dmsg(s) dprintf("%s at %d: %s\n", __FILE__, __LINE__, s)
+
+/* Deprecated. DO NOT USE these anymore, use dprintf instead. */
+# define debug(s) \
+ do { \
+ if (debug_enable) print(s); \
+ } while (0)
+# define debugln(s) \
+ do { \
+ if (debug_enable) println(s); \
+ } while (0)
+# define debug_msg(s) \
+ do { \
+ if (debug_enable) { \
+ print(__FILE__); \
+ print(" at "); \
+ print_dec(__LINE__); \
+ print(" in "); \
+ print(": "); \
+ print(s); \
+ } \
+ } while (0)
+# define debug_dec(data) \
+ do { \
+ if (debug_enable) print_dec(data); \
+ } while (0)
+# define debug_decs(data) \
+ do { \
+ if (debug_enable) print_decs(data); \
+ } while (0)
+# define debug_hex4(data) \
+ do { \
+ if (debug_enable) print_hex4(data); \
+ } while (0)
+# define debug_hex8(data) \
+ do { \
+ if (debug_enable) print_hex8(data); \
+ } while (0)
+# define debug_hex16(data) \
+ do { \
+ if (debug_enable) print_hex16(data); \
+ } while (0)
+# define debug_hex32(data) \
+ do { \
+ if (debug_enable) print_hex32(data); \
+ } while (0)
+# define debug_bin8(data) \
+ do { \
+ if (debug_enable) print_bin8(data); \
+ } while (0)
+# define debug_bin16(data) \
+ do { \
+ if (debug_enable) print_bin16(data); \
+ } while (0)
+# define debug_bin32(data) \
+ do { \
+ if (debug_enable) print_bin32(data); \
+ } while (0)
+# define debug_bin_reverse8(data) \
+ do { \
+ if (debug_enable) print_bin_reverse8(data); \
+ } while (0)
+# define debug_bin_reverse16(data) \
+ do { \
+ if (debug_enable) print_bin_reverse16(data); \
+ } while (0)
+# define debug_bin_reverse32(data) \
+ do { \
+ if (debug_enable) print_bin_reverse32(data); \
+ } while (0)
+# define debug_hex(data) debug_hex8(data)
+# define debug_bin(data) debug_bin8(data)
+# define debug_bin_reverse(data) debug_bin8(data)
+
+#else /* NO_DEBUG */
+
+# define dprint(s)
+# define dprintln(s)
+# define dprintf(fmt, ...)
+# define dmsg(s)
+# define debug(s)
+# define debugln(s)
+# define debug_msg(s)
+# define debug_dec(data)
+# define debug_decs(data)
+# define debug_hex4(data)
+# define debug_hex8(data)
+# define debug_hex16(data)
+# define debug_hex32(data)
+# define debug_bin8(data)
+# define debug_bin16(data)
+# define debug_bin32(data)
+# define debug_bin_reverse8(data)
+# define debug_bin_reverse16(data)
+# define debug_bin_reverse32(data)
+# define debug_hex(data)
+# define debug_bin(data)
+# define debug_bin_reverse(data)
+
+#endif /* NO_DEBUG */
diff --git a/quantum/logging/nodebug.h b/quantum/logging/nodebug.h
new file mode 100644
index 0000000000..0b176684bd
--- /dev/null
+++ b/quantum/logging/nodebug.h
@@ -0,0 +1,26 @@
+/*
+Copyright 2013 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/>.
+*/
+
+#pragma once
+
+#ifndef NO_DEBUG
+# define NO_DEBUG
+# include "debug.h"
+# undef NO_DEBUG
+#else
+# include "debug.h"
+#endif
diff --git a/quantum/logging/print.c b/quantum/logging/print.c
new file mode 100644
index 0000000000..e8440e55ee
--- /dev/null
+++ b/quantum/logging/print.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/quantum/logging/print.h b/quantum/logging/print.h
new file mode 100644
index 0000000000..8c055f549e
--- /dev/null
+++ b/quantum/logging/print.h
@@ -0,0 +1,135 @@
+/* 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 <stdint.h>
+#include <stdbool.h>
+#include "util.h"
+#include "sendchar.h"
+#include "progmem.h"
+
+void print_set_sendchar(sendchar_func_t func);
+
+#ifndef NO_PRINT
+# 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
+
+// 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 /* __has_include_next("_print.h") */
+#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
+// is meant as a lightweight alternative to NOPRINT. Use it when you only want to do
+// a spot of debugging but lack flash resources for allowing all of the codebase to
+// print (and store their wasteful strings).
+//
+// !!! DO NOT USE USER PRINT CALLS IN THE BODY OF QMK/TMK !!!
+
+/* 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))
diff --git a/quantum/logging/print.mk b/quantum/logging/print.mk
new file mode 100644
index 0000000000..67c004192d
--- /dev/null
+++ b/quantum/logging/print.mk
@@ -0,0 +1,9 @@
+PRINTF_PATH = $(LIB_PATH)/printf
+
+VPATH += $(PRINTF_PATH)
+SRC += $(PRINTF_PATH)/printf.c
+QUANTUM_SRC +=$(QUANTUM_DIR)/logging/print.c
+OPT_DEFS += -DPRINTF_DISABLE_SUPPORT_FLOAT
+OPT_DEFS += -DPRINTF_DISABLE_SUPPORT_EXPONENTIAL
+OPT_DEFS += -DPRINTF_DISABLE_SUPPORT_LONG_LONG
+OPT_DEFS += -DPRINTF_DISABLE_SUPPORT_PTRDIFF_T
diff --git a/quantum/logging/sendchar.c b/quantum/logging/sendchar.c
new file mode 100644
index 0000000000..9422382f6f
--- /dev/null
+++ b/quantum/logging/sendchar.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 "sendchar.h"
+
+/* default noop "null" implementation */
+__attribute__((weak)) int8_t sendchar(uint8_t c) { return 0; }
diff --git a/quantum/logging/sendchar.h b/quantum/logging/sendchar.h
new file mode 100644
index 0000000000..edcddaa6bb
--- /dev/null
+++ b/quantum/logging/sendchar.h
@@ -0,0 +1,33 @@
+/*
+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/>.
+*/
+
+#pragma once
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+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);
+
+#ifdef __cplusplus
+}
+#endif