ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
Data Structures | Functions | Variables
printf.c File Reference

Small printf, and verious conversion code with floating point support. More...

#include <stdint.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include "mathio.h"

Go to the source code of this file.

Data Structures

struct  p_ch_t
 Data structure for character buffer with limits. More...
 

Functions

MEMSPACE size_t WEAK_ATR strlen (const char *str)
 String Length. More...
 
MEMSPACE int WEAK_ATR isdigit (int c)
 test if a character is a digit More...
 
MEMSPACE void WEAK_ATR reverse (char *str)
 Reverse a string in place Example: abcdef -> fedcba. More...
 
MEMSPACE void WEAK_ATR strupper (char *str)
 UPPERCASE a string. More...
 
MEMSPACE int bin2num (uint8_t *str, int strmax, int nummin, int base, uint8_t *nump, int numsize, int sign_ch)
 Convert an unsigned number (numsize bytes in size) to ASCII in specified base Notes: No limit except available memory on number size. More...
 
MEMSPACE void pch_init (char *str, int max)
 Initialize character buffer with limits. More...
 
MEMSPACE int pch (char ch)
 Put character in buffer with limits. More...
 
MEMSPACE int pch_ind ()
 Return current index of character buffer with limits. More...
 
MEMSPACE int pch_max_ind ()
 Return maximum valid index for character buffer. More...
 
MEMSPACE void print_flags (f_t f)
 print flags set in t_t structure More...
 
MEMSPACE int p_ntoa (uint8_t *nump, int numsize, char *str, int strmax, int radix, int width, int prec, f_t f)
 Convert number an base 2 .. 16 to ASCII with optional sign Notes: 1) Numbers can be any number of digits long - limited only by memory available To print negative numbers convert to positive before calling this function and set f.b.neg 2) Warning: as with printf width and prec are only minimum sizes - results can be bigger We assume all numbers are positive: More...
 
MEMSPACE void _puts_pad (printf_t *fn, char *s, int width, int count, int left)
 
MEMSPACE void _printf_fn (printf_t *fn, __memx const char *fmt, va_list va)
 vsnprintf function More...
 
MEMSPACE void _putc_buffer_fn (struct _printf_t *p, char ch)
 _putc_buffer_fn - character output to a string buffer Used by snprintf and vsnprintf You can make _printf_fn call this helper for each character More...
 
MEMSPACE int vsnprintf (char *str, size_t size, const char *format, va_list va)
 vsnprintf function More...
 
MEMSPACE int snprintf (char *str, size_t size, const char *format,...)
 snprintf function More...
 

Variables

p_ch_t _pch
 Define data structure for character buffer with limits. More...
 

Detailed Description

Small printf, and verious conversion code with floating point support.

Copyright © 2014-2017 Mike Gore, All rights reserved. GPL License
See also
http://github.com/magore/hp85disk
http://github.com/magore/hp85disk/COPYRIGHT.md for specific Copyright details
You are free to use this code under the terms of GPL
please retain a copy of this notice in any code you use it in.

This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file printf.c.

Function Documentation

MEMSPACE void _printf_fn ( printf_t fn,
__memx const char *  fmt,
va_list  va 
)

vsnprintf function

Parameters
[out]fnoutput character function pointer
[in]fmtprintf forat string
[in]vava_list arguments
Returns
size of string

Calling Variadic Functions

  • exceprt from https://www.gnu.org/software/libc/manual/html_node/Calling-Variadics.html Since the prototype doesn’t specify types for optional arguments, in a call to a variadic function the default argument promotions are performed on the optional argument values. This means the objects of type char or short int (whether signed or not) are promoted to either int or unsigned int, as appropriate; and that objects of type float are promoted to type double. So, if the caller passes a char as an optional argument, it is promoted to an int, and the function can access it with va_arg (ap, int).

Definition at line 741 of file printf.c.

Referenced by fprintf(), snprintf(), tft_printf(), uart0_printf(), vsnprintf(), and vsock_printf().

MEMSPACE void _putc_buffer_fn ( struct _printf_t p,
char  ch 
)

_putc_buffer_fn - character output to a string buffer Used by snprintf and vsnprintf You can make _printf_fn call this helper for each character

Parameters
[in]*pstructure with pointers and buffer to be written to
[in]chcharacter to place in buffer
Returns
void

Definition at line 1103 of file printf.c.

Referenced by snprintf(), and vsnprintf().

MEMSPACE void _puts_pad ( printf_t fn,
char *  s,
int  width,
int  count,
int  left 
)

Definition at line 683 of file printf.c.

Referenced by _printf_fn().

MEMSPACE int bin2num ( uint8_t str,
int  strmax,
int  nummin,
int  base,
uint8_t nump,
int  numsize,
int  sign_ch 
)

