qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

xprintf.h (3246B)


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