diff options
Diffstat (limited to 'tmk_core/common/chibios/printf.h')
-rw-r--r-- | tmk_core/common/chibios/printf.h | 59 |
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 | ||
16 | This library is distributed in the hope that it will be useful, | 16 | This library is distributed in the hope that it will be useful, |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Lesser General Public License for more details. | 19 | See the GNU Lesser General Public License for more details. |
20 | 20 | ||
21 | You should have received a copy of the GNU Lesser General Public | 21 | You 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 | ||
25 | This library is realy just two files: 'printf.h' and 'printf.c'. | 25 | This library is realy just two files: 'printf.h' and 'printf.c'. |
26 | 26 | ||
27 | They provide a simple and small (+200 loc) printf functionality to | 27 | They provide a simple and small (+200 loc) printf functionality to |
28 | be used in embedded systems. | 28 | be used in embedded systems. |
29 | 29 | ||
30 | I've found them so usefull in debugging that I do not bother with a | 30 | I've found them so usefull in debugging that I do not bother with a |
31 | debugger at all. | 31 | debugger at all. |
32 | 32 | ||
33 | They are distributed in source form, so to use them, just compile them | 33 | They are distributed in source form, so to use them, just compile them |
34 | into your project. | 34 | into your project. |
35 | 35 | ||
36 | Two printf variants are provided: printf and sprintf. | 36 | Two printf variants are provided: printf and sprintf. |
37 | 37 | ||
38 | The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'. | 38 | The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'. |
39 | 39 | ||
40 | Zero padding and field width are also supported. | 40 | Zero padding and field width are also supported. |
41 | 41 | ||
42 | If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the | 42 | If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the |
43 | long specifier is also | 43 | long specifier is also |
44 | supported. Note that this will pull in some long math routines (pun intended!) | 44 | supported. Note that this will pull in some long math routines (pun intended!) |
45 | and thus make your executable noticably longer. | 45 | and thus make your executable noticably longer. |
46 | 46 | ||
47 | The memory foot print of course depends on the target cpu, compiler and | 47 | The memory foot print of course depends on the target cpu, compiler and |
48 | compiler options, but a rough guestimate (based on a H8S target) is about | 48 | compiler options, but a rough guestimate (based on a H8S target) is about |
49 | 1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space. | 49 | 1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space. |
50 | Not too bad. Your milage may vary. By hacking the source code you can | 50 | Not too bad. Your milage may vary. By hacking the source code you can |
51 | get rid of some hunred bytes, I'm sure, but personally I feel the balance of | 51 | get rid of some hunred bytes, I'm sure, but personally I feel the balance of |
52 | functionality and flexibility versus code size is close to optimal for | 52 | functionality and flexibility versus code size is close to optimal for |
53 | many embedded systems. | 53 | many embedded systems. |
54 | 54 | ||
55 | To use the printf you need to supply your own character output function, | 55 | To use the printf you need to supply your own character output function, |
56 | something like : | 56 | something 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 | ||
64 | Before you can call printf you need to initialize it to use your | 64 | Before you can call printf you need to initialize it to use your |
65 | character output function with something like: | 65 | character output function with something like: |
66 | 66 | ||
67 | init_printf(NULL,putc); | 67 | init_printf(NULL,putc); |
68 | 68 | ||
69 | Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc', | 69 | Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc', |
70 | the NULL (or any pointer) you pass into the 'init_printf' will eventually be | 70 | the NULL (or any pointer) you pass into the 'init_printf' will eventually be |
71 | passed to your 'putc' routine. This allows you to pass some storage space (or | 71 | passed to your 'putc' routine. This allows you to pass some storage space (or |
72 | anything realy) to the character output function, if necessary. | 72 | anything realy) to the character output function, if necessary. |
73 | This is not often needed but it was implemented like that because it made | 73 | This is not often needed but it was implemented like that because it made |
74 | implementing the sprintf function so neat (look at the source code). | 74 | implementing the sprintf function so neat (look at the source code). |
75 | 75 | ||
76 | The code is re-entrant, except for the 'init_printf' function, so it | 76 | The code is re-entrant, except for the 'init_printf' function, so it |
77 | is safe to call it from interupts too, although this may result in mixed output. | 77 | is safe to call it from interupts too, although this may result in mixed output. |
78 | If you rely on re-entrancy, take care that your 'putc' function is re-entrant! | 78 | If you rely on re-entrancy, take care that your 'putc' function is re-entrant! |
79 | 79 | ||
80 | The printf and sprintf functions are actually macros that translate to | 80 | The 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 |
82 | to use them along with 'stdio.h' printf's in a single source file. | 82 | to use them along with 'stdio.h' printf's in a single source file. |
83 | You just need to undef the names before you include the 'stdio.h'. | 83 | You just need to undef the names before you include the 'stdio.h'. |
84 | Note that these are not function like macros, so if you have variables | 84 | Note that these are not function like macros, so if you have variables |
85 | or struct members with these names, things will explode in your face. | 85 | or struct members with these names, things will explode in your face. |
@@ -92,20 +92,19 @@ For further details see source code. | |||
92 | regs Kusti, 23.10.2004 | 92 | regs 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 | ||
101 | void init_printf(void* putp,void (*putf) (void*,char)); | 100 | void init_printf(void* putp, void (*putf)(void*, char)); |
102 | 101 | ||
103 | void tfp_printf(char *fmt, ...); | 102 | void tfp_printf(char* fmt, ...); |
104 | void tfp_sprintf(char* s,char *fmt, ...); | 103 | void tfp_sprintf(char* s, char* fmt, ...); |
105 | 104 | ||
106 | void tfp_format(void* putp,void (*putf) (void*,char),char *fmt, va_list va); | 105 | void 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 |