Skip to content

Commit 1fab8c8

Browse files
committed
Slightly reduce code utilization by inlining HardwareSerail begin(baud) and operator bool()
1 parent f35ec75 commit 1fab8c8

File tree

2 files changed

+28
-37
lines changed

2 files changed

+28
-37
lines changed

hardware/arduino/avr/cores/arduino/HardwareSerial.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,6 @@ HardwareSerial::HardwareSerial(
281281

282282
// Public Methods //////////////////////////////////////////////////////////////
283283

284-
void HardwareSerial::begin(unsigned long baud)
285-
{
286-
begin(baud, SERIAL_8N1);
287-
}
288-
289284
void HardwareSerial::begin(unsigned long baud, byte config)
290285
{
291286
uint16_t baud_setting;
@@ -402,10 +397,6 @@ size_t HardwareSerial::write(uint8_t c)
402397
return 1;
403398
}
404399

405-
HardwareSerial::operator bool() {
406-
return true;
407-
}
408-
409400
// Preinstantiate Objects //////////////////////////////////////////////////////
410401

411402
#if defined(UBRRH) && defined(UBRRL)

hardware/arduino/avr/cores/arduino/HardwareSerial.h

+28-28
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,32 @@
3737
#define SERIAL_BUFFER_SIZE 64
3838
#endif
3939

40+
// Define config for Serial.begin(baud, config);
41+
#define SERIAL_5N1 0x00
42+
#define SERIAL_6N1 0x02
43+
#define SERIAL_7N1 0x04
44+
#define SERIAL_8N1 0x06
45+
#define SERIAL_5N2 0x08
46+
#define SERIAL_6N2 0x0A
47+
#define SERIAL_7N2 0x0C
48+
#define SERIAL_8N2 0x0E
49+
#define SERIAL_5E1 0x20
50+
#define SERIAL_6E1 0x22
51+
#define SERIAL_7E1 0x24
52+
#define SERIAL_8E1 0x26
53+
#define SERIAL_5E2 0x28
54+
#define SERIAL_6E2 0x2A
55+
#define SERIAL_7E2 0x2C
56+
#define SERIAL_8E2 0x2E
57+
#define SERIAL_5O1 0x30
58+
#define SERIAL_6O1 0x32
59+
#define SERIAL_7O1 0x34
60+
#define SERIAL_8O1 0x36
61+
#define SERIAL_5O2 0x38
62+
#define SERIAL_6O2 0x3A
63+
#define SERIAL_7O2 0x3C
64+
#define SERIAL_8O2 0x3E
65+
4066
class HardwareSerial : public Stream
4167
{
4268
protected:
@@ -70,7 +96,7 @@ class HardwareSerial : public Stream
7096
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
7197
volatile uint8_t *ucsrc, volatile uint8_t *udr,
7298
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x);
73-
void begin(unsigned long);
99+
void begin(unsigned long baud) { begin(baud, SERIAL_8N1); }
74100
void begin(unsigned long, uint8_t);
75101
void end();
76102
virtual int available(void);
@@ -83,35 +109,9 @@ class HardwareSerial : public Stream
83109
inline size_t write(unsigned int n) { return write((uint8_t)n); }
84110
inline size_t write(int n) { return write((uint8_t)n); }
85111
using Print::write; // pull in write(str) and write(buf, size) from Print
86-
operator bool();
112+
operator bool() { return true; }
87113
};
88114

89-
// Define config for Serial.begin(baud, config);
90-
#define SERIAL_5N1 0x00
91-
#define SERIAL_6N1 0x02
92-
#define SERIAL_7N1 0x04
93-
#define SERIAL_8N1 0x06
94-
#define SERIAL_5N2 0x08
95-
#define SERIAL_6N2 0x0A
96-
#define SERIAL_7N2 0x0C
97-
#define SERIAL_8N2 0x0E
98-
#define SERIAL_5E1 0x20
99-
#define SERIAL_6E1 0x22
100-
#define SERIAL_7E1 0x24
101-
#define SERIAL_8E1 0x26
102-
#define SERIAL_5E2 0x28
103-
#define SERIAL_6E2 0x2A
104-
#define SERIAL_7E2 0x2C
105-
#define SERIAL_8E2 0x2E
106-
#define SERIAL_5O1 0x30
107-
#define SERIAL_6O1 0x32
108-
#define SERIAL_7O1 0x34
109-
#define SERIAL_8O1 0x36
110-
#define SERIAL_5O2 0x38
111-
#define SERIAL_6O2 0x3A
112-
#define SERIAL_7O2 0x3C
113-
#define SERIAL_8O2 0x3E
114-
115115
#if defined(UBRRH) || defined(UBRR0H)
116116
extern HardwareSerial Serial;
117117
#elif defined(USBCON)

0 commit comments

Comments
 (0)