eprintf - The Embedded String I/O library

eprintf - The Embedded String I/O library


Overview

eprintf is a collection of string I/O functions specifically written for embedded systems with low-memory capacity and low computing capacity like MCU.
The recommended use of this library includes: debug/maintenance console and writing formatted strings into display device.

API

Output APIs are:
  • void eputchar(int character)
    Writes a character to default I/O.
  • void eputs(const char* string)
    Writes every character from the null-terminated string to default I/O.
  • void eprintf(const char* formatStringPointer, ...)
    Writes a formatted string to default I/O. For the syntax of format placeholder, please refer to the comment at the start of the definition of this function in eprintf.c
  • void esprintf(char *buffer, const char *formatStringPointer, ... )
    Writes a formatted string to a string buffer. The behavior is undefined if the string to be written (plus the terminating null character) exceeds the size of the array pointed to by buffer.
  • void esnprintf(char* buffer, int size, const char* formatStringPointer, ... )
    Writes a formatted string to a string buffer. With the maxium number of characters written designated by parameter size.
  • void evprintf(const char* formatStringPointer, va_list argumentsPointer)
    Writes a formatted string to default I/O using variable argument list.
  • void evsprintf(char *buffer, const char *formatStringPointer, va_list argumentsPointer)
    Writes a formatted string to a string buffer using variable argument list.
Input APIs are:
  • /* upcoming soon */
Others
  • #define CONVERT_CR_TO_CRLF_ENABLED 1
    Set this Macro to 1 when you want a '\n' printed as "\r\n". This Macro is set to 1 in default. However, for some implemetation of putchar(int ch) , compilers like GCC for example, the"\r\n" might be interpreted as "\n\n", then you may want to set this Macro to 0.
  • /* upcoming soon */

Replanting

User shall always remember to use the LINK_USER_OUTPUT() Macro to link the user-defined one-byte output function to the library. e.g.

  • LINK_USER_OUTPUT(UART1_PrintOneByte);
  • LINK_USER_OUTPUT(LCD_PrintOneByte);

Examples

//Examples for eprintf - The Embedded String I/O Library

#include "eprintf.h"
#include "stdio.h"

int main(int argc, char const *argv[])
{
    //link the putchar() function in stdio.h to our library
    LINK_USER_OUTPUT(putchar);

    eprintf("1. Hello world\n");
    eprintf("2. %d\n", 123);
    eprintf("3. %6d,%3d%%\n", -75, 5);
    eprintf("4. %-6u\n", 99);
    eprintf("5. %ld\n", 123456789L);
    eprintf("6. %04x\n", 0xA3);
    eprintf("7. %08LX\n", 0x123ABC);
    eprintf("8. %016b\n", 0x550F);
    eprintf("9. %s\n", "String");
    eprintf("a. %-6s\n", "abc");
    eprintf("b. %6s\n", "abc");
    eprintf("c. %c\n", 'a');
    eprintf("d. %f\n", 10.0);

    return 0;
}

//outputs are:
1. Hello world
2. 123
3.    -75,  5%
4. 99    
5. 123456789
6. 00a3
7. 00123ABC
8. 0101010100001111
9. String
a. abc   
b.    abc
c. a
d. 'f' is not supported
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,614评论 0 23
  • 一盏灯,一座城,找一人;一路的颠沛流离/ 电影《从你的全世界路过》我看了,看完后其实也就感性的跟着哭了两场。然而林...
    风卿云谈阅读 4,567评论 0 2
  • 梦里亦知身是客
    应帆阅读 1,490评论 0 0
  • -I"path" include the header path -L"path" include the dyn...
    dragen阅读 3,414评论 0 0
  • 第一章:无敌寂寞 九天之上矗立着一位英姿飒爽的男人,他身穿银色铠甲,头戴玄宇神盔,身后的披风像发怒...
    无天唯我阅读 2,875评论 1 1

友情链接更多精彩内容