Upgrade gcc4mbed project used by Smoothie.
[clinton/Smoothieware.git] / gcc4mbed / external / mbed / PortInOut.h
1 /* mbed Microcontroller Library - PortInOut
2 * Copyright (c) 2006-2011 ARM Limited. All rights reserved.
3 */
4
5 #ifndef MBED_PORTINOUT_H
6 #define MBED_PORTINOUT_H
7
8 #include "device.h"
9
10 #if DEVICE_PORTINOUT
11
12 #include "PortNames.h"
13 #include "PinNames.h"
14
15 namespace mbed {
16
17 /* Class: PortInOut
18 * A multiple pin digital in/out used to set/read multiple bi-directional pins
19 */
20 class PortInOut {
21 public:
22
23 /* Constructor: PortInOut
24 * Create an PortInOut, connected to the specified port
25 *
26 * Variables:
27 * port - Port to connect to (Port0-Port5)
28 * mask - A bitmask to identify which bits in the port should be included (0 - ignore)
29 */
30 PortInOut(PortName port, int mask = 0xFFFFFFFF);
31
32 /* Function: write
33 * Write the value to the output port
34 *
35 * Variables:
36 * value - An integer specifying a bit to write for every corresponding port pin
37 */
38 void write(int value);
39
40 /* Function: read
41 * Read the value currently output on the port
42 *
43 * Variables:
44 * returns - An integer with each bit corresponding to associated port pin setting
45 */
46 int read();
47
48 /* Function: output
49 * Set as an output
50 */
51 void output();
52
53 /* Function: input
54 * Set as an input
55 */
56 void input();
57
58 /* Function: mode
59 * Set the input pin mode
60 *
61 * Variables:
62 * mode - PullUp, PullDown, PullNone, OpenDrain
63 */
64 void mode(PinMode mode);
65
66 /* Function: operator=
67 * A shorthand for <write>
68 */
69 PortInOut& operator= (int value) {
70 write(value);
71 return *this;
72 }
73
74 PortInOut& operator= (PortInOut& rhs) {
75 write(rhs.read());
76 return *this;
77 }
78
79 /* Function: operator int()
80 * A shorthand for <read>
81 */
82 operator int() {
83 return read();
84 }
85
86 private:
87 #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
88 LPC_GPIO_TypeDef *_gpio;
89 #endif
90 PortName _port;
91 uint32_t _mask;
92 };
93
94 } // namespace mbed
95
96 #endif
97
98 #endif