Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
uart_print.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005 Pascal Brisset, Antoine Drouin
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #ifndef UART_PRINT_H
23 #define UART_PRINT_H
24 
25 #include "mcu_periph/uart.h"
26 #include "mcu_periph/usb_serial.h"
27 
28 #define _PrintString(out_fun, s) { \
29  uint8_t i = 0; \
30  while (s[i]) { \
31  out_fun(s[i]); \
32  i++; \
33  } \
34 }
35 
36 #define _PrintHex(out_fun, c) { \
37  const uint8_t hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', \
38  '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; \
39  uint8_t high = (c & 0xF0)>>4; \
40  uint8_t low = c & 0x0F; \
41  out_fun(hex[high]); \
42  out_fun(hex[low]); \
43 } \
44 
45 #define _PrintHex16(out_fun, c ) { \
46  uint8_t high16 = (uint8_t)(c>>8); \
47  uint8_t low16 = (uint8_t)(c); \
48  _PrintHex(out_fun, high16); \
49  _PrintHex(out_fun, low16); \
50 }
51 
52 #define _PrintHex32(out_fun, c ) { \
53  uint16_t high32 = (uint16_t)(c>>16); \
54  uint16_t low32 = (uint16_t)(c); \
55  _PrintHex16(out_fun, high32); \
56  _PrintHex16(out_fun, low32); \
57 }
58 
59 #ifdef USE_UART0
60 
61 #define UART0PrintHex(c) _PrintHex(UART0Transmit, c)
62 #define UART0PrintHex16(c) _PrintHex16(UART0Transmit, c)
63 #define UART0PrintHex32(c) _PrintHex32(UART0Transmit, c)
64 #define UART0PrintString(s) _PrintString(UART0Transmit, s)
65 
66 #endif /* USE_UART0 */
67 
68 #ifdef USE_UART1
69 
70 #define UART1PrintHex(c) _PrintHex(UART1Transmit, c)
71 #define UART1PrintHex16(c) _PrintHex16(UART1Transmit, c)
72 #define UART1PrintHex32(c) _PrintHex32(UART1Transmit, c)
73 #define UART1PrintString(s) _PrintString(UART1Transmit, s)
74 
75 #endif /* USE_UART1 */
76 
77 #ifdef USE_UART2
78 
79 #define UART2PrintHex(c) _PrintHex(UART2Transmit, c)
80 #define UART2PrintHex16(c) _PrintHex16(UART2Transmit, c)
81 #define UART2PrintHex32(c) _PrintHex32(UART2Transmit, c)
82 #define UART2PrintString(s) _PrintString(UART2Transmit, s)
83 
84 #endif /* USE_UART2 */
85 
86 #ifdef USE_UART3
87 
88 #define UART3PrintHex(c) _PrintHex(UART3Transmit, c)
89 #define UART3PrintHex16(c) _PrintHex16(UART3Transmit, c)
90 #define UART3PrintHex32(c) _PrintHex32(UART3Transmit, c)
91 #define UART3PrintString(s) _PrintString(UART3Transmit, s)
92 
93 #endif /* USE_UART3 */
94 
95 #ifdef USE_UART5
96 
97 #define UART5PrintHex(c) _PrintHex(UART5Transmit, c)
98 #define UART5PrintHex16(c) _PrintHex16(UART5Transmit, c)
99 #define UART5PrintHex32(c) _PrintHex32(UART5Transmit, c)
100 #define UART5PrintString(s) _PrintString(UART5Transmit, s)
101 
102 #endif /* USE_UART5 */
103 
104 #define UsbSPrintHex(c) _PrintHex(VCOM_putchar, c)
105 #define UsbSPrintHex16(c) _PrintHex16(VCOM_putchar, c)
106 #define UsbSPrintString(s) _PrintString(VCOM_putchar, s)
107 
108 
109 #endif /* UART_PRINT_H */
110 
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
arch independent USB API