Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a baud argument for (Raw)Serial objects #2422

Merged
merged 1 commit into from
Oct 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/RawSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace mbed {

RawSerial::RawSerial(PinName tx, PinName rx) : SerialBase(tx, rx) {
RawSerial::RawSerial(PinName tx, PinName rx, int baud) : SerialBase(tx, rx, baud) {
// No lock needed in the constructor
}

Expand Down
5 changes: 3 additions & 2 deletions drivers/RawSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ namespace mbed {
class RawSerial: public SerialBase {

public:
/** Create a RawSerial port, connected to the specified transmit and receive pins
/** Create a RawSerial port, connected to the specified transmit and receive pins, with the specified baud.
*
* @param tx Transmit pin
* @param rx Receive pin
* @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
*
* @note
* Either tx or rx may be specified as NC if unused
*/
RawSerial(PinName tx, PinName rx);
RawSerial(PinName tx, PinName rx, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);

/** Write a char to the serial port
*
Expand Down
5 changes: 4 additions & 1 deletion drivers/Serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@

namespace mbed {

Serial::Serial(PinName tx, PinName rx, const char *name) : SerialBase(tx, rx), Stream(name) {
Serial::Serial(PinName tx, PinName rx, const char *name, int baud) : SerialBase(tx, rx, baud), Stream(name) {
}

Serial::Serial(PinName tx, PinName rx, int baud): SerialBase(tx, rx, baud), Stream(NULL) {
}

int Serial::_getc() {
Expand Down
16 changes: 15 additions & 1 deletion drivers/Serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,25 @@ class Serial : public SerialBase, public Stream {
*
* @param tx Transmit pin
* @param rx Receive pin
* @param name The name of the stream associated with this serial port (optional)
* @param baud The baud rate of the serial port (optional, defaults to MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE)
*
* @note
* Either tx or rx may be specified as NC if unused
*/
Serial(PinName tx, PinName rx, const char *name=NULL);
Serial(PinName tx, PinName rx, const char *name=NULL, int baud = MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);


/** Create a Serial port, connected to the specified transmit and receive pins, with the specified baud
*
* @param tx Transmit pin
* @param rx Receive pin
* @param baud The baud rate of the serial port
*
* @note
* Either tx or rx may be specified as NC if unused
*/
Serial(PinName tx, PinName rx, int baud);

protected:
virtual int _getc();
Expand Down
5 changes: 3 additions & 2 deletions drivers/SerialBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ namespace mbed {

static void donothing() {};

SerialBase::SerialBase(PinName tx, PinName rx) :
SerialBase::SerialBase(PinName tx, PinName rx, int baud) :
#if DEVICE_SERIAL_ASYNCH
_thunk_irq(this), _tx_usage(DMA_USAGE_NEVER),
_rx_usage(DMA_USAGE_NEVER),
#endif
_serial(), _baud(9600) {
_serial(), _baud(baud) {
// No lock needed in the constructor

for (size_t i = 0; i < sizeof _irq / sizeof _irq[0]; i++) {
_irq[i].attach(donothing);
}

serial_init(&_serial, tx, rx);
serial_baud(&_serial, _baud);
serial_irq_handler(&_serial, SerialBase::_irq_handler, (uint32_t)this);
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/SerialBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class SerialBase {
#endif

protected:
SerialBase(PinName tx, PinName rx);
SerialBase(PinName tx, PinName rx, int baud);
virtual ~SerialBase() {
}

Expand Down
5 changes: 5 additions & 0 deletions platform/mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"stdio-flush-at-exit": {
"help": "Enable or disable the flush of standard I/O's at exit.",
"value": true
},

"default-serial-baud-rate": {
"help": "Default baud rate for a Serial or RawSerial instance (if not specified in the constructor)",
"value": 9600
}
},
"target_overrides": {
Expand Down