Skip to content

Commit 295337d

Browse files
author
Alarus
committed
Update hardware/arduino/cores/arduino/HardwareSerial.cpp
New Serial.begin(baud, config);
1 parent 655ca80 commit 295337d

File tree

1 file changed

+7
-47
lines changed

1 file changed

+7
-47
lines changed

hardware/arduino/cores/arduino/HardwareSerial.cpp

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
Modified 23 November 2006 by David A. Mellis
2020
Modified 28 September 2010 by Mark Sproul
21-
Modified 12 August 2012 by Alarus
21+
Modified 14 August 2012 by Alarus
2222
*/
2323

2424
#include <stdlib.h>
@@ -356,10 +356,10 @@ void HardwareSerial::begin(unsigned long baud)
356356
cbi(*_ucsrb, _udrie);
357357
}
358358

359-
void HardwareSerial::begin(unsigned long baud, byte databits, char parity, byte stopbits)
359+
void HardwareSerial::begin(unsigned long baud, byte config)
360360
{
361361
uint16_t baud_setting;
362-
uint8_t config_setting;
362+
uint8_t current_config;
363363
bool use_u2x = true;
364364

365365
#if F_CPU == 16000000UL
@@ -392,49 +392,10 @@ void HardwareSerial::begin(unsigned long baud, byte databits, char parity, byte
392392
*_ubrrl = baud_setting;
393393

394394
//set number of data bits
395-
config_setting = *_ubrrh;
396-
config_setting = *_ucsrc;
397-
if (databits == 5)
398-
{
399-
config_setting |= B10000000;
400-
}
401-
else if (databits == 6)
402-
{
403-
config_setting |= B10000010;
404-
}
405-
else if (databits == 7)
406-
{
407-
config_setting |= B10000100;
408-
}
409-
else // (databits == 8)
410-
{
411-
config_setting |= B10000110;
412-
}
413-
414-
//set parity
415-
if ((parity == 'O')|(parity == 'o'))
416-
{
417-
config_setting |= B10110000;
418-
}
419-
else if ((parity == 'E')|(parity == 'e'))
420-
{
421-
config_setting |= B10100000;
422-
}
423-
else // ((parity == 'N')|(parity == 'n')))
424-
{
425-
config_setting |= B10000000;
426-
}
427-
428-
//set number of stop bits
429-
if (stopbits == 2)
430-
{
431-
config_setting |= B10001000;
432-
}
433-
else // (stopbits == 1)
434-
{
435-
config_setting |= B10000000;
436-
}
437-
*_ucsrc = config_setting;
395+
current_config = *_ubrrh;
396+
current_config = *_ucsrc;
397+
current_config |= config;
398+
*_ucsrc = current_config;
438399

439400
sbi(*_ucsrb, _rxen);
440401
sbi(*_ucsrb, _txen);
@@ -534,4 +495,3 @@ HardwareSerial::operator bool() {
534495
#endif
535496

536497
#endif // whole file
537-

0 commit comments

Comments
 (0)