GlobLib
HAL and API libraries for MCUs and hardware.
String11

Character string library for C11 compilers. More...

Files

file  string11.h
 Header file for C11 string library.
 

Macros

#define print(X)
 Print a given datatype to the output stream.
 
#define prints(X)
 Print a given datatype + 'space' to the output stream.
 
#define printc(X)
 Print a given datatype + 'comma' to the output stream.
 
#define printl(X)
 Print a given datatype + 'newline' to the output stream.
 
#define printt(X)
 Print a given datatype + 'tab' to the output stream.
 
#define MAX_DEC   4
 Maximum number of decimal places a float will contain.
 

Typedefs

typedef void(* v_fp_u8) (uint8_t)
 Function pointer typedef for void function with uint8_t parameter.
 

Functions

int32_t str2int (char *buffer)
 Convert a null terminated string to an integer. More...
 
uint32_t str2uint (char *buffer)
 Convert a null terminated string to an unsigned integer. More...
 
float str2float (char *buffer)
 Convert a null terminated string to a float. More...
 
void STRING11_setOutput (void(*out)(uint8_t))
 Set the target output stream for print functions. More...
 
v_fp_u8 STRING11_getOutput (void)
 Get the current target output stream. More...
 
void print_c (char x)
 Send a character to the output stream. Implemented internally. More...
 
void print_u8 (uint8_t x)
 Send a unsigned byte to the output stream. Implemented internally. More...
 
void print_8 (int8_t x)
 Send a signed byte to the output stream. Implemented internally. More...
 
void print_u16 (uint16_t x)
 Send a unsigned short to the output stream. Implemented internally. More...
 
void print_16 (int16_t x)
 Send a signed short to the output stream. Implemented internally. More...
 
void print_u32 (uint32_t x)
 Send a unsigned integer to the output stream. Implemented internally. More...
 
void print_32 (int32_t x)
 Send a signed integer to the output stream. Implemented internally. More...
 
void print_f (float x)
 Send a float to the output stream. Implemented internally. More...
 
void print_s (char *x)
 Send a string literal to the output stream. Implemented internally. More...
 
void prints_c (char x)
 Send a character plus a space to the output stream. Implemented internally. More...
 
void prints_u8 (uint8_t x)
 Send a unsigned byte plus a space to the output stream. Implemented internally. More...
 
void prints_8 (int8_t x)
 Send a signed byte plus a space to the output stream. Implemented internally. More...
 
void prints_u16 (uint16_t x)
 Send a unsigned short plus a space to the output stream. Implemented internally. More...
 
void prints_16 (int16_t x)
 Send a signed short plus a space to the output stream. Implemented internally. More...
 
void prints_u32 (uint32_t x)
 Send a unsigned integer plus a space to the output stream. Implemented internally. More...
 
void prints_32 (int32_t x)
 Send a signed integer plus a space to the output stream. Implemented internally. More...
 
void prints_f (float x)
 Send a float plus a space to the output stream. Implemented internally. More...
 
void prints_s (char *x)
 Send a string literal plus a space to the output stream. Implemented internally. More...
 
void printt_c (char x)
 Send a character plus a tab to the output stream. Implemented internally. More...
 
void printt_u8 (uint8_t x)
 Send a unsigned byte plus a tab to the output stream. Implemented internally. More...
 
void printt_8 (int8_t x)
 Send a signed byte plus a tab to the output stream. Implemented internally. More...
 
void printt_u16 (uint16_t x)
 Send a unsigned short plus a tab to the output stream. Implemented internally. More...
 
void printt_16 (int16_t x)
 Send a signed short plus a tab to the output stream. Implemented internally. More...
 
void printt_u32 (uint32_t x)
 Send a unsigned integer plus a tab to the output stream. Implemented internally. More...
 
void printt_32 (int32_t x)
 Send a signed integer plus a tab to the output stream. Implemented internally. More...
 
void printt_f (float x)
 Send a float plus a tab to the output stream. Implemented internally. More...
 
void printt_s (char *x)
 Send a string literal plus a tab to the output stream. Implemented internally. More...
 
void printc_c (char x)
 Send a character plus a comma to the output stream. Implemented internally. More...
 
void printc_u8 (uint8_t x)
 Send a unsigned byte plus a comma to the output stream. Implemented internally. More...
 
void printc_8 (int8_t x)
 Send a signed byte plus a comma to the output stream. Implemented internally. More...
 
