Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xprintf.h 3.3KB

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