Synergia AVR 0.1
|
00001 /* 00002 Copyright (c) 2010 Tymon Tobolski 00003 00004 Permission is hereby granted, free of charge, to any person obtaining 00005 a copy of this software and associated documentation files (the 00006 "Software"), to deal in the Software without restriction, including 00007 without limitation the rights to use, copy, modify, merge, publish, 00008 distribute, sublicense, and/or sell copies of the Software, and to 00009 permit persons to whom the Software is furnished to do so, subject to 00010 the following conditions: 00011 00012 The above copyright notice and this permission notice shall be 00013 included in all copies or substantial portions of the Software. 00014 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00016 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00018 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00019 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00020 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00021 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00022 */ 00023 00024 #ifndef _USART_H_ 00025 #define _USART_H_ 00026 00043 #include "buffer.h" 00044 00056 #ifndef USART_BAUD 00057 #define USART_BAUD 9600L 00058 #endif 00059 00066 class Usart { 00067 public: 00068 00074 void push(char c); 00075 00081 unsigned char read(); 00082 00088 bool empty(); 00089 00090 00097 char * readline(); 00098 00099 bool gotLine(); 00100 00107 Usart & operator<<(const unsigned char c); 00108 00115 Usart & operator<<(const char c); 00116 00123 Usart & operator<<(char* string); 00124 00131 Usart & operator<<(const int number); 00132 00139 Usart & operator<<(const long number); 00140 00147 Usart & operator>>(unsigned char &c); 00148 00155 Usart & operator>>(int &c); 00156 00162 virtual void sendByte(unsigned char byte){}; 00163 00164 private: 00165 Buffer buf; 00166 }; 00167 00168 #if defined(__AVR_ATmega128__) 00169 00178 #define USART0(u) Usart0 u; ISR(USART0_RX_vect){ int c; c = UDR0; u.push(c); } 00179 00188 #define USART1(u) Usart1 u; ISR(USART1_RX_vect){ int c; c = UDR1; u.push(c); } 00189 00196 class Usart0: public Usart { 00197 public: 00198 Usart0(); 00199 void sendByte(unsigned char byte); 00200 }; 00201 00208 class Usart1: public Usart { 00209 public: 00210 Usart1(); 00211 void sendByte(unsigned char byte); 00212 }; 00213 00214 #elif defined(__AVR_ATmega32__) 00215 00224 #define USART32(u) Usart32 u; ISR(USART_RXC_vect){ int c; c = UDR; u.push(c); } 00225 00232 class Usart32: public Usart { 00233 public: 00234 Usart32(); 00235 void sendByte(unsigned char byte); 00236 }; 00237 00238 #endif 00239 00240 #endif