void printc_u16 (uint16_t x)
 Send a unsigned short plus a comma to the output stream. Implemented internally. More...
 
void printc_16 (int16_t x)
 Send a signed short plus a comma to the output stream. Implemented internally. More...
 
void printc_u32 (uint32_t x)
 Send a unsigned integer plus a comma to the output stream. Implemented internally. More...
 
void printc_32 (int32_t x)
 Send a signed integer plus a comma to the output stream. Implemented internally. More...
 
void printc_f (float x)
 Send a float plus a comma to the output stream. Implemented internally. More...
 
void printc_s (char *x)
 Send a string literal plus a comma to the output stream. Implemented internally. More...
 
void printl_c (char x)
 Send a character plus a new line to the output stream. Implemented internally. More...
 
void printl_u8 (uint8_t x)
 Send a unsigned byte plus a new line to the output stream. Implemented internally. More...
 
void printl_8 (int8_t x)
 Send a signed byte plus a new line to the output stream. Implemented internally. More...
 
void printl_u16 (uint16_t x)
 Send a unsigned short plus a new line to the output stream. Implemented internally. More...
 
void printl_16 (int16_t x)
 Send a signed short plus a new line to the output stream. Implemented internally. More...
 
void printl_u32 (uint32_t x)
 Send a unsigned integer plus a new line to the output stream. Implemented internally. More...
 
void printl_32 (int32_t x)
 Send a signed integer plus a new line to the output stream. Implemented internally. More...
 
void printl_f (float x)
 Send a float plus a new line to the output stream. Implemented internally. More...
 
void printl_s (char *x)
 Send a string literal plus a new line to the output stream. Implemented internally. More...
 

Detailed Description

Character string library for C11 compilers.

This module is compatable with version C11 of C standard. It impiments the _Generic keyword so a common print() function can be used to create a character stream from multiple data types.

Five main functions exist for usage:

Current limitations

Author
Stuart Ianna
Version
0.2
Date
December 2018
Warning
None
Bug:
None
Todo:
  • Optimisations on functions
Verified Compilers
  • arm-none-eabi-gcc (15:4.9.3+svn231177-1) 4.9.3 20150529 (prerelease)
Example
//Change to include appropriate MCU target
#include <stm32f103cb_core.h>
#include "string11.h"
int main(void)
{
//USART Hardware setup
USART_setup(USART_1);
//Set the string11 library to output on the USART.put function
STRING11_setOutput(USART_add_put(USART_1));
//Create some variables
uint8_t a = 12;
int16_t b = -212;
int32_t c = 1231234;
float d = -1235.23;
char e = '!';
char *f = "Good";
//Print to terminal
while(1){
printt("Some Data"); //Print with a tab
prints(a); //Print with a space
prints(b); //Print with a space
prints(c); //Print with a space
print(d); //Print
prints(e); //Print with a space
prints(123.32f); //Print with a space
printc(f); //Print with a comma
printl("Done"); //Print with a line
for(int i = 0; i < 0x2EEEE;i++); //Wait
}
return 0;
}

Function Documentation

void print_16 ( int16_t  x)

Send a signed short to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 203 of file string11.c.

void print_32 ( int32_t  x)

Send a signed integer to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 243 of file string11.c.

void print_8 ( int8_t  x)

Send a signed byte to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 165 of file string11.c.

void print_c ( char  x)

Send a character to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 137 of file string11.c.

void print_f ( float  x)

Send a float to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 258 of file string11.c.

void print_s ( char *  x)

Send a string literal to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 284 of file string11.c.

void print_u16 ( uint16_t  x)

Send a unsigned short to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 178 of file string11.c.

void print_u32 ( uint32_t  x)

Send a unsigned integer to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 217 of file string11.c.

void print_u8 ( uint8_t  x)

Send a unsigned byte to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 142 of file string11.c.

void printc_16 ( int16_t  x)

Send a signed short plus a comma to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 374 of file string11.c.

void printc_32 ( int32_t  x)

Send a signed integer plus a comma to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 386 of file string11.c.

void printc_8 ( int8_t  x)

Send a signed byte plus a comma to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 362 of file string11.c.

void printc_c ( char  x)

Send a character plus a comma to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 349 of file string11.c.

void printc_f ( float  x)

Send a float plus a comma to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 392 of file string11.c.

