COSA
An Object-Oriented Platform for Arduino Programming
UART.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_SOFT_UART_HH
22 #define COSA_SOFT_UART_HH
23 
24 #include "Cosa/Types.h"
25 #include "Cosa/OutputPin.hh"
27 #include "Cosa/Serial.hh"
28 #include "Cosa/IOBuffer.hh"
29 
30 // Default receiver buffer size
31 #ifndef COSA_SOFT_UART_RX_BUFFER_MAX
32 # if defined(BOARD_ATTINY)
33 # define COSA_SOFT_UART_RX_BUFFER_MAX 16
34 # else
35 # define COSA_SOFT_UART_RX_BUFFER_MAX 32
36 # endif
37 #endif
38 
39 // Default transmitter buffer size
40 #ifndef COSA_SOFT_UART_TX_BUFFER_MAX
41 # if defined(BOARD_ATTINY)
42 # define COSA_SOFT_UART_TX_BUFFER_MAX 16
43 # else
44 # define COSA_SOFT_UART_TX_BUFFER_MAX 32
45 # endif
46 #endif
47 
48 namespace Soft {
49 
55 class UAT : public Serial {
56 public:
62 
70  virtual int putchar(char c);
71 
79  virtual bool begin(uint32_t baudrate = DEFAULT_BAUDRATE,
80  uint8_t format = DEFAULT_FORMAT);
81 
82 protected:
84  uint8_t m_stops;
85  uint8_t m_bits;
86  uint16_t m_count;
87 };
88 
94 class UART : public UAT {
95 public:
97  static const uint8_t RX_BUFFER_MAX = COSA_SOFT_UART_RX_BUFFER_MAX;
98  static const uint8_t TX_BUFFER_MAX = COSA_SOFT_UART_TX_BUFFER_MAX;
99 
110 
116  virtual int available()
117  {
118  return (m_ibuf->available());
119  }
120 
128  virtual int peekchar()
129  {
130  return (m_ibuf->peekchar());
131  }
132 
139  virtual int peekchar(char c)
140  {
141  return (m_ibuf->peekchar(c));
142  }
143 
151  virtual int getchar()
152  {
153  return (m_ibuf->getchar());
154  }
155 
160  virtual void empty()
161  {
162  m_ibuf->empty();
163  }
164 
172  virtual bool begin(uint32_t baudrate = DEFAULT_BAUDRATE,
173  uint8_t format = DEFAULT_FORMAT);
174 
180  virtual bool end()
181  {
182  m_rx.disable();
183  return (true);
184  }
185 
186 protected:
189  public:
191  virtual void on_interrupt(uint16_t arg = 0);
192  protected:
194  };
197  friend class RXPinChangeInterrupt;
198 };
199 
200 };
201 
202 #endif
UART uart
virtual int putchar(char c)
Definition: SOFT_UAT.cpp:35
Definition: SPI.hh:32
IOStream::Device * m_ibuf
Definition: UART.hh:196
#define COSA_SOFT_UART_RX_BUFFER_MAX
Definition: UART.hh:35
UAT(Board::DigitalPin tx)
Definition: SOFT_UAT.cpp:25
virtual int peekchar(char c)
Definition: UART.hh:139
uint16_t m_count
Definition: UART.hh:86
virtual int peekchar()
Definition: UART.hh:128
RXPinChangeInterrupt m_rx
Definition: UART.hh:195
#define COSA_SOFT_UART_TX_BUFFER_MAX
Definition: UART.hh:44
virtual void empty()
Definition: UART.hh:160
virtual int getchar()
Definition: UART.hh:151
OutputPin m_tx
Definition: UART.hh:83
static const uint32_t DEFAULT_BAUDRATE
Definition: Serial.hh:43
Definition: Serial.hh:40
virtual bool begin(uint32_t baudrate=DEFAULT_BAUDRATE, uint8_t format=DEFAULT_FORMAT)
Definition: SOFT_UAT.cpp:51
uint8_t m_stops
Definition: UART.hh:84
uint8_t m_bits
Definition: UART.hh:85
static IOBuffer< UART::RX_BUFFER_MAX > ibuf
Definition: UART.cpp:37
static const uint8_t DEFAULT_FORMAT
Definition: Serial.hh:59
virtual int available()
Definition: UART.hh:116
virtual bool end()
Definition: UART.hh:180