Not work original Lib on F446RE & L432KC . Change usage prime() & setNext() for both TX and RX function due to unexpected behavior (maybe os TimerEvent function problem)
Dependents: BufferedSoftSerial
SoftSerial.cpp@13:6399b30798a5, 2020-05-12 (annotated)
- Committer:
- kenjiArai
- Date:
- Tue May 12 05:27:07 2020 +0000
- Revision:
- 13:6399b30798a5
- Parent:
- 12:cd58d03b8559
expand for several CPU's.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 13:6399b30798a5 | 1 | // Modified by K.Arai / JH1PJL May 12th, 2020 |
kenjiArai | 12:cd58d03b8559 | 2 | |
Sissors | 0:8edaa7abe724 | 3 | #include "SoftSerial.h" |
Sissors | 0:8edaa7abe724 | 4 | |
kenjiArai | 12:cd58d03b8559 | 5 | SoftSerial::SoftSerial(PinName TX, PinName RX, const char* name) |
kenjiArai | 12:cd58d03b8559 | 6 | { |
Sissors | 0:8edaa7abe724 | 7 | tx_en = rx_en = false; |
SonyPony | 11:a0029614de72 | 8 | read_buffer = 0; |
Sissors | 0:8edaa7abe724 | 9 | if (TX != NC) { |
Sissors | 0:8edaa7abe724 | 10 | tx = new DigitalOut(TX); |
Sissors | 0:8edaa7abe724 | 11 | tx_en = true; |
Sissors | 0:8edaa7abe724 | 12 | tx->write(1); |
Sissors | 0:8edaa7abe724 | 13 | tx_bit = -1; |
Sissors | 6:517082212c00 | 14 | txticker.attach(this, &SoftSerial::tx_handler); |
Sissors | 0:8edaa7abe724 | 15 | } |
Sissors | 0:8edaa7abe724 | 16 | if (RX != NC) { |
Sissors | 0:8edaa7abe724 | 17 | rx = new InterruptIn(RX); |
Sissors | 0:8edaa7abe724 | 18 | rx_en = true; |
Sissors | 1:f8b4b764ace7 | 19 | out_valid = false; |
Sissors | 6:517082212c00 | 20 | rxticker.attach(this, &SoftSerial::rx_handler); |
kenjiArai | 12:cd58d03b8559 | 21 | rx->fall(callback(this, &SoftSerial::rx_gpio_irq_handler)); |
Sissors | 0:8edaa7abe724 | 22 | } |
kenjiArai | 12:cd58d03b8559 | 23 | |
Sissors | 0:8edaa7abe724 | 24 | baud(9600); |
Sissors | 0:8edaa7abe724 | 25 | format(); |
Sissors | 0:8edaa7abe724 | 26 | } |
Sissors | 0:8edaa7abe724 | 27 | |
kenjiArai | 12:cd58d03b8559 | 28 | SoftSerial::~SoftSerial() |
kenjiArai | 12:cd58d03b8559 | 29 | { |
kenjiArai | 12:cd58d03b8559 | 30 | if (tx_en) { |
Sissors | 9:4e4617c4a441 | 31 | delete(tx); |
kenjiArai | 12:cd58d03b8559 | 32 | } |
kenjiArai | 12:cd58d03b8559 | 33 | if (rx_en) { |
Sissors | 9:4e4617c4a441 | 34 | delete(rx); |
kenjiArai | 12:cd58d03b8559 | 35 | } |
Sissors | 9:4e4617c4a441 | 36 | } |
Sissors | 9:4e4617c4a441 | 37 | |
kenjiArai | 12:cd58d03b8559 | 38 | void SoftSerial::baud(int baudrate) |
kenjiArai | 12:cd58d03b8559 | 39 | { |
Sissors | 0:8edaa7abe724 | 40 | bit_period = 1000000 / baudrate; |
Sissors | 0:8edaa7abe724 | 41 | } |
Sissors | 0:8edaa7abe724 | 42 | |
kenjiArai | 12:cd58d03b8559 | 43 | void SoftSerial::format(int bits, Parity parity, int stop_bits) |
kenjiArai | 12:cd58d03b8559 | 44 | { |
Sissors | 0:8edaa7abe724 | 45 | _bits = bits; |
Sissors | 0:8edaa7abe724 | 46 | _parity = parity; |
Sissors | 0:8edaa7abe724 | 47 | _stop_bits = stop_bits; |
kenjiArai | 12:cd58d03b8559 | 48 | _total_bits = 2 + _bits + _stop_bits + (bool)_parity; |
Sissors | 0:8edaa7abe724 | 49 | } |