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@12:55d78fef0327, 2017-05-09 (annotated)
- Committer:
- rsquires
- Date:
- Tue May 09 18:36:31 2017 +0000
- Revision:
- 12:55d78fef0327
- Parent:
- 11:a0029614de72
Fixed detach
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; |
| SonyPony | 11:a0029614de72 | 5 | read_buffer = 0; |
| Sissors | 0:8edaa7abe724 | 6 | if (TX != NC) { |
| Sissors | 0:8edaa7abe724 | 7 | tx = new DigitalOut(TX); |
| Sissors | 0:8edaa7abe724 | 8 | tx_en = true; |
| Sissors | 0:8edaa7abe724 | 9 | tx->write(1); |
| Sissors | 0:8edaa7abe724 | 10 | tx_bit = -1; |
| Sissors | 6:517082212c00 | 11 | txticker.attach(this, &SoftSerial::tx_handler); |
| Sissors | 0:8edaa7abe724 | 12 | } |
| Sissors | 0:8edaa7abe724 | 13 | if (RX != NC) { |
| Sissors | 0:8edaa7abe724 | 14 | rx = new InterruptIn(RX); |
| Sissors | 0:8edaa7abe724 | 15 | rx_en = true; |
| Sissors | 1:f8b4b764ace7 | 16 | out_valid = false; |
| Sissors | 6:517082212c00 | 17 | rxticker.attach(this, &SoftSerial::rx_handler); |
| Sissors | 0:8edaa7abe724 | 18 | rx->fall(this, &SoftSerial::rx_gpio_irq_handler); |
| Sissors | 0:8edaa7abe724 | 19 | } |
| Sissors | 0:8edaa7abe724 | 20 | |
| Sissors | 0:8edaa7abe724 | 21 | baud(9600); |
| Sissors | 0:8edaa7abe724 | 22 | format(); |
| Sissors | 0:8edaa7abe724 | 23 | } |
| Sissors | 0:8edaa7abe724 | 24 | |
| Sissors | 9:4e4617c4a441 | 25 | SoftSerial::~SoftSerial() { |
| rsquires | 12:55d78fef0327 | 26 | if (tx_en) { |
| rsquires | 12:55d78fef0327 | 27 | txticker.detach(); |
| Sissors | 9:4e4617c4a441 | 28 | delete(tx); |
| rsquires | 12:55d78fef0327 | 29 | } |
| rsquires | 12:55d78fef0327 | 30 | if (rx_en) { |
| rsquires | 12:55d78fef0327 | 31 | rxticker.detach(); |
| Sissors | 9:4e4617c4a441 | 32 | delete(rx); |
| rsquires | 12:55d78fef0327 | 33 | } |
| Sissors | 9:4e4617c4a441 | 34 | } |
| Sissors | 9:4e4617c4a441 | 35 | |
| Sissors | 0:8edaa7abe724 | 36 | void SoftSerial::baud(int baudrate) { |
| Sissors | 0:8edaa7abe724 | 37 | bit_period = 1000000 / baudrate; |
| Sissors | 0:8edaa7abe724 | 38 | } |
| Sissors | 0:8edaa7abe724 | 39 | |
| Sissors | 0:8edaa7abe724 | 40 | void SoftSerial::format(int bits, Parity parity, int stop_bits) { |
| Sissors | 0:8edaa7abe724 | 41 | _bits = bits; |
| Sissors | 0:8edaa7abe724 | 42 | _parity = parity; |
| Sissors | 0:8edaa7abe724 | 43 | _stop_bits = stop_bits; |
| Sissors | 2:9e01a38606b4 | 44 | _total_bits = 1 + _bits + _stop_bits + (bool)_parity; |
| Sissors | 0:8edaa7abe724 | 45 | } |