void printc_s ( char *  x)

Send a string literal plus a comma to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 398 of file string11.c.

void printc_u16 ( uint16_t  x)

Send a unsigned short plus a comma to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 368 of file string11.c.

void printc_u32 ( uint32_t  x)

Send a unsigned integer plus a comma to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 380 of file string11.c.

void printc_u8 ( uint8_t  x)

Send a unsigned byte plus a comma to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 355 of file string11.c.

void printl_16 ( int16_t  x)

Send a signed short plus a new line to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 433 of file string11.c.

void printl_32 ( int32_t  x)

Send a signed integer plus a new line to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 447 of file string11.c.

void printl_8 ( int8_t  x)

Send a signed byte plus a new line to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 419 of file string11.c.

void printl_c ( char  x)

Send a character plus a new line to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 404 of file string11.c.

void printl_f ( float  x)

Send a float plus a new line to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 454 of file string11.c.

void printl_s ( char *  x)

Send a string literal plus a new line to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 461 of file string11.c.

void printl_u16 ( uint16_t  x)

Send a unsigned short plus a new line to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 426 of file string11.c.

void printl_u32 ( uint32_t  x)

Send a unsigned integer plus a new line to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 440 of file string11.c.

void printl_u8 ( uint8_t  x)

Send a unsigned byte plus a new line to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 411 of file string11.c.

void prints_16 ( int16_t  x)

Send a signed short plus a space to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 319 of file string11.c.

void prints_32 ( int32_t  x)

Send a signed integer plus a space to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 331 of file string11.c.

void prints_8 ( int8_t  x)

Send a signed byte plus a space to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 307 of file string11.c.

void prints_c ( char  x)

Send a character plus a space to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 294 of file string11.c.

void prints_f ( float  x)

Send a float plus a space to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 337 of file string11.c.

void prints_s ( char *  x)

Send a string literal plus a space to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 343 of file string11.c.

void prints_u16 ( uint16_t  x)

Send a unsigned short plus a space to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 313 of file string11.c.

void prints_u32 ( uint32_t  x)

Send a unsigned integer plus a space to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 325 of file string11.c.

void prints_u8 ( uint8_t  x)

Send a unsigned byte plus a space to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 300 of file string11.c.

void printt_16 ( int16_t  x)

Send a signed short plus a tab to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 493 of file string11.c.

void printt_32 ( int32_t  x)

Send a signed integer plus a tab to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 505 of file string11.c.

void printt_8 ( int8_t  x)

Send a signed byte plus a tab to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 481 of file string11.c.

void printt_c ( char  x)

Send a character plus a tab to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 468 of file string11.c.

void printt_f ( float  x)

Send a float plus a tab to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 511 of file string11.c.

void printt_s ( char *  x)

Send a string literal plus a tab to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 517 of file string11.c.

void printt_u16 ( uint16_t  x)

Send a unsigned short plus a tab to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 487 of file string11.c.

void printt_u32 ( uint32_t  x)

Send a unsigned integer plus a tab to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 499 of file string11.c.

void printt_u8 ( uint8_t  x)

Send a unsigned byte plus a tab to the output stream. Implemented internally.

This function is called by macro defined _Generic.

Parameters
xThe data to be printed.
Returns
none.

Definition at line 474 of file string11.c.

float str2float ( char *  buffer)

Convert a null terminated string to a float.

Parameters
bufferCharacter array containing the number
Returns
The parsed integer, returns 0 if contained invalid characters.

Definition at line 76 of file string11.c.

int32_t str2int ( char *  buffer)

Convert a null terminated string to an integer.

Parameters
bufferCharacter array containing the number
Returns
The parsed integer, returns 0 if contained invalid characters.

Definition at line 21 of file string11.c.

uint32_t str2uint ( char *  buffer)

Convert a null terminated string to an unsigned integer.

Parameters
bufferCharacter array containing the number
Returns
The parsed integer, returns 0 if contained invalid characters.

Definition at line 56 of file string11.c.

v_fp_u8 STRING11_getOutput ( void  )

Get the current target output stream.

Returns
Function pointer to output stream or Null if not defined.

Definition at line 128 of file string11.c.

void STRING11_setOutput ( void(*)(uint8_t)  out)

Set the target output stream for print functions.

This function must be called before any print function will work.

Parameters
outPointer to the output stream function.
Returns
none.

Definition at line 122 of file string11.c.