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
11 extern void (*xfunc_out)(uint8_t);
\r
12 #define xdev_out(func) xfunc_out = (void(*)(uint8_t))(func)
\r
14 /* This is a pointer to user defined output function. It must be initialized
\r
15 before using this modle.
\r
18 void xputc(char chr);
\r
20 /* This is a stub function to forward outputs to user defined output function.
\r
21 All outputs from this module are output via this function.
\r
25 /*-----------------------------------------------------------------------------*/
\r
26 void xputs(const char *string_p);
\r
28 /* The string placed in the ROM is forwarded to xputc() directly.
\r
32 /*-----------------------------------------------------------------------------*/
\r
33 void xitoa(long value, char radix, char width);
\r
37 value radix width output
\r
41 4294967295 10 0 "4294967295"
\r
42 4294967295 -10 0 "-1"
\r
43 655360 16 -8 "000A0000"
\r
45 0x55 2 -8 "01010101"
\r
49 /*-----------------------------------------------------------------------------*/
\r
50 #define xprintf(format, ...) __xprintf(PSTR(format), ##__VA_ARGS__)
\r
51 #define xsprintf(str, format, ...) __xsprintf(str, PSTR(format), ##__VA_ARGS__)
\r
52 #define xfprintf(func, format, ...) __xfprintf(func, PSTR(format), ##__VA_ARGS__)
\r
54 void __xprintf(const char *format_p, ...); /* Send formatted string to the registered device */
\r
55 void __xsprintf(char*, const char *format_p, ...); /* Put formatted string to the memory */
\r
56 void __xfprintf(void(*func)(uint8_t), const char *format_p, ...); /* Send formatted string to the specified device */
\r
58 /* Format string is placed in the ROM. The format flags is similar to printf().
\r
60 %[flag][width][size]type
\r
63 A '0' means filled with '0' when output is shorter than width.
\r
64 ' ' is used in default. This is effective only numeral type.
\r
66 Minimum width in decimal number. This is effective only numeral type.
\r
67 Default width is zero.
\r
69 A 'l' means the argument is long(32bit). Default is short(16bit).
\r
70 This is effective only numeral type.
\r
72 'c' : Character, argument is the value
\r
73 's' : String placed on the RAM, argument is the pointer
\r
74 'S' : String placed on the ROM, argument is the pointer
\r
75 'd' : Signed decimal, argument is the value
\r
76 'u' : Unsigned decimal, argument is the value
\r
77 'X' : Hexdecimal, argument is the value
\r
78 'b' : Binary, argument is the value
\r
84 /*-----------------------------------------------------------------------------*/
\r
85 char xatoi(char **str, long *ret);
\r
87 /* Get value of the numeral string.
\r
90 Pointer to pointer to source string
\r
94 "0xff800" hexdecimal
\r
99 Pointer to return value
\r