DeBugPrint (dbprint)
Homebrew minimal low-level println/printf replacement
dbprint.h
Go to the documentation of this file.
1 /***************************************************************************//**
2  * @file dbprint.h
3  * @brief Homebrew println/printf replacement "DeBugPrint".
4  * @version 7.0
5  * @author Brecht Van Eeckhoudt
6  *
7  * ******************************************************************************
8  *
9  * @section License
10  *
11  * **Copyright (C) 2019 - Brecht Van Eeckhoudt**
12  *
13  * This program is free software: you can redistribute it and/or modify
14  * it under the terms of the **GNU General Public License** as published by
15  * the Free Software Foundation, either **version 3** of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * *A copy of the GNU General Public License can be found in the `LICENSE`
24  * file along with this source code.*
25  *
26  * @n
27  *
28  * Some methods also use code obtained from examples from [Silicon Labs' GitHub](https://github.com/SiliconLabs/peripheral_examples).
29  * These sections are licensed under the Silabs License Agreement. See the file
30  * "Silabs_License_Agreement.txt" for details. Before using this software for
31  * any purpose, you must agree to the terms of that agreement.
32  *
33  ******************************************************************************/
34 
35 
36 /* Include guards prevent multiple inclusions of the same header */
37 #ifndef _DBPRINT_H_
38 #define _DBPRINT_H_
39 
40 
41 /* Includes necessary for this header file */
42 #include <stdint.h> /* (u)intXX_t */
43 #include <stdbool.h> /* "bool", "true", "false" */
44 #include "em_usart.h" /* Universal synchr./asynchr. receiver/transmitter (USART/UART) Peripheral API */
45 
46 
47 /** Public definition to configure the buffer size. */
48 #define DBPRINT_BUFFER_SIZE 80
49 
50 
51 /** Enum type for the color selection. */
52 typedef enum dbprint_colors
53 {
54  RED,
62 
63 
64 /* Public prototypes */
65 void dbprint_INIT (USART_TypeDef* pointer, uint8_t location, bool vcom, bool interrupts);
66 
67 void dbAlert (void);
68 void dbClear (void);
69 
70 void dbprint (char *message);
71 void dbprintln (char *message);
72 
73 void dbprintInt (int32_t value);
74 void dbprintlnInt (int32_t value);
75 
76 void dbprintInt_hex (int32_t value);
77 void dbprintlnInt_hex (int32_t value);
78 
79 void dbprint_color (char *message, dbprint_color_t color);
80 void dbprintln_color (char *message, dbprint_color_t color);
81 
82 void dbinfo (char *message);
83 void dbwarn (char *message);
84 void dbcrit (char *message);
85 
86 void dbinfoInt (char *message1, int32_t value, char *message2);
87 void dbwarnInt (char *message1, int32_t value, char *message2);
88 void dbcritInt (char *message1, int32_t value, char *message2);
89 
90 void dbinfoInt_hex (char *message1, int32_t value, char *message2);
91 void dbwarnInt_hex (char *message1, int32_t value, char *message2);
92 void dbcritInt_hex (char *message1, int32_t value, char *message2);
93 
94 char dbReadChar (void);
95 uint8_t dbReadInt (void);
96 void dbReadLine (char *buf);
97 
98 bool dbGet_RXstatus (void);
99 // void dbSet_TXbuffer (char *message); // TODO: Needs fixing (but probably won't ever be used)
100 void dbGet_RXbuffer (char *buf);
101 
102 
103 #endif /* _DBPRINT_H_ */
Definition: dbprint.h:57
void dbcritInt(char *message1, int32_t value, char *message2)
Print a critical value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:631
void dbprintln_color(char *message, dbprint_color_t color)
Print a string (char array) to USARTx in a given color and go to the next line.
Definition: dbprint.c:482
void dbprintlnInt_hex(int32_t value)
Print a number in hexadecimal notation to USARTx and go to the next line.
Definition: dbprint.c:813
Definition: dbprint.h:54
void dbwarnInt_hex(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:692
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
Definition: dbprint.c:505
void dbprintlnInt(int32_t value)
Print a number in decimal notation to USARTx and go to the next line.
Definition: dbprint.c:776
uint8_t dbReadInt(void)
Read a decimal character from USARTx and convert it to a uint8_t value.
Definition: dbprint.c:850
dbprint_colors
Definition: dbprint.h:52
void dbwarnInt(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:600
Definition: dbprint.h:55
void dbAlert(void)
Sound an alert in the terminal.
Definition: dbprint.c:344
void dbprintln(char *message)
Print a string (char array) to USARTx and go to the next line.
Definition: dbprint.c:397
void dbprint_INIT(USART_TypeDef *pointer, uint8_t location, bool vcom, bool interrupts)
Initialize USARTx.
Definition: dbprint.c:150
Definition: dbprint.h:59
Definition: dbprint.h:56
void dbprint_color(char *message, dbprint_color_t color)
Print a string (char array) to USARTx in a given color.
Definition: dbprint.c:423
void dbprintInt_hex(int32_t value)
Print a number in hexadecimal notation to USARTx.
Definition: dbprint.c:796
void dbGet_RXbuffer(char *buf)
Get the value of the RX buffer and clear the dataReceived flag.
Definition: dbprint.c:1019
char dbReadChar(void)
Read a character from USARTx.
Definition: dbprint.c:832
void dbprintInt(int32_t value)
Print a number in decimal notation to USARTx.
Definition: dbprint.c:740
void dbReadLine(char *buf)
Read a string (char array) from USARTx.
Definition: dbprint.c:874
void dbcritInt_hex(char *message1, int32_t value, char *message2)
Print a critical value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:723
bool dbGet_RXstatus(void)
Check if data was received using interrupts in the RX buffer.
Definition: dbprint.c:911
void dbprint(char *message)
Print a string (char array) to USARTx.
Definition: dbprint.c:375
enum dbprint_colors dbprint_color_t
void dbwarn(char *message)
Print a warning string (char array) in yellow to USARTx and go to the next line.
Definition: dbprint.c:523
void dbClear(void)
Clear the terminal.
Definition: dbprint.c:358
void dbinfoInt(char *message1, int32_t value, char *message2)
Print an info value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:569
void dbinfoInt_hex(char *message1, int32_t value, char *message2)
Print an info value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:661
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
Definition: dbprint.c:541