DeBugPrint (dbprint)
Homebrew minimal low-level println/printf replacement
dbprint.c
Go to the documentation of this file.
1 /***************************************************************************//**
2  * @file dbprint.c
3  * @brief Homebrew println/printf replacement "DeBugPrint".
4  * @details Originally designed for use on the Silicion Labs Happy Gecko EFM32 board (EFM32HG322 -- TQFP48).
5  * @version 7.0
6  * @author Brecht Van Eeckhoudt
7  *
8  * ******************************************************************************
9  *
10  * @section Versions
11  *
12  * Please check https://github.com/Fescron/dbprint to find the latest version of dbprint!
13  *
14  * @li v1.0: "define" used to jump between VCOM or other mode, itoa (<stdlib.h>) used aswell as stdio.h
15  * @li v1.1: Separated printInt method in a separate function for printing "int32_t" and "uint32_t" values.
16  * @li v1.2: Added more options to the initialize method (location selection & boolean if VCOM is used).
17  * @li v2.0: Restructured files to be used in other projects, added a lot more documentation, added "dbAlert" and "dbClear" methods.
18  * @li v2.1: Added interrupt functionality.
19  * @li v2.2: Added parse functions, separated method for printing uint values in a separate one for DEC and HEX notation.
20  * @li v2.3: Updated documentation.
21  * @li v2.4: Fixed notes.
22  * @li v2.5: Separated method for printing int values in a separate one for DEC and HEX notation.
23  * @li v2.6: Stopped using itoa (<stdlib.h>) in all methods.
24  * @li v3.0: Simplified number printing, stopped using separate methods for uint and int values.
25  * @li v3.1: Removed useless if... check.
26  * @li v3.2: Added the ability to print text in a color.
27  * @li v3.3: Added info, warning and critical error printing methods.
28  * @li v3.4: Added printInt(_hex) methods that directly go to a new line.
29  * @li v3.5: Added USART0 IRQ handlers.
30  * @li v3.6: Added the ability to print (u)int values as INFO, WARN or CRIT lines.
31  * @li v3.7: Added separate "_hex" methods for dbinfo/warn/critInt instead of a boolean to select (hexa)decimal notation.
32  * @li v3.8: Added ReadChar-Int-Line methods.
33  * @li v3.9: Added "void" between argument brackets were before nothing was.
34  * @li v4.0: Added more documentation.
35  * @li v4.1: Added color reset before welcome message.
36  * @li v5.0: Made uint-char conversion methods static, moved color functionality to enum,
37  * started moving interrupt functionality to use getters and setters.
38  * @li v5.1: Fixed interrupt functionality with getters and setters.
39  * @li v6.0: Cleaned up interrupt functionality and added some documentation.
40  * (put some code in comments to maybe fix later if ever necessary)
41  * @li v6.1: Made `dbpointer` a local variable (removed `extern`).
42  * Removed `extern` from the documentation.
43  * @li v6.2: Removed `static` before the local variables (not necessary).
44  * @li v7.0: Updated documentation.
45  *
46  * ******************************************************************************
47  *
48  * @todo
49  * **Future improvements:**@n
50  * - Implement `dbSet_TXbuffer` and `charHex_to_uint32` (if necessary).
51  * - Add more functionality to print numbers, ...
52  * - Separate back-end <-> MCU specific code
53  *
54  * ******************************************************************************
55  *
56  * @section License
57  *
58  * **Copyright (C) 2019 - Brecht Van Eeckhoudt**
59  *
60  * This program is free software: you can redistribute it and/or modify
61  * it under the terms of the **GNU General Public License** as published by
62  * the Free Software Foundation, either **version 3** of the License, or
63  * (at your option) any later version.
64  *
65  * This program is distributed in the hope that it will be useful,
66  * but WITHOUT ANY WARRANTY; without even the implied warranty of
67  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68  * GNU General Public License for more details.
69  *
70  * *A copy of the GNU General Public License can be found in the `LICENSE`
71  * file along with this source code.*
72  *
73  * @n
74  *
75  * Some methods also use code obtained from examples from [Silicon Labs' GitHub](https://github.com/SiliconLabs/peripheral_examples).
76  * These sections are licensed under the Silabs License Agreement. See the file
77  * "Silabs_License_Agreement.txt" for details. Before using this software for
78  * any purpose, you must agree to the terms of that agreement.
79  *
80  * ******************************************************************************
81  *
82  * @attention
83  * See the file `dbprint_documentation.h` for a lot of useful documentation!
84  *
85  ******************************************************************************/
86 
87 
88 #include "debug_dbprint.h" /* Enable or disable printing to UART for debugging */
89 
90 #if DEBUG_DBPRINT == 1 /* DEBUG_DBPRINT */
91 
92 
93 #include <stdint.h> /* (u)intXX_t */
94 #include <stdbool.h> /* "bool", "true", "false" */
95 #include "em_cmu.h" /* Clock Management Unit */
96 #include "em_gpio.h" /* General Purpose IO (GPIO) peripheral API */
97 #include "em_usart.h" /* Universal synchr./asynchr. receiver/transmitter (USART/UART) Peripheral API */
98 
99 
100 /* Local definitions */
101 /* Macro definitions that return a character when given a value */
102 #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) */
103 #define TO_DEC(i) (i <= 9 ? '0' + i : '?') /* return "?" if out of range */
104 
105 /* ANSI colors */
106 #define COLOR_RED "\x1b[31m"
107 #define COLOR_GREEN "\x1b[32m"
108 #define COLOR_BLUE "\x1b[34m"
109 #define COLOR_CYAN "\x1b[36m"
110 #define COLOR_MAGENTA "\x1b[35m"
111 #define COLOR_YELLOW "\x1b[33m"
112 #define COLOR_RESET "\x1b[0m"
113 
114 
115 /** Local variable to store the settings (pointer). */
116 USART_TypeDef* dbpointer;
117 
118 /* Local variables to store data */
119 /* -> Volatile because it's modified by an interrupt service routine (@RAM) */
120 volatile bool dataReceived = false; /* true if there is a line of data received */
123 
124 
125 /* Local prototypes */
126 static void uint32_to_charHex (char *buf, uint32_t value, bool spacing);
127 static void uint32_to_charDec (char *buf, uint32_t value);
128 static uint32_t charDec_to_uint32 (char *buf);
129 //static uint32_t charHex_to_uint32 (char *buf); // Unused but kept here just in case
130 
131 
132 /**************************************************************************//**
133  * @brief
134  * Initialize USARTx.
135  *
136  * @param[in] pointer
137  * Pointer to USARTx.
138  *
139  * @param[in] location
140  * Location for pin routing.
141  *
142  * @param[in] vcom
143  * @li `true` - Isolation switch enabled by setting `PA9` high so the **Virtual COM port (CDC)** can be used.
144  * @li `false` - Isolation switch disabled on the Happy Gecko board.
145  *
146  * @param[in] interrupts
147  * @li `true` - Enable interrupt functionality.
148  * @li `false` - No interrupt functionality is initialized.
149  *****************************************************************************/
150 void dbprint_INIT (USART_TypeDef* pointer, uint8_t location, bool vcom, bool interrupts)
151 {
152  /* Store the pointer in the global variable */
153  dbpointer = pointer;
154 
155  /*
156  * USART_INITASYNC_DEFAULT:
157  * config.enable = usartEnable // Specifies whether TX and/or RX is enabled when initialization is completed
158  * // (Enable RX/TX when initialization is complete).
159  * config.refFreq = 0 // USART/UART reference clock assumed when configuring baud rate setup
160  * // (0 = Use current configured reference clock for configuring baud rate).
161  * config.baudrate = 115200 // Desired baudrate (115200 bits/s).
162  * config.oversampling = usartOVS16 // Oversampling used (16x oversampling).
163  * config.databits = usartDatabits8 // Number of data bits in frame (8 data bits).
164  * config.parity = usartNoParity // Parity mode to use (no parity).
165  * config.stopbits = usartStopbits1 // Number of stop bits to use (1 stop bit).
166  * config.mvdis = false // Majority Vote Disable for 16x, 8x and 6x oversampling modes (Do not disable majority vote).
167  * config.prsRxEnable = false // Enable USART Rx via PRS (Not USART PRS input mode).
168  * config.prsRxCh = 0 // Select PRS channel for USART Rx. (Only valid if prsRxEnable is true - PRS channel 0).
169  * config.autoCsEnable = false // Auto CS enabling (Auto CS functionality enable/disable switch - disabled).
170  */
171 
172  USART_InitAsync_TypeDef config = USART_INITASYNC_DEFAULT;
173 
174  /* Enable oscillator to GPIO*/
175  CMU_ClockEnable(cmuClock_GPIO, true);
176 
177 
178  /* Enable oscillator to USARTx modules */
179  if (dbpointer == USART0)
180  {
181  CMU_ClockEnable(cmuClock_USART0, true);
182  }
183  else if (dbpointer == USART1)
184  {
185  CMU_ClockEnable(cmuClock_USART1, true);
186  }
187 
188 
189  /* Set PA9 (EFM_BC_EN) high if necessary to enable the isolation switch */
190  if (vcom)
191  {
192  GPIO_PinModeSet(gpioPortA, 9, gpioModePushPull, 1);
193  GPIO_PinOutSet(gpioPortA, 9);
194  }
195 
196 
197  /* Set pin modes for UART TX and RX pins */
198  if (dbpointer == USART0)
199  {
200  switch (location)
201  {
202  case 0:
203  GPIO_PinModeSet(gpioPortE, 11, gpioModeInput, 0); /* RX */
204  GPIO_PinModeSet(gpioPortE, 10, gpioModePushPull, 1); /* TX */
205  break;
206  case 2:
207  GPIO_PinModeSet(gpioPortC, 10, gpioModeInput, 0); /* RX */
208  /* No TX pin in this mode */
209  break;
210  case 3:
211  GPIO_PinModeSet(gpioPortE, 12, gpioModeInput, 0); /* RX */
212  GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 1); /* TX */
213  break;
214  case 4:
215  GPIO_PinModeSet(gpioPortB, 8, gpioModeInput, 0); /* RX */
216  GPIO_PinModeSet(gpioPortB, 7, gpioModePushPull, 1); /* TX */
217  break;
218  case 5:
219  case 6:
220  GPIO_PinModeSet(gpioPortC, 1, gpioModeInput, 0); /* RX */
221  GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1); /* TX */
222  break;
223  /* default: */
224  /* No default */
225  }
226  }
227  else if (dbpointer == USART1)
228  {
229  switch (location)
230  {
231  case 0:
232  GPIO_PinModeSet(gpioPortC, 1, gpioModeInput, 0); /* RX */
233  GPIO_PinModeSet(gpioPortC, 0, gpioModePushPull, 1); /* TX */
234  break;
235  case 2:
236  case 3:
237  GPIO_PinModeSet(gpioPortD, 6, gpioModeInput, 0); /* RX */
238  GPIO_PinModeSet(gpioPortD, 7, gpioModePushPull, 1); /* TX */
239  break;
240  case 4:
241  GPIO_PinModeSet(gpioPortA, 0, gpioModeInput, 0); /* RX */
242  GPIO_PinModeSet(gpioPortF, 2, gpioModePushPull, 1); /* TX */
243  break;
244  case 5:
245  GPIO_PinModeSet(gpioPortC, 2, gpioModeInput, 0); /* RX */
246  GPIO_PinModeSet(gpioPortC, 1, gpioModePushPull, 1); /* TX */
247  break;
248  /* default: */
249  /* No default */
250  }
251  }
252 
253 
254  /* Initialize USART asynchronous mode */
255  USART_InitAsync(dbpointer, &config);
256 
257  /* Route pins */
258  switch (location)
259  {
260  case 0:
261  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC0;
262  break;
263  case 1:
264  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC1;
265  break;
266  case 2:
267  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC2;
268  break;
269  case 3:
270  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC3;
271  break;
272  case 4:
273  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC4;
274  break;
275  case 5:
276  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC5;
277  break;
278  case 6:
279  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_LOC6;
280  break;
281  default:
282  dbpointer->ROUTE |= USART_ROUTE_TXPEN | USART_ROUTE_RXPEN | USART_ROUTE_LOCATION_DEFAULT;
283  }
284 
285  /* Enable interrupts if necessary and print welcome string (and make an alert sound in the console) */
286  if (interrupts)
287  {
288  /* Initialize USART interrupts */
289 
290  /* RX Data Valid Interrupt Enable
291  * Set when data is available in the receive buffer. Cleared when the receive buffer is empty. */
292  USART_IntEnable(dbpointer, USART_IEN_RXDATAV);
293 
294  /* TX Complete Interrupt Enable
295  * Set when a transmission has completed and no more data is available in the transmit buffer.
296  * Cleared when a new transmission starts. */
297  USART_IntEnable(dbpointer, USART_IEN_TXC);
298 
299  if (dbpointer == USART0)
300  {
301  /* Enable USART interrupts */
302  NVIC_EnableIRQ(USART0_RX_IRQn);
303  NVIC_EnableIRQ(USART0_TX_IRQn);
304  }
305  else if (dbpointer == USART1)
306  {
307  /* Enable USART interrupts */
308  NVIC_EnableIRQ(USART1_RX_IRQn);
309  NVIC_EnableIRQ(USART1_TX_IRQn);
310  }
311 
312  /* Print welcome string */
314  dbprintln("\a\r\f### UART initialized (interrupt mode) ###");
315  dbinfo("This is an info message.");
316  dbwarn("This is a warning message.");
317  dbcrit("This is a critical error message.");
318  dbprintln("### Start executing programmed code ###\n");
319 
320  /* Set TX Complete Interrupt Flag (transmission has completed and no more data
321  * is available in the transmit buffer) */
322  USART_IntSet(dbpointer, USART_IFS_TXC);
323  }
324  /* Print welcome string (and make an alert sound in the console) if not in interrupt mode */
325  else
326  {
328  dbprintln("\a\r\f### UART initialized (no interrupts) ###");
329  dbinfo("This is an info message.");
330  dbwarn("This is a warning message.");
331  dbcrit("This is a critical error message.");
332  dbprintln("### Start executing programmed code ###\n");
333  }
334 }
335 
336 
337 /**************************************************************************//**
338  * @brief
339  * Sound an alert in the terminal.
340  *
341  * @details
342  * Print the *bell* (alert) character to USARTx.
343  *****************************************************************************/
344 void dbAlert (void)
345 {
346  USART_Tx(dbpointer, '\a');
347 }
348 
349 
350 /**************************************************************************//**
351  * @brief
352  * Clear the terminal.
353  *
354  * @details
355  * Print the *form feed* character to USARTx. Accessing old data is still
356  * possible by scrolling up in the serial port program.
357  *****************************************************************************/
358 void dbClear (void)
359 {
360  USART_Tx(dbpointer, '\f');
361 }
362 
363 
364 /**************************************************************************//**
365  * @brief
366  * Print a string (char array) to USARTx.
367  *
368  * @note
369  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
370  * the input message (array) needs to end with NULL (`"\0"`)!
371  *
372  * @param[in] message
373  * The string to print to USARTx.
374  *****************************************************************************/
375 void dbprint (char *message)
376 {
377  /* "message[i] != 0" makes "uint32_t length = strlen(message)"
378  * not necessary (given string MUST be terminated by NULL for this to work) */
379  for (uint32_t i = 0; message[i] != 0; i++)
380  {
381  USART_Tx(dbpointer, message[i]);
382  }
383 }
384 
385 
386 /**************************************************************************//**
387  * @brief
388  * Print a string (char array) to USARTx and go to the next line.
389  *
390  * @note
391  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
392  * the input message (array) needs to end with NULL (`"\0"`)!
393  *
394  * @param[in] message
395  * The string to print to USARTx.
396  *****************************************************************************/
397 void dbprintln (char *message)
398 {
399  dbprint(message);
400 
401  /* Carriage return */
402  USART_Tx(dbpointer, '\r');
403 
404  /* Line feed (new line) */
405  USART_Tx(dbpointer, '\n');
406 }
407 
408 
409 /**************************************************************************//**
410  * @brief
411  * Print a string (char array) to USARTx in a given color.
412  *
413  * @note
414  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
415  * the input message (array) needs to end with NULL (`"\0"`)!
416  *
417  * @param[in] message
418  * The string to print to USARTx.
419  *
420  * @param[in] color
421  * The color to print the text in.
422  *****************************************************************************/
423 void dbprint_color (char *message, dbprint_color_t color)
424 {
425  switch (color)
426  {
427  case DEFAULT_COLOR:
429  dbprint(message);
430  break;
431  case RED:
433  dbprint(message);
435  break;
436  case GREEN:
438  dbprint(message);
440  break;
441  case BLUE:
443  dbprint(message);
445  break;
446  case CYAN:
448  dbprint(message);
450  break;
451  case MAGENTA:
453  dbprint(message);
455  break;
456  case YELLOW:
458  dbprint(message);
460  break;
461  default:
463  dbprint(message);
464  }
465 }
466 
467 
468 /**************************************************************************//**
469  * @brief
470  * Print a string (char array) to USARTx in a given color and go to the next line.
471  *
472  * @note
473  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
474  * the input message (array) needs to end with NULL (`"\0"`)!
475  *
476  * @param[in] message
477  * The string to print to USARTx.
478  *
479  * @param[in] color
480  * The color to print the text in.
481  *****************************************************************************/
482 void dbprintln_color (char *message, dbprint_color_t color)
483 {
484  dbprint_color(message, color);
485 
486  /* Carriage return */
487  USART_Tx(dbpointer, '\r');
488 
489  /* Line feed (new line) */
490  USART_Tx(dbpointer, '\n');
491 }
492 
493 
494 /**************************************************************************//**
495  * @brief
496  * Print an *info* string (char array) to USARTx and go to the next line.
497  *
498  * @note
499  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
500  * the input message (array) needs to end with NULL (`"\0"`)!
501  *
502  * @param[in] message
503  * The string to print to USARTx.
504  *****************************************************************************/
505 void dbinfo (char *message)
506 {
507  dbprint("INFO: ");
508  dbprintln(message);
509 }
510 
511 
512 /**************************************************************************//**
513  * @brief
514  * Print a *warning* string (char array) in yellow to USARTx and go to the next line.
515  *
516  * @note
517  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
518  * the input message (array) needs to end with NULL (`"\0"`)!
519  *
520  * @param[in] message
521  * The string to print to USARTx.
522  *****************************************************************************/
523 void dbwarn (char *message)
524 {
525  dbprint_color("WARN: ", YELLOW);
526  dbprintln_color(message, YELLOW);
527 }
528 
529 
530 /**************************************************************************//**
531  * @brief
532  * Print a *critical error* string (char array) in red to USARTx and go to the next line.
533  *
534  * @note
535  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
536  * the input message (array) needs to end with NULL (`"\0"`)!
537  *
538  * @param[in] message
539  * The string to print to USARTx.
540  *****************************************************************************/
541 void dbcrit (char *message)
542 {
543  dbprint_color("CRIT: ", RED);
544  dbprintln_color(message, RED);
545 }
546 
547 
548 /**************************************************************************//**
549  * @brief
550  * Print an *info* value surrounded by two strings (char array) to USARTx.
551  *
552  * @details
553  * "INFO: " gets added in front, the decimal notation is used and
554  * the function advances to the next line.
555  *
556  * @note
557  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
558  * the input message (array) needs to end with NULL (`"\0"`)!
559  *
560  * @param[in] message1
561  * The first part of the string to print to USARTx.
562  *
563  * @param[in] value
564  * The value to print between the two string parts.
565  *
566  * @param[in] message2
567  * The second part of the string to print to USARTx.
568  *****************************************************************************/
569 void dbinfoInt (char *message1, int32_t value, char *message2)
570 {
571  dbprint("INFO: ");
572  dbprint(message1);
573  dbprintInt(value);
574  dbprintln(message2);
575 }
576 
577 
578 /**************************************************************************//**
579  * @brief
580  * Print a *warning* value surrounded by two strings (char array) to USARTx.
581  *
582  * @details
583  * "WARN: " gets added in front, the decimal notation is used and
584  * the function advances to the next line. The value is in the color white,
585  * the rest is yellow.
586  *
587  * @note
588  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
589  * the input message (array) needs to end with NULL (`"\0"`)!
590  *
591  * @param[in] message1
592  * The first part of the string to print to USARTx.
593  *
594  * @param[in] value
595  * The value to print between the two string parts.
596  *
597  * @param[in] message2
598  * The second part of the string to print to USARTx.
599  *****************************************************************************/
600 void dbwarnInt (char *message1, int32_t value, char *message2)
601 {
602  dbprint_color("WARN: ", YELLOW);
603  dbprint_color(message1, YELLOW);
604  dbprintInt(value);
605  dbprintln_color(message2, YELLOW);
606 }
607 
608 
609 /**************************************************************************//**
610  * @brief
611  * Print a *critical* value surrounded by two strings (char array) to USARTx.
612  *
613  * @details
614  * "CRIT: " gets added in front, the decimal notation is used and
615  * the function advances to the next line. The value is in the color white,
616  * the rest is red.
617  *
618  * @note
619  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
620  * the input message (array) needs to end with NULL (`"\0"`)!
621  *
622  * @param[in] message1
623  * The first part of the string to print to USARTx.
624  *
625  * @param[in] value
626  * The value to print between the two string parts.
627  *
628  * @param[in] message2
629  * The second part of the string to print to USARTx.
630  *****************************************************************************/
631 void dbcritInt (char *message1, int32_t value, char *message2)
632 {
633  dbprint_color("CRIT: ", RED);
634  dbprint_color(message1, RED);
635  dbprintInt(value);
636  dbprintln_color(message2, RED);
637 }
638 
639 
640 /**************************************************************************//**
641  * @brief
642  * Print an *info* value surrounded by two strings (char array) to USARTx.
643  *
644  * @details
645  * "INFO: " gets added in front, the hexadecimal notation is used and
646  * the function advances to the next line.
647  *
648  * @note
649  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
650  * the input message (array) needs to end with NULL (`"\0"`)!
651  *
652  * @param[in] message1
653  * The first part of the string to print to USARTx.
654  *
655  * @param[in] value
656  * The value to print between the two string parts.
657  *
658  * @param[in] message2
659  * The second part of the string to print to USARTx.
660  *****************************************************************************/
661 void dbinfoInt_hex (char *message1, int32_t value, char *message2)
662 {
663  dbprint("INFO: ");
664  dbprint(message1);
665  dbprintInt_hex(value);
666  dbprintln(message2);
667 }
668 
669 
670 /**************************************************************************//**
671  * @brief
672  * Print a *warning* value surrounded by two strings (char array) to USARTx.
673  *
674  * @details
675  * "WARN: " gets added in front, the hexadecimal notation is used and
676  * the function advances to the next line. The value is in the color white,
677  * the rest is yellow.
678  *
679  * @note
680  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
681  * the input message (array) needs to end with NULL (`"\0"`)!
682  *
683  * @param[in] message1
684  * The first part of the string to print to USARTx.
685  *
686  * @param[in] value
687  * The value to print between the two string parts.
688  *
689  * @param[in] message2
690  * The second part of the string to print to USARTx.
691  *****************************************************************************/
692 void dbwarnInt_hex (char *message1, int32_t value, char *message2)
693 {
694  dbprint_color("WARN: ", YELLOW);
695  dbprint_color(message1, YELLOW);
696  dbprintInt_hex(value);
697  dbprintln_color(message2, YELLOW);
698 }
699 
700 
701 /**************************************************************************//**
702  * @brief
703  * Print a *critical* value surrounded by two strings (char array) to USARTx.
704  *
705  * @details
706  * "CRIT: " gets added in front, the hexadecimal notation is used and
707  * the function advances to the next line. The value is in the color white,
708  * the rest is red.
709  *
710  * @note
711  * If the input is not a string (ex.: `"Hello world!"`) but a char array,
712  * the input message (array) needs to end with NULL (`"\0"`)!
713  *
714  * @param[in] message1
715  * The first part of the string to print to USARTx.
716  *
717  * @param[in] value
718  * The value to print between the two string parts.
719  *
720  * @param[in] message2
721  * The second part of the string to print to USARTx.
722  *****************************************************************************/
723 void dbcritInt_hex (char *message1, int32_t value, char *message2)
724 {
725  dbprint_color("CRIT: ", RED);
726  dbprint_color(message1, RED);
727  dbprintInt_hex(value);
728  dbprintln_color(message2, RED);
729 }
730 
731 
732 /**************************************************************************//**
733  * @brief
734  * Print a number in decimal notation to USARTx.
735  *
736  * @param[in] value
737  * The number to print to USARTx.@n
738  * This can be of type `uint32_t` or `int32_t`.
739  *****************************************************************************/
740 void dbprintInt (int32_t value)
741 {
742  /* Buffer to put the char array in (Needs to be 10) */
743  char decchar[10];
744 
745  /* Convert a negative number to a positive one and print the "-" */
746  if (value < 0)
747  {
748  /* Negative of value = flip all bits, +1
749  * bitwise logic: "~" = "NOT" */
750  uint32_t negativeValue = (~value) + 1;
751 
752  dbprint("-");
753 
754  /* Convert the value */
755  uint32_to_charDec(decchar, negativeValue);
756  }
757  else
758  {
759  /* Convert the value */
760  uint32_to_charDec(decchar, value);
761  }
762 
763  /* Print the buffer */
764  dbprint(decchar);
765 }
766 
767 
768 /**************************************************************************//**
769  * @brief
770  * Print a number in decimal notation to USARTx and go to the next line.
771  *
772  * @param[in] value
773  * The number to print to USARTx.@n
774  * This can be of type `uint32_t` or `int32_t`.
775  *****************************************************************************/
776 void dbprintlnInt (int32_t value)
777 {
778  dbprintInt(value);
779 
780  /* Carriage return */
781  USART_Tx(dbpointer, '\r');
782 
783  /* Line feed (new line) */
784  USART_Tx(dbpointer, '\n');
785 }
786 
787 
788 /**************************************************************************//**
789  * @brief
790  * Print a number in hexadecimal notation to USARTx.
791  *
792  * @param[in] value
793  * The number to print to USARTx.@n
794  * This can be of type `uint32_t` or `int32_t`.
795  *****************************************************************************/
796 void dbprintInt_hex (int32_t value)
797 {
798  char hexchar[9]; /* Needs to be 9 */
799  uint32_to_charHex(hexchar, value, true); /* true: add spacing between eight HEX chars */
800  dbprint("0x");
801  dbprint(hexchar);
802 }
803 
804 
805 /**************************************************************************//**
806  * @brief
807  * Print a number in hexadecimal notation to USARTx and go to the next line.
808  *
809  * @param[in] value
810  * The number to print to USARTx.@n
811  * This can be of type `uint32_t` or `int32_t`.
812  *****************************************************************************/
813 void dbprintlnInt_hex (int32_t value)
814 {
815  dbprintInt_hex(value);
816 
817  /* Carriage return */
818  USART_Tx(dbpointer, '\r');
819 
820  /* Line feed (new line) */
821  USART_Tx(dbpointer, '\n');
822 }
823 
824 
825 /**************************************************************************//**
826  * @brief
827  * Read a character from USARTx.
828  *
829  * @return
830  * The character read from USARTx.
831  *****************************************************************************/
832 char dbReadChar (void)
833 {
834  return (USART_Rx(dbpointer));
835 }
836 
837 
838 /**************************************************************************//**
839  * @brief
840  * Read a decimal character from USARTx and convert it to a `uint8_t` value.
841  *
842  * @note
843  * Specific methods exist to read `uint16_t` and `uint32_t` values:
844  * - `uint16_t USART_RxDouble(USART_TypeDef *usart);`
845  * - `uint32_t USART_RxDoubleExt(USART_TypeDef *usart);`
846  *
847  * @return
848  * The converted `uint8_t` value.
849  *****************************************************************************/
850 uint8_t dbReadInt (void)
851 {
852  /* Method expects a char array ending with a null termination character */
853  char value[2];
854  value[0]= dbReadChar();
855  value[1] = '\0';
856 
857  return (charDec_to_uint32(value));
858 }
859 
860 
861 /**************************************************************************//**
862  * @brief
863  * Read a string (char array) from USARTx.
864  *
865  * @note
866  * The reading stops when a `"CR"` (Carriage Return, ENTER) character
867  * is received or the maximum length (`DBPRINT_BUFFER_SIZE`) is reached.
868  *
869  * @param[in] buf
870  * The buffer to put the resulting string in.@n
871  * **This needs to have a length of `DBPRINT_BUFFER_SIZE` for the function
872  * to work properly: `char buf[DBPRINT_BUFFER_SIZE];`!**
873  *****************************************************************************/
874 void dbReadLine (char *buf)
875 {
876  for (uint32_t i = 0; i < DBPRINT_BUFFER_SIZE - 1 ; i++ )
877  {
878  char localBuffer = USART_Rx(dbpointer);
879 
880  /* Check if a CR character is received */
881  if (localBuffer == '\r')
882  {
883  /* End with a null termination character, expected by the dbprintln method */
884  buf[i] = '\0';
885  break;
886  }
887  else
888  {
889  buf[i] = localBuffer;
890  }
891  }
892 }
893 
894 
895 /**************************************************************************//**
896  * @brief
897  * Check if data was received using interrupts in the RX buffer.
898  *
899  * @note
900  * The index of the RX buffer gets reset in the RX handler when a CR character
901  * is received or the buffer is filled.
902  *
903  * @attention
904  * Interrupt functionality has to be enabled on initialization for this
905  * function to work correctly.
906  *
907  * @return
908  * @li `true` - Data is received in the RX buffer.
909  * @li `false` - No data is received.
910  *****************************************************************************/
911 bool dbGet_RXstatus (void)
912 {
913  return (dataReceived);
914 }
915 
916 
917 // TODO: Needs fixing (but probably won't ever be used):
918 //**************************************************************************//**
919 // * @brief
920 // * Set the value of the TX buffer and start transmitting it using interrupts.
921 // *
922 // * @details
923 // * The `"TX Complete Interrupt Flag"` also gets set at the end of the
924 // * function (transmission has completed and no more data is available
925 // * in the transmit buffer).
926 // *
927 // * @note
928 // * If the input is not a string (ex.: `"Hello world!"`) but a char array,
929 // * the input message (array) needs to end with NULL (`"\0"`)!
930 // *
931 // * @note
932 // * The index of the RX buffer gets reset in the TX handler when all the
933 // * characters in the buffer are send.
934 // *
935 // * @attention
936 // * Interrupt functionality has to be enabled on initialization for this
937 // * function to work correctly.
938 // *
939 // * @param[in] message
940 // * The string to put in the TX buffer.
941 // *****************************************************************************/
942 //void dbSet_TXbuffer (char *message)
943 //{
944 // uint32_t i;
945 //
946 // /* Copy data to the TX buffer */
947 // for (i = 0; message[i] != 0 && i < DBPRINT_BUFFER_SIZE-1; i++)
948 // {
949 // tx_buffer[i] = message[i];
950 // }
951 //
952 // /* Set TX Complete Interrupt Flag (transmission has completed and no more data
953 // * is available in the transmit buffer) */
954 // USART_IntSet(dbpointer, USART_IFS_TXC);
955 //
956 // TODO: Perhaps some functionality needs to be added to send numbers and
957 // that might need functionality to disable interrupts. For reference
958 // some old code that could be put in a main.c file is put below.
959 // /* Data is ready to retransmit (notified by the RX handler) */
960 // if (dbprint_rxdata)
961 // {
962 // uint32_t i;
963 //
964 // /* RX Data Valid Interrupt Enable
965 // * Set when data is available in the receive buffer. Cleared when the receive buffer is empty.
966 // *
967 // * TX Complete Interrupt Enable
968 // * Set when a transmission has completed and no more data is available in the transmit buffer.
969 // * Cleared when a new transmission starts.
970 // */
971 //
972 // /* Disable "RX Data Valid Interrupt Enable" and "TX Complete Interrupt Enable" interrupts */
973 // USART_IntDisable(dbpointer, USART_IEN_RXDATAV);
974 // USART_IntDisable(dbpointer, USART_IEN_TXC);
975 //
976 // /* Copy data from the RX buffer to the TX buffer */
977 // for (i = 0; dbprint_rx_buffer[i] != 0 && i < DBPRINT_BUFFER_SIZE-3; i++)
978 // {
979 // dbprint_tx_buffer[i] = dbprint_rx_buffer[i];
980 // }
981 //
982 // /* Add "new line" characters */
983 // dbprint_tx_buffer[i++] = '\r';
984 // dbprint_tx_buffer[i++] = '\n';
985 // dbprint_tx_buffer[i] = '\0';
986 //
987 // /* Reset "notification" variable */
988 // dbprint_rxdata = false;
989 //
990 // /* Enable "RX Data Valid Interrupt" and "TX Complete Interrupt" interrupts */
991 // USART_IntEnable(dbpointer, USART_IEN_RXDATAV);
992 // USART_IntEnable(dbpointer, USART_IEN_TXC);
993 //
994 // /* Set TX Complete Interrupt Flag (transmission has completed and no more data
995 // * is available in the transmit buffer) */
996 // USART_IntSet(dbpointer, USART_IFS_TXC);
997 // }
998 //
999 //}
1000 
1001 
1002 /**************************************************************************//**
1003  * @brief
1004  * Get the value of the RX buffer and clear the `dataReceived` flag.
1005  *
1006  * @note
1007  * The index of the RX buffer gets reset in the RX handler when a CR character
1008  * is received or the buffer is filled.
1009  *
1010  * @attention
1011  * Interrupt functionality has to be enabled on initialization for this
1012  * function to work correctly.
1013  *
1014  * @param[in] buf
1015  * The buffer to put the resulting string in.@n
1016  * **This needs to have a length of `DBPRINT_BUFFER_SIZE` for the function
1017  * to work properly: `char buf[DBPRINT_BUFFER_SIZE];`!**
1018  *****************************************************************************/
1019 void dbGet_RXbuffer (char *buf)
1020 {
1021  if (dataReceived)
1022  {
1023  uint32_t i;
1024 
1025  /* Copy data from the RX buffer to the given buffer */
1026  for (i = 0; rx_buffer[i] != 0 && i < DBPRINT_BUFFER_SIZE-1; i++)
1027  {
1028  buf[i] = rx_buffer[i];
1029  }
1030 
1031  /* Add NULL termination character */
1032  buf[i++] = '\0';
1033 
1034  /* Reset "notification" variable */
1035  dataReceived = false;
1036  }
1037  else
1038  {
1039  dbcrit("No received data available!");
1040  }
1041 }
1042 
1043 
1044 /**************************************************************************//**
1045  * @brief
1046  * Convert a `uint32_t` value to a hexadecimal char array (string).
1047  *
1048  * @note
1049  * This is a static method because it's only internally used in this file
1050  * and called by other methods if necessary.
1051  *
1052  * @param[out] buf
1053  * The buffer to put the resulting string in.@n
1054  * **This needs to have a length of 9: `char buf[9];`!**
1055  *
1056  * @param[in] value
1057  * The `uint32_t` value to convert to a string.
1058  *
1059  * @param[in] spacing
1060  * @li `true` - Add spacing between the eight HEX chars to make two groups of four.
1061  * @li `false` - Don't add spacing between the eight HEX chars.
1062  *****************************************************************************/
1063 static void uint32_to_charHex (char *buf, uint32_t value, bool spacing)
1064 {
1065  /* 4 nibble HEX representation */
1066  if (value <= 0xFFFF)
1067  {
1068  /* Only get necessary nibble by ANDing with a mask and
1069  * shifting one nibble (4 bits) per position */
1070  buf[0] = TO_HEX(((value & 0xF000) >> 12));
1071  buf[1] = TO_HEX(((value & 0x0F00) >> 8 ));
1072  buf[2] = TO_HEX(((value & 0x00F0) >> 4 ));
1073  buf[3] = TO_HEX( (value & 0x000F) );
1074  buf[4] = '\0'; /* NULL termination character */
1075  }
1076 
1077  /* 8 nibble HEX representation */
1078  else
1079  {
1080  /* Only get necessary nibble by ANDing with a mask and
1081  * shifting one nibble (4 bits) per position */
1082  buf[0] = TO_HEX(((value & 0xF0000000) >> 28));
1083  buf[1] = TO_HEX(((value & 0x0F000000) >> 24));
1084  buf[2] = TO_HEX(((value & 0x00F00000) >> 20));
1085  buf[3] = TO_HEX(((value & 0x000F0000) >> 16));
1086 
1087  /* Add spacing if necessary */
1088  if (spacing)
1089  {
1090  buf[4] = ' '; /* Spacing */
1091  buf[5] = TO_HEX(((value & 0x0000F000) >> 12));
1092  buf[6] = TO_HEX(((value & 0x00000F00) >> 8 ));
1093  buf[7] = TO_HEX(((value & 0x000000F0) >> 4 ));
1094  buf[8] = TO_HEX( (value & 0x0000000F) );
1095  buf[9] = '\0'; /* NULL termination character */
1096  }
1097  else
1098  {
1099  buf[4] = TO_HEX(((value & 0x0000F000) >> 12));
1100  buf[5] = TO_HEX(((value & 0x00000F00) >> 8 ));
1101  buf[6] = TO_HEX(((value & 0x000000F0) >> 4 ));
1102  buf[7] = TO_HEX( (value & 0x0000000F) );
1103  buf[8] = '\0'; /* NULL termination character */
1104  }
1105  }
1106 }
1107 
1108 
1109 /**************************************************************************//**
1110  * @brief
1111  * Convert a `uint32_t` value to a decimal char array (string).
1112  *
1113  * @note
1114  * This is a static method because it's only internally used in this file
1115  * and called by other methods if necessary.
1116  *
1117  * @param[out] buf
1118  * The buffer to put the resulting string in.@n
1119  * **This needs to have a length of 10: `char buf[10];`!**
1120  *
1121  * @param[in] value
1122  * The `uint32_t` value to convert to a string.
1123  *****************************************************************************/
1124 static void uint32_to_charDec (char *buf, uint32_t value)
1125 {
1126  if (value == 0)
1127  {
1128  buf[0] = '0';
1129  buf[1] = '\0'; /* NULL termination character */
1130  }
1131  else
1132  {
1133  /* MAX uint32_t value = FFFFFFFFh = 4294967295d (10 decimal chars) */
1134  char backwardsBuf[10];
1135 
1136  uint32_t calcval = value;
1137  uint8_t length = 0;
1138  uint8_t lengthCounter = 0;
1139 
1140 
1141  /* Loop until the value is zero (separate characters 0-9) and calculate length */
1142  while (calcval)
1143  {
1144  uint32_t rem = calcval % 10;
1145  backwardsBuf[length] = TO_DEC(rem); /* Convert to ASCII character */
1146  length++;
1147 
1148  calcval = calcval - rem;
1149  calcval = calcval / 10;
1150  }
1151 
1152  /* Backwards counter */
1153  lengthCounter = length;
1154 
1155  /* Reverse the characters in the buffer for the final string */
1156  for (uint8_t i = 0; i < length; i++)
1157  {
1158  buf[i] = backwardsBuf[lengthCounter-1];
1159  lengthCounter--;
1160  }
1161 
1162  /* Add NULL termination character */
1163  buf[length] = '\0';
1164  }
1165 }
1166 
1167 
1168 /**************************************************************************//**
1169  * @brief
1170  * Convert a string (char array) in decimal notation to a `uint32_t` value.
1171  *
1172  * @note
1173  * If the input is not a string (ex.: `"00BA0FA1"`) but a char array,
1174  * the input buffer (array) needs to end with NULL (`"\0"`)!
1175  *
1176  * @note
1177  * This is a static method because it's only internally used in this file
1178  * and called by other methods if necessary.
1179  *
1180  * @param[in] buf
1181  * The decimal string to convert to a `uint32_t` value.
1182  *
1183  * @return
1184  * The resulting `uint32_t` value.
1185  *****************************************************************************/
1186 static uint32_t charDec_to_uint32 (char *buf)
1187 {
1188  /* Value to eventually return */
1189  uint32_t value = 0;
1190 
1191  /* Loop until buffer is empty */
1192  while (*buf)
1193  {
1194  /* Get current character, increment afterwards */
1195  uint8_t byte = *buf++;
1196 
1197  /* Check if the next value we need to add can fit in a uint32_t */
1198  if ( (value <= 0xFFFFFFF) && ((byte - '0') <= 0xF) )
1199  {
1200  /* Convert the ASCII (decimal) character to the representing decimal value
1201  * and add it to the value (which is multiplied by 10 for each position) */
1202  value = (value * 10) + (byte - '0');
1203  }
1204  else
1205  {
1206  /* Given buffer can't fit in uint32_t */
1207  return (0);
1208  }
1209  }
1210 
1211  return (value);
1212 }
1213 
1214 
1215 // Unused but kept here just in case:
1216 //**************************************************************************//**
1217 // * @brief
1218 // * Convert a string (char array) in hexadecimal notation to a `uint32_t` value.
1219 // *
1220 // * @note
1221 // * If the input is not a string (ex.: `"00120561"`) but a char array,
1222 // * the input buffer (array) needs to end with NULL (`"\0"`)!@n
1223 // * The input string can't have the prefix `0x`.
1224 // *
1225 // * @note
1226 // * This is a static method because it's only internally used in this file
1227 // * and called by other methods if necessary.
1228 // *
1229 // * @param[in] buf
1230 // * The hexadecimal string to convert to a `uint32_t` value.
1231 // *
1232 // * @return
1233 // * The resulting `uint32_t` value.
1234 // *****************************************************************************/
1235 //static uint32_t charHex_to_uint32 (char *buf)
1236 //{
1237 // /* Value to eventually return */
1238 // uint32_t value = 0;
1239 //
1240 // /* Loop until buffer is empty */
1241 // while (*buf)
1242 // {
1243 // /* Get current character, increment afterwards */
1244 // uint8_t byte = *buf++;
1245 //
1246 // /* Convert the hex character to the 4-bit equivalent
1247 // * number using the ASCII table indexes */
1248 // if (byte >= '0' && byte <= '9') byte = byte - '0';
1249 // else if (byte >= 'a' && byte <='f') byte = byte - 'a' + 10;
1250 // else if (byte >= 'A' && byte <='F') byte = byte - 'A' + 10;
1251 //
1252 // /* Check if the next byte we need to add can fit in a uint32_t */
1253 // if ( (value <= 0xFFFFFFF) && (byte <= 0xF) )
1254 // {
1255 // /* Shift one nibble (4 bits) to make space for a new digit
1256 // * and add the 4 bits (ANDing with a mask, 0xF = 0b1111) */
1257 // value = (value << 4) | (byte & 0xF);
1258 // }
1259 // else
1260 // {
1261 // /* Given buffer can't fit in uint32_t */
1262 // return (0);
1263 // }
1264 // }
1265 //
1266 // return (value);
1267 //}
1268 
1269 
1270 /**************************************************************************//**
1271  * @brief
1272  * USART0 RX interrupt service routine.
1273  *
1274  * @details
1275  * The index gets reset to zero when a special character (CR) is received or
1276  * the buffer is filled.
1277  *
1278  * @note
1279  * The *weak* definition for this method is located in `system_efm32hg.h`.
1280  *****************************************************************************/
1282 {
1283  /* "static" so it keeps its value between invocations */
1284  static uint32_t i = 0;
1285 
1286  /* Get and clear the pending USART interrupt flags */
1287  uint32_t flags = USART_IntGet(dbpointer);
1288  USART_IntClear(dbpointer, flags);
1289 
1290  /* Store incoming data into dbprint_rx_buffer */
1291  rx_buffer[i++] = USART_Rx(dbpointer);
1292 
1293  /* Set dbprint_rxdata when a special character is received (~ full line received) */
1294  if ( (rx_buffer[i - 1] == '\r') || (rx_buffer[i - 1] == '\f') )
1295  {
1296  dataReceived = true;
1297  rx_buffer[i - 1] = '\0'; /* Overwrite CR or LF character */
1298  i = 0;
1299  }
1300 
1301  /* Set dbprint_rxdata when the buffer is full */
1302  if (i >= (DBPRINT_BUFFER_SIZE - 2))
1303  {
1304  dataReceived = true;
1305  rx_buffer[i] = '\0'; /* Do not overwrite last character */
1306  i = 0;
1307  }
1308 }
1309 
1310 
1311 /**************************************************************************//**
1312  * @brief
1313  * USART0 TX interrupt service routine.
1314  *
1315  * @details
1316  * The index gets reset to zero when all the characters in the buffer are send.
1317  *
1318  * @note
1319  * The *weak* definition for this method is located in `system_efm32hg.h`.
1320  *****************************************************************************/
1322 {
1323  /* "static" so it keeps its value between invocations */
1324  static uint32_t i = 0;
1325 
1326  /* Get and clear the pending USART interrupt flags */
1327  uint32_t flags = USART_IntGet(dbpointer);
1328  USART_IntClear(dbpointer, flags);
1329 
1330  /* Mask flags AND "TX Complete Interrupt Flag" */
1331  if (flags & USART_IF_TXC)
1332  {
1333  /* Index is smaller than the maximum buffer size and
1334  * the current item to print is not "NULL" (\0) */
1335  if ( (i < DBPRINT_BUFFER_SIZE) && (tx_buffer[i] != '\0') )
1336  {
1337  /* Transmit byte at current index and increment index */
1338  USART_Tx(dbpointer, tx_buffer[i++]);
1339  }
1340  else
1341  {
1342  i = 0; /* No more data to send */
1343  }
1344  }
1345 }
1346 
1347 
1348 /**************************************************************************//**
1349  * @brief
1350  * USART1 RX interrupt service routine.
1351  *
1352  * @note
1353  * The *weak* definition for this method is located in `system_efm32hg.h`.
1354  *****************************************************************************/
1356 {
1357  /* Call other handler */
1359 }
1360 
1361 
1362 /**************************************************************************//**
1363  * @brief
1364  * USART1 TX interrupt service routine.
1365  *
1366  * @note
1367  * The *weak* definition for this method is located in `system_efm32hg.h`.
1368  *****************************************************************************/
1370 {
1371  /* Call other handler */
1373 }
1374 
1375 #endif /* DEBUG_DBPRINT */
Definition: dbprint.h:57
#define COLOR_GREEN
Definition: dbprint.c:107
void dbprint(char *message)
Print a string (char array) to USARTx.
Definition: dbprint.c:375
#define COLOR_YELLOW
Definition: dbprint.c:111
void dbprintlnInt(int32_t value)
Print a number in decimal notation to USARTx and go to the next line.
Definition: dbprint.c:776
Definition: dbprint.h:54
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 dbprintln(char *message)
Print a string (char array) to USARTx and go to the next line.
Definition: dbprint.c:397
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 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 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 dbAlert(void)
Sound an alert in the terminal.
Definition: dbprint.c:344
volatile char tx_buffer[80]
Definition: dbprint.c:122
#define COLOR_MAGENTA
Definition: dbprint.c:110
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 dbwarnInt(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
Definition: dbprint.c:600
#define TO_DEC(i)
Definition: dbprint.c:103
void dbinfo(char *message)
Print an info string (char array) to USARTx and go to the next line.
Definition: dbprint.c:505
uint8_t dbReadInt(void)
Read a decimal character from USARTx and convert it to a uint8_t value.
Definition: dbprint.c:850
#define COLOR_RED
Definition: dbprint.c:106
volatile bool dataReceived
Definition: dbprint.c:120
static uint32_t charDec_to_uint32(char *buf)
Convert a string (char array) in decimal notation to a uint32_t value.
Definition: dbprint.c:1186
Definition: dbprint.h:55
void dbprintlnInt_hex(int32_t value)
Print a number in hexadecimal notation to USARTx and go to the next line.
Definition: dbprint.c:813
volatile char rx_buffer[80]
Definition: dbprint.c:121
static void uint32_to_charDec(char *buf, uint32_t value)
Convert a uint32_t value to a decimal char array (string).
Definition: dbprint.c:1124
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
Definition: dbprint.h:59
Definition: dbprint.h:56
void USART1_TX_IRQHandler(void)
USART1 TX interrupt service routine.
Definition: dbprint.c:1369
#define COLOR_BLUE
Definition: dbprint.c:108
USART_TypeDef * dbpointer
Definition: dbprint.c:116
#define COLOR_CYAN
Definition: dbprint.c:109
char dbReadChar(void)
Read a character from USARTx.
Definition: dbprint.c:832
#define TO_HEX(i)
Definition: dbprint.c:102
void dbClear(void)
Clear the terminal.
Definition: dbprint.c:358
void dbprint_INIT(USART_TypeDef *pointer, uint8_t location, bool vcom, bool interrupts)
Initialize USARTx.
Definition: dbprint.c:150
void USART1_RX_IRQHandler(void)
USART1 RX interrupt service routine.
Definition: dbprint.c:1355
#define DBPRINT_BUFFER_SIZE
Definition: dbprint.h:48
Enable or disable printing to UART with dbprint.
void USART0_TX_IRQHandler(void)
USART0 TX interrupt service routine.
Definition: dbprint.c:1321
void dbprintInt(int32_t value)
Print a number in decimal notation to USARTx.
Definition: dbprint.c:740
bool dbGet_RXstatus(void)
Check if data was received using interrupts in the RX buffer.
Definition: dbprint.c:911
void dbprintInt_hex(int32_t value)
Print a number in hexadecimal notation to USARTx.
Definition: dbprint.c:796
enum dbprint_colors dbprint_color_t
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
#define COLOR_RESET
Definition: dbprint.c:112
void dbReadLine(char *buf)
Read a string (char array) from USARTx.
Definition: dbprint.c:874
void dbGet_RXbuffer(char *buf)
Get the value of the RX buffer and clear the dataReceived flag.
Definition: dbprint.c:1019
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
static void uint32_to_charHex(char *buf, uint32_t value, bool spacing)
Convert a uint32_t value to a hexadecimal char array (string).
Definition: dbprint.c:1063
void USART0_RX_IRQHandler(void)
USART0 RX interrupt service routine.
Definition: dbprint.c:1281
void dbprint_color(char *message, dbprint_color_t color)
Print a string (char array) to USARTx in a given color.
Definition: dbprint.c:423