aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common/chibios/printf.h
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common/chibios/printf.h')
-rw-r--r--tmk_core/common/chibios/printf.h59
1 files changed, 29 insertions, 30 deletions
diff --git a/tmk_core/common/chibios/printf.h b/tmk_core/common/chibios/printf.h
index 678a100c6..2cdf55ed9 100644
--- a/tmk_core/common/chibios/printf.h
+++ b/tmk_core/common/chibios/printf.h
@@ -15,7 +15,7 @@ version 2.1 of the License, or (at your option) any later version.
15 15
16This library is distributed in the hope that it will be useful, 16This library is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of 17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19See the GNU Lesser General Public License for more details. 19See the GNU Lesser General Public License for more details.
20 20
21You should have received a copy of the GNU Lesser General Public 21You should have received a copy of the GNU Lesser General Public
@@ -24,35 +24,35 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 24
25This library is realy just two files: 'printf.h' and 'printf.c'. 25This library is realy just two files: 'printf.h' and 'printf.c'.
26 26
27They provide a simple and small (+200 loc) printf functionality to 27They provide a simple and small (+200 loc) printf functionality to
28be used in embedded systems. 28be used in embedded systems.
29 29
30I've found them so usefull in debugging that I do not bother with a 30I've found them so usefull in debugging that I do not bother with a
31debugger at all. 31debugger at all.
32 32
33They are distributed in source form, so to use them, just compile them 33They are distributed in source form, so to use them, just compile them
34into your project. 34into your project.
35 35
36Two printf variants are provided: printf and sprintf. 36Two printf variants are provided: printf and sprintf.
37 37
38The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'. 38The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'.
39 39
40Zero padding and field width are also supported. 40Zero padding and field width are also supported.
41 41
42If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the 42If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the
43long specifier is also 43long specifier is also
44supported. Note that this will pull in some long math routines (pun intended!) 44supported. Note that this will pull in some long math routines (pun intended!)
45and thus make your executable noticably longer. 45and thus make your executable noticably longer.
46 46
47The memory foot print of course depends on the target cpu, compiler and 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 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. 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 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 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 52functionality and flexibility versus code size is close to optimal for
53many embedded systems. 53many embedded systems.
54 54
55To use the printf you need to supply your own character output function, 55To use the printf you need to supply your own character output function,
56something like : 56something like :
57 57
58 void putc ( void* p, char c) 58 void putc ( void* p, char c)
@@ -61,25 +61,25 @@ something like :
61 SERIAL_PORT_TX_REGISTER = c; 61 SERIAL_PORT_TX_REGISTER = c;
62 } 62 }
63 63
64Before you can call printf you need to initialize it to use your 64Before you can call printf you need to initialize it to use your
65character output function with something like: 65character output function with something like:
66 66
67 init_printf(NULL,putc); 67 init_printf(NULL,putc);
68 68
69Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc', 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 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 71passed to your 'putc' routine. This allows you to pass some storage space (or
72anything realy) to the character output function, if necessary. 72anything realy) to the character output function, if necessary.
73This is not often needed but it was implemented like that because it made 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). 74implementing the sprintf function so neat (look at the source code).
75 75
76The code is re-entrant, except for the 'init_printf' function, so it 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. 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! 78If you rely on re-entrancy, take care that your 'putc' function is re-entrant!
79 79
80The printf and sprintf functions are actually macros that translate to 80The printf and sprintf functions are actually macros that translate to
81'tfp_printf' and 'tfp_sprintf'. This makes it possible 81'tfp_printf' and 'tfp_sprintf'. This makes it possible
82to use them along with 'stdio.h' printf's in a single source file. 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'. 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 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. 85or struct members with these names, things will explode in your face.
@@ -92,20 +92,19 @@ For further details see source code.
92regs Kusti, 23.10.2004 92regs Kusti, 23.10.2004
93*/ 93*/
94 94
95
96#ifndef __TFP_PRINTF__ 95#ifndef __TFP_PRINTF__
97#define __TFP_PRINTF__ 96#define __TFP_PRINTF__
98 97
99#include <stdarg.h> 98#include <stdarg.h>
100 99
101void init_printf(void* putp,void (*putf) (void*,char)); 100void init_printf(void* putp, void (*putf)(void*, char));
102 101
103void tfp_printf(char *fmt, ...); 102void tfp_printf(char* fmt, ...);
104void tfp_sprintf(char* s,char *fmt, ...); 103void tfp_sprintf(char* s, char* fmt, ...);
105 104
106void tfp_format(void* putp,void (*putf) (void*,char),char *fmt, va_list va); 105void tfp_format(void* putp, void (*putf)(void*, char), char* fmt, va_list va);
107 106
108#define printf tfp_printf 107#define printf tfp_printf
109#define sprintf tfp_sprintf 108#define sprintf tfp_sprintf
110 109
111#endif 110#endif