An alternative Serial Library for Arduino 1.0

I didn't mark the overrides as virtual since I didn't want someone to override my functions in a class derived from SerialPort since SerialPort is a template.

I understand the inline problem but this code is a beta prototype to test the API and use of templates for buffer size. It's a pain to move functions out of a template to make them non-inline at this stage. I will optimize flash use later.

I have already totally changed the internal structure by making SerialRingBuffer and SerialRegisters classes and moving most of the code to these classes which don't have inline functions plus it reduces duplicated code for RX and TX. That reduced flash use a lot.

Write is now just these two lines

      // wait for TX ISR if buffer is full
      while (!txbuf_->put(b)) {}
      // enable interrupts
      usart_->ucsrb |= M_UDRIE;

I tested the input buffering buffering in the MegaTest program. It couldn't work if there was no input buffering.

This sketch tests output buffering:

#include <SerialPort.h>
SerialPort<0, 63, 63> NewSerial;

// use macro to substitute for Serial
#define Serial NewSerial

void setup() {
  Serial.begin(9600);
  uint32_t t = micros();
  Serial.println("12345678901234567890");
  t = micros() - t;
  Serial.print("micros: ");
  Serial.println(t);
}
void loop() {}

It writes 20 characters in 220 microseconds so output buffering is working. Here is the output:

12345678901234567890
micros: 220