Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
src/BufferedSerial.cpp
- Committer:
- Marc Nijdam
- Date:
- 2017-07-06
- Revision:
- 14:af7682f4e610
File content as of revision 14:af7682f4e610:
/*
* Copyright 2017, Helium Systems, Inc.
* All Rights Reserved. See LICENSE.txt for license information
*/
#include "BufferedSerial.h"
BufferedSerial:: BufferedSerial(PinName tx,
PinName rx,
int baud)
: RawSerial(tx, rx, baud)
{
this->attach(callback(this, &BufferedSerial::_rx_interrupt),
Serial::RxIrq);
}
BufferedSerial::~BufferedSerial()
{
this->attach(NULL, Serial::RxIrq);
}
void BufferedSerial::_rx_interrupt()
{
_rx_buffer.push(serial_getc(&_serial));
}
void BufferedSerial::baud(int baud)
{
serial_baud(&_serial, baud);
}
int BufferedSerial::getc()
{
uint8_t ch;
if (_rx_buffer.pop(&ch))
{
return ch;
}
return -1;
}
int BufferedSerial::putc(int ch)
{
serial_putc(&_serial, ch);
return ch;
}
int BufferedSerial::readable()
{
return _rx_buffer.available() > 0;
}