COSA
An Object-Oriented Platform for Arduino Programming
CDC.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_CDC_HH
22 #define COSA_CDC_HH
23 
24 #include "Cosa/Types.h"
25 #include "Cosa/Power.hh"
26 #include "Cosa/IOStream.hh"
27 
28 #if defined(USBCON)
29 
30 class CDC : public IOStream::Device {
31 public:
33  static const uint8_t BUFFER_MAX = 64;
34 
39  enum {
40  DATA5 = 0,
41  DATA6 = _BV(UCSZ00),
42  DATA7 = _BV(UCSZ01),
43  DATA8 = _BV(UCSZ01) | _BV(UCSZ00),
44  DATA9 = _BV(UCSZ02) | _BV(UCSZ01) | _BV(UCSZ00),
45  NO_PARITY = 0,
46  EVEN_PARITY = _BV(UPM01),
47  ODD_PARITY = _BV(UPM01) | _BV(UPM00),
48  STOP1 = 0,
49  STOP2 = _BV(USBS0)
50  } __attribute__((packed));
51 
56  CDC(IOStream::Device* ibuf) :
57  IOStream::Device(),
58  m_ibuf(ibuf)
59  {}
60 
66  virtual int available()
67  {
68  return (m_ibuf->available());
69  }
70 
73 
81  virtual int write(const void* buf, size_t size);
82 
90  virtual int peekchar()
91  {
92  return (m_ibuf->peekchar());
93  }
94 
101  virtual int peekchar(char c)
102  {
103  return (m_ibuf->peekchar(c));
104  }
105 
113  virtual int getchar()
114  {
115  return (m_ibuf->getchar());
116  }
117 
123  virtual int flush();
124 
129  virtual void empty();
130 
138  bool begin(uint32_t baudrate = 9600, uint8_t format = DATA8 + STOP2 + NO_PARITY);
139 
144  bool end()
145  {
146  Power::usb_disable();
147  return (true);
148  }
149 
150 protected:
152  IOStream::Device* m_ibuf;
153 
157  void accept();
158 
160  friend void USB_GEN_vect(void);
161 };
162 
166 extern CDC cdc;
167 #endif
168 #endif
virtual int write(const void *buf, size_t size)
#define UPM00
Definition: Leonardo.hh:292
virtual void empty()
#define USBS0
Definition: Leonardo.hh:294
#define UCSZ00
Definition: Leonardo.hh:289
#define UCSZ01
Definition: Leonardo.hh:290
#define UCSZ02
Definition: Leonardo.hh:291
#define UPM01
Definition: Leonardo.hh:293
void USB_GEN_vect(void)
virtual int flush()
virtual int available()
virtual int getchar()
virtual int peekchar()
static IOBuffer< UART::RX_BUFFER_MAX > ibuf
Definition: UART.cpp:37