ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
mathio.h
Go to the documentation of this file.
1 
27 #ifndef _MATHIO_H_
28 #define _MATHIO_H_
29 
30 // Define what memory space the function is located in
31 // With ESP8266 we can use this for cached and non-cached code space
32 #ifndef MEMSPACE
33 #define MEMSPACE
34 #endif
35 
36 // With AVR CPU types we can make this a 24bit pointer
37 #ifndef AVR
38 #define __memx
39 #endif
40 
41 // Weak attribute
42 // Allow functions defined here to be overridden by an external ones
43 
44 #ifndef WEAK_ATR
45 #define WEAK_ATR __attribute__((weak))
46 #endif
47 
48 extern int putchar(int c);
49 
50 // =============================================
51 /* mathio.c */
52 MEMSPACE int atodigit ( int c , int radix );
53 MEMSPACE long atoh ( const char *p );
54 MEMSPACE long aton ( char *str , int base );
55 MEMSPACE int mul10str ( uint8_t *str , int size );
56 MEMSPACE long strtol ( const char *nptr , char **endptr , int base );
57 MEMSPACE long long strtoll ( const char *nptr , char **endptr , int base );
58 #ifdef __SIZEOF_INT128__
59 MEMSPACE __uint128_t strto128 ( const char *nptr , char **endptr , int base );
60 #endif
61 MEMSPACE int atoi ( const char *str );
62 MEMSPACE long atol ( const char *str );
63 MEMSPACE double iexp ( double num , int exp );
64 MEMSPACE double scale10 ( double num , int *exp );
65 MEMSPACE double strtod ( const char *nptr , char **endptr );
66 MEMSPACE double atof ( const char *str );
67 
68 
69 // =============================================
70 
71 #undef atof
72 #undef strlen
74 #undef isdigit
75 #undef vnsprintf
76 #undef snprintf
77 
78 // =============================================
79 /* printf.c */
81 typedef struct _printf_t
82 {
83  void (*put)(struct _printf_t *, char);
84  void *buffer;
85  int len;
86  int sent;
87 } printf_t;
88 
90 typedef union {
91  struct {
92  unsigned short width : 1;
93  unsigned short prec : 1;
94  unsigned short plus : 1;
95  unsigned short left : 1;
96  unsigned short space : 1;
97  unsigned short zero : 1;
98  unsigned short neg: 1;
99  unsigned short alt: 1;
100  } b;
101  unsigned short all;
102 } f_t;
103 
104 /* printf.c */
105 MEMSPACE size_t WEAK_ATR strlen ( const char *str );
106 MEMSPACE int WEAK_ATR isdigit ( int c );
107 MEMSPACE void WEAK_ATR reverse ( char *str );
108 MEMSPACE void WEAK_ATR strupper ( char *str );
109 MEMSPACE int bin2num ( uint8_t *str , int strmax , int nummin , int base , uint8_t *nump , int numsize , int sign_ch );
110 MEMSPACE void pch_init ( char *str , int max );
111 MEMSPACE int pch ( char ch );
112 MEMSPACE int pch_ind ( void );
113 MEMSPACE int pch_max_ind ( void );
114 MEMSPACE void print_flags ( f_t f );
115 MEMSPACE int p_ntoa ( uint8_t *nump , int numsize , char *str , int strmax , int radix , int width , int prec , f_t f );
116 MEMSPACE int p_ftoa ( double val , char *str , int max , int width , int prec , f_t f );
117 MEMSPACE int p_etoa ( double val , char *str , int max , int width , int prec , f_t f );
118 MEMSPACE void _puts_pad ( printf_t *fn , char *s , int width , int count , int left );
119 MEMSPACE void _printf_fn ( printf_t *fn , __memx const char *fmt , va_list va );
120 MEMSPACE void _putc_buffer_fn ( struct _printf_t *p , char ch );
121 MEMSPACE int vsnprintf ( char *str , size_t size , const char *format , va_list va );
122 MEMSPACE int snprintf ( char *str , size_t size , const char *format , ...);
123 MEMSPACE int printf ( const char *format , ...);
124 #ifdef AVR
125 MEMSPACE int vsnprintf_P ( char *str , size_t size , __memx const char *format , va_list va );
126 MEMSPACE int snprintf_P ( char *str , size_t size , __memx const char *format , ...);
127 MEMSPACE int sprintf_P ( char *str , __memx const char *format , ...);
128 MEMSPACE int printf_P ( __memx const char *format , ...);
129 #endif
130 
131 
132 /* sscanf.c */
133 int sscanf ( const char *strp , const char *fmt , ...);
134 
135 #endif // ifndef _MATHIO_H_
MEMSPACE void pch_init(char *str, int max)
Initialize character buffer with limits.
Definition: printf.c:222
MEMSPACE int vsnprintf(char *str, size_t size, const char *format, va_list va)
vsnprintf function
Definition: printf.c:1135
#define __memx
Definition: mathio.h:38
MEMSPACE int pch_ind(void)
Return current index of character buffer with limits.
Definition: printf.c:250
MEMSPACE double scale10(double num, int *exp)
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 ...
Definition: printf.c:139
MEMSPACE long atol(const char *str)
Convert ASCII string to number in base 10.
Definition: mathio.c:295
#define MEMSPACE
Definition: mathio.h:33
MEMSPACE int pch(char ch)
Put character in buffer with limits.
Definition: printf.c:237
MEMSPACE void _printf_fn(printf_t *fn, __memx const char *fmt, va_list va)
vsnprintf function
Definition: printf.c:741
MEMSPACE long atoh(const char *p)
Convert ASCII hex string to long integer.
Definition: mathio.c:79
MEMSPACE long strtol(const char *nptr, char **endptr, int base)
Convert ASCII string to number in a given base.
Definition: mathio.c:136
MEMSPACE void WEAK_ATR strupper(char *str)
UPPERCASE a string.
Definition: stringsup.c:253
int putchar(int c)
put a character to stdout See fdevopen() sets stream->put get for TTY devices
Definition: posix.c:351
MEMSPACE size_t WEAK_ATR strlen(const char *str)
String Length.
Definition: stringsup.c:146
MEMSPACE double atof(const char *str)
struct _printf_t printf_t
undefine any potential macro version of these functions
MEMSPACE double strtod(const char *nptr, char **endptr)
#define WEAK_ATR
Definition: mathio.h:45
void * buffer
Definition: mathio.h:84
MEMSPACE long long strtoll(const char *nptr, char **endptr, int base)
Convert ASCII string to number in a given base.
Definition: mathio.c:183
MEMSPACE double iexp(double num, int exp)
int sscanf(const char *strp, const char *fmt,...)
int len
Definition: mathio.h:85
MEMSPACE int WEAK_ATR isdigit(int c)
test if a character is a digit
Definition: stringsup.c:48
MEMSPACE int mul10str(uint8_t *str, int size)
Fast multiply number of any size by 10.
Definition: mathio.c:108
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 dig...
Definition: printf.c:314
MEMSPACE int pch_max_ind(void)
Return maximum valid index for character buffer.
Definition: printf.c:258
unsigned short all
Definition: mathio.h:101
MEMSPACE int printf(const char *format,...)
MEMSPACE int p_etoa(double val, char *str, int max, int width, int prec, f_t f)
MEMSPACE void print_flags(f_t f)
print flags set in t_t structure
Definition: printf.c:270
MEMSPACE void _puts_pad(printf_t *fn, char *s, int width, int count, int left)
Definition: printf.c:683
MEMSPACE long aton(char *str, int base)
Convert ASCII string to number in a given base.
Definition: mathio.c:93
int sent
Definition: mathio.h:86
MEMSPACE int snprintf(char *str, size_t size, const char *format,...)
snprintf function
Definition: printf.c:1164
MEMSPACE void WEAK_ATR reverse(char *str)
Reverse a string in place Example: abcdef -> fedcba.
Definition: stringsup.c:231
format specifier flags
Definition: mathio.h:90
unsigned char uint8_t
Definition: send.c:17
MEMSPACE int atodigit(int c, int radix)
Convert ASCII character to radix based digit , or -1.
Definition: mathio.c:58
MEMSPACE int p_ftoa(double val, char *str, int max, int width, int prec, f_t f)
void(* put)(struct _printf_t *, char)
Definition: mathio.h:83
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 _pr...
Definition: printf.c:1103
MEMSPACE int atoi(const char *str)
Convert ASCII string to number in base 10.
Definition: mathio.c:281
undefine any potential macro version of these functions
Definition: mathio.h:81