xitoa.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*---------------------------------------------------------------------------
  2. Extended itoa, puts and printf (C)ChaN, 2011
  3. -----------------------------------------------------------------------------*/
  4. #ifndef XITOA
  5. #define XITOA
  6. #define __PROG_TYPES_COMPAT__
  7. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  8. #include <inttypes.h>
  9. #include <avr/pgmspace.h>
  10. extern void (*xfunc_out)(uint8_t);
  11. #define xdev_out(func) xfunc_out = (void(*)(uint8_t))(func)
  12. /* This is a pointer to user defined output function. It must be initialized
  13. before using this modle.
  14. */
  15. void xputc(char chr);
  16. /* This is a stub function to forward outputs to user defined output function.
  17. All outputs from this module are output via this function.
  18. */
  19. /*-----------------------------------------------------------------------------*/
  20. void xputs(const prog_char *string);
  21. /* The string placed in the ROM is forwarded to xputc() directly.
  22. */
  23. /*-----------------------------------------------------------------------------*/
  24. void xitoa(long value, char radix, char width);
  25. /* Extended itoa().
  26. value radix width output
  27. 100 10 6 " 100"
  28. 100 10 -6 "000100"
  29. 100 10 0 "100"
  30. 4294967295 10 0 "4294967295"
  31. 4294967295 -10 0 "-1"
  32. 655360 16 -8 "000A0000"
  33. 1024 16 0 "400"
  34. 0x55 2 -8 "01010101"
  35. */
  36. /*-----------------------------------------------------------------------------*/
  37. void xprintf(const prog_char *format, ...); /* Send formatted string to the registered device */
  38. void xsprintf(char*, const prog_char *format, ...); /* Put formatted string to the memory */
  39. void xfprintf(void(*func)(uint8_t), const prog_char *format, ...); /* Send formatted string to the specified device */
  40. /* Format string is placed in the ROM. The format flags is similar to printf().
  41. %[flag][width][size]type
  42. flag
  43. A '0' means filled with '0' when output is shorter than width.
  44. ' ' is used in default. This is effective only numeral type.
  45. width
  46. Minimum width in decimal number. This is effective only numeral type.
  47. Default width is zero.
  48. size
  49. A 'l' means the argument is long(32bit). Default is short(16bit).
  50. This is effective only numeral type.
  51. type
  52. 'c' : Character, argument is the value
  53. 's' : String placed on the RAM, argument is the pointer
  54. 'S' : String placed on the ROM, argument is the pointer
  55. 'd' : Signed decimal, argument is the value
  56. 'u' : Unsigned decimal, argument is the value
  57. 'X' : Hexdecimal, argument is the value
  58. 'b' : Binary, argument is the value
  59. '%' : '%'
  60. */
  61. /*-----------------------------------------------------------------------------*/
  62. char xatoi(char **str, long *ret);
  63. /* Get value of the numeral string.
  64. str
  65. Pointer to pointer to source string
  66. "0b11001010" binary
  67. "0377" octal
  68. "0xff800" hexdecimal
  69. "1250000" decimal
  70. "-25000" decimal
  71. ret
  72. Pointer to return value
  73. */
  74. #endif /* XITOA */