]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/tests/libs/SerialHalfDuplex/SerialHalfDuplex.h
1 /* mbed Microcontroller Library - SerialHalfDuplex
2 * Copyright (c) 2010-2011 ARM Limited. All rights reserved.
4 #ifndef MBED_SERIALHALFDUPLEX_H
5 #define MBED_SERIALHALFDUPLEX_H
16 /** A serial port (UART) for communication with other devices using
17 * Half-Duplex, allowing transmit and receive on a single
18 * shared transmit and receive line. Only one end should be transmitting
21 * Both the tx and rx pin should be defined, and wired together.
22 * This is in addition to them being wired to the other serial
23 * device to allow both read and write functions to operate.
25 * For Simplex and Full-Duplex Serial communication, see Serial()
29 * // Send a byte to a second HalfDuplex device, and read the response
33 * // p9 and p10 should be wired together to form "a"
34 * // p28 and p27 should be wired together to form "b"
35 * // p9/p10 should be wired to p28/p27 as the Half Duplex connection
37 * SerialHalfDuplex a(p9, p10);
38 * SerialHalfDuplex b(p28, p27);
40 * void b_rx() { // second device response
41 * b.putc(b.getc() + 4);
46 * for (int c = 'A'; c < 'Z'; c++) {
48 * printf("sent [%c]\n", c);
49 * wait(0.5); // b should respond
51 * printf("received [%c]\n", a.getc());
57 class SerialHalfDuplex
: public Serial
{
60 /** Create a half-duplex serial port, connected to the specified transmit
63 * These pins should be wired together, as well as to the target device
65 * @param tx Transmit pin
66 * @param rx Receive pin
68 SerialHalfDuplex(PinName tx
, PinName rx
);
73 virtual int _putc(int c
);
74 virtual int _getc(void);
76 }; // End class SerialHalfDuplex