|
18 | 18 | |
19 | 19 | Modified 23 November 2006 by David A. Mellis |
20 | 20 | Modified 28 September 2010 by Mark Sproul |
21 | | - Modified 12 August 2012 by Alarus |
| 21 | + Modified 14 August 2012 by Alarus |
22 | 22 | */ |
23 | 23 |
|
24 | 24 | #include <stdlib.h> |
@@ -356,10 +356,10 @@ void HardwareSerial::begin(unsigned long baud) |
356 | 356 | cbi(*_ucsrb, _udrie); |
357 | 357 | } |
358 | 358 |
|
359 | | -void HardwareSerial::begin(unsigned long baud, byte databits, char parity, byte stopbits) |
| 359 | +void HardwareSerial::begin(unsigned long baud, byte config) |
360 | 360 | { |
361 | 361 | uint16_t baud_setting; |
362 | | - uint8_t config_setting; |
| 362 | + uint8_t current_config; |
363 | 363 | bool use_u2x = true; |
364 | 364 |
|
365 | 365 | #if F_CPU == 16000000UL |
@@ -392,49 +392,10 @@ void HardwareSerial::begin(unsigned long baud, byte databits, char parity, byte |
392 | 392 | *_ubrrl = baud_setting; |
393 | 393 |
|
394 | 394 | //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; |
438 | 399 |
|
439 | 400 | sbi(*_ucsrb, _rxen); |
440 | 401 | sbi(*_ucsrb, _txen); |
@@ -534,4 +495,3 @@ HardwareSerial::operator bool() { |
534 | 495 | #endif |
535 | 496 |
|
536 | 497 | #endif // whole file |
537 | | - |
0 commit comments