]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/tests/libs/SerialHalfDuplex/SerialHalfDuplex.h
Merge commit '657d9f23fe47fb88cf221adb23095082f191ba6a'
[tmk_keyboard.git] / 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.
3 */
4 #ifndef MBED_SERIALHALFDUPLEX_H
5 #define MBED_SERIALHALFDUPLEX_H
6
7 #include "platform.h"
8
9 #if DEVICE_SERIAL
10
11 #include "Serial.h"
12 #include "gpio_api.h"
13
14 namespace mbed {
15
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
19 * at a time.
20 *
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.
24 *
25 * For Simplex and Full-Duplex Serial communication, see Serial()
26 *
27 * Example:
28 * @code
29 * // Send a byte to a second HalfDuplex device, and read the response
30 *
31 * #include "mbed.h"
32 *
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
36 *
37 * SerialHalfDuplex a(p9, p10);
38 * SerialHalfDuplex b(p28, p27);
39 *
40 * void b_rx() { // second device response
41 * b.putc(b.getc() + 4);
42 * }
43 *
44 * int main() {
45 * b.attach(&b_rx);
46 * for (int c = 'A'; c < 'Z'; c++) {
47 * a.putc(c);
48 * printf("sent [%c]\n", c);
49 * wait(0.5); // b should respond
50 * if (a.readable()) {
51 * printf("received [%c]\n", a.getc());
52 * }
53 * }
54 * }
55 * @endcode
56 */
57 class SerialHalfDuplex : public Serial {
58
59 public:
60 /** Create a half-duplex serial port, connected to the specified transmit
61 * and receive pins.
62 *
63 * These pins should be wired together, as well as to the target device
64 *
65 * @param tx Transmit pin
66 * @param rx Receive pin
67 */
68 SerialHalfDuplex(PinName tx, PinName rx);
69
70 protected:
71 gpio_object gpio;
72
73 virtual int _putc(int c);
74 virtual int _getc(void);
75
76 }; // End class SerialHalfDuplex
77
78 } // End namespace
79
80 #endif
81
82 #endif
Imprint / Impressum