]> git.gir.st - tmk_keyboard.git/blob - protocol/lufa/LUFA-120730/LUFA/Drivers/Peripheral/XMEGA/Serial_XMEGA.c
Squashed 'tmk_core/' changes from b9e0ea0..caca2c0
[tmk_keyboard.git] / protocol / lufa / LUFA-120730 / LUFA / Drivers / Peripheral / XMEGA / Serial_XMEGA.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2012.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 */
8
9 /*
10 Copyright 2012 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 #include "../../../Common/Common.h"
32 #if (ARCH == ARCH_XMEGA)
33
34 #define __INCLUDE_FROM_SERIAL_C
35 #include "../Serial.h"
36
37 FILE USARTSerialStream;
38
39 int Serial_putchar(char DataByte,
40 FILE *Stream)
41 {
42 USART_t* USART = fdev_get_udata(Stream);
43
44 Serial_SendByte(USART, DataByte);
45 return 0;
46 }
47
48 int Serial_getchar(FILE *Stream)
49 {
50 USART_t* USART = fdev_get_udata(Stream);
51
52 if (!(Serial_IsCharReceived(USART)))
53 return _FDEV_EOF;
54
55 return Serial_ReceiveByte(USART);
56 }
57
58 int Serial_getchar_Blocking(FILE *Stream)
59 {
60 USART_t* USART = fdev_get_udata(Stream);
61
62 while (!(Serial_IsCharReceived(USART)));
63 return Serial_ReceiveByte(USART);
64 }
65
66 void Serial_SendString_P(USART_t* const USART,
67 const char* FlashStringPtr)
68 {
69 uint8_t CurrByte;
70
71 while ((CurrByte = pgm_read_byte(FlashStringPtr)) != 0x00)
72 {
73 Serial_SendByte(USART, CurrByte);
74 FlashStringPtr++;
75 }
76 }
77
78 void Serial_SendString(USART_t* const USART,
79 const char* StringPtr)
80 {
81 uint8_t CurrByte;
82
83 while ((CurrByte = *StringPtr) != 0x00)
84 {
85 Serial_SendByte(USART, CurrByte);
86 StringPtr++;
87 }
88 }
89
90 void Serial_SendData(USART_t* const USART,
91 const uint8_t* Buffer,
92 uint16_t Length)
93 {
94 while (Length--)
95 Serial_SendByte(USART, *(Buffer++));
96 }
97
98 void Serial_CreateStream(FILE* Stream)
99 {
100 if (!(Stream))
101 {
102 Stream = &USARTSerialStream;
103 stdin = Stream;
104 stdout = Stream;
105 }
106
107 *Stream = (FILE)FDEV_SETUP_STREAM(Serial_putchar, Serial_getchar, _FDEV_SETUP_RW);
108 }
109
110 void Serial_CreateBlockingStream(FILE* Stream)
111 {
112 if (!(Stream))
113 {
114 Stream = &USARTSerialStream;
115 stdin = Stream;
116 stdout = Stream;
117 }
118
119 *Stream = (FILE)FDEV_SETUP_STREAM(Serial_putchar, Serial_getchar_Blocking, _FDEV_SETUP_RW);
120 }
121
122 #endif
Imprint / Impressum