Skip to content

Commit 331aa0f

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.
1 parent 1fed013 commit 331aa0f

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

drivers/SerialBase.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -329,25 +329,27 @@ 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+
serial_t _serial {};
345340
Callback<void()> _irq[IrqCnt];
346341
int _baud;
347-
bool _rx_enabled;
348-
bool _tx_enabled;
342+
bool _rx_enabled = true;
343+
bool _tx_enabled = true;
349344
const PinName _tx_pin;
350345
const PinName _rx_pin;
346+
347+
#if DEVICE_SERIAL_FC
348+
Flow _flow_type = Disabled;
349+
PinName _flow1 = NC;
350+
PinName _flow2 = NC;
351+
#endif
352+
351353
#endif
352354
};
353355

drivers/source/SerialBase.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,10 @@ 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),
42-
_tx_pin(tx),
31+
_tx_pin(tx),
4332
_rx_pin(rx)
4433
{
4534
// No lock needed in the constructor

0 commit comments

Comments
 (0)