1 ///////////////////////////////////////////////////////////////////////////////
\r
2 // \author (c) Marco Paland (info@paland.com)
\r
3 // 2014-2019, PALANDesign Hannover, Germany
\r
5 // \license The MIT License (MIT)
\r
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
\r
8 // of this software and associated documentation files (the "Software"), to deal
\r
9 // in the Software without restriction, including without limitation the rights
\r
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
11 // copies of the Software, and to permit persons to whom the Software is
\r
12 // furnished to do so, subject to the following conditions:
\r
14 // The above copyright notice and this permission notice shall be included in
\r
15 // all copies or substantial portions of the Software.
\r
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
25 // \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on
\r
26 // embedded systems with a very limited resources.
\r
27 // Use this instead of bloated standard/newlib printf.
\r
28 // These routines are thread safe and reentrant.
\r
30 ///////////////////////////////////////////////////////////////////////////////
\r
45 * Output a character to a custom device like UART, used by the printf() function
\r
46 * This function is declared here only. You have to write your custom implementation somewhere
\r
47 * \param character Character to output
\r
49 void _putchar(char character);
\r
53 * Tiny printf implementation
\r
54 * You have to implement _putchar if you use printf()
\r
55 * To avoid conflicts with the regular printf() API it is overridden by macro defines
\r
56 * and internal underscore-appended functions like printf_() are used
\r
57 * \param format A string that specifies the format of the output
\r
58 * \return The number of characters that are written into the array, not counting the terminating null character
\r
60 int printf_(const char* format, ...);
\r
64 * Tiny sprintf implementation
\r
65 * Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD!
\r
66 * \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output!
\r
67 * \param format A string that specifies the format of the output
\r
68 * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
\r
70 int sprintf_(char* buffer, const char* format, ...);
\r
74 * Tiny snprintf/vsnprintf implementation
\r
75 * \param buffer A pointer to the buffer where to store the formatted string
\r
76 * \param count The maximum number of characters to store in the buffer, including a terminating null character
\r
77 * \param format A string that specifies the format of the output
\r
78 * \param va A value identifying a variable arguments list
\r
79 * \return The number of characters that COULD have been written into the buffer, not counting the terminating
\r
80 * null character. A value equal or larger than count indicates truncation. Only when the returned value
\r
81 * is non-negative and less than count, the string has been completely written.
\r
83 int snprintf_(char* buffer, size_t count, const char* format, ...);
\r
84 int vsnprintf_(char* buffer, size_t count, const char* format, va_list va);
\r
88 * Tiny vprintf implementation
\r
89 * \param format A string that specifies the format of the output
\r
90 * \param va A value identifying a variable arguments list
\r
91 * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
\r
93 int vprintf_(const char* format, va_list va);
\r
97 * printf with output function
\r
98 * You may use this as dynamic alternative to printf() with its fixed _putchar() output
\r
99 * \param out An output function which takes one character and an argument pointer
\r
100 * \param arg An argument pointer for user data passed to output function
\r
101 * \param format A string that specifies the format of the output
\r
102 * \return The number of characters that are sent to the output function, not counting the terminating null character
\r
104 int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...);
\r
112 #endif // _PRINTF_H_
\r