DeBugPrint (dbprint)
Homebrew minimal low-level println/printf replacement
|
Homebrew println/printf replacement "DeBugPrint". More...
#include "debug_dbprint.h"
#include <stdint.h>
#include <stdbool.h>
#include "em_cmu.h"
#include "em_gpio.h"
#include "em_usart.h"
Go to the source code of this file.
Macros | |
#define | TO_HEX(i) (i <= 9 ? '0' + i : 'A' - 10 + i) /* "?:" = ternary operator (return ['0' + i] if [i <= 9] = true, ['A' - 10 + i] if false) */ |
#define | TO_DEC(i) (i <= 9 ? '0' + i : '?') /* return "?" if out of range */ |
#define | COLOR_RED "\x1b[31m" |
#define | COLOR_GREEN "\x1b[32m" |
#define | COLOR_BLUE "\x1b[34m" |
#define | COLOR_CYAN "\x1b[36m" |
#define | COLOR_MAGENTA "\x1b[35m" |
#define | COLOR_YELLOW "\x1b[33m" |
#define | COLOR_RESET "\x1b[0m" |
Functions | |
static void | uint32_to_charHex (char *buf, uint32_t value, bool spacing) |
Convert a uint32_t value to a hexadecimal char array (string). More... | |
static void | uint32_to_charDec (char *buf, uint32_t value) |
Convert a uint32_t value to a decimal char array (string). More... | |
static uint32_t | charDec_to_uint32 (char *buf) |
Convert a string (char array) in decimal notation to a uint32_t value. More... | |
void | dbprint_INIT (USART_TypeDef *pointer, uint8_t location, bool vcom, bool interrupts) |
Initialize USARTx. More... | |
void | dbAlert (void) |
Sound an alert in the terminal. More... | |
void | dbClear (void) |
Clear the terminal. More... | |
void | dbprint (char *message) |
Print a string (char array) to USARTx. More... | |
void | dbprintln (char *message) |
Print a string (char array) to USARTx and go to the next line. More... | |
void | dbprint_color (char *message, dbprint_color_t color) |
Print a string (char array) to USARTx in a given color. More... | |
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. More... | |
void | dbinfo (char *message) |
Print an info string (char array) to USARTx and go to the next line. More... | |
void | dbwarn (char *message) |
Print a warning string (char array) in yellow to USARTx and go to the next line. More... | |
void | dbcrit (char *message) |
Print a critical error string (char array) in red to USARTx and go to the next line. More... | |
void | dbinfoInt (char *message1, int32_t value, char *message2) |
Print an info value surrounded by two strings (char array) to USARTx. More... | |
void | dbwarnInt (char *message1, int32_t value, char *message2) |
Print a warning value surrounded by two strings (char array) to USARTx. More... | |
void | dbcritInt (char *message1, int32_t value, char *message2) |
Print a critical value surrounded by two strings (char array) to USARTx. More... | |
void | dbinfoInt_hex (char *message1, int32_t value, char *message2) |
Print an info value surrounded by two strings (char array) to USARTx. More... | |
void | dbwarnInt_hex (char *message1, int32_t value, char *message2) |
Print a warning value surrounded by two strings (char array) to USARTx. More... | |
void | dbcritInt_hex (char *message1, int32_t value, char *message2) |
Print a critical value surrounded by two strings (char array) to USARTx. More... | |
void | dbprintInt (int32_t value) |
Print a number in decimal notation to USARTx. More... | |
void | dbprintlnInt (int32_t value) |
Print a number in decimal notation to USARTx and go to the next line. More... | |
void | dbprintInt_hex (int32_t value) |
Print a number in hexadecimal notation to USARTx. More... | |
void | dbprintlnInt_hex (int32_t value) |
Print a number in hexadecimal notation to USARTx and go to the next line. More... | |
char | dbReadChar (void) |
Read a character from USARTx. More... | |
uint8_t | dbReadInt (void) |
Read a decimal character from USARTx and convert it to a uint8_t value. More... | |
void | dbReadLine (char *buf) |
Read a string (char array) from USARTx. More... | |
bool | dbGet_RXstatus (void) |
Check if data was received using interrupts in the RX buffer. More... | |
void | dbGet_RXbuffer (char *buf) |
Get the value of the RX buffer and clear the dataReceived flag. More... | |
void | USART0_RX_IRQHandler (void) |
USART0 RX interrupt service routine. More... | |
void | USART0_TX_IRQHandler (void) |
USART0 TX interrupt service routine. More... | |
void | USART1_RX_IRQHandler (void) |
USART1 RX interrupt service routine. More... | |
void | USART1_TX_IRQHandler (void) |
USART1 TX interrupt service routine. More... | |
Variables | |
USART_TypeDef * | dbpointer |
volatile bool | dataReceived = false |
volatile char | rx_buffer [80] |
volatile char | tx_buffer [80] |
Homebrew println/printf replacement "DeBugPrint".
Originally designed for use on the Silicion Labs Happy Gecko EFM32 board (EFM32HG322 – TQFP48).
Please check https://github.com/Fescron/dbprint to find the latest version of dbprint!
dbpointer
a local variable (removed extern
). Removed extern
from the documentation. static
before the local variables (not necessary). dbSet_TXbuffer
and charHex_to_uint32
(if necessary).Copyright (C) 2019 - Brecht Van Eeckhoudt
This program 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 program 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.
A copy of the GNU General Public License can be found in the LICENSE
file along with this source code.
Some methods also use code obtained from examples from Silicon Labs' GitHub. These sections are licensed under the Silabs License Agreement. See the file "Silabs_License_Agreement.txt" for details. Before using this software for any purpose, you must agree to the terms of that agreement.
dbprint_documentation.h
for a lot of useful documentation! Definition in file dbprint.c.
#define TO_DEC | ( | i | ) | (i <= 9 ? '0' + i : '?') /* return "?" if out of range */ |
#define TO_HEX | ( | i | ) | (i <= 9 ? '0' + i : 'A' - 10 + i) /* "?:" = ternary operator (return ['0' + i] if [i <= 9] = true, ['A' - 10 + i] if false) */ |
|
static |
Convert a string (char array) in decimal notation to a uint32_t
value.
"00BA0FA1"
) but a char array, the input buffer (array) needs to end with NULL ("\0"
)![in] | buf | The decimal string to convert to a uint32_t value. |
uint32_t
value. Definition at line 1186 of file dbprint.c.
void dbAlert | ( | void | ) |
void dbClear | ( | void | ) |
void dbcrit | ( | char * | message | ) |
Print a critical error string (char array) in red to USARTx and go to the next line.
"Hello world!"
) but a char array, the input message (array) needs to end with NULL ("\0"
)![in] | message | The string to print to USARTx. |
Definition at line 541 of file dbprint.c.
void dbcritInt | ( | char * | message1, |
int32_t | value, | ||
char * | message2 | ||
) |
Print a critical value surrounded by two strings (char array) to USARTx.
"CRIT: " gets added in front, the decimal notation is used and the function advances to the next line. The value is in the color white, the rest is red.
"Hello world!"
) but a char array, the input message (array) needs to end with NULL ("\0"
)![in] | message1 | The first part of the string to print to USARTx. |
[in] | value | The value to print between the two string parts. |
[in] | message2 | The second part of the string to print to USARTx. |
Definition at line 631 of file dbprint.c.
void dbcritInt_hex | ( | char * | message1, |
int32_t | value, | ||
char * | message2 | ||
) |
Print a critical value surrounded by two strings (char array) to USARTx.
"CRIT: " gets added in front, the hexadecimal notation is used and the function advances to the next line. The value is in the color white, the rest is red.
"Hello world!"
) but a char array, the input message (array) needs to end with NULL ("\0"
)![in] | message1 | The first part of the string to print to USARTx. |
[in] | value | The value to print between the two string parts. |
[in] | message2 | The second part of the string to print to USARTx. |
Definition at line 723 of file dbprint.c.
void dbGet_RXbuffer | ( | char * | buf | ) |
Get the value of the RX buffer and clear the dataReceived
flag.
[in] | buf | The buffer to put the resulting string in. This needs to have a length of DBPRINT_BUFFER_SIZE for the function to work properly: char buf[DBPRINT_BUFFER_SIZE]; ! |
Definition at line 1019 of file dbprint.c.
bool dbGet_RXstatus | ( | void | ) |
Check if data was received using interrupts in the RX buffer.
true
- Data is received in the RX buffer. false
- No data is received. Definition at line 911 of file dbprint.c.
void dbinfo | ( | char * | message | ) |
Print an info string (char array) to USARTx and go to the next line.
"Hello world!"
) but a char array, the input message (array) needs to end with NULL ("\0"
)![in] | message | The string to print to USARTx. |
Definition at line 505 of file dbprint.c.
void dbinfoInt | ( | char * | message1, |
int32_t | value, | ||
char * | message2 | ||
) |
Print an info value surrounded by two strings (char array) to USARTx.
"INFO: " gets added in front, the decimal notation is used and the function advances to the next line.
"Hello world!"
) but a char array, the input message (array) needs to end with NULL ("\0"
)![in] | message1 | The first part of the string to print to USARTx. |
[in] | value | The value to print between the two string parts. |
[in] | message2 | The second part of the string to print to USARTx. |
Definition at line 569 of file dbprint.c.
void dbinfoInt_hex | ( | char * | message1, |
int32_t | value, | ||
char * | message2 | ||
) |
Print an info value surrounded by two strings (char array) to USARTx.
"INFO: " gets added in front, the hexadecimal notation is used and the function advances to the next line.
"Hello world!"
) but a char array, the input message (array) needs to end with NULL ("\0"
)![in] | message1 | The first part of the string to print to USARTx. |
[in] | value | The value to print between the two string parts. |
[in] | message2 | The second part of the string to print to USARTx. |
Definition at line 661 of file dbprint.c.
void dbprint | ( | char * | message | ) |
void dbprint_color | ( | char * | message, |
dbprint_color_t | color | ||
) |
Print a string (char array) to USARTx in a given color.
"Hello world!"
) but a char array, the input message (array) needs to end with NULL ("\0"
)![in] | message | The string to print to USARTx. |
[in] | color | The color to print the text in. |
Definition at line 423 of file dbprint.c.
void dbprint_INIT | ( | USART_TypeDef * | pointer, |
uint8_t | location, | ||
bool | vcom, | ||
bool | interrupts | ||
) |
Initialize USARTx.
[in] | pointer | Pointer to USARTx. |
[in] | location | Location for pin routing. |
[in] | vcom |
|
[in] | interrupts |
|
Definition at line 150 of file dbprint.c.
void dbprintInt | ( | int32_t | value | ) |
Print a number in decimal notation to USARTx.
[in] | value | The number to print to USARTx. This can be of type uint32_t or int32_t . |
Definition at line 740 of file dbprint.c.
void dbprintInt_hex | ( | int32_t | value | ) |
Print a number in hexadecimal notation to USARTx.
[in] | value | The number to print to USARTx. This can be of type uint32_t or int32_t . |
Definition at line 796 of file dbprint.c.
void dbprintln | ( | char * | message | ) |
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.
"Hello world!"
) but a char array, the input message (array) needs to end with NULL ("\0"
)![in] | message | The string to print to USARTx. |
[in] | color | The color to print the text in. |
Definition at line 482 of file dbprint.c.
void dbprintlnInt | ( | int32_t | value | ) |
Print a number in decimal notation to USARTx and go to the next line.
[in] | value | The number to print to USARTx. This can be of type uint32_t or int32_t . |
Definition at line 776 of file dbprint.c.
void dbprintlnInt_hex | ( | int32_t | value | ) |
Print a number in hexadecimal notation to USARTx and go to the next line.
[in] | value | The number to print to USARTx. This can be of type uint32_t or int32_t . |
Definition at line 813 of file dbprint.c.
char dbReadChar | ( | void | ) |
uint8_t dbReadInt | ( | void | ) |
Read a decimal character from USARTx and convert it to a uint8_t
value.
uint16_t
and uint32_t
values:uint16_t USART_RxDouble(USART_TypeDef *usart);
uint32_t USART_RxDoubleExt(USART_TypeDef *usart);
uint8_t
value. Definition at line 850 of file dbprint.c.
void dbReadLine | ( | char * | buf | ) |
Read a string (char array) from USARTx.
"CR"
(Carriage Return, ENTER) character is received or the maximum length (DBPRINT_BUFFER_SIZE
) is reached.[in] | buf | The buffer to put the resulting string in. This needs to have a length of DBPRINT_BUFFER_SIZE for the function to work properly: char buf[DBPRINT_BUFFER_SIZE]; ! |
Definition at line 874 of file dbprint.c.
void dbwarn | ( | char * | message | ) |
Print a warning string (char array) in yellow to USARTx and go to the next line.
"Hello world!"
) but a char array, the input message (array) needs to end with NULL ("\0"
)![in] | message | The string to print to USARTx. |
Definition at line 523 of file dbprint.c.
void dbwarnInt | ( | char * | message1, |
int32_t | value, | ||
char * | message2 | ||
) |
Print a warning value surrounded by two strings (char array) to USARTx.
"WARN: " gets added in front, the decimal notation is used and the function advances to the next line. The value is in the color white, the rest is yellow.
"Hello world!"
) but a char array, the input message (array) needs to end with NULL ("\0"
)![in] | message1 | The first part of the string to print to USARTx. |
[in] | value | The value to print between the two string parts. |
[in] | message2 | The second part of the string to print to USARTx. |
Definition at line 600 of file dbprint.c.
void dbwarnInt_hex | ( | char * | message1, |
int32_t | value, | ||
char * | message2 | ||
) |
Print a warning value surrounded by two strings (char array) to USARTx.
"WARN: " gets added in front, the hexadecimal notation is used and the function advances to the next line. The value is in the color white, the rest is yellow.
"Hello world!"
) but a char array, the input message (array) needs to end with NULL ("\0"
)![in] | message1 | The first part of the string to print to USARTx. |
[in] | value | The value to print between the two string parts. |
[in] | message2 | The second part of the string to print to USARTx. |
Definition at line 692 of file dbprint.c.
|
static |
Convert a uint32_t
value to a decimal char array (string).
[out] | buf | The buffer to put the resulting string in. This needs to have a length of 10: char buf[10]; ! |
[in] | value | The uint32_t value to convert to a string. |
Definition at line 1124 of file dbprint.c.
|
static |
Convert a uint32_t
value to a hexadecimal char array (string).
[out] | buf | The buffer to put the resulting string in. This needs to have a length of 9: char buf[9]; ! |
[in] | value | The uint32_t value to convert to a string. |
[in] | spacing |
|
Definition at line 1063 of file dbprint.c.
void USART0_RX_IRQHandler | ( | void | ) |
void USART0_TX_IRQHandler | ( | void | ) |
void USART1_RX_IRQHandler | ( | void | ) |
USART1 RX interrupt service routine.
system_efm32hg.h
. Definition at line 1355 of file dbprint.c.
void USART1_TX_IRQHandler | ( | void | ) |
USART1 TX interrupt service routine.
system_efm32hg.h
. Definition at line 1369 of file dbprint.c.
USART_TypeDef* dbpointer |