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 BufferedSerial by
uart_interface.h@15:6de17cf2269d, 2016-04-05 (annotated)
- Committer:
- bhepp
- Date:
- Tue Apr 05 09:19:51 2016 +0000
- Revision:
- 15:6de17cf2269d
- Parent:
- 14:2150f1edc9bc
Fixed issue with interrupt handling
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bhepp | 14:2150f1edc9bc | 1 | #pragma once |
bhepp | 14:2150f1edc9bc | 2 | |
bhepp | 14:2150f1edc9bc | 3 | #ifdef __MBED__ |
bhepp | 14:2150f1edc9bc | 4 | #include "mbed.h" |
bhepp | 14:2150f1edc9bc | 5 | #include "BufferedSerial.h" |
bhepp | 14:2150f1edc9bc | 6 | #endif |
bhepp | 14:2150f1edc9bc | 7 | |
bhepp | 14:2150f1edc9bc | 8 | namespace ait { |
bhepp | 14:2150f1edc9bc | 9 | |
bhepp | 14:2150f1edc9bc | 10 | class UART_Interface { |
bhepp | 14:2150f1edc9bc | 11 | public: |
bhepp | 14:2150f1edc9bc | 12 | virtual bool writeChar(uint8_t c) = 0; |
bhepp | 14:2150f1edc9bc | 13 | virtual bool isCharAvailable() = 0; |
bhepp | 14:2150f1edc9bc | 14 | virtual uint8_t readChar(bool* err_flag = NULL) = 0; |
bhepp | 14:2150f1edc9bc | 15 | }; |
bhepp | 14:2150f1edc9bc | 16 | |
bhepp | 14:2150f1edc9bc | 17 | #ifdef __MBED__ |
bhepp | 14:2150f1edc9bc | 18 | class UART_Mbed : public UART_Interface { |
bhepp | 14:2150f1edc9bc | 19 | BufferedSerial* serial_; |
bhepp | 14:2150f1edc9bc | 20 | |
bhepp | 14:2150f1edc9bc | 21 | public: |
bhepp | 14:2150f1edc9bc | 22 | UART_Mbed(BufferedSerial* serial) |
bhepp | 14:2150f1edc9bc | 23 | : serial_(serial) { |
bhepp | 14:2150f1edc9bc | 24 | } |
bhepp | 14:2150f1edc9bc | 25 | |
bhepp | 14:2150f1edc9bc | 26 | virtual bool writeChar(uint8_t c) { |
bhepp | 14:2150f1edc9bc | 27 | int ret = serial_->putc(c); |
bhepp | 14:2150f1edc9bc | 28 | if (ret == -1) { |
bhepp | 14:2150f1edc9bc | 29 | return false; |
bhepp | 14:2150f1edc9bc | 30 | //throw std::exception("Unable to write on serial port"); |
bhepp | 14:2150f1edc9bc | 31 | } |
bhepp | 14:2150f1edc9bc | 32 | return true; |
bhepp | 14:2150f1edc9bc | 33 | } |
bhepp | 14:2150f1edc9bc | 34 | |
bhepp | 14:2150f1edc9bc | 35 | virtual bool isCharAvailable() { |
bhepp | 14:2150f1edc9bc | 36 | return serial_->readable(); |
bhepp | 14:2150f1edc9bc | 37 | } |
bhepp | 14:2150f1edc9bc | 38 | |
bhepp | 14:2150f1edc9bc | 39 | virtual uint8_t readChar(bool* err_flag = NULL) { |
bhepp | 14:2150f1edc9bc | 40 | int c = serial_->getc(); |
bhepp | 14:2150f1edc9bc | 41 | if (err_flag != NULL) { |
bhepp | 14:2150f1edc9bc | 42 | if (c == -1) |
bhepp | 14:2150f1edc9bc | 43 | *err_flag = true; |
bhepp | 14:2150f1edc9bc | 44 | else |
bhepp | 14:2150f1edc9bc | 45 | *err_flag = false; |
bhepp | 14:2150f1edc9bc | 46 | } |
bhepp | 14:2150f1edc9bc | 47 | return static_cast<uint8_t>(c); |
bhepp | 14:2150f1edc9bc | 48 | } |
bhepp | 14:2150f1edc9bc | 49 | }; |
bhepp | 14:2150f1edc9bc | 50 | #endif // __MBED__ |
bhepp | 14:2150f1edc9bc | 51 | |
bhepp | 14:2150f1edc9bc | 52 | } |