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@9:4e4617c4a441, 2014-07-05 (annotated)
- Committer:
- Sissors
- Date:
- Sat Jul 05 08:07:49 2014 +0000
- Revision:
- 9:4e4617c4a441
- Parent:
- 6:517082212c00
- Child:
- 11:a0029614de72
Added destructor
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 | 9:4e4617c4a441 | 24 | SoftSerial::~SoftSerial() { |
| Sissors | 9:4e4617c4a441 | 25 | if (tx_en) |
| Sissors | 9:4e4617c4a441 | 26 | delete(tx); |
| Sissors | 9:4e4617c4a441 | 27 | if (rx_en) |
| Sissors | 9:4e4617c4a441 | 28 | delete(rx); |
| Sissors | 9:4e4617c4a441 | 29 | } |
| Sissors | 9:4e4617c4a441 | 30 | |
| Sissors | 0:8edaa7abe724 | 31 | void SoftSerial::baud(int baudrate) { |
| Sissors | 0:8edaa7abe724 | 32 | bit_period = 1000000 / baudrate; |
| Sissors | 0:8edaa7abe724 | 33 | } |
| Sissors | 0:8edaa7abe724 | 34 | |
| Sissors | 0:8edaa7abe724 | 35 | void SoftSerial::format(int bits, Parity parity, int stop_bits) { |
| Sissors | 0:8edaa7abe724 | 36 | _bits = bits; |
| Sissors | 0:8edaa7abe724 | 37 | _parity = parity; |
| Sissors | 0:8edaa7abe724 | 38 | _stop_bits = stop_bits; |
| Sissors | 2:9e01a38606b4 | 39 | _total_bits = 1 + _bits + _stop_bits + (bool)_parity; |
| Sissors | 0:8edaa7abe724 | 40 | } |
