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