Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SoftSerial by
SoftSerial.cpp@6:517082212c00, 2014-04-27 (annotated)
- Committer:
- Sissors
- Date:
- Sun Apr 27 08:33:17 2014 +0000
- Revision:
- 6:517082212c00
- Parent:
- 5:acfd0329f648
- Child:
- 9:4e4617c4a441
Added custom ticker lib to allow for baudrate up to 57600
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Sissors | 0:8edaa7abe724 | 1 | #include "SoftSerial.h" |
| Sissors | 0:8edaa7abe724 | 2 | |
| Sissors | 5:acfd0329f648 | 3 | SoftSerial::SoftSerial(PinName TX, PinName RX, const char* name) { |
| Sissors | 0:8edaa7abe724 | 4 | tx_en = rx_en = false; |
| Sissors | 0:8edaa7abe724 | 5 | if (TX != NC) { |
| Sissors | 0:8edaa7abe724 | 6 | tx = new DigitalOut(TX); |
| Sissors | 0:8edaa7abe724 | 7 | tx_en = true; |
| Sissors | 0:8edaa7abe724 | 8 | tx->write(1); |
| Sissors | 0:8edaa7abe724 | 9 | tx_bit = -1; |
| Sissors | 6:517082212c00 | 10 | txticker.attach(this, &SoftSerial::tx_handler); |
| Sissors | 0:8edaa7abe724 | 11 | } |
| Sissors | 0:8edaa7abe724 | 12 | if (RX != NC) { |
| Sissors | 0:8edaa7abe724 | 13 | rx = new InterruptIn(RX); |
| Sissors | 0:8edaa7abe724 | 14 | rx_en = true; |
| Sissors | 1:f8b4b764ace7 | 15 | out_valid = false; |
| Sissors | 6:517082212c00 | 16 | rxticker.attach(this, &SoftSerial::rx_handler); |
| Sissors | 0:8edaa7abe724 | 17 | rx->fall(this, &SoftSerial::rx_gpio_irq_handler); |
| Sissors | 0:8edaa7abe724 | 18 | } |
| Sissors | 0:8edaa7abe724 | 19 | |
| Sissors | 0:8edaa7abe724 | 20 | baud(9600); |
| Sissors | 0:8edaa7abe724 | 21 | format(); |
| Sissors | 0:8edaa7abe724 | 22 | } |
| Sissors | 0:8edaa7abe724 | 23 | |
| Sissors | 0:8edaa7abe724 | 24 | void SoftSerial::baud(int baudrate) { |
| Sissors | 0:8edaa7abe724 | 25 | bit_period = 1000000 / baudrate; |
| Sissors | 0:8edaa7abe724 | 26 | } |
| Sissors | 0:8edaa7abe724 | 27 | |
| Sissors | 0:8edaa7abe724 | 28 | void SoftSerial::format(int bits, Parity parity, int stop_bits) { |
| Sissors | 0:8edaa7abe724 | 29 | _bits = bits; |
| Sissors | 0:8edaa7abe724 | 30 | _parity = parity; |
| Sissors | 0:8edaa7abe724 | 31 | _stop_bits = stop_bits; |
| Sissors | 2:9e01a38606b4 | 32 | _total_bits = 1 + _bits + _stop_bits + (bool)_parity; |
| Sissors | 0:8edaa7abe724 | 33 | } |
