]> git.donarmstrong.com Git - tmk_firmware.git/blob - common/avr/xprintf.h
Merge branch 'rn42' into merge_rn42
[tmk_firmware.git] / common / avr / xprintf.h
1 /*---------------------------------------------------------------------------\r
2    Extended itoa, puts and printf                    (C)ChaN, 2011\r
3 -----------------------------------------------------------------------------*/\r
4 \r
5 #ifndef XPRINTF_H\r
6 #define XPRINTF_H\r
7 \r
8 #include <inttypes.h>\r
9 #include <avr/pgmspace.h>\r
10 \r
11 #ifdef __cplusplus\r
12 extern "C" {\r
13 #endif\r
14 \r
15 extern void (*xfunc_out)(uint8_t);\r
16 #define xdev_out(func) xfunc_out = (void(*)(uint8_t))(func)\r
17 \r
18 /* This is a pointer to user defined output function. It must be initialized\r
19    before using this modle.\r
20 */\r
21 \r
22 void xputc(char chr);\r
23 \r
24 /* This is a stub function to forward outputs to user defined output function.\r
25    All outputs from this module are output via this function.\r
26 */\r
27 \r
28 \r
29 /*-----------------------------------------------------------------------------*/\r
30 void xputs(const char *string_p);\r
31 \r
32 /*  The string placed in the ROM is forwarded to xputc() directly.\r
33 */\r
34 \r
35 \r
36 /*-----------------------------------------------------------------------------*/\r
37 void xitoa(long value, char radix, char width);\r
38 \r
39 /* Extended itoa().\r
40 \r
41       value  radix  width   output\r
42         100     10      6   "   100"\r
43         100     10     -6   "000100"\r
44         100     10      0   "100"\r
45  4294967295     10      0   "4294967295"\r
46  4294967295    -10      0   "-1"\r
47      655360     16     -8   "000A0000"\r
48        1024     16      0   "400"\r
49        0x55      2     -8   "01010101"\r
50 */\r
51 \r
52 \r
53 /*-----------------------------------------------------------------------------*/\r
54 #define xprintf(format, ...)            __xprintf(PSTR(format), ##__VA_ARGS__)\r
55 #define xsprintf(str, format, ...)      __xsprintf(str, PSTR(format), ##__VA_ARGS__)\r
56 #define xfprintf(func, format, ...)     __xfprintf(func, PSTR(format), ##__VA_ARGS__)\r
57 \r
58 void __xprintf(const char *format_p, ...);      /* Send formatted string to the registered device */\r
59 void __xsprintf(char*, const char *format_p, ...);      /* Put formatted string to the memory */\r
60 void __xfprintf(void(*func)(uint8_t), const char *format_p, ...); /* Send formatted string to the specified device */\r
61 \r
62 /* Format string is placed in the ROM. The format flags is similar to printf().\r
63 \r
64    %[flag][width][size]type\r
65 \r
66    flag\r
67      A '0' means filled with '0' when output is shorter than width.\r
68      ' ' is used in default. This is effective only numeral type.\r
69    width\r
70      Minimum width in decimal number. This is effective only numeral type.\r
71      Default width is zero.\r
72    size\r
73      A 'l' means the argument is long(32bit). Default is short(16bit).\r
74      This is effective only numeral type.\r
75    type\r
76      'c' : Character, argument is the value\r
77      's' : String placed on the RAM, argument is the pointer\r
78      'S' : String placed on the ROM, argument is the pointer\r
79      'd' : Signed decimal, argument is the value\r
80      'u' : Unsigned decimal, argument is the value\r
81      'X' : Hexdecimal, argument is the value\r
82      'b' : Binary, argument is the value\r
83      '%' : '%'\r
84 \r
85 */\r
86 \r
87 \r
88 /*-----------------------------------------------------------------------------*/\r
89 char xatoi(char **str, long *ret);\r
90 \r
91 /* Get value of the numeral string. \r
92 \r
93   str\r
94     Pointer to pointer to source string\r
95 \r
96     "0b11001010" binary\r
97     "0377" octal\r
98     "0xff800" hexdecimal\r
99     "1250000" decimal\r
100     "-25000" decimal\r
101 \r
102   ret\r
103     Pointer to return value\r
104 */\r
105 \r
106 #ifdef __cplusplus\r
107 }\r
108 #endif\r
109 \r
110 #endif\r
111 \r