1 /*---------------------------------------------------------------------------
\r
2 Extended itoa, puts and printf (C)ChaN, 2011
\r
3 -----------------------------------------------------------------------------*/
\r
8 #include <inttypes.h>
\r
9 #include <avr/pgmspace.h>
\r
15 extern void (*xfunc_out)(uint8_t);
\r
16 #define xdev_out(func) xfunc_out = (void(*)(uint8_t))(func)
\r
18 /* This is a pointer to user defined output function. It must be initialized
\r
19 before using this modle.
\r
22 void xputc(char chr);
\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
29 /*-----------------------------------------------------------------------------*/
\r
30 void xputs(const char *string_p);
\r
32 /* The string placed in the ROM is forwarded to xputc() directly.
\r
36 /*-----------------------------------------------------------------------------*/
\r
37 void xitoa(long value, char radix, char width);
\r
41 value radix width output
\r
45 4294967295 10 0 "4294967295"
\r
46 4294967295 -10 0 "-1"
\r
47 655360 16 -8 "000A0000"
\r
49 0x55 2 -8 "01010101"
\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
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
62 /* Format string is placed in the ROM. The format flags is similar to printf().
\r
64 %[flag][width][size]type
\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
70 Minimum width in decimal number. This is effective only numeral type.
\r
71 Default width is zero.
\r
73 A 'l' means the argument is long(32bit). Default is short(16bit).
\r
74 This is effective only numeral 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
88 /*-----------------------------------------------------------------------------*/
\r
89 char xatoi(char **str, long *ret);
\r
91 /* Get value of the numeral string.
\r
94 Pointer to pointer to source string
\r
98 "0xff800" hexdecimal
\r
103 Pointer to return value
\r