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.
Dependents: TestVirtualisation Bf_SoftSerial_IR
SoftSerial_IR.cpp@12:79d63607bbb1, 2018-12-17 (annotated)
- Committer:
- kenjiArai
- Date:
- Mon Dec 17 03:38:12 2018 +0000
- Revision:
- 12:79d63607bbb1
- Parent:
- SoftSerial.cpp@11:a0029614de72
- Child:
- 13:2b5649a1278a
change only for Infra-Red LED & IR-Remote
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 12:79d63607bbb1 | 1 | #include "SoftSerial_IR.h" |
Sissors | 0:8edaa7abe724 | 2 | |
kenjiArai | 12:79d63607bbb1 | 3 | SoftSerial_IR::SoftSerial_IR(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) { |
kenjiArai | 12:79d63607bbb1 | 7 | tx = new PwmOut(TX); |
Sissors | 0:8edaa7abe724 | 8 | tx_en = true; |
kenjiArai | 12:79d63607bbb1 | 9 | tx->write(0.0f); |
Sissors | 0:8edaa7abe724 | 10 | tx_bit = -1; |
kenjiArai | 12:79d63607bbb1 | 11 | send_tx_bit = 0; |
kenjiArai | 12:79d63607bbb1 | 12 | tx->period(1.0f / 38000.0f); // PWM = 38kHz |
kenjiArai | 12:79d63607bbb1 | 13 | txticker.attach(this, &SoftSerial_IR::tx_handler); |
Sissors | 0:8edaa7abe724 | 14 | } |
Sissors | 0:8edaa7abe724 | 15 | if (RX != NC) { |
Sissors | 0:8edaa7abe724 | 16 | rx = new InterruptIn(RX); |
Sissors | 0:8edaa7abe724 | 17 | rx_en = true; |
Sissors | 1:f8b4b764ace7 | 18 | out_valid = false; |
kenjiArai | 12:79d63607bbb1 | 19 | rxticker.attach(this, &SoftSerial_IR::rx_handler); |
kenjiArai | 12:79d63607bbb1 | 20 | rx->fall(this, &SoftSerial_IR::rx_gpio_irq_handler); |
Sissors | 0:8edaa7abe724 | 21 | } |
Sissors | 0:8edaa7abe724 | 22 | |
kenjiArai | 12:79d63607bbb1 | 23 | baud(1200); |
Sissors | 0:8edaa7abe724 | 24 | format(); |
Sissors | 0:8edaa7abe724 | 25 | } |
Sissors | 0:8edaa7abe724 | 26 | |
kenjiArai | 12:79d63607bbb1 | 27 | SoftSerial_IR::~SoftSerial_IR() { |
kenjiArai | 12:79d63607bbb1 | 28 | if (tx_en){ |
Sissors | 9:4e4617c4a441 | 29 | delete(tx); |
kenjiArai | 12:79d63607bbb1 | 30 | } |
kenjiArai | 12:79d63607bbb1 | 31 | if (rx_en){ |
Sissors | 9:4e4617c4a441 | 32 | delete(rx); |
kenjiArai | 12:79d63607bbb1 | 33 | } |
Sissors | 9:4e4617c4a441 | 34 | } |
Sissors | 9:4e4617c4a441 | 35 | |
kenjiArai | 12:79d63607bbb1 | 36 | void SoftSerial_IR::baud(int baudrate) { |
Sissors | 0:8edaa7abe724 | 37 | bit_period = 1000000 / baudrate; |
Sissors | 0:8edaa7abe724 | 38 | } |
Sissors | 0:8edaa7abe724 | 39 | |
kenjiArai | 12:79d63607bbb1 | 40 | void SoftSerial_IR::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 | } |