aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2020-05-04 07:19:51 +0100
committerGitHub <noreply@github.com>2020-05-03 23:19:51 -0700
commite17b55e33ad5b3dcefcf7b828ac99aeb2daeeae2 (patch)
treee6430a88e4ce4e73783f2a2f4fd4939885b1e402
parentf31bf1b2025ece2d61cec10293cbd4e18b537eeb (diff)
downloadqmk_firmware-e17b55e33ad5b3dcefcf7b828ac99aeb2daeeae2.tar.gz
qmk_firmware-e17b55e33ad5b3dcefcf7b828ac99aeb2daeeae2.zip
Fix conflicting types for 'tfp_printf' (#8269)
* Refactor to use mpaland/printf * trim firmware size * remove keymap changes * run clang format * Fixup after rebase * fix up git-submodule command for printf
-rw-r--r--.gitmodules3
-rw-r--r--Makefile1
m---------lib/printf0
-rw-r--r--tmk_core/common.mk9
-rw-r--r--tmk_core/common/chibios/printf.c233
-rw-r--r--tmk_core/common/chibios/printf.h110
-rw-r--r--tmk_core/common/print.h5
-rw-r--r--tmk_core/protocol/chibios/main.c3
-rw-r--r--tmk_core/protocol/chibios/usb_main.c5
-rw-r--r--tmk_core/protocol/chibios/usb_main.h2
10 files changed, 15 insertions, 356 deletions
diff --git a/.gitmodules b/.gitmodules
index 6d8ab8b94..b8c66034b 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -16,3 +16,6 @@
16[submodule "lib/lufa"] 16[submodule "lib/lufa"]
17 path = lib/lufa 17 path = lib/lufa
18 url = https://github.com/qmk/lufa 18 url = https://github.com/qmk/lufa
19[submodule "lib/printf"]
20 path = lib/printf
21 url = https://github.com/mpaland/printf.git
diff --git a/Makefile b/Makefile
index 9478c14f8..cc3bde6b1 100644
--- a/Makefile
+++ b/Makefile
@@ -567,6 +567,7 @@ ifndef SKIP_GIT
567 if [ ! -e lib/chibios-contrib ]; then git submodule sync lib/chibios-contrib && git submodule update --depth 50 --init lib/chibios-contrib; fi 567 if [ ! -e lib/chibios-contrib ]; then git submodule sync lib/chibios-contrib && git submodule update --depth 50 --init lib/chibios-contrib; fi
568 if [ ! -e lib/ugfx ]; then git submodule sync lib/ugfx && git submodule update --depth 50 --init lib/ugfx; fi 568 if [ ! -e lib/ugfx ]; then git submodule sync lib/ugfx && git submodule update --depth 50 --init lib/ugfx; fi
569 if [ ! -e lib/lufa ]; then git submodule sync lib/lufa && git submodule update --depth 50 --init lib/lufa; fi 569 if [ ! -e lib/lufa ]; then git submodule sync lib/lufa && git submodule update --depth 50 --init lib/lufa; fi
570 if [ ! -e lib/printf ]; then git submodule sync lib/printf && git submodule update --depth 50 --init lib/printf; fi
570 git submodule status --recursive 2>/dev/null | \ 571 git submodule status --recursive 2>/dev/null | \
571 while IFS= read -r x; do \ 572 while IFS= read -r x; do \
572 case "$$x" in \ 573 case "$$x" in \
diff --git a/lib/printf b/lib/printf
new file mode 160000
Subproject d3b984684bb8a8bdc48cc7a1abecb93ce59bbe3
diff --git a/tmk_core/common.mk b/tmk_core/common.mk
index aa8a0eb7a..63de7c7ed 100644
--- a/tmk_core/common.mk
+++ b/tmk_core/common.mk
@@ -1,3 +1,5 @@
1PRINTF_PATH = $(LIB_PATH)/printf
2
1COMMON_DIR = common 3COMMON_DIR = common
2PLATFORM_COMMON_DIR = $(COMMON_DIR)/$(PLATFORM_KEY) 4PLATFORM_COMMON_DIR = $(COMMON_DIR)/$(PLATFORM_KEY)
3 5
@@ -21,7 +23,12 @@ TMK_COMMON_SRC += $(COMMON_DIR)/host.c \
21ifeq ($(PLATFORM),AVR) 23ifeq ($(PLATFORM),AVR)
22 TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/xprintf.S 24 TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/xprintf.S
23else ifeq ($(PLATFORM),CHIBIOS) 25else ifeq ($(PLATFORM),CHIBIOS)
24 TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/printf.c 26 TMK_COMMON_SRC += $(PRINTF_PATH)/printf.c
27 TMK_COMMON_DEFS += -DPRINTF_DISABLE_SUPPORT_FLOAT
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)
25else ifeq ($(PLATFORM),ARM_ATSAM) 32else ifeq ($(PLATFORM),ARM_ATSAM)
26 TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/printf.c 33 TMK_COMMON_SRC += $(PLATFORM_COMMON_DIR)/printf.c
27endif 34endif
diff --git a/tmk_core/common/chibios/printf.c b/tmk_core/common/chibios/printf.c
deleted file mode 100644
index a99752bb3..000000000
--- a/tmk_core/common/chibios/printf.c
+++ /dev/null
@@ -1,233 +0,0 @@
1/*
2 * found at: http://www.sparetimelabs.com/tinyprintf/tinyprintf.php
3 * and: http://www.sparetimelabs.com/printfrevisited/printfrevisited.php
4 */
5
6/*
7File: printf.c
8
9Copyright (C) 2004 Kustaa Nyholm
10
11This library is free software; you can redistribute it and/or
12modify it under the terms of the GNU Lesser General Public
13License as published by the Free Software Foundation; either
14version 2.1 of the License, or (at your option) any later version.
15
16This library is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19Lesser General Public License for more details.
20
21You should have received a copy of the GNU Lesser General Public
22License along with this library; if not, write to the Free Software
23Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
25*/
26
27#include "printf.h"
28
29typedef void (*putcf)(void*, char);
30static putcf stdout_putf;
31static void* stdout_putp;
32
33// this adds cca 400 bytes
34#define PRINTF_LONG_SUPPORT
35
36#ifdef PRINTF_LONG_SUPPORT
37
38static void uli2a(unsigned long int num, unsigned int base, int uc, char* bf) {
39 int n = 0;
40 unsigned int d = 1;
41 while (num / d >= base) d *= base;
42 while (d != 0) {
43 int dgt = num / d;
44 num %= d;
45 d /= base;
46 if (n || dgt > 0 || d == 0) {
47 *bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10);
48 ++n;
49 }
50 }
51 *bf = 0;
52}
53
54static void li2a(long num, char* bf) {
55 if (num < 0) {
56 num = -num;
57 *bf++ = '-';
58 }
59 uli2a(num, 10, 0, bf);
60}
61
62#endif
63
64static void ui2a(unsigned int num, unsigned int base, int uc, char* bf) {
65 int n = 0;
66 unsigned int d = 1;
67 while (num / d >= base) d *= base;
68 while (d != 0) {
69 int dgt = num / d;
70 num %= d;
71 d /= base;
72 if (n || dgt > 0 || d == 0) {
73 *bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10);
74 ++n;
75 }
76 }
77 *bf = 0;
78}
79
80static void i2a(int num, char* bf) {
81 if (num < 0) {
82 num = -num;
83 *bf++ = '-';
84 }
85 ui2a(num, 10, 0, bf);
86}
87
88static int a2d(char ch) {
89 if (ch >= '0' && ch <= '9')
90 return ch - '0';
91 else if (ch >= 'a' && ch <= 'f')
92 return ch - 'a' + 10;
93 else if (ch >= 'A' && ch <= 'F')
94 return ch - 'A' + 10;
95 else
96 return -1;
97}
98
99static char a2i(char ch, const char** src, int base, int* nump) {
100 const char* p = *src;
101 int num = 0;
102 int digit;
103 while ((digit = a2d(ch)) >= 0) {
104 if (digit > base) break;
105 num = num * base + digit;
106 ch = *p++;
107 }
108 *src = p;
109 *nump = num;
110 return ch;
111}
112
113static void putchw(void* putp, putcf putf, int n, char z, char* bf) {
114 char fc = z ? '0' : ' ';
115 char ch;
116 char* p = bf;
117 while (*p++ && n > 0) n--;
118 while (n-- > 0) putf(putp, fc);
119 while ((ch = *bf++)) putf(putp, ch);
120}
121
122void tfp_format(void* putp, putcf putf, const char* fmt, va_list va) {
123 // This used to handle max of 12, but binary support jumps this to at least 32
124 char bf[36];
125
126 char ch;
127
128 while ((ch = *(fmt++))) {
129 if (ch != '%')
130 putf(putp, ch);
131 else {
132 char lz = 0;
133#ifdef PRINTF_LONG_SUPPORT
134 char lng = 0;
135#endif
136 int w = 0;
137 ch = *(fmt++);
138 if (ch == '0') {
139 ch = *(fmt++);
140 lz = 1;
141 }
142 if (ch >= '0' && ch <= '9') {
143 ch = a2i(ch, &fmt, 10, &w);
144 }
145#ifdef PRINTF_LONG_SUPPORT
146 if (ch == 'l') {
147 ch = *(fmt++);
148 lng = 1;
149 }
150#endif
151 switch (ch) {
152 case 0:
153 goto abort;
154 case 'u': {
155#ifdef PRINTF_LONG_SUPPORT
156 if (lng)
157 uli2a(va_arg(va, unsigned long int), 10, 0, bf);
158 else
159#endif
160 ui2a(va_arg(va, unsigned int), 10, 0, bf);
161 putchw(putp, putf, w, lz, bf);
162 break;
163 }
164 case 'd': {
165#ifdef PRINTF_LONG_SUPPORT
166 if (lng)
167 li2a(va_arg(va, unsigned long int), bf);
168 else
169#endif
170 i2a(va_arg(va, int), bf);
171 putchw(putp, putf, w, lz, bf);
172 break;
173 }
174 case 'x':
175 case 'X':
176#ifdef PRINTF_LONG_SUPPORT
177 if (lng)
178 uli2a(va_arg(va, unsigned long int), 16, (ch == 'X'), bf);
179 else
180#endif
181 ui2a(va_arg(va, unsigned int), 16, (ch == 'X'), bf);
182 putchw(putp, putf, w, lz, bf);
183 break;
184 case 'c':
185 putf(putp, (char)(va_arg(va, int)));
186 break;
187 case 's':
188 putchw(putp, putf, w, 0, va_arg(va, char*));
189 break;
190 case 'b':
191#ifdef PRINTF_LONG_SUPPORT
192 if (lng)
193 uli2a(va_arg(va, unsigned long int), 2, 0, bf);
194 else
195#endif
196 ui2a(va_arg(va, unsigned int), 2, 0, bf);
197 putchw(putp, putf, w, lz, bf);
198 break;
199 case '%':
200 putf(putp, ch);
201 default:
202 break;
203 }
204 }
205 }
206abort:;
207}
208
209void init_printf(void* putp, void (*putf)(void*, char)) {
210 stdout_putf = putf;
211 stdout_putp = putp;
212}
213
214int tfp_printf(const char* fmt, ...) {
215 va_list va;
216 va_start(va, fmt);
217 tfp_format(stdout_putp, stdout_putf, fmt, va);
218 va_end(va);
219
220 return 1;
221}
222
223static void putcp(void* p, char c) { *(*((char**)p))++ = c; }
224
225int tfp_sprintf(char* s, const char* fmt, ...) {
226 va_list va;
227 va_start(va, fmt);
228 tfp_format(&s, putcp, fmt, va);
229 putcp(&s, 0);
230 va_end(va);
231
232 return 1;
233}
diff --git a/tmk_core/common/chibios/printf.h b/tmk_core/common/chibios/printf.h
deleted file mode 100644
index 775459e1e..000000000
--- a/tmk_core/common/chibios/printf.h
+++ /dev/null
@@ -1,110 +0,0 @@
1/*
2 * found at: http://www.sparetimelabs.com/tinyprintf/tinyprintf.php
3 * and: http://www.sparetimelabs.com/printfrevisited/printfrevisited.php
4 */
5
6/*
7File: printf.h
8
9Copyright (C) 2004 Kustaa Nyholm
10
11This library is free software; you can redistribute it and/or
12modify it under the terms of the GNU Lesser General Public
13License as published by the Free Software Foundation; either
14version 2.1 of the License, or (at your option) any later version.
15
16This library is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19See the GNU Lesser General Public License for more details.
20
21You should have received a copy of the GNU Lesser General Public
22License along with this library; if not, write to the Free Software
23Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
25This library is realy just two files: 'printf.h' and 'printf.c'.
26
27They provide a simple and small (+200 loc) printf functionality to
28be used in embedded systems.
29
30I've found them so usefull in debugging that I do not bother with a
31debugger at all.
32
33They are distributed in source form, so to use them, just compile them
34into your project.
35
36Two printf variants are provided: printf and sprintf.
37
38The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'.
39
40Zero padding and field width are also supported.
41
42If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the
43long specifier is also
44supported. Note that this will pull in some long math routines (pun intended!)
45and thus make your executable noticably longer.
46
47The memory foot print of course depends on the target cpu, compiler and
48compiler options, but a rough guestimate (based on a H8S target) is about
491.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space.
50Not too bad. Your milage may vary. By hacking the source code you can
51get rid of some hunred bytes, I'm sure, but personally I feel the balance of
52functionality and flexibility versus code size is close to optimal for
53many embedded systems.
54
55To use the printf you need to supply your own character output function,
56something like :
57
58 void putc ( void* p, char c)
59 {
60 while (!SERIAL_PORT_EMPTY) ;
61 SERIAL_PORT_TX_REGISTER = c;
62 }
63
64Before you can call printf you need to initialize it to use your
65character output function with something like:
66
67 init_printf(NULL,putc);
68
69Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc',
70the NULL (or any pointer) you pass into the 'init_printf' will eventually be
71passed to your 'putc' routine. This allows you to pass some storage space (or
72anything realy) to the character output function, if necessary.
73This is not often needed but it was implemented like that because it made
74implementing the sprintf function so neat (look at the source code).
75
76The code is re-entrant, except for the 'init_printf' function, so it
77is safe to call it from interupts too, although this may result in mixed output.
78If you rely on re-entrancy, take care that your 'putc' function is re-entrant!
79
80The printf and sprintf functions are actually macros that translate to
81'tfp_printf' and 'tfp_sprintf'. This makes it possible
82to use them along with 'stdio.h' printf's in a single source file.
83You just need to undef the names before you include the 'stdio.h'.
84Note that these are not function like macros, so if you have variables
85or struct members with these names, things will explode in your face.
86Without variadic macros this is the best we can do to wrap these
87fucnction. If it is a problem just give up the macros and use the
88functions directly or rename them.
89
90For further details see source code.
91
92regs Kusti, 23.10.2004
93*/
94
95#ifndef __TFP_PRINTF__
96#define __TFP_PRINTF__
97
98#include <stdarg.h>
99
100void init_printf(void* putp, void (*putf)(void*, char));
101
102int tfp_printf(const char* fmt, ...);
103int tfp_sprintf(char* s, const char* fmt, ...);
104
105void tfp_format(void* putp, void (*putf)(void*, char), const char* fmt, va_list va);
106
107#define printf tfp_printf
108#define sprintf tfp_sprintf
109
110#endif
diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h
index 04ca55810..1c7723621 100644
--- a/tmk_core/common/print.h
+++ b/tmk_core/common/print.h
@@ -72,9 +72,7 @@ extern "C"
72 72
73# elif defined(PROTOCOL_CHIBIOS) /* PROTOCOL_CHIBIOS */ 73# elif defined(PROTOCOL_CHIBIOS) /* PROTOCOL_CHIBIOS */
74 74
75# ifndef TERMINAL_ENABLE 75# include "printf.h" // lib/printf/printf.h
76# include "chibios/printf.h"
77# endif
78 76
79# ifdef USER_PRINT /* USER_PRINT */ 77# ifdef USER_PRINT /* USER_PRINT */
80 78
@@ -89,7 +87,6 @@ extern "C"
89# define uprintf printf 87# define uprintf printf
90 88
91# else /* NORMAL PRINT */ 89# else /* NORMAL PRINT */
92
93// Create user & normal print defines 90// Create user & normal print defines
94# define print(s) printf(s) 91# define print(s) printf(s)
95# define println(s) printf(s "\r\n") 92# define println(s) printf(s "\r\n")
diff --git a/tmk_core/protocol/chibios/main.c b/tmk_core/protocol/chibios/main.c
index 61665eb6f..7d32c16ed 100644
--- a/tmk_core/protocol/chibios/main.c
+++ b/tmk_core/protocol/chibios/main.c
@@ -158,9 +158,6 @@ int main(void) {
158 /* Init USB */ 158 /* Init USB */
159 init_usb_driver(&USB_DRIVER); 159 init_usb_driver(&USB_DRIVER);
160 160
161 /* init printf */
162 init_printf(NULL, sendchar_pf);
163
164#ifdef MIDI_ENABLE 161#ifdef MIDI_ENABLE
165 setup_midi(); 162 setup_midi();
166#endif 163#endif
diff --git a/tmk_core/protocol/chibios/usb_main.c b/tmk_core/protocol/chibios/usb_main.c
index ecc83d9ec..65bd291be 100644
--- a/tmk_core/protocol/chibios/usb_main.c
+++ b/tmk_core/protocol/chibios/usb_main.c
@@ -796,9 +796,8 @@ int8_t sendchar(uint8_t c) {
796} 796}
797#endif /* CONSOLE_ENABLE */ 797#endif /* CONSOLE_ENABLE */
798 798
799void sendchar_pf(void *p, char c) { 799void _putchar(char character) {
800 (void)p; 800 sendchar(character);
801 sendchar((uint8_t)c);
802} 801}
803 802
804#ifdef RAW_ENABLE 803#ifdef RAW_ENABLE
diff --git a/tmk_core/protocol/chibios/usb_main.h b/tmk_core/protocol/chibios/usb_main.h
index 17041b4f2..94baf9b35 100644
--- a/tmk_core/protocol/chibios/usb_main.h
+++ b/tmk_core/protocol/chibios/usb_main.h
@@ -87,6 +87,4 @@ void console_flush_output(void);
87 87
88#endif /* CONSOLE_ENABLE */ 88#endif /* CONSOLE_ENABLE */
89 89
90void sendchar_pf(void *p, char c);
91
92#endif /* _USB_MAIN_H_ */ 90#endif /* _USB_MAIN_H_ */