root / arduino-1.0 / hardware / arduino / cores / arduino / HardwareSerial.h @ 58d82c77
History | View | Annotate | Download (2.29 KB)
1 |
/*
|
---|---|
2 |
HardwareSerial.h - Hardware serial library for Wiring
|
3 |
Copyright (c) 2006 Nicholas Zambetti. All right reserved.
|
4 |
|
5 |
This library is free software; you can redistribute it and/or
|
6 |
modify it under the terms of the GNU Lesser General Public
|
7 |
License as published by the Free Software Foundation; either
|
8 |
version 2.1 of the License, or (at your option) any later version.
|
9 |
|
10 |
This library is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 |
Lesser General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU Lesser General Public
|
16 |
License along with this library; if not, write to the Free Software
|
17 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
18 |
|
19 |
Modified 28 September 2010 by Mark Sproul
|
20 |
*/
|
21 |
|
22 |
#ifndef HardwareSerial_h
|
23 |
#define HardwareSerial_h
|
24 |
|
25 |
#include <inttypes.h> |
26 |
|
27 |
#include "Stream.h" |
28 |
|
29 |
struct ring_buffer;
|
30 |
|
31 |
class HardwareSerial : public Stream |
32 |
{ |
33 |
private:
|
34 |
ring_buffer *_rx_buffer; |
35 |
ring_buffer *_tx_buffer; |
36 |
volatile uint8_t *_ubrrh;
|
37 |
volatile uint8_t *_ubrrl;
|
38 |
volatile uint8_t *_ucsra;
|
39 |
volatile uint8_t *_ucsrb;
|
40 |
volatile uint8_t *_udr;
|
41 |
uint8_t _rxen; |
42 |
uint8_t _txen; |
43 |
uint8_t _rxcie; |
44 |
uint8_t _udrie; |
45 |
uint8_t _u2x; |
46 |
public:
|
47 |
HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer, |
48 |
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, |
49 |
volatile uint8_t *ucsra, volatile uint8_t *ucsrb, |
50 |
volatile uint8_t *udr,
|
51 |
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x); |
52 |
void begin(unsigned long); |
53 |
void end();
|
54 |
virtual int available(void); |
55 |
virtual int peek(void); |
56 |
virtual int read(void); |
57 |
virtual void flush(void); |
58 |
virtual size_t write(uint8_t); |
59 |
using Print::write; // pull in write(str) and write(buf, size) from Print
|
60 |
}; |
61 |
|
62 |
#if defined(UBRRH) || defined(UBRR0H)
|
63 |
extern HardwareSerial Serial;
|
64 |
#elif defined(USBCON)
|
65 |
#include "USBAPI.h" |
66 |
// extern HardwareSerial Serial_;
|
67 |
#endif
|
68 |
#if defined(UBRR1H)
|
69 |
extern HardwareSerial Serial1;
|
70 |
#endif
|
71 |
#if defined(UBRR2H)
|
72 |
extern HardwareSerial Serial2;
|
73 |
#endif
|
74 |
#if defined(UBRR3H)
|
75 |
extern HardwareSerial Serial3;
|
76 |
#endif
|
77 |
|
78 |
extern void serialEventRun(void) __attribute__((weak)); |
79 |
|
80 |
#endif
|