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