COSA
An Object-Oriented Platform for Arduino Programming
SOFT_UAT.cpp
Go to the documentation of this file.
1 
21 #include "Cosa/Soft/UART.hh"
22 
23 using namespace Soft;
24 
26  Serial(),
27  m_tx(tx, 1),
28  m_stops(2),
29  m_bits(8),
30  m_count((F_CPU / 9600) / 4)
31 {
32 }
33 
34 int
35 UAT::putchar(char c)
36 {
37  uint16_t data = ((0xff00 | c) << 1);
38  uint8_t bits = m_bits + m_stops + 1;
39  uint16_t count = m_count;
40  synchronized {
41  do {
42  m_tx._write(data & 0x01);
43  _delay_loop_2(count);
44  data >>= 1;
45  } while (--bits);
46  }
47  return (c & 0xff);
48 }
49 
50 bool
51 UAT::begin(uint32_t baudrate, uint8_t format)
52 {
53  m_stops = 1 + ((format & STOP2) != 0);
54  m_bits = 5 + ((format & DATA8) >> 1);
55  m_count = ((F_CPU / baudrate) - I_CPU) / 4;
56  if (baudrate > 19600) m_count -= 1;
57  return (true);
58 }
virtual int putchar(char c)
Definition: SOFT_UAT.cpp:35
Definition: SPI.hh:32
UAT(Board::DigitalPin tx)
Definition: SOFT_UAT.cpp:25
uint16_t m_count
Definition: UART.hh:86
OutputPin m_tx
Definition: UART.hh:83
void _write(int value) const
Definition: OutputPin.hh:219
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
#define I_CPU
Definition: Types.h:274
uint8_t m_bits
Definition: UART.hh:85