Skip to content

Commit dba19e2

Browse files
author
Janne Kiiskila
committed
C++11 style initializer for SerialBase
Kudos to Kevin Bracey, as her his suggestion - we can drop the initializer list if we just set the values directly in the SerialBase.h. No need to worry about the "right order" after that. (One tab to space issue with _tx_pin(tx) fixed).
1 parent 1fed013 commit dba19e2

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

drivers/SerialBase.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -329,25 +329,28 @@ class SerialBase : private NonCopyable<SerialBase> {
329329

330330
#if DEVICE_SERIAL_ASYNCH
331331
CThunk<SerialBase> _thunk_irq;
332-
DMAUsage _tx_usage;
333-
DMAUsage _rx_usage;
332+
DMAUsage _tx_usage = DMA_USAGE_NEVER;
333+
DMAUsage _rx_usage = DMA_USAGE_NEVER;
334334
event_callback_t _tx_callback;
335335
event_callback_t _rx_callback;
336-
bool _tx_asynch_set;
337-
bool _rx_asynch_set;
336+
bool _tx_asynch_set = false;
337+
bool _rx_asynch_set = false;
338338
#endif
339-
#if DEVICE_SERIAL_FC
340-
Flow _flow_type;
341-
PinName _flow1;
342-
PinName _flow2;
343-
#endif
344-
serial_t _serial;
339+
340+
serial_t _serial {};
345341
Callback<void()> _irq[IrqCnt];
346342
int _baud;
347-
bool _rx_enabled;
348-
bool _tx_enabled;
343+
bool _rx_enabled = true;
344+
bool _tx_enabled = true;
349345
const PinName _tx_pin;
350346
const PinName _rx_pin;
347+
348+
#if DEVICE_SERIAL_FC
349+
Flow _flow_type = Disabled;
350+
PinName _flow1 = NC;
351+
PinName _flow2 = NC;
352+
#endif
353+
351354
#endif
352355
};
353356

drivers/source/SerialBase.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,9 @@ namespace mbed {
2525

2626
SerialBase::SerialBase(PinName tx, PinName rx, int baud) :
2727
#if DEVICE_SERIAL_ASYNCH
28-
_thunk_irq(this), _tx_usage(DMA_USAGE_NEVER),
29-
_rx_usage(DMA_USAGE_NEVER), _tx_callback(NULL),
30-
_rx_callback(NULL), _tx_asynch_set(false),
31-
_rx_asynch_set(false),
28+
_thunk_irq(this),
3229
#endif
33-
#if DEVICE_SERIAL_FC
34-
_flow_type(Disabled),
35-
_flow1(NC),
36-
_flow2(NC),
37-
#endif
38-
_serial(),
3930
_baud(baud),
40-
_rx_enabled(true),
41-
_tx_enabled(true),
4231
_tx_pin(tx),
4332
_rx_pin(rx)
4433
{

0 commit comments

Comments
 (0)