]> git.donarmstrong.com Git - qmk_firmware.git/blob - protocol/lufa/LUFA-120730/LUFA/Drivers/Peripheral/AVR8/Serial_AVR8.c
Change TOP_DIR to TMK_DIR in makefiles
[qmk_firmware.git] / protocol / lufa / LUFA-120730 / LUFA / Drivers / Peripheral / AVR8 / Serial_AVR8.c
1 /*\r
2              LUFA Library\r
3      Copyright (C) Dean Camera, 2012.\r
4 \r
5   dean [at] fourwalledcubicle [dot] com\r
6            www.lufa-lib.org\r
7 */\r
8 \r
9 /*\r
10   Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
11 \r
12   Permission to use, copy, modify, distribute, and sell this\r
13   software and its documentation for any purpose is hereby granted\r
14   without fee, provided that the above copyright notice appear in\r
15   all copies and that both that the copyright notice and this\r
16   permission notice and warranty disclaimer appear in supporting\r
17   documentation, and that the name of the author not be used in\r
18   advertising or publicity pertaining to distribution of the\r
19   software without specific, written prior permission.\r
20 \r
21   The author disclaim all warranties with regard to this\r
22   software, including all implied warranties of merchantability\r
23   and fitness.  In no event shall the author be liable for any\r
24   special, indirect or consequential damages or any damages\r
25   whatsoever resulting from loss of use, data or profits, whether\r
26   in an action of contract, negligence or other tortious action,\r
27   arising out of or in connection with the use or performance of\r
28   this software.\r
29 */\r
30 \r
31 #include "../../../Common/Common.h"\r
32 #if (ARCH == ARCH_AVR8)\r
33 \r
34 #define  __INCLUDE_FROM_SERIAL_C\r
35 #include "../Serial.h"\r
36 \r
37 FILE USARTSerialStream;\r
38 \r
39 int Serial_putchar(char DataByte,\r
40                    FILE *Stream)\r
41 {\r
42         (void)Stream;\r
43 \r
44         Serial_SendByte(DataByte);\r
45         return 0;\r
46 }\r
47 \r
48 int Serial_getchar(FILE *Stream)\r
49 {\r
50         (void)Stream;\r
51 \r
52         if (!(Serial_IsCharReceived()))\r
53           return _FDEV_EOF;\r
54 \r
55         return Serial_ReceiveByte();\r
56 }\r
57 \r
58 int Serial_getchar_Blocking(FILE *Stream)\r
59 {\r
60         (void)Stream;\r
61 \r
62         while (!(Serial_IsCharReceived()));\r
63         return Serial_ReceiveByte();\r
64 }\r
65 \r
66 void Serial_SendString_P(const char* FlashStringPtr)\r
67 {\r
68         uint8_t CurrByte;\r
69 \r
70         while ((CurrByte = pgm_read_byte(FlashStringPtr)) != 0x00)\r
71         {\r
72                 Serial_SendByte(CurrByte);\r
73                 FlashStringPtr++;\r
74         }\r
75 }\r
76 \r
77 void Serial_SendString(const char* StringPtr)\r
78 {\r
79         uint8_t CurrByte;\r
80 \r
81         while ((CurrByte = *StringPtr) != 0x00)\r
82         {\r
83                 Serial_SendByte(CurrByte);\r
84                 StringPtr++;\r
85         }\r
86 }\r
87 \r
88 void Serial_SendData(const uint8_t* Buffer,\r
89                      uint16_t Length)\r
90 {\r
91         while (Length--)\r
92           Serial_SendByte(*(Buffer++));\r
93 }\r
94 \r
95 void Serial_CreateStream(FILE* Stream)\r
96 {\r
97         if (!(Stream))\r
98         {\r
99                 Stream = &USARTSerialStream;\r
100                 stdin  = Stream;\r
101                 stdout = Stream;\r
102         }\r
103 \r
104         *Stream = (FILE)FDEV_SETUP_STREAM(Serial_putchar, Serial_getchar, _FDEV_SETUP_RW);\r
105 }\r
106 \r
107 void Serial_CreateBlockingStream(FILE* Stream)\r
108 {\r
109         if (!(Stream))\r
110         {\r
111                 Stream = &USARTSerialStream;\r
112                 stdin  = Stream;\r
113                 stdout = Stream;\r
114         }\r
115 \r
116         *Stream = (FILE)FDEV_SETUP_STREAM(Serial_putchar, Serial_getchar_Blocking, _FDEV_SETUP_RW);\r
117 }\r
118 \r
119 #endif\r