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 00105 Usart & operator<<(const unsigned char c); 00106 00113 Usart & operator<<(const char c); 00114 00121 Usart & operator<<(char* string); 00122 00129 Usart & operator<<(const int number); 00130 00137 Usart & operator<<(const long number); 00138 00145 Usart & operator>>(unsigned char &c); 00146 00153 Usart & operator>>(int &c); 00154 00160 virtual void sendByte(unsigned char byte){}; 00161 00162 private: 00163 Buffer buf; 00164 }; 00165 00166 #if defined(__AVR_ATmega128__) 00167 00176 #define USART0(u) Usart0 u; ISR(USART0_RX_vect){ int c; c = UDR0; u.push(c); } 00177 00186 #define USART1(u) Usart1 u; ISR(USART1_RX_vect){ int c; c = UDR1; u.push(c); } 00187 00194 class Usart0: public Usart { 00195 public: 00196 Usart0(); 00197 void sendByte(unsigned char byte); 00198 }; 00199 00206 class Usart1: public Usart { 00207 public: 00208 Usart1(); 00209 void sendByte(unsigned char byte); 00210 }; 00211 00212 #elif defined(__AVR_ATmega32__) 00213 00222 #define USART32(u) Usart32 u; ISR(USART_RXC_vect){ int c; c = UDR; u.push(c); } 00223 00230 class Usart32: public Usart { 00231 public: 00232 Usart32(); 00233 void sendByte(unsigned char byte); 00234 }; 00235 00236 #endif 00237 00238 #endif