Moved all source to the trunk directory.
[pub/USBasp.git] / LUFA / Drivers / AT90USBXXX / Serial_Stream.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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 #ifndef __SERIAL_STREAM_H__
39 #define __SERIAL_STREAM_H__
40
41 /* Includes: */
42 #include <avr/io.h>
43 #include <stdio.h>
44
45 #include "Serial.h"
46
47 /* Enable C linkage for C++ Compilers: */
48 #if defined(__cplusplus)
49 extern "C" {
50 #endif
51
52 /* Private Interface - For use in library only: */
53 #if !defined(__DOXYGEN__)
54 /* External Variables: */
55 extern FILE USARTStream;
56
57 /* Function Prototypes: */
58 int SerialStream_TxByte(char DataByte, FILE *Stream) ATTR_NON_NULL_PTR_ARG(2);
59 int SerialStream_RxByte(FILE *Stream) ATTR_NON_NULL_PTR_ARG(1);
60 #endif
61
62 /* Public Interface - May be used in end-application: */
63 /* Inline Functions: */
64 /** Initializes the serial stream (and regular USART driver) so that both the stream and regular
65 * USART driver functions can be used. Must be called before any stream or regular USART functions.
66 *
67 * \param BaudRate Baud rate to configure the USART to
68 * \param DoubleSpeed Enables double speed mode when set, halving the sample time to double the baud rate
69 */
70 static inline void SerialStream_Init(const uint32_t BaudRate, const bool DoubleSpeed)
71 {
72 Serial_Init(BaudRate, DoubleSpeed);
73
74 stdout = &USARTStream;
75 }
76
77 /* Disable C linkage for C++ Compilers: */
78 #if defined(__cplusplus)
79 }
80 #endif
81
82 #endif