mbedmicro/mbed — pull request #99 by xiongyihui (2013-11-01 04:53:17+00:00)
Title: add readable(), writeable() and settings changed callback to USBSerial

For class Serial has readable() and writeable(), add them to class USBSerial, switch between Serial and USBSerial easily.
Add settings changed callback to USBSerial to implement a USB to UART bridge.
```
#include "mbed.h"
#include "USBSerial.h"

Serial uart(USBTX, USBRX);
USBSerial pc;

void settingsChanged(int baud, int bits, int parity, int stop) // Called by ISR
{
const Serial::Parity parityTable[] = {Serial::None, Serial::Odd, Serial::Even, Serial::Forced0, Serial::Forced1};
if (stop != 2) {
stop = 1; // stop bit(s) = 1 or 1.5
}
uart.baud(baud);
uart.format(bits, parityTable[parity], stop);
}

int main()
{
pc.attach(settingsChanged);
while (1) {
while (uart.readable()) {
pc.putc(uart.getc());
}
while (pc.readable()) {
uart.putc(pc.getc());
}
}
}
```