COSA
An Object-Oriented Platform for Arduino Programming
SOFT_UART.cpp
Go to the documentation of this file.
1 
21 #include "Cosa/Soft/UART.hh"
22 
23 using namespace Soft;
24 
26  UAT(tx),
27  m_rx(rx, this),
28  m_ibuf(ibuf)
29 {
30 }
31 
32 bool
33 UART::begin(uint32_t baudrate, uint8_t format)
34 {
35  if (!UAT::begin(baudrate, format)) return (false);
37  m_rx.enable();
38  return (true);
39 }
40 
42  UART* uart) :
43  PinChangeInterrupt(pin),
44  m_uart(uart)
45 {
46 }
47 
48 void
50 {
51  UNUSED(arg);
52  if (is_set()) return;
53  uint16_t count = m_uart->m_count;
54  uint8_t bits = m_uart->m_bits;
55  uint8_t mask = 1;
56  uint8_t data = 0;
57  do {
58  _delay_loop_2(count);
59  if (is_set()) data |= mask;
60  mask <<= 1;
61  } while (--bits);
62  m_uart->m_ibuf->putchar(data);
63 }
virtual int putchar(char c)
UART(Board::DigitalPin tx, Board::InterruptPin rx, IOStream::Device *ibuf)
Definition: SOFT_UART.cpp:25
Definition: SPI.hh:32
IOStream::Device * m_ibuf
Definition: UART.hh:196
UART uart(0,&ibuf,&obuf)
uint16_t m_count
Definition: UART.hh:86
RXPinChangeInterrupt m_rx
Definition: UART.hh:195
bool is_set() const
Definition: Pin.hh:112
RXPinChangeInterrupt(Board::InterruptPin pin, UART *uart)
Definition: SOFT_UART.cpp:41
#define UNUSED(x)
Definition: ATmega328P.hh:31
virtual bool begin(uint32_t baudrate=DEFAULT_BAUDRATE, uint8_t format=DEFAULT_FORMAT)
Definition: SOFT_UAT.cpp:51
virtual void on_interrupt(uint16_t arg=0)
Definition: SOFT_UART.cpp:49
uint8_t m_bits
Definition: UART.hh:85
static IOBuffer< UART::RX_BUFFER_MAX > ibuf
Definition: UART.cpp:37
virtual bool begin(uint32_t baudrate=DEFAULT_BAUDRATE, uint8_t format=DEFAULT_FORMAT)
Definition: SOFT_UART.cpp:33