Add more include protection macros to give the user warnings when they try to manuall...
[pub/USBasp.git] / LUFA / Drivers / Peripheral / SerialStream.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 /** \file
32 *
33 * Serial stream driver for the USART subsystem on supported USB AVRs. This makes use of the functions in the
34 * regular USART driver, but allows the avr-libc standard stream functions (printf, puts, etc.) to work with the
35 * USART.
36 **/
37
38 /** \ingroup Group_PeripheralDrivers
39 * @defgroup Group_SerialStream Serial Stream Driver - LUFA/Drivers/Peripheral/SerialStream.h
40 *
41 * \section Sec_Dependencies Module Source Dependencies
42 * The following files must be built with any user project that uses this module:
43 * - LUFA/Drivers/Peripheral/SerialStream.c
44 *
45 * \section Module Description
46 * Serial stream driver for the USART subsystem on supported USB AVRs. This makes use of the functions in the
47 * regular USART driver, but allows the avr-libc standard stream functions (printf, puts, etc.) to work with the
48 * USART.
49 *
50 * @{
51 */
52
53 #ifndef __SERIAL_STREAM_H__
54 #define __SERIAL_STREAM_H__
55
56 /* Includes: */
57 #include <avr/io.h>
58 #include <stdio.h>
59
60 #include "Serial.h"
61
62 /* Enable C linkage for C++ Compilers: */
63 #if defined(__cplusplus)
64 extern "C" {
65 #endif
66
67 /* Private Interface - For use in library only: */
68 #if !defined(__DOXYGEN__)
69 /* External Variables: */
70 extern FILE USARTStream;
71
72 /* Function Prototypes: */
73 #if defined(__INCLUDE_FROM_SERIALSTREAM_C)
74 static int SerialStream_TxByte(char DataByte, FILE *Stream) ATTR_NON_NULL_PTR_ARG(2);
75 static int SerialStream_RxByte(FILE *Stream) ATTR_NON_NULL_PTR_ARG(1);
76 #endif
77 #endif
78
79 /* Public Interface - May be used in end-application: */
80 /* Inline Functions: */
81 /** Initializes the serial stream (and regular USART driver) so that both the stream and regular
82 * USART driver functions can be used. Must be called before any stream or regular USART functions.
83 *
84 * \param[in] BaudRate Baud rate to configure the USART to
85 * \param[in] DoubleSpeed Enables double speed mode when set, halving the sample time to double the baud rate
86 */
87 static inline void SerialStream_Init(const uint32_t BaudRate, const bool DoubleSpeed)
88 {
89 Serial_Init(BaudRate, DoubleSpeed);
90
91 stdout = &USARTStream;
92 stdin = &USARTStream;
93 }
94
95 /** Turns off the serial stream (and regular USART driver), disabling and returning used hardware to
96 * their default configuration.
97 */
98 static inline void SerialStream_ShutDown(void)
99 {
100 Serial_ShutDown();
101 }
102
103 /* Disable C linkage for C++ Compilers: */
104 #if defined(__cplusplus)
105 }
106 #endif
107
108 #endif
109
110 /** @} */