Convert an unsigned number (numsize bytes in size) to ASCII in specified base Notes: No limit except available memory on number size.

  • Does not use divide or of multiply instructions - great on 8bit CPU's How it works: Say you have a table of powers of 2 in a given base base
  • To get the result add each table entry, in the base, that corresponds to each 1 bit in the binary number.
  • Now instead of a table we can start with 1 and multiple by 2 contraining each digit into the base we want - this is the same as using the table except we build it on the fly
    Parameters
    [out]strASCII number string result
    [in]strmaxmaximum size of str in bytes
    [in]numminminimum number of digits to display
    [in]*numpPointer to binary number
    [in]numsizesize of binary number in bytes
    [in]sign_chsign of binary number return converted number string numsize in bytes

Definition at line 139 of file printf.c.

Referenced by p_ntoa().

MEMSPACE int WEAK_ATR isdigit ( int  c)

test if a character is a digit

Parameters
[in]ccharacter
Returns
true or false

Definition at line 70 of file printf.c.

Referenced by _printf_fn().

MEMSPACE int p_ntoa ( uint8_t nump,
int  numsize,
char *  str,
int  strmax,
int  radix,
int  width,
int  prec,
f_t  f 
)

Convert number an base 2 .. 16 to ASCII with optional sign Notes: 1) Numbers can be any number of digits long - limited only by memory available To print negative numbers convert to positive before calling this function and set f.b.neg 2) Warning: as with printf width and prec are only minimum sizes - results can be bigger We assume all numbers are positive:

Parameters
[in]numpnumber pointer
[in]numsizenumber size in bytes
[out]*strstring result
[in]strmaxstrmaximum length of string result
[in]radixRadix may be 2 .. 16
[in]widthWidth of result padded if needed
[in]precminumum number of digits, zero padded if needed
[in]fflags f.b.left justify left f.b.plus display + for positive number, - for negative numbers f.b.space display ' ' for positive, - for negative f.b.zero pad with zeros if needed f.b.alt Alternate display form - work in progress f.b.width Width of result - pad if required f.b.prec Zero padd to prec if sepcified f.b.neg Sign of number is negative

Definition at line 314 of file printf.c.

Referenced by _printf_fn().

MEMSPACE int pch ( char  ch)

Put character in buffer with limits.

Parameters
[in]strstring
[in]maxmaximum number of characters plus EOS init_p_ch
Returns
void

Definition at line 237 of file printf.c.

Referenced by p_ntoa().

MEMSPACE int pch_ind ( void  )

Return current index of character buffer with limits.

Returns
Buffer index

Definition at line 250 of file printf.c.

Referenced by p_ntoa().

MEMSPACE void pch_init ( char *  str,
int  max 
)

Initialize character buffer with limits.

Parameters
[in]strstring
[in]maxmaximum number of characters plus EOS
Returns
void

base of string to write to

current string index

maximum string size including EOS

Definition at line 222 of file printf.c.

Referenced by p_ntoa().

MEMSPACE int pch_max_ind ( void  )

Return maximum valid index for character buffer.

Returns
Buffer index

Definition at line 258 of file printf.c.

MEMSPACE void print_flags ( f_t  f)

print flags set in t_t structure

Parameters
[in]ff_t flags structure
Returns
void

Definition at line 270 of file printf.c.

MEMSPACE void WEAK_ATR reverse ( char *  str)

Reverse a string in place Example: abcdef -> fedcba.

Parameters
[in]strstring
Returns
string length

Definition at line 88 of file printf.c.

Referenced by bin2num().

MEMSPACE int snprintf ( char *  str,
size_t  size,
const char *  format,
  ... 
)

snprintf function

Parameters
[out]strstring buffer for result
[in]sizemaximum length of converted string
[in]formatprintf forat string
[in]...list of arguments
Returns
string size

Definition at line 1164 of file printf.c.

MEMSPACE size_t WEAK_ATR strlen ( const char *  str)

String Length.

Parameters
[in]strstring
Returns
string length

Definition at line 53 of file printf.c.

Referenced by _printf_fn(), p_ntoa(), reverse(), snprintf(), and vsnprintf().

MEMSPACE void WEAK_ATR strupper ( char *  str)

UPPERCASE a string.

Parameters
[in]strstring
Returns
void

Definition at line 109 of file printf.c.

Referenced by _printf_fn().

MEMSPACE int vsnprintf ( char *  str,
size_t  size,
const char *  format,
va_list  va 
)

vsnprintf function

Parameters
[out]strstring buffer for result
[in]sizemaximum length of converted string
[in]formatprintf forat string
[in]vava_list list of arguments
Returns
string size

Definition at line 1135 of file printf.c.

Referenced by html_msg(), and snprintf().

Variable Documentation

p_ch_t _pch

Define data structure for character buffer with limits.

Definition at line 215 of file printf.c.