COSA
An Object-Oriented Platform for Arduino Programming
Serial.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_SERIAL_HH
22 #define COSA_SERIAL_HH
23 
24 #include "Cosa/Types.h"
25 #include "Cosa/IOStream.hh"
26 
27 #if defined(BOARD_ATTINY)
28 # define UCSZ00 1
29 # define UCSZ01 2
30 # define USBS0 3
31 # define UPM00 4
32 # define UPM01 5
33 #endif
34 
40 class Serial : public IOStream::Device {
41 public:
43  static const uint32_t DEFAULT_BAUDRATE = 9600L;
44 
46  enum {
47  DATA5 = 0,
48  DATA6 = _BV(UCSZ00),
49  DATA7 = _BV(UCSZ01),
50  DATA8 = _BV(UCSZ01) | _BV(UCSZ00),
51  NO_PARITY = 0,
53  ODD_PARITY = _BV(UPM01) | _BV(UPM00),
54  STOP1 = 0,
55  STOP2 = _BV(USBS0),
56  } __attribute__((packed));
57 
59  static const uint8_t DEFAULT_FORMAT = DATA8 + NO_PARITY + STOP2;
60 
65 
74  virtual bool begin(uint32_t baudrate = DEFAULT_BAUDRATE,
75  uint8_t format = DEFAULT_FORMAT) = 0;
76 
82  virtual bool end()
83  {
84  return (true);
85  }
86 
91  virtual void powerup() {}
92 
97  virtual void powerdown() {}
98 };
99 
100 #endif
virtual bool begin(uint32_t baudrate=DEFAULT_BAUDRATE, uint8_t format=DEFAULT_FORMAT)=0
#define UPM00
Definition: Leonardo.hh:292
Serial()
Definition: Serial.hh:64
virtual void powerup()
Definition: Serial.hh:91
#define USBS0
Definition: Leonardo.hh:294
#define UCSZ00
Definition: Leonardo.hh:289
virtual void powerdown()
Definition: Serial.hh:97
#define UCSZ01
Definition: Leonardo.hh:290
#define UPM01
Definition: Leonardo.hh:293
virtual bool end()
Definition: Serial.hh:82
static const uint32_t DEFAULT_BAUDRATE
Definition: Serial.hh:43
Definition: Serial.hh:40
static const uint8_t DEFAULT_FORMAT
Definition: Serial.hh:59