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 SerialHalfDuplex by
Diff: SerialHalfDuplex.cpp
- Revision:
- 2:242a54f3629b
- Parent:
- 1:7ce196329ced
--- a/SerialHalfDuplex.cpp Sun Mar 25 20:38:37 2018 +0000
+++ b/SerialHalfDuplex.cpp Wed Apr 25 17:13:38 2018 +0000
@@ -1,77 +1,16 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2006-2012 ARM Limited
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- *
- * NOTE: This is an unsupported legacy untested library.
- */
#include "SerialHalfDuplex.h"
-#if DEVICE_SERIAL
-
-#include "mbed.h"
-#include "pinmap.h"
-#include "serial_api.h"
-#include "gpio_api.h"
-
-namespace mbed {
-
-SerialHalfDuplex::SerialHalfDuplex(PinName tx, PinName rx, const char *name)
- : Serial(tx, rx, name) {
- _txpin = tx;
+SerialHalfDuplex::SerialHalfDuplex(PinName tx, PinName rx) : out(tx, NC, 1000000), in(NC, rx, 1000000) {
- DigitalIn TXPIN(_txpin); // set as input
- pin_mode(_txpin, PullNone); // no pull
- pin_function(_txpin, 0); // set as gpio
}
-// To transmit a byte in half duplex mode:
-// 1. Disable interrupts, so we don't trigger on loopback byte
-// 2. Set tx pin to UART out
-// 3. Transmit byte as normal
-// 4. Read back byte from looped back tx pin - this both confirms that the
-// transmit has occurred, and also clears the byte from the buffer.
-// 5. Return pin to input mode
-// 6. Re-enable interrupts
-
-int SerialHalfDuplex::_putc(int c) {
- int retc;
-
- // TODO: We should not disable all interrupts
- __disable_irq();
-
- serial_pinout_tx(_txpin);
-
- Serial::_putc(c);
- retc = Serial::getc(); // reading also clears any interrupt
-
- pin_function(_txpin, 0);
-
- __enable_irq();
-
- return retc;
+int SerialHalfDuplex::putc(int byte) {
+ out.putc(byte);
+ while(in.readable()) {
+ in.getc();
+ }
}
-int SerialHalfDuplex::_getc(void) {
- return Serial::_getc();
-}
-
-} // End namespace
-
-#endif
+int SerialHalfDuplex::getc() {
+ return 0;
+}
\ No newline at end of file
