Lazuli
Functions
printf.c File Reference

printf implementation. More...

#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <Lazuli/common.h>
#include <Lazuli/config.h>
#include <Lazuli/sys/printf.h>

Go to the source code of this file.

Functions

static char GetHexDigit (const uint8_t i, const bool isUpper)
 Convert a base 16 unit value to its hexadecimal digit representation. More...
 
static uint8_t ConvertU16ToHexadecimal (uint16_t value, char *const buffer, const bool isUpper)
 Convert an unsigned 16-bit integer to its ASCII hexadecimal representation. More...
 
static uint8_t ConvertU16ToOctal (uint16_t value, char *const buffer)
 Convert an unsigned 16-bit integer to its ASCII octal representation. More...
 
static int OutputPadding (uint8_t padLength, const uint8_t size, const char padChar, const bool isNegative)
 Output the padding, according to the selected options. More...
 
static void OutputBuffer (const char *const buffer, const uint8_t size)
 Output the content of the buffer. More...
 
static void OutputReverseBuffer (const char *const buffer, uint8_t size)
 Output the content of the buffer in reverse order. More...
 
int printf (const char *format,...)
 Produce unbuffered formatted output to the serial line. More...
 

Detailed Description

printf implementation.

This file describes the implementation of printf. For now, this module is useless if module SERIAL is not used.

Definition in file printf.c.

Function Documentation

◆ GetHexDigit()

static char GetHexDigit ( const uint8_t  i,
const bool  isUpper 
)
static

Convert a base 16 unit value to its hexadecimal digit representation.

The value must be <= 15.

Parameters
iThe value to convert.
isUpperA boolean value indicating if the conversion must be done in uppercase.
Returns
The hexadecimal character representing the value.

Definition at line 41 of file printf.c.

◆ ConvertU16ToHexadecimal()

static uint8_t ConvertU16ToHexadecimal ( uint16_t  value,
char *const  buffer,
const bool  isUpper 
)
static

Convert an unsigned 16-bit integer to its ASCII hexadecimal representation.

Warning
The conversion is put in the buffer buffer in reverse order and without a final NUL character. The caller of this function then has to use the return value in order to use the characters in the buffer in the right order.
Parameters
valueThe 16-bit input value to convert.
bufferA valid pointer to an allocated buffer of minimum size 4 chars.
isUpperA boolean value indicating if the conversion must be done in uppercase.
Returns
The number of characters actually written to the buffer.

Definition at line 71 of file printf.c.

◆ ConvertU16ToOctal()

static uint8_t ConvertU16ToOctal ( uint16_t  value,
char *const  buffer 
)
static

Convert an unsigned 16-bit integer to its ASCII octal representation.

Warning
The conversion is put in the buffer buffer in reverse order and without a final NUL character. The caller of this function then has to use the return value in order to use the characters in the buffer in the right order.
Parameters
valueThe 16-bit input value to convert.
bufferA valid pointer to an allocated buffer of minimum size 6 chars.
Returns
The number of characters actually written to the buffer.

Definition at line 102 of file printf.c.

◆ OutputPadding()

static int OutputPadding ( uint8_t  padLength,
const uint8_t  size,
const char  padChar,
const bool  isNegative 
)
static

Output the padding, according to the selected options.

Parameters
padLengthThe desired pad length.
sizeThe size of the buffer.
padCharThe character to use for padding.
isNegativeA boolean value indicating if the value to display is negative.
Returns
The final size of the actual output padding.

Definition at line 132 of file printf.c.

◆ OutputBuffer()

static void OutputBuffer ( const char *const  buffer,
const uint8_t  size 
)
static

Output the content of the buffer.

Parameters
bufferA valid pointer to the buffer.
sizeThe size of the buffer.

Definition at line 163 of file printf.c.

◆ OutputReverseBuffer()

static void OutputReverseBuffer ( const char *const  buffer,
uint8_t  size 
)
static

Output the content of the buffer in reverse order.

Parameters
bufferA valid pointer to the buffer.
sizeThe size of the buffer.

Definition at line 179 of file printf.c.

◆ printf()

int printf ( const char *  format,
  ... 
)

Produce unbuffered formatted output to the serial line.

This function is fully reentrant. No locking mechanism is provided.

Flag characters

0 The value should be zero-padded.

Field width

A decimal digit string can be used to specify a minimum field width.

Conversion specifiers

The following conversion specifiers are currently allowed:

d, i The int argument is converted to decimal.

u The unsigned int argument is converted to decimal.

% The character '' is output.

Parameters
formatThe format string.
...The variadic parameters.
Returns
The number of characters output to the serial line, or a negative value if an error occured.
Warning
The stack usage of this function is important.

Definition at line 191 of file printf.c.