first commit
[clinton/Smoothieware.git] / gcc4mbed / external / mbed / DigitalInOut.h
1 /* mbed Microcontroller Library - DigitalInOut
2 * Copyright (c) 2006-2009 ARM Limited. All rights reserved.
3 * sford
4 */
5
6 #ifndef MBED_DIGITALINOUT_H
7 #define MBED_DIGITALINOUT_H
8
9 #include "platform.h"
10 #include "PinNames.h"
11 #include "PeripheralNames.h"
12 #include "Base.h"
13
14 namespace mbed {
15
16 /* Class: DigitalInOut
17 * A digital input/output, used for setting or reading a bi-directional pin
18 */
19 class DigitalInOut : public Base {
20
21 public:
22
23 /* Constructor: DigitalInOut
24 * Create a DigitalInOut connected to the specified pin
25 *
26 * Variables:
27 * pin - DigitalInOut pin to connect to
28 */
29 DigitalInOut(PinName pin, const char* name = NULL);
30
31 /* Function: write
32 * Set the output, specified as 0 or 1 (int)
33 *
34 * Variables:
35 * value - An integer specifying the pin output value,
36 * 0 for logical 0 and 1 (or any other non-zero value) for logical 1
37 */
38 void write(int value) {
39 if(value) {
40 _gpio->FIOSET = _mask;
41 } else {
42 _gpio->FIOCLR = _mask;
43 }
44 }
45
46 /* Function: read
47 * Return the output setting, represented as 0 or 1 (int)
48 *
49 * Variables:
50 * returns - An integer representing the output setting of the pin if it is an output,
51 * or read the input if set as an input
52 */
53 int read() {
54 return ((_gpio->FIOPIN & _mask) ? 1 : 0);
55 }
56
57
58 /* Function: output
59 * Set as an output
60 */
61 void output();
62
63 /* Function: input
64 * Set as an input
65 */
66 void input();
67
68 /* Function: mode
69 * Set the input pin mode
70 *
71 * Variables:
72 * mode - PullUp, PullDown, PullNone, OpenDrain
73 */
74 void mode(PinMode pull);
75
76 #ifdef MBED_OPERATORS
77 /* Function: operator=
78 * A shorthand for <write>
79 */
80 DigitalInOut& operator= (int value) {
81 write(value);
82 return *this;
83 }
84
85 DigitalInOut& operator= (DigitalInOut& rhs) {
86 write(rhs.read());
87 return *this;
88 }
89
90 /* Function: operator int()
91 * A shorthand for <read>
92 */
93 operator int() {
94 return read();
95 }
96 #endif
97
98 #ifdef MBED_RPC
99 virtual const struct rpc_method *get_rpc_methods();
100 static struct rpc_class *get_rpc_class();
101 #endif
102
103 protected:
104
105 PinName _pin;
106 LPC_GPIO_TypeDef *_gpio;
107 uint32_t _mask;
108
109 };
110
111 } // namespace mbed
112
113 #endif