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 | |
parent | 72e515547aedbfd0b91296a51a81861236be8fe5 (diff) | |
download | qmk_firmware-1f2fe2eab99548f4bde2a79b03e3303cc9b73214.tar.gz qmk_firmware-1f2fe2eab99548f4bde2a79b03e3303cc9b73214.zip |
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>
-rw-r--r-- | tmk_core/common.mk | 19 | ||||
-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 | ||||
-rw-r--r-- | tmk_core/protocol/chibios/usb_main.c | 7 | ||||
-rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 1 | ||||
-rw-r--r-- | tmk_core/protocol/vusb/main.c | 7 |
17 files changed, 221 insertions, 280 deletions
diff --git a/tmk_core/common.mk b/tmk_core/common.mk index 3cf3edde3..238b3c69f 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk | |||
@@ -1,5 +1,3 @@ | |||
1 | PRINTF_PATH = $(LIB_PATH)/printf | ||
2 | |||
3 | COMMON_DIR = common | 1 | COMMON_DIR = common |
4 | PLATFORM_COMMON_DIR = $(COMMON_DIR)/$(PLATFORM_KEY) | 2 | PLATFORM_COMMON_DIR = $(COMMON_DIR)/$(PLATFORM_KEY) |
5 | 3 | ||
@@ -10,7 +8,6 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \ | |||
10 | $(COMMON_DIR)/action_macro.c \ | 8 | $(COMMON_DIR)/action_macro.c \ |
11 | $(COMMON_DIR)/action_layer.c \ | 9 | $(COMMON_DIR)/action_layer.c \ |
12 | $(COMMON_DIR)/action_util.c \ | 10 | $(COMMON_DIR)/action_util.c \ |
13 | $(COMMON_DIR)/print.c \ | ||
14 | $(COMMON_DIR)/debug.c \ | 11 | $(COMMON_DIR)/debug.c \ |
15 | $(COMMON_DIR)/sendchar_null.c \ | 12 | $(COMMON_DIR)/sendchar_null.c \ |
16 | $(COMMON_DIR)/eeconfig.c \ | 13 | $(COMMON_DIR)/eeconfig.c \ |
@@ -20,17 +17,11 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \ | |||
20 | $(COMMON_DIR)/sync_timer.c \ | 17 | $(COMMON_DIR)/sync_timer.c \ |
21 | $(PLATFORM_COMMON_DIR)/bootloader.c \ | 18 | $(PLATFORM_COMMON_DIR)/bootloader.c \ |
22 | 19 | ||
23 | ifeq ($(PLATFORM),AVR) | 20 | # Use platform provided print - fall back to lib/printf |
24 | TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/xprintf.S | 21 | ifneq ("$(wildcard $(TMK_PATH)/$(PLATFORM_COMMON_DIR)/printf.mk)","") |
25 | else ifeq ($(PLATFORM),CHIBIOS) | 22 | include $(TMK_PATH)/$(PLATFORM_COMMON_DIR)/printf.mk |
26 | TMK_COMMON_SRC += $(PRINTF_PATH)/printf.c | 23 | else |
27 | TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_FLOAT | 24 | include $(TMK_PATH)/$(COMMON_DIR)/lib_printf.mk |
28 | TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_EXPONENTIAL | ||
29 | TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_LONG_LONG | ||
30 | TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_PTRDIFF_T | ||
31 | VPATH += $(PRINTF_PATH) | ||
32 | else ifeq ($(PLATFORM),ARM_ATSAM) | ||
33 | TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/printf.c | ||
34 | endif | 25 | endif |
35 | 26 | ||
36 | # Option modules | 27 | # Option modules |
diff --git a/tmk_core/common/print.c b/tmk_core/common/arm_atsam/_print.h index 07aef0b0e..a774f5d8d 100644 --- a/tmk_core/common/print.c +++ b/tmk_core/common/arm_atsam/_print.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* Copyright 2012,2013 Jun Wako <wakojun@gmail.com> */ | 1 | /* Copyright 2012 Jun Wako <wakojun@gmail.com> */ |
2 | /* Very basic print functions, intended to be used with usb_debug_only.c | 2 | /* Very basic print functions, intended to be used with usb_debug_only.c |
3 | * http://www.pjrc.com/teensy/ | 3 | * http://www.pjrc.com/teensy/ |
4 | * Copyright (c) 2008 PJRC.COM, LLC | 4 | * Copyright (c) 2008 PJRC.COM, LLC |
@@ -21,27 +21,14 @@ | |||
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | * THE SOFTWARE. | 22 | * THE SOFTWARE. |
23 | */ | 23 | */ |
24 | #pragma once | ||
24 | 25 | ||
25 | #include <stdint.h> | 26 | #include "arm_atsam/printf.h" |
26 | #include "print.h" | ||
27 | 27 | ||
28 | #ifndef NO_PRINT | 28 | // Create user & normal print defines |
29 | 29 | #define xprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) | |
30 | # if defined(__AVR__) | 30 | #define print(s) xprintf(s) |
31 | 31 | #define println(s) xprintf(s "\r\n") | |
32 | # define sendchar(c) xputc(c) | 32 | #define uprint(s) print(s) |
33 | 33 | #define uprintln(s) println(s) | |
34 | void print_set_sendchar(int8_t (*sendchar_func)(uint8_t)) { xdev_out(sendchar_func); } | 34 | #define uprintf(fmt, ...) xprintf(fmt, ##__VA_ARGS__) |
35 | |||
36 | # elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */ | ||
37 | |||
38 | // don't need anything extra | ||
39 | |||
40 | # elif defined(__arm__) /* __AVR__ */ | ||
41 | |||
42 | // TODO | ||
43 | // void print_set_sendchar(int8_t (*sendchar_func)(uint8_t)) { } | ||
44 | |||
45 | # endif /* __AVR__ */ | ||
46 | |||
47 | #endif | ||
diff --git a/tmk_core/common/arm_atsam/printf.c b/tmk_core/common/arm_atsam/printf.c index cd7cdb52e..2cb59706a 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 | |||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include "printf.h" | ||
19 | #include "sendchar.h" | ||
20 | |||
18 | #ifdef CONSOLE_ENABLE | 21 | #ifdef CONSOLE_ENABLE |
19 | 22 | ||
20 | # include "samd51j18a.h" | 23 | # include "samd51j18a.h" |
21 | # include "arm_atsam_protocol.h" | 24 | # include "arm_atsam_protocol.h" |
22 | # include "printf.h" | ||
23 | # include <string.h> | 25 | # include <string.h> |
24 | # include <stdarg.h> | 26 | # include <stdarg.h> |
25 | 27 | ||
@@ -66,3 +68,5 @@ void console_printf(char *fmt, ...) { | |||
66 | } | 68 | } |
67 | 69 | ||
68 | #endif // CONSOLE_ENABLE | 70 | #endif // CONSOLE_ENABLE |
71 | |||
72 | 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 000000000..f70e02731 --- /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 000000000..f9b79bdf8 --- /dev/null +++ b/tmk_core/common/avr/_print.h | |||
@@ -0,0 +1,33 @@ | |||
1 | /* Copyright 2012 Jun Wako <wakojun@gmail.com> */ | ||
2 | /* Very basic print functions, intended to be used with usb_debug_only.c | ||
3 | * http://www.pjrc.com/teensy/ | ||
4 | * Copyright (c) 2008 PJRC.COM, LLC | ||
5 | * | ||
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
7 | * of this software and associated documentation files (the "Software"), to deal | ||
8 | * in the Software without restriction, including without limitation the rights | ||
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
10 | * copies of the Software, and to permit persons to whom the Software is | ||
11 | * furnished to do so, subject to the following conditions: | ||
12 | * | ||
13 | * The above copyright notice and this permission notice shall be included in | ||
14 | * all copies or substantial portions of the Software. | ||
15 | * | ||
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
22 | * THE SOFTWARE. | ||
23 | */ | ||
24 | #pragma once | ||
25 | |||
26 | #include "avr/xprintf.h" | ||
27 | |||
28 | // Create user & normal print defines | ||
29 | #define print(s) xputs(PSTR(s)) | ||
30 | #define println(s) xputs(PSTR(s "\r\n")) | ||
31 | #define uprint(s) print(s) | ||
32 | #define uprintln(s) println(s) | ||
33 | #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 000000000..9ad7a3869 --- /dev/null +++ b/tmk_core/common/avr/printf.c | |||
@@ -0,0 +1,20 @@ | |||
1 | /* | ||
2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | #include "xprintf.h" | ||
18 | #include "sendchar.h" | ||
19 | |||
20 | 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 000000000..060ad88c5 --- /dev/null +++ b/tmk_core/common/avr/printf.mk | |||
@@ -0,0 +1,2 @@ | |||
1 | TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/xprintf.S | ||
2 | TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/printf.c | ||
diff --git a/tmk_core/common/debug.c b/tmk_core/common/debug.c index bea96dfc1..ea62deaa8 100644 --- a/tmk_core/common/debug.c +++ b/tmk_core/common/debug.c | |||
@@ -1,24 +1,25 @@ | |||
1 | #include <stdbool.h> | 1 | /* |
2 | #include "debug.h" | 2 | Copyright 2011 Jun Wako <wakojun@gmail.com> |
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
3 | 8 | ||
4 | #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) | 9 | This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | #include "debug.h" | ||
5 | 18 | ||
6 | debug_config_t debug_config = { | 19 | debug_config_t debug_config = { |
7 | /* GCC Bug 10676 - Using unnamed fields in initializers | 20 | .enable = false, // |
8 | * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10676 */ | 21 | .matrix = false, // |
9 | #if GCC_VERSION >= 40600 | 22 | .keyboard = false, // |
10 | .enable = false, | 23 | .mouse = false, // |
11 | .matrix = false, | 24 | .reserved = 0 // |
12 | .keyboard = false, | ||
13 | .mouse = false, | ||
14 | .reserved = 0 | ||
15 | #else | ||
16 | { | ||
17 | false, // .enable | ||
18 | false, // .matrix | ||
19 | false, // .keyboard | ||
20 | false, // .mouse | ||
21 | 0 // .reserved | ||
22 | } | ||
23 | #endif | ||
24 | }; | 25 | }; |
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c index a6bde9df8..299bda2c1 100644 --- a/tmk_core/common/keyboard.c +++ b/tmk_core/common/keyboard.c | |||
@@ -229,6 +229,7 @@ void keyboard_setup(void) { | |||
229 | #ifndef NO_JTAG_DISABLE | 229 | #ifndef NO_JTAG_DISABLE |
230 | disable_jtag(); | 230 | disable_jtag(); |
231 | #endif | 231 | #endif |
232 | print_set_sendchar(sendchar); | ||
232 | matrix_setup(); | 233 | matrix_setup(); |
233 | keyboard_pre_init_kb(); | 234 | keyboard_pre_init_kb(); |
234 | } | 235 | } |
diff --git a/tmk_core/common/lib_printf.mk b/tmk_core/common/lib_printf.mk new file mode 100644 index 000000000..10d2d8468 --- /dev/null +++ b/tmk_core/common/lib_printf.mk | |||
@@ -0,0 +1,9 @@ | |||
1 | PRINTF_PATH = $(LIB_PATH)/printf | ||
2 | |||
3 | TMK_COMMON_SRC += $(PRINTF_PATH)/printf.c | ||
4 | TMK_COMMON_SRC += $(COMMON_DIR)/printf.c | ||
5 | TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_FLOAT | ||
6 | TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_EXPONENTIAL | ||
7 | TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_LONG_LONG | ||
8 | TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_PTRDIFF_T | ||
9 | VPATH += $(PRINTF_PATH) | ||
diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h index 35fcad0f4..48f91e634 100644 --- a/tmk_core/common/print.h +++ b/tmk_core/common/print.h | |||
@@ -27,104 +27,76 @@ | |||
27 | #include <stdint.h> | 27 | #include <stdint.h> |
28 | #include <stdbool.h> | 28 | #include <stdbool.h> |
29 | #include "util.h" | 29 | #include "util.h" |
30 | #include "sendchar.h" | ||
31 | #include "progmem.h" | ||
30 | 32 | ||
31 | #if defined(PROTOCOL_CHIBIOS) || defined(PROTOCOL_ARM_ATSAM) | 33 | void print_set_sendchar(sendchar_func_t func); |
32 | # define PSTR(x) x | ||
33 | #endif | ||
34 | 34 | ||
35 | #ifndef NO_PRINT | 35 | #ifndef NO_PRINT |
36 | 36 | # if __has_include_next("_print.h") | |
37 | # if defined(__AVR__) /* __AVR__ */ | 37 | # include_next "_print.h" /* Include the platforms print.h */ |
38 | 38 | # else | |
39 | # include "avr/xprintf.h" | 39 | // Fall back to lib/printf |
40 | |||
41 | # ifdef USER_PRINT /* USER_PRINT */ | ||
42 | |||
43 | // Remove normal print defines | ||
44 | # define print(s) | ||
45 | # define println(s) | ||
46 | # undef xprintf | ||
47 | # define xprintf(fmt, ...) | ||
48 | |||
49 | // Create user print defines | ||
50 | # define uprint(s) xputs(PSTR(s)) | ||
51 | # define uprintln(s) xputs(PSTR(s "\r\n")) | ||
52 | # define uprintf(fmt, ...) __xprintf(PSTR(fmt), ##__VA_ARGS__) | ||
53 | |||
54 | # else /* NORMAL PRINT */ | ||
55 | |||
56 | // Create user & normal print defines | ||
57 | # define print(s) xputs(PSTR(s)) | ||
58 | # define println(s) xputs(PSTR(s "\r\n")) | ||
59 | # define uprint(s) print(s) | ||
60 | # define uprintln(s) println(s) | ||
61 | # define uprintf(fmt, ...) xprintf(fmt, ##__VA_ARGS__) | ||
62 | |||
63 | # endif /* USER_PRINT / NORMAL PRINT */ | ||
64 | |||
65 | # ifdef __cplusplus | ||
66 | extern "C" | ||
67 | # endif | ||
68 | |||
69 | /* function pointer of sendchar to be used by print utility */ | ||
70 | void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); | ||
71 | |||
72 | # elif defined(PROTOCOL_CHIBIOS) /* PROTOCOL_CHIBIOS */ | ||
73 | |||
74 | # include "printf.h" // lib/printf/printf.h | 40 | # include "printf.h" // lib/printf/printf.h |
75 | 41 | ||
76 | # ifdef USER_PRINT /* USER_PRINT */ | ||
77 | |||
78 | // Remove normal print defines | ||
79 | # define print(s) | ||
80 | # define println(s) | ||
81 | # define xprintf(fmt, ...) | ||
82 | |||
83 | // Create user print defines | ||
84 | # define uprint(s) printf(s) | ||
85 | # define uprintln(s) printf(s "\r\n") | ||
86 | # define uprintf printf | ||
87 | |||
88 | # else /* NORMAL PRINT */ | ||
89 | // Create user & normal print defines | 42 | // Create user & normal print defines |
90 | # define print(s) printf(s) | 43 | # define print(s) printf(s) |
91 | # define println(s) printf(s "\r\n") | 44 | # define println(s) printf(s "\r\n") |
92 | # define xprintf printf | 45 | # define xprintf printf |
93 | # define uprint(s) printf(s) | 46 | # define uprint(s) printf(s) |
94 | # define uprintln(s) printf(s "\r\n") | 47 | # define uprintln(s) printf(s "\r\n") |
95 | # define uprintf printf | 48 | # define uprintf printf |
96 | |||
97 | # endif /* USER_PRINT / NORMAL PRINT */ | ||
98 | |||
99 | # elif defined(PROTOCOL_ARM_ATSAM) /* PROTOCOL_ARM_ATSAM */ | ||
100 | 49 | ||
101 | # include "arm_atsam/printf.h" | 50 | # endif /* __AVR__ / PROTOCOL_CHIBIOS / PROTOCOL_ARM_ATSAM */ |
51 | #else /* NO_PRINT */ | ||
52 | # undef xprintf | ||
53 | // Remove print defines | ||
54 | # define print(s) | ||
55 | # define println(s) | ||
56 | # define xprintf(fmt, ...) | ||
57 | # define uprintf(fmt, ...) | ||
58 | # define uprint(s) | ||
59 | # define uprintln(s) | ||
102 | 60 | ||
103 | # ifdef USER_PRINT /* USER_PRINT */ | 61 | #endif /* NO_PRINT */ |
104 | 62 | ||
63 | #ifdef USER_PRINT | ||
105 | // Remove normal print defines | 64 | // Remove normal print defines |
106 | # define print(s) | 65 | # undef print |
107 | # define println(s) | 66 | # undef println |
108 | # define xprintf(fmt, ...) | 67 | # undef xprintf |
109 | 68 | # define print(s) | |
110 | // Create user print defines | 69 | # define println(s) |
111 | # define uprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) | 70 | # define xprintf(fmt, ...) |
112 | # define uprint(s) xprintf(s) | 71 | #endif |
113 | # define uprintln(s) xprintf(s "\r\n") | ||
114 | |||
115 | # else /* NORMAL PRINT */ | ||
116 | |||
117 | // Create user & normal print defines | ||
118 | # define xprintf(fmt, ...) __xprintf(fmt, ##__VA_ARGS__) | ||
119 | # define print(s) xprintf(s) | ||
120 | # define println(s) xprintf(s "\r\n") | ||
121 | # define uprint(s) print(s) | ||
122 | # define uprintln(s) println(s) | ||
123 | # define uprintf(fmt, ...) xprintf(fmt, ##__VA_ARGS__) | ||
124 | |||
125 | # endif /* USER_PRINT / NORMAL PRINT */ | ||
126 | 72 | ||
127 | # endif /* __AVR__ / PROTOCOL_CHIBIOS / PROTOCOL_ARM_ATSAM */ | 73 | #define print_dec(i) xprintf("%u", i) |
74 | #define print_decs(i) xprintf("%d", i) | ||
75 | /* hex */ | ||
76 | #define print_hex4(i) xprintf("%X", i) | ||
77 | #define print_hex8(i) xprintf("%02X", i) | ||
78 | #define print_hex16(i) xprintf("%04X", i) | ||
79 | #define print_hex32(i) xprintf("%08lX", i) | ||
80 | /* binary */ | ||
81 | #define print_bin4(i) xprintf("%04b", i) | ||
82 | #define print_bin8(i) xprintf("%08b", i) | ||
83 | #define print_bin16(i) xprintf("%016b", i) | ||
84 | #define print_bin32(i) xprintf("%032lb", i) | ||
85 | #define print_bin_reverse8(i) xprintf("%08b", bitrev(i)) | ||
86 | #define print_bin_reverse16(i) xprintf("%016b", bitrev16(i)) | ||
87 | #define print_bin_reverse32(i) xprintf("%032lb", bitrev32(i)) | ||
88 | /* print value utility */ | ||
89 | #define print_val_dec(v) xprintf(#v ": %u\n", v) | ||
90 | #define print_val_decs(v) xprintf(#v ": %d\n", v) | ||
91 | #define print_val_hex8(v) xprintf(#v ": %X\n", v) | ||
92 | #define print_val_hex16(v) xprintf(#v ": %02X\n", v) | ||
93 | #define print_val_hex32(v) xprintf(#v ": %04lX\n", v) | ||
94 | #define print_val_bin8(v) xprintf(#v ": %08b\n", v) | ||
95 | #define print_val_bin16(v) xprintf(#v ": %016b\n", v) | ||
96 | #define print_val_bin32(v) xprintf(#v ": %032lb\n", v) | ||
97 | #define print_val_bin_reverse8(v) xprintf(#v ": %08b\n", bitrev(v)) | ||
98 | #define print_val_bin_reverse16(v) xprintf(#v ": %016b\n", bitrev16(v)) | ||
99 | #define print_val_bin_reverse32(v) xprintf(#v ": %032lb\n", bitrev32(v)) | ||
128 | 100 | ||
129 | // User print disables the normal print messages in the body of QMK/TMK code and | 101 | // User print disables the normal print messages in the body of QMK/TMK code and |
130 | // is meant as a lightweight alternative to NOPRINT. Use it when you only want to do | 102 | // is meant as a lightweight alternative to NOPRINT. Use it when you only want to do |
@@ -132,129 +104,32 @@ extern "C" | |||
132 | // print (and store their wasteful strings). | 104 | // print (and store their wasteful strings). |
133 | // | 105 | // |
134 | // !!! DO NOT USE USER PRINT CALLS IN THE BODY OF QMK/TMK !!! | 106 | // !!! DO NOT USE USER PRINT CALLS IN THE BODY OF QMK/TMK !!! |
135 | // | ||
136 | # ifdef USER_PRINT | ||
137 | |||
138 | // Disable normal print | ||
139 | # define print_dec(data) | ||
140 | # define print_decs(data) | ||
141 | # define print_hex4(data) | ||
142 | # define print_hex8(data) | ||
143 | # define print_hex16(data) | ||
144 | # define print_hex32(data) | ||
145 | # define print_bin4(data) | ||
146 | # define print_bin8(data) | ||
147 | # define print_bin16(data) | ||
148 | # define print_bin32(data) | ||
149 | # define print_bin_reverse8(data) | ||
150 | # define print_bin_reverse16(data) | ||
151 | # define print_bin_reverse32(data) | ||
152 | # define print_val_dec(v) | ||
153 | # define print_val_decs(v) | ||
154 | # define print_val_hex8(v) | ||
155 | # define print_val_hex16(v) | ||
156 | # define print_val_hex32(v) | ||
157 | # define print_val_bin8(v) | ||
158 | # define print_val_bin16(v) | ||
159 | # define print_val_bin32(v) | ||
160 | # define print_val_bin_reverse8(v) | ||
161 | # define print_val_bin_reverse16(v) | ||
162 | # define print_val_bin_reverse32(v) | ||
163 | |||
164 | # else /* NORMAL_PRINT */ | ||
165 | 107 | ||
166 | // Enable normal print | ||
167 | /* decimal */ | 108 | /* decimal */ |
168 | # define print_dec(i) xprintf("%u", i) | 109 | #define uprint_dec(i) uprintf("%u", i) |
169 | # define print_decs(i) xprintf("%d", i) | 110 | #define uprint_decs(i) uprintf("%d", i) |
170 | /* hex */ | 111 | /* hex */ |
171 | # define print_hex4(i) xprintf("%X", i) | 112 | #define uprint_hex4(i) uprintf("%X", i) |
172 | # define print_hex8(i) xprintf("%02X", i) | 113 | #define uprint_hex8(i) uprintf("%02X", i) |
173 | # define print_hex16(i) xprintf("%04X", i) | 114 | #define uprint_hex16(i) uprintf("%04X", i) |
174 | # define print_hex32(i) xprintf("%08lX", i) | 115 | #define uprint_hex32(i) uprintf("%08lX", i) |
175 | /* binary */ | 116 | /* binary */ |
176 | # define print_bin4(i) xprintf("%04b", i) | 117 | #define uprint_bin4(i) uprintf("%04b", i) |
177 | # define print_bin8(i) xprintf("%08b", i) | 118 | #define uprint_bin8(i) uprintf("%08b", i) |
178 | # define print_bin16(i) xprintf("%016b", i) | 119 | #define uprint_bin16(i) uprintf("%016b", i) |
179 | # define print_bin32(i) xprintf("%032lb", i) | 120 | #define uprint_bin32(i) uprintf("%032lb", i) |
180 | # define print_bin_reverse8(i) xprintf("%08b", bitrev(i)) | 121 | #define uprint_bin_reverse8(i) uprintf("%08b", bitrev(i)) |
181 | # define print_bin_reverse16(i) xprintf("%016b", bitrev16(i)) | 122 | #define uprint_bin_reverse16(i) uprintf("%016b", bitrev16(i)) |
182 | # define print_bin_reverse32(i) xprintf("%032lb", bitrev32(i)) | 123 | #define uprint_bin_reverse32(i) uprintf("%032lb", bitrev32(i)) |
183 | /* print value utility */ | 124 | /* print value utility */ |
184 | # define print_val_dec(v) xprintf(# v ": %u\n", v) | 125 | #define uprint_val_dec(v) uprintf(#v ": %u\n", v) |
185 | # define print_val_decs(v) xprintf(# v ": %d\n", v) | 126 | #define uprint_val_decs(v) uprintf(#v ": %d\n", v) |
186 | # define print_val_hex8(v) xprintf(# v ": %X\n", v) | 127 | #define uprint_val_hex8(v) uprintf(#v ": %X\n", v) |
187 | # define print_val_hex16(v) xprintf(# v ": %02X\n", v) | 128 | #define uprint_val_hex16(v) uprintf(#v ": %02X\n", v) |
188 | # define print_val_hex32(v) xprintf(# v ": %04lX\n", v) | 129 | #define uprint_val_hex32(v) uprintf(#v ": %04lX\n", v) |
189 | # define print_val_bin8(v) xprintf(# v ": %08b\n", v) | 130 | #define uprint_val_bin8(v) uprintf(#v ": %08b\n", v) |
190 | # define print_val_bin16(v) xprintf(# v ": %016b\n", v) | 131 | #define uprint_val_bin16(v) uprintf(#v ": %016b\n", v) |
191 | # define print_val_bin32(v) xprintf(# v ": %032lb\n", v) | 132 | #define uprint_val_bin32(v) uprintf(#v ": %032lb\n", v) |
192 | # define print_val_bin_reverse8(v) xprintf(# v ": %08b\n", bitrev(v)) | 133 | #define uprint_val_bin_reverse8(v) uprintf(#v ": %08b\n", bitrev(v)) |
193 | # define print_val_bin_reverse16(v) xprintf(# v ": %016b\n", bitrev16(v)) | 134 | #define uprint_val_bin_reverse16(v) uprintf(#v ": %016b\n", bitrev16(v)) |
194 | # define print_val_bin_reverse32(v) xprintf(# v ": %032lb\n", bitrev32(v)) | 135 | #define uprint_val_bin_reverse32(v) uprintf(#v ": %032lb\n", bitrev32(v)) |
195 | |||
196 | # endif /* USER_PRINT / NORMAL_PRINT */ | ||
197 | |||
198 | // User Print | ||
199 | |||
200 | /* decimal */ | ||
201 | # define uprint_dec(i) uprintf("%u", i) | ||
202 | # define uprint_decs(i) uprintf("%d", i) | ||
203 | /* hex */ | ||
204 | # define uprint_hex4(i) uprintf("%X", i) | ||
205 | # define uprint_hex8(i) uprintf("%02X", i) | ||
206 | # define uprint_hex16(i) uprintf("%04X", i) | ||
207 | # define uprint_hex32(i) uprintf("%08lX", i) | ||
208 | /* binary */ | ||
209 | # define uprint_bin4(i) uprintf("%04b", i) | ||
210 | # define uprint_bin8(i) uprintf("%08b", i) | ||
211 | # define uprint_bin16(i) uprintf("%016b", i) | ||
212 | # define uprint_bin32(i) uprintf("%032lb", i) | ||
213 | # define uprint_bin_reverse8(i) uprintf("%08b", bitrev(i)) | ||
214 | # define uprint_bin_reverse16(i) uprintf("%016b", bitrev16(i)) | ||
215 | # define uprint_bin_reverse32(i) uprintf("%032lb", bitrev32(i)) | ||
216 | /* print value utility */ | ||
217 | # define uprint_val_dec(v) uprintf(# v ": %u\n", v) | ||
218 | # define uprint_val_decs(v) uprintf(# v ": %d\n", v) | ||
219 | # define uprint_val_hex8(v) uprintf(# v ": %X\n", v) | ||
220 | # define uprint_val_hex16(v) uprintf(# v ": %02X\n", v) | ||
221 | # define uprint_val_hex32(v) uprintf(# v ": %04lX\n", v) | ||
222 | # define uprint_val_bin8(v) uprintf(# v ": %08b\n", v) | ||
223 | # define uprint_val_bin16(v) uprintf(# v ": %016b\n", v) | ||
224 | # define uprint_val_bin32(v) uprintf(# v ": %032lb\n", v) | ||
225 | # define uprint_val_bin_reverse8(v) uprintf(# v ": %08b\n", bitrev(v)) | ||
226 | # define uprint_val_bin_reverse16(v) uprintf(# v ": %016b\n", bitrev16(v)) | ||
227 | # define uprint_val_bin_reverse32(v) uprintf(# v ": %032lb\n", bitrev32(v)) | ||
228 | |||
229 | #else /* NO_PRINT */ | ||
230 | |||
231 | # define xprintf(fmt, ...) | ||
232 | # define print(s) | ||
233 | # define println(s) | ||
234 | # define print_set_sendchar(func) | ||
235 | # define print_dec(data) | ||
236 | # define print_decs(data) | ||
237 | # define print_hex4(data) | ||
238 | # define print_hex8(data) | ||
239 | # define print_hex16(data) | ||
240 | # define print_hex32(data) | ||
241 | # define print_bin4(data) | ||
242 | # define print_bin8(data) | ||
243 | # define print_bin16(data) | ||
244 | # define print_bin32(data) | ||
245 | # define print_bin_reverse8(data) | ||
246 | # define print_bin_reverse16(data) | ||
247 | # define print_bin_reverse32(data) | ||
248 | # define print_val_dec(v) | ||
249 | # define print_val_decs(v) | ||
250 | # define print_val_hex8(v) | ||
251 | # define print_val_hex16(v) | ||
252 | # define print_val_hex32(v) | ||
253 | # define print_val_bin8(v) | ||
254 | # define print_val_bin16(v) | ||
255 | # define print_val_bin32(v) | ||
256 | # define print_val_bin_reverse8(v) | ||
257 | # define print_val_bin_reverse16(v) | ||
258 | # define print_val_bin_reverse32(v) | ||
259 | |||
260 | #endif /* NO_PRINT */ | ||
diff --git a/tmk_core/common/printf.c b/tmk_core/common/printf.c new file mode 100644 index 000000000..e8440e55e --- /dev/null +++ b/tmk_core/common/printf.c | |||
@@ -0,0 +1,27 @@ | |||
1 | /* | ||
2 | Copyright 2011 Jun Wako <wakojun@gmail.com> | ||
3 | |||
4 | This program is free software: you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation, either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
16 | */ | ||
17 | #include <stddef.h> | ||
18 | #include "sendchar.h" | ||
19 | |||
20 | // bind lib/printf to console interface - sendchar | ||
21 | |||
22 | static int8_t null_sendchar_func(uint8_t c) { return 0; } | ||
23 | static sendchar_func_t func = null_sendchar_func; | ||
24 | |||
25 | void print_set_sendchar(sendchar_func_t send) { func = send; } | ||
26 | |||
27 | void _putchar(char character) { func(character); } | ||
diff --git a/tmk_core/common/progmem.h b/tmk_core/common/progmem.h index c8863d3ad..4e4771e52 100644 --- a/tmk_core/common/progmem.h +++ b/tmk_core/common/progmem.h | |||
@@ -4,6 +4,7 @@ | |||
4 | # include <avr/pgmspace.h> | 4 | # include <avr/pgmspace.h> |
5 | #else | 5 | #else |
6 | # define PROGMEM | 6 | # define PROGMEM |
7 | # define PSTR(x) x | ||
7 | # define PGM_P const char* | 8 | # define PGM_P const char* |
8 | # define memcpy_P(dest, src, n) memcpy(dest, src, n) | 9 | # define memcpy_P(dest, src, n) memcpy(dest, src, n) |
9 | # define pgm_read_byte(address_short) *((uint8_t*)(address_short)) | 10 | # 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 b150dd464..edcddaa6b 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/>. | |||
23 | extern "C" { | 23 | extern "C" { |
24 | #endif | 24 | #endif |
25 | 25 | ||
26 | typedef int8_t (*sendchar_func_t)(uint8_t c); | ||
27 | |||
26 | /* transmit a character. return 0 on success, -1 on error. */ | 28 | /* transmit a character. return 0 on success, -1 on error. */ |
27 | int8_t sendchar(uint8_t c); | 29 | int8_t sendchar(uint8_t c); |
28 | 30 | ||
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c index 13b1e34d2..4c088e2b5 100644 --- a/tmk_core/protocol/chibios/usb_main.c +++ b/tmk_core/protocol/chibios/usb_main.c | |||
@@ -953,15 +953,8 @@ void console_task(void) { | |||
953 | } while (size > 0); | 953 | } while (size > 0); |
954 | } | 954 | } |
955 | 955 | ||
956 | #else /* CONSOLE_ENABLE */ | ||
957 | int8_t sendchar(uint8_t c) { | ||
958 | (void)c; | ||
959 | return 0; | ||
960 | } | ||
961 | #endif /* CONSOLE_ENABLE */ | 956 | #endif /* CONSOLE_ENABLE */ |
962 | 957 | ||
963 | void _putchar(char character) { sendchar(character); } | ||
964 | |||
965 | #ifdef RAW_ENABLE | 958 | #ifdef RAW_ENABLE |
966 | void raw_hid_send(uint8_t *data, uint8_t length) { | 959 | void raw_hid_send(uint8_t *data, uint8_t length) { |
967 | // TODO: implement variable size packet | 960 | // TODO: implement variable size packet |
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 74e48222d..bd9daaac9 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c | |||
@@ -1025,7 +1025,6 @@ static void setup_usb(void) { | |||
1025 | 1025 | ||
1026 | // for Console_Task | 1026 | // for Console_Task |
1027 | USB_Device_EnableSOFEvents(); | 1027 | USB_Device_EnableSOFEvents(); |
1028 | print_set_sendchar(sendchar); | ||
1029 | } | 1028 | } |
1030 | 1029 | ||
1031 | /** \brief Main | 1030 | /** \brief Main |
diff --git a/tmk_core/protocol/vusb/main.c b/tmk_core/protocol/vusb/main.c index 2e8bb2fbb..3f93ef6d2 100644 --- a/tmk_core/protocol/vusb/main.c +++ b/tmk_core/protocol/vusb/main.c | |||
@@ -74,12 +74,7 @@ static void usb_remote_wakeup(void) { | |||
74 | * | 74 | * |
75 | * FIXME: Needs doc | 75 | * FIXME: Needs doc |
76 | */ | 76 | */ |
77 | static void setup_usb(void) { | 77 | static void setup_usb(void) { initForUsbConnectivity(); } |
78 | initForUsbConnectivity(); | ||
79 | |||
80 | // for Console_Task | ||
81 | print_set_sendchar(sendchar); | ||
82 | } | ||
83 | 78 | ||
84 | /** \brief Main | 79 | /** \brief Main |
85 | * | 80 | * |