1 /* mbed Microcontroller Library - SerialHalfDuplex
2 * Copyright (c) 2010-2011 ARM Limited. All rights reserved.
4 #include "SerialHalfDuplex.h"
9 #include "serial_api.h"
13 SerialHalfDuplex::SerialHalfDuplex(PinName tx, PinName rx)
16 gpio_init(&gpio, tx, PIN_INPUT);
17 gpio_mode(&gpio, PullNone); // no pull
20 // To transmit a byte in half duplex mode:
21 // 1. Disable interrupts, so we don't trigger on loopback byte
22 // 2. Set tx pin to UART out
23 // 3. Transmit byte as normal
24 // 4. Read back byte from looped back tx pin - this both confirms that the
25 // transmit has occurred, and also clears the byte from the buffer.
26 // 5. Return pin to input mode
27 // 6. Re-enable interrupts
28 int SerialHalfDuplex::_putc(int c) {
31 // TODO: We should not disable all interrupts
34 serial_pinout_tx(gpio.pin);
37 retc = Serial::getc(); // reading also clears any interrupt
39 pin_function(gpio.pin, 0);
46 int SerialHalfDuplex::_getc(void) {
47 return Serial::_getc();